]> git.proxmox.com Git - pve-manager.git/blob - PVE/CLI/pve6to7.pm
pve6to7: improve user.cfg parser
[pve-manager.git] / PVE / CLI / pve6to7.pm
1 package PVE::CLI::pve6to7;
2
3 use strict;
4 use warnings;
5
6 use PVE::API2::APT;
7 use PVE::API2::Ceph;
8 use PVE::API2::LXC;
9 use PVE::API2::Qemu;
10 use PVE::API2::Certificates;
11
12 use PVE::AccessControl;
13 use PVE::Ceph::Tools;
14 use PVE::Cluster;
15 use PVE::Corosync;
16 use PVE::INotify;
17 use PVE::JSONSchema;
18 use PVE::RPCEnvironment;
19 use PVE::Storage;
20 use PVE::Tools qw(run_command split_list);
21 use PVE::QemuServer;
22 use PVE::VZDump::Common;
23
24 use File::Slurp;
25 use Term::ANSIColor;
26
27 use PVE::CLIHandler;
28
29 use base qw(PVE::CLIHandler);
30
31 my $nodename = PVE::INotify::nodename();
32
33 sub setup_environment {
34 PVE::RPCEnvironment->setup_default_cli_env();
35 }
36
37 my $min_pve_major = 6;
38 my $min_pve_minor = 4;
39 my $min_pve_pkgrel = 1;
40
41 my $counters = {
42 pass => 0,
43 skip => 0,
44 warn => 0,
45 fail => 0,
46 };
47
48 my $log_line = sub {
49 my ($level, $line) = @_;
50
51 $counters->{$level}++ if defined($level) && defined($counters->{$level});
52
53 print uc($level), ': ' if defined($level);
54 print "$line\n";
55 };
56
57 sub log_pass {
58 print color('green');
59 $log_line->('pass', @_);
60 print color('reset');
61 }
62
63 sub log_info {
64 $log_line->('info', @_);
65 }
66 sub log_skip {
67 $log_line->('skip', @_);
68 }
69 sub log_warn {
70 print color('yellow');
71 $log_line->('warn', @_);
72 print color('reset');
73 }
74 sub log_fail {
75 print color('red');
76 $log_line->('fail', @_);
77 print color('reset');
78 }
79
80 my $print_header_first = 1;
81 sub print_header {
82 my ($h) = @_;
83 print "\n" if !$print_header_first;
84 print "= $h =\n\n";
85 $print_header_first = 0;
86 }
87
88 my $get_systemd_unit_state = sub {
89 my ($unit) = @_;
90
91 my $state;
92 my $filter_output = sub {
93 $state = shift;
94 chomp $state;
95 };
96 eval {
97 run_command(['systemctl', 'is-enabled', "$unit"], outfunc => $filter_output, noerr => 1);
98 return if !defined($state);
99 run_command(['systemctl', 'is-active', "$unit"], outfunc => $filter_output, noerr => 1);
100 };
101
102 return $state // 'unknown';
103 };
104 my $log_systemd_unit_state = sub {
105 my ($unit, $no_fail_on_inactive) = @_;
106
107 my $log_method = \&log_warn;
108
109 my $state = $get_systemd_unit_state->($unit);
110 if ($state eq 'active') {
111 $log_method = \&log_pass;
112 } elsif ($state eq 'inactive') {
113 $log_method = $no_fail_on_inactive ? \&log_warn : \&log_fail;
114 } elsif ($state eq 'failed') {
115 $log_method = \&log_fail;
116 }
117
118 $log_method->("systemd unit '$unit' is in state '$state'");
119 };
120
121 my $versions;
122 my $get_pkg = sub {
123 my ($pkg) = @_;
124
125 $versions = eval { PVE::API2::APT->versions({ node => $nodename }) } if !defined($versions);
126
127 if (!defined($versions)) {
128 my $msg = "unable to retrieve package version information";
129 $msg .= "- $@" if $@;
130 log_fail("$msg");
131 return undef;
132 }
133
134 my $pkgs = [ grep { $_->{Package} eq $pkg } @$versions ];
135 if (!defined $pkgs || $pkgs == 0) {
136 log_fail("unable to determine installed $pkg version.");
137 return undef;
138 } else {
139 return $pkgs->[0];
140 }
141 };
142
143 sub check_pve_packages {
144 print_header("CHECKING VERSION INFORMATION FOR PVE PACKAGES");
145
146 print "Checking for package updates..\n";
147 my $updates = eval { PVE::API2::APT->list_updates({ node => $nodename }); };
148 if (!defined($updates)) {
149 log_warn("$@") if $@;
150 log_fail("unable to retrieve list of package updates!");
151 } elsif (@$updates > 0) {
152 my $pkgs = join(', ', map { $_->{Package} } @$updates);
153 log_warn("updates for the following packages are available:\n $pkgs");
154 } else {
155 log_pass("all packages uptodate");
156 }
157
158 print "\nChecking proxmox-ve package version..\n";
159 if (defined(my $proxmox_ve = $get_pkg->('proxmox-ve'))) {
160 my $min_pve_ver = "$min_pve_major.$min_pve_minor-$min_pve_pkgrel";
161
162 my ($maj, $min, $pkgrel) = $proxmox_ve->{OldVersion} =~ m/^(\d+)\.(\d+)-(\d+)/;
163
164 my $upgraded = 0;
165
166 if ($maj > $min_pve_major) {
167 log_pass("already upgraded to Proxmox VE " . ($min_pve_major + 1));
168 $upgraded = 1;
169 } elsif ($maj >= $min_pve_major && $min >= $min_pve_minor && $pkgrel >= $min_pve_pkgrel) {
170 log_pass("proxmox-ve package has version >= $min_pve_ver");
171 } else {
172 log_fail("proxmox-ve package is too old, please upgrade to >= $min_pve_ver!");
173 }
174
175 my ($krunning, $kinstalled) = (qr/5\.11/, 'pve-kernel-5.11');
176 if (!$upgraded) {
177 ($krunning, $kinstalled) = (qr/5\.(?:4|11)/, 'pve-kernel-4.15');
178 }
179
180 print "\nChecking running kernel version..\n";
181 my $kernel_ver = $proxmox_ve->{RunningKernel};
182 if (!defined($kernel_ver)) {
183 log_fail("unable to determine running kernel version.");
184 } elsif ($kernel_ver =~ /^$krunning/) {
185 log_pass("expected running kernel '$kernel_ver'.");
186 } elsif ($get_pkg->($kinstalled)) {
187 log_warn("expected kernel '$kinstalled' intalled but not yet rebooted!");
188 } else {
189 log_warn("unexpected running and installed kernel '$kernel_ver'.");
190 }
191 } else {
192 log_fail("proxmox-ve package not found!");
193 }
194 }
195
196
197 sub check_storage_health {
198 print_header("CHECKING CONFIGURED STORAGES");
199 my $cfg = PVE::Storage::config();
200
201 my $ctime = time();
202
203 my $info = PVE::Storage::storage_info($cfg);
204
205 foreach my $storeid (keys %$info) {
206 my $d = $info->{$storeid};
207 if ($d->{enabled}) {
208 if ($d->{type} eq 'sheepdog') {
209 log_fail("storage '$storeid' of type 'sheepdog' is enabled - experimental sheepdog support dropped in PVE 6")
210 } elsif ($d->{active}) {
211 log_pass("storage '$storeid' enabled and active.");
212 } else {
213 log_warn("storage '$storeid' enabled but not active!");
214 }
215 } else {
216 log_skip("storage '$storeid' disabled.");
217 }
218 }
219 }
220
221 sub check_cluster_corosync {
222 print_header("CHECKING CLUSTER HEALTH/SETTINGS");
223
224 if (!PVE::Corosync::check_conf_exists(1)) {
225 log_skip("standalone node.");
226 return;
227 }
228
229 $log_systemd_unit_state->('pve-cluster.service');
230 $log_systemd_unit_state->('corosync.service');
231
232 if (PVE::Cluster::check_cfs_quorum(1)) {
233 log_pass("Cluster Filesystem is quorate.");
234 } else {
235 log_fail("Cluster Filesystem readonly, lost quorum?!");
236 }
237
238 my $conf = PVE::Cluster::cfs_read_file('corosync.conf');
239 my $conf_nodelist = PVE::Corosync::nodelist($conf);
240 my $node_votes = 0;
241
242 print "\nAnalzying quorum settings and state..\n";
243 if (!defined($conf_nodelist)) {
244 log_fail("unable to retrieve nodelist from corosync.conf");
245 } else {
246 if (grep { $conf_nodelist->{$_}->{quorum_votes} != 1 } keys %$conf_nodelist) {
247 log_warn("non-default quorum_votes distribution detected!");
248 }
249 map { $node_votes += $conf_nodelist->{$_}->{quorum_votes} // 0 } keys %$conf_nodelist;
250 }
251
252 my ($expected_votes, $total_votes);
253 my $filter_output = sub {
254 my $line = shift;
255 ($expected_votes) = $line =~ /^Expected votes:\s*(\d+)\s*$/
256 if !defined($expected_votes);
257 ($total_votes) = $line =~ /^Total votes:\s*(\d+)\s*$/
258 if !defined($total_votes);
259 };
260 eval {
261 run_command(['corosync-quorumtool', '-s'], outfunc => $filter_output, noerr => 1);
262 };
263
264 if (!defined($expected_votes)) {
265 log_fail("unable to get expected number of votes, setting to 0.");
266 $expected_votes = 0;
267 }
268 if (!defined($total_votes)) {
269 log_fail("unable to get expected number of votes, setting to 0.");
270 $total_votes = 0;
271 }
272
273 my $cfs_nodelist = PVE::Cluster::get_clinfo()->{nodelist};
274 my $offline_nodes = grep { $cfs_nodelist->{$_}->{online} != 1 } keys %$cfs_nodelist;
275 if ($offline_nodes > 0) {
276 log_fail("$offline_nodes nodes are offline!");
277 }
278
279 my $qdevice_votes = 0;
280 if (my $qdevice_setup = $conf->{main}->{quorum}->{device}) {
281 $qdevice_votes = $qdevice_setup->{votes} // 1;
282 }
283
284 log_info("configured votes - nodes: $node_votes");
285 log_info("configured votes - qdevice: $qdevice_votes");
286 log_info("current expected votes: $expected_votes");
287 log_info("current total votes: $total_votes");
288
289 log_warn("expected votes set to non-standard value '$expected_votes'.")
290 if $expected_votes != $node_votes + $qdevice_votes;
291 log_warn("total votes < expected votes: $total_votes/$expected_votes!")
292 if $total_votes < $expected_votes;
293
294 my $conf_nodelist_count = scalar(keys %$conf_nodelist);
295 my $cfs_nodelist_count = scalar(keys %$cfs_nodelist);
296 log_warn("cluster consists of less than three quorum-providing nodes!")
297 if $conf_nodelist_count < 3 && $conf_nodelist_count + $qdevice_votes < 3;
298
299 log_fail("corosync.conf ($conf_nodelist_count) and pmxcfs ($cfs_nodelist_count) don't agree about size of nodelist.")
300 if $conf_nodelist_count != $cfs_nodelist_count;
301
302 print "\nChecking nodelist entries..\n";
303 for my $cs_node (sort keys %$conf_nodelist) {
304 my $entry = $conf_nodelist->{$cs_node};
305 log_fail("$cs_node: no name entry in corosync.conf.")
306 if !defined($entry->{name});
307 log_fail("$cs_node: no nodeid configured in corosync.conf.")
308 if !defined($entry->{nodeid});
309 my $gotLinks = 0;
310 for my $link (0..7) {
311 $gotLinks++ if defined($entry->{"ring${link}_addr"});
312 }
313 log_fail("$cs_node: no ringX_addr (0 <= X <= 7) link defined in corosync.conf.") if $gotLinks <= 0;
314
315 my $verify_ring_ip = sub {
316 my $key = shift;
317 if (defined(my $ring = $entry->{$key})) {
318 my ($resolved_ip, undef) = PVE::Corosync::resolve_hostname_like_corosync($ring, $conf);
319 if (defined($resolved_ip)) {
320 if ($resolved_ip ne $ring) {
321 log_warn("$cs_node: $key '$ring' resolves to '$resolved_ip'.\n Consider replacing it with the currently resolved IP address.");
322 } else {
323 log_pass("$cs_node: $key is configured to use IP address '$ring'");
324 }
325 } else {
326 log_fail("$cs_node: unable to resolve $key '$ring' to an IP address according to Corosync's resolve strategy - cluster will potentially fail with Corosync 3.x/kronosnet!");
327 }
328 }
329 };
330 for my $link (0..7) {
331 $verify_ring_ip->("ring${link}_addr");
332 }
333 }
334
335 print "\nChecking totem settings..\n";
336 my $totem = $conf->{main}->{totem};
337 my $transport = $totem->{transport};
338 if (defined($transport)) {
339 if ($transport ne 'knet') {
340 log_fail("Corosync transport explicitly set to '$transport' instead of implicit default!");
341 } else {
342 log_pass("Corosync transport set to '$transport'.");
343 }
344 } else {
345 log_pass("Corosync transport set to implicit default.");
346 }
347
348 # TODO: are those values still up-to-date?
349 if ((!defined($totem->{secauth}) || $totem->{secauth} ne 'on') && (!defined($totem->{crypto_cipher}) || $totem->{crypto_cipher} eq 'none')) {
350 log_fail("Corosync authentication/encryption is not explicitly enabled (secauth / crypto_cipher / crypto_hash)!");
351 } else {
352 if (defined($totem->{crypto_cipher}) && $totem->{crypto_cipher} eq '3des') {
353 log_fail("Corosync encryption cipher set to '3des', no longer supported in Corosync 3.x!"); # FIXME: can be removed?
354 } else {
355 log_pass("Corosync encryption and authentication enabled.");
356 }
357 }
358
359 print "\n";
360 log_info("run 'pvecm status' to get detailed cluster status..");
361
362 print_header("CHECKING INSTALLED COROSYNC VERSION");
363 if (defined(my $corosync = $get_pkg->('corosync'))) {
364 if ($corosync->{OldVersion} =~ m/^2\./) {
365 log_fail("corosync 2.x installed, cluster-wide upgrade to 3.x needed!");
366 } elsif ($corosync->{OldVersion} =~ m/^3\./) {
367 log_pass("corosync 3.x installed.");
368 } else {
369 log_fail("unexpected corosync version installed: $corosync->{OldVersion}!");
370 }
371 }
372 }
373
374 sub check_ceph {
375 print_header("CHECKING HYPER-CONVERGED CEPH STATUS");
376
377 if (PVE::Ceph::Tools::check_ceph_inited(1)) {
378 log_info("hyper-converged ceph setup detected!");
379 } else {
380 log_skip("no hyper-converged ceph setup detected!");
381 return;
382 }
383
384 log_info("getting Ceph status/health information..");
385 my $ceph_status = eval { PVE::API2::Ceph->status({ node => $nodename }); };
386 my $osd_flags = eval { PVE::API2::Ceph->get_flags({ node => $nodename }); };
387 my $noout_wanted = 1;
388 my $noout = $osd_flags && $osd_flags =~ m/noout/;
389
390 if (!$ceph_status || !$ceph_status->{health}) {
391 log_fail("unable to determine Ceph status!");
392 } else {
393 my $ceph_health = $ceph_status->{health}->{status};
394 if (!$ceph_health) {
395 log_fail("unable to determine Ceph health!");
396 } elsif ($ceph_health eq 'HEALTH_OK') {
397 log_pass("Ceph health reported as 'HEALTH_OK'.");
398 } elsif ($ceph_health eq 'HEALTH_WARN' && $noout && (keys %{$ceph_status->{health}->{checks}} == 1)) {
399 log_pass("Ceph health reported as 'HEALTH_WARN' with a single failing check and 'noout' flag set.");
400 } else {
401 log_warn("Ceph health reported as '$ceph_health'.\n Use the PVE ".
402 "dashboard or 'ceph -s' to determine the specific issues and try to resolve them.");
403 }
404 }
405
406 log_info("getting Ceph OSD flags..");
407 eval {
408 if (!$osd_flags) {
409 log_fail("unable to get Ceph OSD flags!");
410 } else {
411 if ($osd_flags =~ m/recovery_deletes/ && $osd_flags =~ m/purged_snapdirs/) {
412 log_pass("all PGs have been scrubbed at least once while running Ceph Luminous."); # FIXME: remove?
413 } else {
414 log_fail("missing 'recovery_deletes' and/or 'purged_snapdirs' flag, scrub of all PGs required before upgrading to Nautilus!");
415 }
416 }
417 };
418
419 # TODO: check OSD min-required version, if to low it breaks stuff!
420
421 log_info("getting Ceph daemon versions..");
422 my $ceph_versions = eval { PVE::Ceph::Tools::get_cluster_versions(undef, 1); };
423 if (!$ceph_versions) {
424 log_fail("unable to determine Ceph daemon versions!");
425 } else {
426 my $services = [
427 { 'key' => 'mon', 'name' => 'monitor' },
428 { 'key' => 'mgr', 'name' => 'manager' },
429 { 'key' => 'mds', 'name' => 'MDS' },
430 { 'key' => 'osd', 'name' => 'OSD' },
431 ];
432
433 foreach my $service (@$services) {
434 my $name = $service->{name};
435 if (my $service_versions = $ceph_versions->{$service->{key}}) {
436 if (keys %$service_versions == 0) {
437 log_skip("no running instances detected for daemon type $name.");
438 } elsif (keys %$service_versions == 1) {
439 log_pass("single running version detected for daemon type $name.");
440 } else {
441 log_warn("multiple running versions detected for daemon type $name!");
442 }
443 } else {
444 log_skip("unable to determine versions of running Ceph $name instances.");
445 }
446 }
447
448 my $overall_versions = $ceph_versions->{overall};
449 if (!$overall_versions) {
450 log_warn("unable to determine overall Ceph daemon versions!");
451 } elsif (keys %$overall_versions == 1) {
452 log_pass("single running overall version detected for all Ceph daemon types.");
453 if ((keys %$overall_versions)[0] =~ /^ceph version 15\./) {
454 $noout_wanted = 0;
455 }
456 } else {
457 log_warn("overall version mismatch detected, check 'ceph versions' output for details!");
458 }
459 }
460
461 if ($noout) {
462 if ($noout_wanted) {
463 log_pass("'noout' flag set to prevent rebalancing during cluster-wide upgrades.");
464 } else {
465 log_warn("'noout' flag set, Ceph cluster upgrade seems finished.");
466 }
467 } elsif ($noout_wanted) {
468 log_warn("'noout' flag not set - recommended to prevent rebalancing during upgrades.");
469 }
470
471 log_info("checking Ceph config..");
472 my $conf = PVE::Cluster::cfs_read_file('ceph.conf');
473 if (%$conf) {
474 my $global = $conf->{global};
475
476 my $global_monhost = $global->{mon_host} // $global->{"mon host"} // $global->{"mon-host"};
477 if (!defined($global_monhost)) {
478 log_warn("No 'mon_host' entry found in ceph config.\n It's recommended to add mon_host with all monitor addresses (without ports) to the global section.");
479 } else {
480 log_pass("Found 'mon_host' entry.");
481 }
482
483 my $ipv6 = $global->{ms_bind_ipv6} // $global->{"ms bind ipv6"} // $global->{"ms-bind-ipv6"};
484 if ($ipv6) {
485 my $ipv4 = $global->{ms_bind_ipv4} // $global->{"ms bind ipv4"} // $global->{"ms-bind-ipv4"};
486 if ($ipv6 eq 'true' && (!defined($ipv4) || $ipv4 ne 'false')) {
487 log_warn("'ms_bind_ipv6' is enabled but 'ms_bind_ipv4' is not disabled.\n Make sure to disable 'ms_bind_ipv4' for ipv6 only clusters, or add an ipv4 network to public/cluster network.");
488 } else {
489 log_pass("'ms_bind_ipv6' is enabled and 'ms_bind_ipv4' disabled");
490 }
491 } else {
492 log_pass("'ms_bind_ipv6' not enabled");
493 }
494
495 if (defined($global->{keyring})) {
496 log_warn("[global] config section contains 'keyring' option, which will prevent services from starting with Nautilus.\n Move 'keyring' option to [client] section instead.");
497 } else {
498 log_pass("no 'keyring' option in [global] section found.");
499 }
500
501 } else {
502 log_warn("Empty ceph config found");
503 }
504
505 my $local_ceph_ver = PVE::Ceph::Tools::get_local_version(1);
506 if (defined($local_ceph_ver)) {
507 if ($local_ceph_ver == 14) {
508 my $ceph_volume_osds = PVE::Ceph::Tools::ceph_volume_list();
509 my $scanned_osds = PVE::Tools::dir_glob_regex('/etc/ceph/osd', '^.*\.json$');
510 if (-e '/var/lib/ceph/osd/' && !defined($scanned_osds) && !(keys %$ceph_volume_osds)) {
511 log_warn("local Ceph version is Nautilus, local OSDs detected, but no conversion from ceph-disk to ceph-volume done (yet).");
512 }
513 }
514 } else {
515 log_fail("unable to determine local Ceph version.");
516 }
517 }
518
519 sub check_backup_retention_settings {
520 log_info("Checking backup retention settings..");
521
522 my $pass = 1;
523
524 my $node_has_retention;
525
526 my $maxfiles_msg = "parameter 'maxfiles' is deprecated with PVE 7.x and will be removed in a " .
527 "future version, use 'prune-backups' instead.";
528
529 eval {
530 my $confdesc = PVE::VZDump::Common::get_confdesc();
531
532 my $fn = "/etc/vzdump.conf";
533 my $raw = PVE::Tools::file_get_contents($fn);
534
535 my $conf_schema = { type => 'object', properties => $confdesc, };
536 my $param = PVE::JSONSchema::parse_config($conf_schema, $fn, $raw);
537
538 if (defined($param->{maxfiles})) {
539 $pass = 0;
540 log_warn("$fn - $maxfiles_msg");
541 }
542
543 $node_has_retention = defined($param->{maxfiles}) || defined($param->{'prune-backups'});
544 };
545 if (my $err = $@) {
546 $pass = 0;
547 log_warn("unable to parse node's VZDump configuration - $err");
548 }
549
550 my $storage_cfg = PVE::Storage::config();
551
552 for my $storeid (keys $storage_cfg->{ids}->%*) {
553 my $scfg = $storage_cfg->{ids}->{$storeid};
554
555 if (defined($scfg->{maxfiles})) {
556 $pass = 0;
557 log_warn("storage '$storeid' - $maxfiles_msg");
558 }
559
560 next if !$scfg->{content}->{backup};
561 next if defined($scfg->{maxfiles}) || defined($scfg->{'prune-backups'});
562 next if $node_has_retention;
563
564 log_info("storage '$storeid' - no backup retention settings defined - by default, PVE " .
565 "7.x will no longer keep only the last backup, but all backups");
566 }
567
568 eval {
569 my $vzdump_cron = PVE::Cluster::cfs_read_file('vzdump.cron');
570
571 # only warn once, there might be many jobs...
572 if (scalar(grep { defined($_->{maxfiles}) } $vzdump_cron->{jobs}->@*)) {
573 $pass = 0;
574 log_warn("/etc/pve/vzdump.cron - $maxfiles_msg");
575 }
576 };
577 if (my $err = $@) {
578 $pass = 0;
579 log_warn("unable to parse node's VZDump configuration - $err");
580 }
581
582 log_pass("no problems found.") if $pass;
583 }
584
585 sub check_cifs_credential_location {
586 log_info("checking CIFS credential location..");
587
588 my $regex = qr/^(.*)\.cred$/;
589
590 my $found;
591
592 PVE::Tools::dir_glob_foreach('/etc/pve/priv/', $regex, sub {
593 my ($filename) = @_;
594
595 my ($basename) = $filename =~ $regex;
596
597 log_warn("CIFS credentials '/etc/pve/priv/$filename' will be moved to " .
598 "'/etc/pve/priv/storage/$basename.pw' during the update");
599
600 $found = 1;
601 });
602
603 log_pass("no CIFS credentials at outdated location found.") if !$found;
604 }
605
606 sub check_custom_pool_roles {
607 log_info("Checking custom roles for pool permissions..");
608
609 my $raw = read_file('/etc/pve/user.cfg');
610
611 my $roles = {};
612 while ($raw =~ /^\s*(.+?)\s*$/gm) {
613 my $line = $1;
614 my @data;
615
616 foreach my $d (split (/:/, $line)) {
617 $d =~ s/^\s+//;
618 $d =~ s/\s+$//;
619 push @data, $d
620 }
621
622 my $et = shift @data;
623 next if $et ne 'role';
624
625 my ($role, $privlist) = @data;
626 if (!PVE::AccessControl::verify_rolename($role, 1)) {
627 warn "user config - ignore role '$role' - invalid characters in role name\n";
628 next;
629 }
630
631 $roles->{$role} = {} if !$roles->{$role};
632 foreach my $priv (split_list($privlist)) {
633 $roles->{$role}->{$priv} = 1;
634 }
635 }
636
637 foreach my $role (sort keys %{$roles}) {
638 if (PVE::AccessControl::role_is_special($role)) {
639 next;
640 }
641
642 if ($role eq "PVEPoolUser") {
643 # the user created a custom role named PVEPoolUser
644 log_fail("Custom role '$role' has a restricted name - a built-in role 'PVEPoolUser' will be available with the upgrade");
645 } else {
646 log_pass("Custom role '$role' has no restricted name");
647 }
648
649 my $perms = $roles->{$role};
650 if ($perms->{'Pool.Allocate'} && $perms->{'Pool.Audit'}) {
651 log_pass("Custom role '$role' contains updated pool permissions");
652 } elsif ($perms->{'Pool.Allocate'}) {
653 log_warn("Custom role '$role' contains permission 'Pool.Allocate' - to ensure same behavior add 'Pool.Audit' to this role");
654 } else {
655 log_pass("Custom role '$role' contains no permissions that need to be updated");
656 }
657 }
658 }
659
660 sub check_misc {
661 print_header("MISCELLANEOUS CHECKS");
662 my $ssh_config = eval { PVE::Tools::file_get_contents('/root/.ssh/config') };
663 if (defined($ssh_config)) {
664 log_fail("Unsupported SSH Cipher configured for root in /root/.ssh/config: $1")
665 if $ssh_config =~ /^Ciphers .*(blowfish|arcfour|3des).*$/m;
666 } else {
667 log_skip("No SSH config file found.");
668 }
669
670 log_info("Checking common daemon services..");
671 $log_systemd_unit_state->('pveproxy.service');
672 $log_systemd_unit_state->('pvedaemon.service');
673 $log_systemd_unit_state->('pvestatd.service');
674
675 my $root_free = PVE::Tools::df('/', 10);
676 log_warn("Less than 2G free space on root file system.")
677 if defined($root_free) && $root_free->{avail} < 2*1024*1024*1024;
678
679 log_info("Checking for running guests..");
680 my $running_guests = 0;
681
682 my $vms = eval { PVE::API2::Qemu->vmlist({ node => $nodename }) };
683 log_warn("Failed to retrieve information about this node's VMs - $@") if $@;
684 $running_guests += grep { $_->{status} eq 'running' } @$vms if defined($vms);
685
686 my $cts = eval { PVE::API2::LXC->vmlist({ node => $nodename }) };
687 log_warn("Failed to retrieve information about this node's CTs - $@") if $@;
688 $running_guests += grep { $_->{status} eq 'running' } @$cts if defined($cts);
689
690 if ($running_guests > 0) {
691 log_warn("$running_guests running guest(s) detected - consider migrating or stopping them.")
692 } else {
693 log_pass("no running guest detected.")
694 }
695
696 log_info("Checking if the local node's hostname '$nodename' is resolvable..");
697 my $local_ip = eval { PVE::Network::get_ip_from_hostname($nodename) };
698 if ($@) {
699 log_warn("Failed to resolve hostname '$nodename' to IP - $@");
700 } else {
701 log_info("Checking if resolved IP is configured on local node..");
702 my $cidr = Net::IP::ip_is_ipv6($local_ip) ? "$local_ip/128" : "$local_ip/32";
703 my $configured_ips = PVE::Network::get_local_ip_from_cidr($cidr);
704 my $ip_count = scalar(@$configured_ips);
705
706 if ($ip_count <= 0) {
707 log_fail("Resolved node IP '$local_ip' not configured or active for '$nodename'");
708 } elsif ($ip_count > 1) {
709 log_warn("Resolved node IP '$local_ip' active on multiple ($ip_count) interfaces!");
710 } else {
711 log_pass("Resolved node IP '$local_ip' configured and active on single interface.");
712 }
713 }
714
715 log_info("Check node certificate's RSA key size");
716 my $certs = PVE::API2::Certificates->info({ node => $nodename });
717 my $certs_check = {
718 'rsaEncryption' => {
719 minsize => 2048,
720 name => 'RSA',
721 },
722 'id-ecPublicKey' => {
723 minsize => 224,
724 name => 'ECC',
725 },
726 };
727
728 my $certs_check_failed = 0;
729 foreach my $cert (@$certs) {
730 my ($type, $size, $fn) = $cert->@{qw(public-key-type public-key-bits filename)};
731
732 if (!defined($type) || !defined($size)) {
733 log_warn("'$fn': cannot check certificate, failed to get it's type or size!");
734 }
735
736 my $check = $certs_check->{$type};
737 if (!defined($check)) {
738 log_warn("'$fn': certificate's public key type '$type' unknown, check Debian Busters release notes");
739 next;
740 }
741
742 if ($size < $check->{minsize}) {
743 log_fail("'$fn', certificate's $check->{name} public key size is less than 2048 bit");
744 $certs_check_failed = 1;
745 } else {
746 log_pass("Certificate '$fn' passed Debian Busters security level for TLS connections ($size >= 2048)");
747 }
748 }
749
750 check_backup_retention_settings();
751 check_cifs_credential_location();
752 check_custom_pool_roles();
753 }
754
755 __PACKAGE__->register_method ({
756 name => 'checklist',
757 path => 'checklist',
758 method => 'GET',
759 description => 'Check (pre-/post-)upgrade conditions.',
760 parameters => {
761 additionalProperties => 0,
762 properties => {
763 },
764 },
765 returns => { type => 'null' },
766 code => sub {
767 my ($param) = @_;
768
769 check_pve_packages();
770 check_cluster_corosync();
771 check_ceph();
772 check_storage_health();
773 check_misc();
774
775 print_header("SUMMARY");
776
777 my $total = 0;
778 $total += $_ for values %$counters;
779
780 print "TOTAL: $total\n";
781 print colored("PASSED: $counters->{pass}\n", 'green');
782 print "SKIPPED: $counters->{skip}\n";
783 print colored("WARNINGS: $counters->{warn}\n", 'yellow');
784 print colored("FAILURES: $counters->{fail}\n", 'red');
785
786 if ($counters->{warn} > 0 || $counters->{fail} > 0) {
787 my $color = $counters->{fail} > 0 ? 'red' : 'yellow';
788 print colored("\nATTENTION: Please check the output for detailed information!\n", $color);
789 print colored("Try to solve the problems one at a time and then run this checklist tool again.\n", $color) if $counters->{fail} > 0;
790 }
791
792 return undef;
793 }});
794
795 our $cmddef = [ __PACKAGE__, 'checklist', [], {}];
796
797 # for now drop all unknown params and just check
798 @ARGV = ();
799
800 1;