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