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