]> git.proxmox.com Git - pve-manager.git/blame - PVE/CLI/pve7to8.pm
pve6to7: add hint that there's a newer upgrade possible
[pve-manager.git] / PVE / CLI / pve7to8.pm
CommitLineData
855e0adb
TL
1package PVE::CLI::pve7to8;
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;
11use PVE::API2::Cluster::Ceph;
12
13use PVE::AccessControl;
14use PVE::Ceph::Tools;
15use PVE::Cluster;
16use PVE::Corosync;
17use PVE::INotify;
18use PVE::JSONSchema;
19use PVE::NodeConfig;
20use PVE::RPCEnvironment;
21use PVE::Storage;
22use PVE::Storage::Plugin;
23use PVE::Tools qw(run_command split_list);
24use PVE::QemuConfig;
25use PVE::QemuServer;
26use PVE::VZDump::Common;
27use PVE::LXC;
28use PVE::LXC::Config;
29use PVE::LXC::Setup;
30
31use Term::ANSIColor;
32
33use PVE::CLIHandler;
34
35use base qw(PVE::CLIHandler);
36
37my $nodename = PVE::INotify::nodename();
38
39sub setup_environment {
40 PVE::RPCEnvironment->setup_default_cli_env();
41}
42
82bbcfad 43my ($min_pve_major, $min_pve_minor, $min_pve_pkgrel) = (7, 4, 1);
855e0adb
TL
44
45my $forced_legacy_cgroup = 0;
46
47my $counters = {
48 pass => 0,
49 skip => 0,
50 warn => 0,
51 fail => 0,
52};
53
54my $log_line = sub {
55 my ($level, $line) = @_;
56
57 $counters->{$level}++ if defined($level) && defined($counters->{$level});
58
59 print uc($level), ': ' if defined($level);
60 print "$line\n";
61};
62
63sub log_pass {
64 print color('green');
65 $log_line->('pass', @_);
66 print color('reset');
67}
68
69sub log_info {
70 $log_line->('info', @_);
71}
72sub log_skip {
73 $log_line->('skip', @_);
74}
75sub log_warn {
76 print color('yellow');
77 $log_line->('warn', @_);
78 print color('reset');
79}
80sub log_fail {
81 print color('red');
82 $log_line->('fail', @_);
83 print color('reset');
84}
85
86my $print_header_first = 1;
87sub print_header {
88 my ($h) = @_;
89 print "\n" if !$print_header_first;
90 print "= $h =\n\n";
91 $print_header_first = 0;
92}
93
94my $get_systemd_unit_state = sub {
95 my ($unit) = @_;
96
97 my $state;
98 my $filter_output = sub {
99 $state = shift;
100 chomp $state;
101 };
102 eval {
103 run_command(['systemctl', 'is-enabled', "$unit"], outfunc => $filter_output, noerr => 1);
104 return if !defined($state);
105 run_command(['systemctl', 'is-active', "$unit"], outfunc => $filter_output, noerr => 1);
106 };
107
108 return $state // 'unknown';
109};
110my $log_systemd_unit_state = sub {
111 my ($unit, $no_fail_on_inactive) = @_;
112
113 my $log_method = \&log_warn;
114
115 my $state = $get_systemd_unit_state->($unit);
116 if ($state eq 'active') {
117 $log_method = \&log_pass;
118 } elsif ($state eq 'inactive') {
119 $log_method = $no_fail_on_inactive ? \&log_warn : \&log_fail;
120 } elsif ($state eq 'failed') {
121 $log_method = \&log_fail;
122 }
123
124 $log_method->("systemd unit '$unit' is in state '$state'");
125};
126
127my $versions;
128my $get_pkg = sub {
129 my ($pkg) = @_;
130
131 $versions = eval { PVE::API2::APT->versions({ node => $nodename }) } if !defined($versions);
132
133 if (!defined($versions)) {
134 my $msg = "unable to retrieve package version information";
135 $msg .= "- $@" if $@;
136 log_fail("$msg");
137 return undef;
138 }
139
140 my $pkgs = [ grep { $_->{Package} eq $pkg } @$versions ];
141 if (!defined $pkgs || $pkgs == 0) {
142 log_fail("unable to determine installed $pkg version.");
143 return undef;
144 } else {
145 return $pkgs->[0];
146 }
147};
148
149sub check_pve_packages {
150 print_header("CHECKING VERSION INFORMATION FOR PVE PACKAGES");
151
152 print "Checking for package updates..\n";
153 my $updates = eval { PVE::API2::APT->list_updates({ node => $nodename }); };
154 if (!defined($updates)) {
155 log_warn("$@") if $@;
156 log_fail("unable to retrieve list of package updates!");
157 } elsif (@$updates > 0) {
158 my $pkgs = join(', ', map { $_->{Package} } @$updates);
159 log_warn("updates for the following packages are available:\n $pkgs");
160 } else {
161 log_pass("all packages uptodate");
162 }
163
164 print "\nChecking proxmox-ve package version..\n";
165 if (defined(my $proxmox_ve = $get_pkg->('proxmox-ve'))) {
166 my $min_pve_ver = "$min_pve_major.$min_pve_minor-$min_pve_pkgrel";
167
168 my ($maj, $min, $pkgrel) = $proxmox_ve->{OldVersion} =~ m/^(\d+)\.(\d+)-(\d+)/;
169
170 my $upgraded = 0;
171
172 if ($maj > $min_pve_major) {
173 log_pass("already upgraded to Proxmox VE " . ($min_pve_major + 1));
174 $upgraded = 1;
175 } elsif ($maj >= $min_pve_major && $min >= $min_pve_minor && $pkgrel >= $min_pve_pkgrel) {
176 log_pass("proxmox-ve package has version >= $min_pve_ver");
177 } else {
178 log_fail("proxmox-ve package is too old, please upgrade to >= $min_pve_ver!");
179 }
180
82bbcfad 181 my ($krunning, $kinstalled) = (qr/6\.(?:2|5)/, 'pve-kernel-6.2');
855e0adb 182 if (!$upgraded) {
82bbcfad
TL
183 # we got a few that avoided 5.15 in cluster with mixed CPUs, so allow older too
184 ($krunning, $kinstalled) = (qr/(?:5\.(?:13|15)|6\.2)/, 'pve-kernel-5.15');
855e0adb
TL
185 }
186
187 print "\nChecking running kernel version..\n";
188 my $kernel_ver = $proxmox_ve->{RunningKernel};
189 if (!defined($kernel_ver)) {
190 log_fail("unable to determine running kernel version.");
191 } elsif ($kernel_ver =~ /^$krunning/) {
82bbcfad 192 log_pass("running kernel '$kernel_ver' is considered suitable for upgrade.");
855e0adb
TL
193 } elsif ($get_pkg->($kinstalled)) {
194 log_warn("expected kernel '$kinstalled' intalled but not yet rebooted!");
195 } else {
196 log_warn("unexpected running and installed kernel '$kernel_ver'.");
197 }
198 } else {
199 log_fail("proxmox-ve package not found!");
200 }
201}
202
203
204sub check_storage_health {
205 print_header("CHECKING CONFIGURED STORAGES");
206 my $cfg = PVE::Storage::config();
207
208 my $ctime = time();
209
210 my $info = PVE::Storage::storage_info($cfg);
211
212 foreach my $storeid (sort keys %$info) {
213 my $d = $info->{$storeid};
214 if ($d->{enabled}) {
82bbcfad 215 if ($d->{active}) {
855e0adb
TL
216 log_pass("storage '$storeid' enabled and active.");
217 } else {
218 log_warn("storage '$storeid' enabled but not active!");
219 }
220 } else {
221 log_skip("storage '$storeid' disabled.");
222 }
223 }
3019f374
TL
224
225 check_storage_content();
855e0adb
TL
226}
227
228sub check_cluster_corosync {
229 print_header("CHECKING CLUSTER HEALTH/SETTINGS");
230
231 if (!PVE::Corosync::check_conf_exists(1)) {
232 log_skip("standalone node.");
233 return;
234 }
235
236 $log_systemd_unit_state->('pve-cluster.service');
237 $log_systemd_unit_state->('corosync.service');
238
239 if (PVE::Cluster::check_cfs_quorum(1)) {
240 log_pass("Cluster Filesystem is quorate.");
241 } else {
242 log_fail("Cluster Filesystem readonly, lost quorum?!");
243 }
244
245 my $conf = PVE::Cluster::cfs_read_file('corosync.conf');
246 my $conf_nodelist = PVE::Corosync::nodelist($conf);
247 my $node_votes = 0;
248
249 print "\nAnalzying quorum settings and state..\n";
250 if (!defined($conf_nodelist)) {
251 log_fail("unable to retrieve nodelist from corosync.conf");
252 } else {
253 if (grep { $conf_nodelist->{$_}->{quorum_votes} != 1 } keys %$conf_nodelist) {
254 log_warn("non-default quorum_votes distribution detected!");
255 }
256 map { $node_votes += $conf_nodelist->{$_}->{quorum_votes} // 0 } keys %$conf_nodelist;
257 }
258
259 my ($expected_votes, $total_votes);
260 my $filter_output = sub {
261 my $line = shift;
262 ($expected_votes) = $line =~ /^Expected votes:\s*(\d+)\s*$/
263 if !defined($expected_votes);
264 ($total_votes) = $line =~ /^Total votes:\s*(\d+)\s*$/
265 if !defined($total_votes);
266 };
267 eval {
268 run_command(['corosync-quorumtool', '-s'], outfunc => $filter_output, noerr => 1);
269 };
270
271 if (!defined($expected_votes)) {
82bbcfad 272 log_fail("unable to get expected number of votes, assuming 0.");
855e0adb
TL
273 $expected_votes = 0;
274 }
275 if (!defined($total_votes)) {
82bbcfad 276 log_fail("unable to get expected number of votes, assuming 0.");
855e0adb
TL
277 $total_votes = 0;
278 }
279
280 my $cfs_nodelist = PVE::Cluster::get_clinfo()->{nodelist};
281 my $offline_nodes = grep { $cfs_nodelist->{$_}->{online} != 1 } keys %$cfs_nodelist;
282 if ($offline_nodes > 0) {
283 log_fail("$offline_nodes nodes are offline!");
284 }
285
286 my $qdevice_votes = 0;
287 if (my $qdevice_setup = $conf->{main}->{quorum}->{device}) {
288 $qdevice_votes = $qdevice_setup->{votes} // 1;
289 }
290
291 log_info("configured votes - nodes: $node_votes");
292 log_info("configured votes - qdevice: $qdevice_votes");
293 log_info("current expected votes: $expected_votes");
294 log_info("current total votes: $total_votes");
295
296 log_warn("expected votes set to non-standard value '$expected_votes'.")
297 if $expected_votes != $node_votes + $qdevice_votes;
298 log_warn("total votes < expected votes: $total_votes/$expected_votes!")
299 if $total_votes < $expected_votes;
300
301 my $conf_nodelist_count = scalar(keys %$conf_nodelist);
302 my $cfs_nodelist_count = scalar(keys %$cfs_nodelist);
303 log_warn("cluster consists of less than three quorum-providing nodes!")
304 if $conf_nodelist_count < 3 && $conf_nodelist_count + $qdevice_votes < 3;
305
306 log_fail("corosync.conf ($conf_nodelist_count) and pmxcfs ($cfs_nodelist_count) don't agree about size of nodelist.")
307 if $conf_nodelist_count != $cfs_nodelist_count;
308
309 print "\nChecking nodelist entries..\n";
310 my $nodelist_pass = 1;
311 for my $cs_node (sort keys %$conf_nodelist) {
312 my $entry = $conf_nodelist->{$cs_node};
313 if (!defined($entry->{name})) {
314 $nodelist_pass = 0;
315 log_fail("$cs_node: no name entry in corosync.conf.");
316 }
317 if (!defined($entry->{nodeid})) {
318 $nodelist_pass = 0;
319 log_fail("$cs_node: no nodeid configured in corosync.conf.");
320 }
321 my $gotLinks = 0;
322 for my $link (0..7) {
323 $gotLinks++ if defined($entry->{"ring${link}_addr"});
324 }
325 if ($gotLinks <= 0) {
326 $nodelist_pass = 0;
327 log_fail("$cs_node: no ringX_addr (0 <= X <= 7) link defined in corosync.conf.");
328 }
329
330 my $verify_ring_ip = sub {
331 my $key = shift;
332 if (defined(my $ring = $entry->{$key})) {
333 my ($resolved_ip, undef) = PVE::Corosync::resolve_hostname_like_corosync($ring, $conf);
334 if (defined($resolved_ip)) {
335 if ($resolved_ip ne $ring) {
336 $nodelist_pass = 0;
82bbcfad
TL
337 log_warn(
338 "$cs_node: $key '$ring' resolves to '$resolved_ip'.\n"
339 ." Consider replacing it with the currently resolved IP address."
340 );
855e0adb
TL
341 }
342 } else {
343 $nodelist_pass = 0;
82bbcfad
TL
344 log_fail(
345 "$cs_node: unable to resolve $key '$ring' to an IP address according to Corosync's"
346 ." resolve strategy - cluster will potentially fail with Corosync 3.x/kronosnet!"
347 );
855e0adb
TL
348 }
349 }
350 };
351 for my $link (0..7) {
352 $verify_ring_ip->("ring${link}_addr");
353 }
354 }
355 log_pass("nodelist settings OK") if $nodelist_pass;
356
357 print "\nChecking totem settings..\n";
358 my $totem = $conf->{main}->{totem};
359 my $totem_pass = 1;
360
361 my $transport = $totem->{transport};
362 if (defined($transport)) {
363 if ($transport ne 'knet') {
364 $totem_pass = 0;
365 log_fail("Corosync transport explicitly set to '$transport' instead of implicit default!");
366 }
367 }
368
369 # TODO: are those values still up-to-date?
370 if ((!defined($totem->{secauth}) || $totem->{secauth} ne 'on') && (!defined($totem->{crypto_cipher}) || $totem->{crypto_cipher} eq 'none')) {
371 $totem_pass = 0;
372 log_fail("Corosync authentication/encryption is not explicitly enabled (secauth / crypto_cipher / crypto_hash)!");
373 } elsif (defined($totem->{crypto_cipher}) && $totem->{crypto_cipher} eq '3des') {
374 $totem_pass = 0;
375 log_fail("Corosync encryption cipher set to '3des', no longer supported in Corosync 3.x!"); # FIXME: can be removed?
376 }
377
378 log_pass("totem settings OK") if $totem_pass;
379 print "\n";
380 log_info("run 'pvecm status' to get detailed cluster status..");
381
382 if (defined(my $corosync = $get_pkg->('corosync'))) {
383 if ($corosync->{OldVersion} =~ m/^2\./) {
384 log_fail("\ncorosync 2.x installed, cluster-wide upgrade to 3.x needed!");
385 } elsif ($corosync->{OldVersion} !~ m/^3\./) {
386 log_fail("\nunexpected corosync version installed: $corosync->{OldVersion}!");
387 }
388 }
389}
390
391sub check_ceph {
392 print_header("CHECKING HYPER-CONVERGED CEPH STATUS");
393
394 if (PVE::Ceph::Tools::check_ceph_inited(1)) {
395 log_info("hyper-converged ceph setup detected!");
396 } else {
397 log_skip("no hyper-converged ceph setup detected!");
398 return;
399 }
400
401 log_info("getting Ceph status/health information..");
402 my $ceph_status = eval { PVE::API2::Ceph->status({ node => $nodename }); };
403 my $noout = eval { PVE::API2::Cluster::Ceph->get_flag({ flag => "noout" }); };
404 if ($@) {
405 log_fail("failed to get 'noout' flag status - $@");
406 }
407
408 my $noout_wanted = 1;
409
410 if (!$ceph_status || !$ceph_status->{health}) {
411 log_fail("unable to determine Ceph status!");
412 } else {
413 my $ceph_health = $ceph_status->{health}->{status};
414 if (!$ceph_health) {
415 log_fail("unable to determine Ceph health!");
416 } elsif ($ceph_health eq 'HEALTH_OK') {
417 log_pass("Ceph health reported as 'HEALTH_OK'.");
418 } elsif ($ceph_health eq 'HEALTH_WARN' && $noout && (keys %{$ceph_status->{health}->{checks}} == 1)) {
419 log_pass("Ceph health reported as 'HEALTH_WARN' with a single failing check and 'noout' flag set.");
420 } else {
421 log_warn("Ceph health reported as '$ceph_health'.\n Use the PVE ".
422 "dashboard or 'ceph -s' to determine the specific issues and try to resolve them.");
423 }
424 }
425
426 # TODO: check OSD min-required version, if to low it breaks stuff!
427
428 log_info("getting Ceph daemon versions..");
429 my $ceph_versions = eval { PVE::Ceph::Tools::get_cluster_versions(undef, 1); };
430 if (!$ceph_versions) {
431 log_fail("unable to determine Ceph daemon versions!");
432 } else {
433 my $services = [
434 { 'key' => 'mon', 'name' => 'monitor' },
435 { 'key' => 'mgr', 'name' => 'manager' },
436 { 'key' => 'mds', 'name' => 'MDS' },
437 { 'key' => 'osd', 'name' => 'OSD' },
438 ];
439
440 foreach my $service (@$services) {
441 my $name = $service->{name};
442 if (my $service_versions = $ceph_versions->{$service->{key}}) {
443 if (keys %$service_versions == 0) {
444 log_skip("no running instances detected for daemon type $name.");
445 } elsif (keys %$service_versions == 1) {
446 log_pass("single running version detected for daemon type $name.");
447 } else {
448 log_warn("multiple running versions detected for daemon type $name!");
449 }
450 } else {
451 log_skip("unable to determine versions of running Ceph $name instances.");
452 }
453 }
454
455 my $overall_versions = $ceph_versions->{overall};
456 if (!$overall_versions) {
457 log_warn("unable to determine overall Ceph daemon versions!");
458 } elsif (keys %$overall_versions == 1) {
459 log_pass("single running overall version detected for all Ceph daemon types.");
460 $noout_wanted = 0; # off post-upgrade, on pre-upgrade
461 } else {
462 log_warn("overall version mismatch detected, check 'ceph versions' output for details!");
463 }
464 }
465
466 if ($noout) {
467 if ($noout_wanted) {
468 log_pass("'noout' flag set to prevent rebalancing during cluster-wide upgrades.");
469 } else {
470 log_warn("'noout' flag set, Ceph cluster upgrade seems finished.");
471 }
472 } elsif ($noout_wanted) {
473 log_warn("'noout' flag not set - recommended to prevent rebalancing during upgrades.");
474 }
475
476 log_info("checking Ceph config..");
477 my $conf = PVE::Cluster::cfs_read_file('ceph.conf');
478 if (%$conf) {
479 my $global = $conf->{global};
480
481 my $global_monhost = $global->{mon_host} // $global->{"mon host"} // $global->{"mon-host"};
482 if (!defined($global_monhost)) {
82bbcfad
TL
483 log_warn(
484 "No 'mon_host' entry found in ceph config.\n It's recommended to add mon_host with"
485 ." all monitor addresses (without ports) to the global section."
486 );
855e0adb
TL
487 }
488
489 my $ipv6 = $global->{ms_bind_ipv6} // $global->{"ms bind ipv6"} // $global->{"ms-bind-ipv6"};
490 if ($ipv6) {
491 my $ipv4 = $global->{ms_bind_ipv4} // $global->{"ms bind ipv4"} // $global->{"ms-bind-ipv4"};
492 if ($ipv6 eq 'true' && (!defined($ipv4) || $ipv4 ne 'false')) {
82bbcfad
TL
493 log_warn(
494 "'ms_bind_ipv6' is enabled but 'ms_bind_ipv4' is not disabled.\n Make sure to"
495 ." disable 'ms_bind_ipv4' for ipv6 only clusters, or add an ipv4 network to public/cluster network."
496 );
855e0adb
TL
497 }
498 }
499
500 if (defined($global->{keyring})) {
82bbcfad
TL
501 log_warn(
502 "[global] config section contains 'keyring' option, which will prevent services from"
503 ." starting with Nautilus.\n Move 'keyring' option to [client] section instead."
504 );
855e0adb
TL
505 }
506
507 } else {
508 log_warn("Empty ceph config found");
509 }
510
511 my $local_ceph_ver = PVE::Ceph::Tools::get_local_version(1);
512 if (defined($local_ceph_ver)) {
513 if ($local_ceph_ver <= 14) {
514 log_fail("local Ceph version too low, at least Octopus required..");
515 }
516 } else {
517 log_fail("unable to determine local Ceph version.");
518 }
519}
520
521sub 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
82bbcfad
TL
566 log_info(
567 "storage '$storeid' - no backup retention settings defined - by default, since PVE 7.0"
568 ." it will no longer keep only the last backup, but all backups"
569 );
855e0adb
TL
570 }
571
572 eval {
573 my $vzdump_cron = PVE::Cluster::cfs_read_file('vzdump.cron');
574
575 # only warn once, there might be many jobs...
576 if (scalar(grep { defined($_->{maxfiles}) } $vzdump_cron->{jobs}->@*)) {
577 $pass = 0;
578 log_warn("/etc/pve/vzdump.cron - $maxfiles_msg");
579 }
580 };
581 if (my $err = $@) {
582 $pass = 0;
583 log_warn("unable to parse node's VZDump configuration - $err");
584 }
585
586 log_pass("no problems found.") if $pass;
587}
588
589sub check_cifs_credential_location {
590 log_info("checking CIFS credential location..");
591
592 my $regex = qr/^(.*)\.cred$/;
593
594 my $found;
595
596 PVE::Tools::dir_glob_foreach('/etc/pve/priv/', $regex, sub {
597 my ($filename) = @_;
598
599 my ($basename) = $filename =~ $regex;
600
82bbcfad
TL
601 log_warn(
602 "CIFS credentials '/etc/pve/priv/$filename' will be moved to"
603 ." '/etc/pve/priv/storage/$basename.pw' during the update"
604 );
855e0adb
TL
605
606 $found = 1;
607 });
608
609 log_pass("no CIFS credentials at outdated location found.") if !$found;
610}
611
612sub check_custom_pool_roles {
613 log_info("Checking custom roles for pool permissions..");
614
615 if (! -f "/etc/pve/user.cfg") {
616 log_skip("user.cfg does not exist");
617 return;
618 }
619
620 my $raw = eval { PVE::Tools::file_get_contents('/etc/pve/user.cfg'); };
621 if ($@) {
622 log_fail("Failed to read '/etc/pve/user.cfg' - $@");
623 return;
624 }
625
626 my $roles = {};
627 while ($raw =~ /^\s*(.+?)\s*$/gm) {
628 my $line = $1;
629 my @data;
630
631 foreach my $d (split (/:/, $line)) {
632 $d =~ s/^\s+//;
633 $d =~ s/\s+$//;
634 push @data, $d
635 }
636
637 my $et = shift @data;
638 next if $et ne 'role';
639
640 my ($role, $privlist) = @data;
641 if (!PVE::AccessControl::verify_rolename($role, 1)) {
642 warn "user config - ignore role '$role' - invalid characters in role name\n";
643 next;
644 }
645
646 $roles->{$role} = {} if !$roles->{$role};
647 foreach my $priv (split_list($privlist)) {
648 $roles->{$role}->{$priv} = 1;
649 }
650 }
651
652 foreach my $role (sort keys %{$roles}) {
82bbcfad 653 next if PVE::AccessControl::role_is_special($role);
855e0adb 654
82bbcfad 655 # TODO: any role updates?
855e0adb
TL
656 }
657}
658
659my sub check_max_length {
660 my ($raw, $max_length, $warning) = @_;
661 log_warn($warning) if defined($raw) && length($raw) > $max_length;
662}
663
664sub check_node_and_guest_configurations {
665 log_info("Checking node and guest description/note legnth..");
666
667 my @affected_nodes = grep {
668 my $desc = PVE::NodeConfig::load_config($_)->{desc};
669 defined($desc) && length($desc) > 64 * 1024
670 } PVE::Cluster::get_nodelist();
671
672 if (scalar(@affected_nodes) > 0) {
673 log_warn("Node config description of the following nodes too long for new limit of 64 KiB:\n "
674 . join(', ', @affected_nodes));
675 } else {
676 log_pass("All node config descriptions fit in the new limit of 64 KiB");
677 }
678
679 my $affected_guests_long_desc = [];
680 my $affected_cts_cgroup_keys = [];
681
682 my $cts = PVE::LXC::config_list();
683 for my $vmid (sort { $a <=> $b } keys %$cts) {
684 my $conf = PVE::LXC::Config->load_config($vmid);
685
686 my $desc = $conf->{description};
687 push @$affected_guests_long_desc, "CT $vmid" if defined($desc) && length($desc) > 8 * 1024;
688
689 my $lxc_raw_conf = $conf->{lxc};
690 push @$affected_cts_cgroup_keys, "CT $vmid" if (grep (@$_[0] =~ /^lxc\.cgroup\./, @$lxc_raw_conf));
691 }
692 my $vms = PVE::QemuServer::config_list();
693 for my $vmid (sort { $a <=> $b } keys %$vms) {
694 my $desc = PVE::QemuConfig->load_config($vmid)->{description};
695 push @$affected_guests_long_desc, "VM $vmid" if defined($desc) && length($desc) > 8 * 1024;
696 }
697 if (scalar($affected_guests_long_desc->@*) > 0) {
698 log_warn("Guest config description of the following virtual-guests too long for new limit of 64 KiB:\n"
699 ." " . join(", ", $affected_guests_long_desc->@*));
700 } else {
701 log_pass("All guest config descriptions fit in the new limit of 8 KiB");
702 }
703
704 log_info("Checking container configs for deprecated lxc.cgroup entries");
705
706 if (scalar($affected_cts_cgroup_keys->@*) > 0) {
707 if ($forced_legacy_cgroup) {
708 log_pass("Found legacy 'lxc.cgroup' keys, but system explicitly configured for legacy hybrid cgroup hierarchy.");
709 } else {
710 log_warn("The following CTs have 'lxc.cgroup' keys configured, which will be ignored in the new default unified cgroupv2:\n"
711 ." " . join(", ", $affected_cts_cgroup_keys->@*) ."\n"
712 ." Often it can be enough to change to the new 'lxc.cgroup2' prefix after the upgrade to Proxmox VE 7.x");
713 }
714 } else {
715 log_pass("No legacy 'lxc.cgroup' keys found.");
716 }
717}
718
719sub check_storage_content {
720 log_info("Checking storage content type configuration..");
721
722 my $found;
723 my $pass = 1;
724
725 my $storage_cfg = PVE::Storage::config();
726
727 for my $storeid (sort keys $storage_cfg->{ids}->%*) {
728 my $scfg = $storage_cfg->{ids}->{$storeid};
729
730 next if $scfg->{shared};
731 next if !PVE::Storage::storage_check_enabled($storage_cfg, $storeid, undef, 1);
732
733 my $valid_content = PVE::Storage::Plugin::valid_content_types($scfg->{type});
734
735 if (scalar(keys $scfg->{content}->%*) == 0 && !$valid_content->{none}) {
736 $pass = 0;
737 log_fail("storage '$storeid' does not support configured content type 'none'");
738 delete $scfg->{content}->{none}; # scan for guest images below
739 }
740
741 next if $scfg->{content}->{images};
742 next if $scfg->{content}->{rootdir};
743
744 # Skip 'iscsi(direct)' (and foreign plugins with potentially similiar behavior) with 'none',
745 # because that means "use LUNs directly" and vdisk_list() in PVE 6.x still lists those.
746 # It's enough to *not* skip 'dir', because it is the only other storage that supports 'none'
747 # and 'images' or 'rootdir', hence being potentially misconfigured.
748 next if $scfg->{type} ne 'dir' && $scfg->{content}->{none};
749
750 eval { PVE::Storage::activate_storage($storage_cfg, $storeid) };
751 if (my $err = $@) {
752 log_warn("activating '$storeid' failed - $err");
753 next;
754 }
755
756 my $res = eval { PVE::Storage::vdisk_list($storage_cfg, $storeid); };
757 if (my $err = $@) {
758 log_warn("listing images on '$storeid' failed - $err");
759 next;
760 }
761 my @volids = map { $_->{volid} } $res->{$storeid}->@*;
762
763 my $number = scalar(@volids);
764 if ($number > 0) {
82bbcfad
TL
765 log_info(
766 "storage '$storeid' - neither content type 'images' nor 'rootdir' configured, but"
767 ."found $number guest volume(s)"
768 );
855e0adb
TL
769 }
770 }
771
772 my $check_volid = sub {
773 my ($volid, $vmid, $vmtype, $reference) = @_;
774
775 my $guesttext = $vmtype eq 'qemu' ? 'VM' : 'CT';
776 my $prefix = "$guesttext $vmid - volume '$volid' ($reference)";
777
778 my ($storeid) = PVE::Storage::parse_volume_id($volid, 1);
779 return if !defined($storeid);
780
781 my $scfg = $storage_cfg->{ids}->{$storeid};
782 if (!$scfg) {
783 $pass = 0;
784 log_warn("$prefix - storage does not exist!");
785 return;
786 }
787
788 # cannot use parse_volname for containers, as it can return 'images'
789 # but containers cannot have ISO images attached, so assume 'rootdir'
790 my $vtype = 'rootdir';
791 if ($vmtype eq 'qemu') {
792 ($vtype) = eval { PVE::Storage::parse_volname($storage_cfg, $volid); };
793 return if $@;
794 }
795
796 if (!$scfg->{content}->{$vtype}) {
797 $found = 1;
798 $pass = 0;
799 log_warn("$prefix - storage does not have content type '$vtype' configured.");
800 }
801 };
802
803 my $cts = PVE::LXC::config_list();
804 for my $vmid (sort { $a <=> $b } keys %$cts) {
805 my $conf = PVE::LXC::Config->load_config($vmid);
806
807 my $volhash = {};
808
809 my $check = sub {
810 my ($ms, $mountpoint, $reference) = @_;
811
812 my $volid = $mountpoint->{volume};
813 return if !$volid || $mountpoint->{type} ne 'volume';
814
815 return if $volhash->{$volid}; # volume might be referenced multiple times
816
817 $volhash->{$volid} = 1;
818
819 $check_volid->($volid, $vmid, 'lxc', $reference);
820 };
821
822 my $opts = { include_unused => 1 };
823 PVE::LXC::Config->foreach_volume_full($conf, $opts, $check, 'in config');
824 for my $snapname (keys $conf->{snapshots}->%*) {
825 my $snap = $conf->{snapshots}->{$snapname};
826 PVE::LXC::Config->foreach_volume_full($snap, $opts, $check, "in snapshot '$snapname'");
827 }
828 }
829
830 my $vms = PVE::QemuServer::config_list();
831 for my $vmid (sort { $a <=> $b } keys %$vms) {
832 my $conf = PVE::QemuConfig->load_config($vmid);
833
834 my $volhash = {};
835
836 my $check = sub {
837 my ($key, $drive, $reference) = @_;
838
839 my $volid = $drive->{file};
840 return if $volid =~ m|^/|;
855e0adb
TL
841 return if $volhash->{$volid}; # volume might be referenced multiple times
842
843 $volhash->{$volid} = 1;
855e0adb
TL
844 $check_volid->($volid, $vmid, 'qemu', $reference);
845 };
846
847 my $opts = {
848 extra_keys => ['vmstate'],
849 include_unused => 1,
850 };
851 # startup from a suspended state works even without 'images' content type on the
852 # state storage, so do not check 'vmstate' for $conf
853 PVE::QemuConfig->foreach_volume_full($conf, { include_unused => 1 }, $check, 'in config');
854 for my $snapname (keys $conf->{snapshots}->%*) {
855 my $snap = $conf->{snapshots}->{$snapname};
856 PVE::QemuConfig->foreach_volume_full($snap, $opts, $check, "in snapshot '$snapname'");
857 }
858 }
859
860 if ($found) {
82bbcfad 861 log_warn("Proxmox VE enforces stricter content type checks since 7.0. The guests above " .
855e0adb
TL
862 "might not work until the storage configuration is fixed.");
863 }
864
865 if ($pass) {
866 log_pass("no problems found");
867 }
868}
869
870sub check_containers_cgroup_compat {
871 if ($forced_legacy_cgroup) {
82bbcfad
TL
872 log_warn("System explicitly configured for legacy hybrid cgroup hierarchy.\n"
873 ." NOTE: support for the hybrid cgroup hierachy will be removed in future Proxmox VE 9 (~ 2025)."
874 );
855e0adb
TL
875 }
876
877 my $supports_cgroupv2 = sub {
878 my ($conf, $rootdir, $ctid) = @_;
879
880 my $get_systemd_version = sub {
881 my ($self) = @_;
882
883 my $sd_lib_dir = -d "/lib/systemd" ? "/lib/systemd" : "/usr/lib/systemd";
884 my $libsd = PVE::Tools::dir_glob_regex($sd_lib_dir, "libsystemd-shared-.+\.so");
885 if (defined($libsd) && $libsd =~ /libsystemd-shared-(\d+)\.so/) {
886 return $1;
887 }
888
889 return undef;
890 };
891
892 my $unified_cgroupv2_support = sub {
893 my ($self) = @_;
894
895 # https://www.freedesktop.org/software/systemd/man/systemd.html
896 # systemd is installed as symlink to /sbin/init
897 my $systemd = CORE::readlink('/sbin/init');
898
899 # assume non-systemd init will run with unified cgroupv2
900 if (!defined($systemd) || $systemd !~ m@/systemd$@) {
901 return 1;
902 }
903
904 # systemd version 232 (e.g. debian stretch) supports the unified hierarchy
905 my $sdver = $get_systemd_version->();
906 if (!defined($sdver) || $sdver < 232) {
907 return 0;
908 }
909
910 return 1;
911 };
912
913 my $ostype = $conf->{ostype};
914 if (!defined($ostype)) {
915 log_warn("Found CT ($ctid) without 'ostype' set!");
916 } elsif ($ostype eq 'devuan' || $ostype eq 'alpine') {
917 return 1; # no systemd, no cgroup problems
918 }
919
920 my $lxc_setup = PVE::LXC::Setup->new($conf, $rootdir);
921 return $lxc_setup->protected_call($unified_cgroupv2_support);
922 };
923
924 my $log_problem = sub {
925 my ($ctid) = @_;
82bbcfad
TL
926 my $extra = $forced_legacy_cgroup ? '' : " or set systemd.unified_cgroup_hierarchy=0 in the Proxmox VE hosts' kernel cmdline";
927 log_warn(
928 "Found at least one CT ($ctid) which does not support running in a unified cgroup v2 layout\n"
929 ." Consider upgrading the Containers distro${extra}! Skipping further CT compat checks."
855e0adb
TL
930 );
931 };
932
933 my $cts = eval { PVE::API2::LXC->vmlist({ node => $nodename }) };
934 if ($@) {
935 log_warn("Failed to retrieve information about this node's CTs - $@");
936 return;
937 }
938
939 if (!defined($cts) || !scalar(@$cts)) {
940 log_skip("No containers on node detected.");
941 return;
942 }
943
944 my @running_cts = sort { $a <=> $b } grep { $_->{status} eq 'running' } @$cts;
945 my @offline_cts = sort { $a <=> $b } grep { $_->{status} ne 'running' } @$cts;
946
947 for my $ct (@running_cts) {
948 my $ctid = $ct->{vmid};
949 my $pid = eval { PVE::LXC::find_lxc_pid($ctid) };
950 if (my $err = $@) {
951 log_warn("Failed to get PID for running CT $ctid - $err");
952 next;
953 }
954 my $rootdir = "/proc/$pid/root";
955 my $conf = PVE::LXC::Config->load_config($ctid);
956
957 my $ret = eval { $supports_cgroupv2->($conf, $rootdir, $ctid) };
958 if (my $err = $@) {
959 log_warn("Failed to get cgroup support status for CT $ctid - $err");
960 next;
961 }
962 if (!$ret) {
963 $log_problem->($ctid);
964 return;
965 }
966 }
967
968 my $storage_cfg = PVE::Storage::config();
969 for my $ct (@offline_cts) {
970 my $ctid = $ct->{vmid};
971 my ($conf, $rootdir, $ret);
972 eval {
973 $conf = PVE::LXC::Config->load_config($ctid);
974 $rootdir = PVE::LXC::mount_all($ctid, $storage_cfg, $conf);
975 $ret = $supports_cgroupv2->($conf, $rootdir, $ctid);
976 };
977 if (my $err = $@) {
978 log_warn("Failed to load config and mount CT $ctid - $err");
979 eval { PVE::LXC::umount_all($ctid, $storage_cfg, $conf) };
980 next;
981 }
982 if (!$ret) {
983 $log_problem->($ctid);
984 eval { PVE::LXC::umount_all($ctid, $storage_cfg, $conf) };
985 last;
986 }
987
988 eval { PVE::LXC::umount_all($ctid, $storage_cfg, $conf) };
989 }
990};
991
64fa63b7 992sub check_apt_repos {
855e0adb
TL
993 log_info("Checking if the suite for the Debian security repository is correct..");
994
995 my $found = 0;
996
997 my $dir = '/etc/apt/sources.list.d';
998 my $in_dir = 0;
999
64fa63b7
TL
1000 # TODO: check that (original) debian and Proxmox VE mirrors are present.
1001
855e0adb
TL
1002 my $check_file = sub {
1003 my ($file) = @_;
1004
1005 $file = "${dir}/${file}" if $in_dir;
1006
1007 my $raw = eval { PVE::Tools::file_get_contents($file) };
1008 return if !defined($raw);
1009 my @lines = split(/\n/, $raw);
1010
1011 my $number = 0;
1012 for my $line (@lines) {
1013 $number++;
1014
1015 next if length($line) == 0; # split would result in undef then...
1016
1017 ($line) = split(/#/, $line);
1018
1019 next if $line !~ m/^deb[[:space:]]/; # is case sensitive
1020
1021 my $suite;
1022
1023 # catch any of
1024 # https://deb.debian.org/debian-security
1025 # http://security.debian.org/debian-security
1026 # http://security.debian.org/
1027 if ($line =~ m|https?://deb\.debian\.org/debian-security/?\s+(\S*)|i) {
1028 $suite = $1;
1029 } elsif ($line =~ m|https?://security\.debian\.org(?:.*?)\s+(\S*)|i) {
1030 $suite = $1;
1031 } else {
1032 next;
1033 }
1034
1035 $found = 1;
1036
1037 my $where = "in ${file}:${number}";
1038
1039 if ($suite eq 'buster/updates') {
1040 log_info("Make sure to change the suite of the Debian security repository " .
1041 "from 'buster/updates' to 'bullseye-security' - $where");
1042 } elsif ($suite eq 'bullseye-security') {
1043 log_pass("already using 'bullseye-security'");
1044 } else {
1045 log_fail("The new suite of the Debian security repository should be " .
1046 "'bullseye-security' - $where");
1047 }
1048 }
1049 };
1050
1051 $check_file->("/etc/apt/sources.list");
1052
1053 $in_dir = 1;
1054
1055 PVE::Tools::dir_glob_foreach($dir, '^.*\.list$', $check_file);
1056
1057 if (!$found) {
1058 # only warn, it might be defined in a .sources file or in a way not catched above
1059 log_warn("No Debian security repository detected in /etc/apt/sources.list and " .
1060 "/etc/apt/sources.list.d/*.list");
1061 }
1062}
1063
1064sub check_misc {
1065 print_header("MISCELLANEOUS CHECKS");
1066 my $ssh_config = eval { PVE::Tools::file_get_contents('/root/.ssh/config') };
1067 if (defined($ssh_config)) {
1068 log_fail("Unsupported SSH Cipher configured for root in /root/.ssh/config: $1")
1069 if $ssh_config =~ /^Ciphers .*(blowfish|arcfour|3des).*$/m;
1070 } else {
1071 log_skip("No SSH config file found.");
1072 }
1073
1074 log_info("Checking common daemon services..");
1075 $log_systemd_unit_state->('pveproxy.service');
1076 $log_systemd_unit_state->('pvedaemon.service');
69eaceb3 1077 $log_systemd_unit_state->('pvescheduler.service');
855e0adb
TL
1078 $log_systemd_unit_state->('pvestatd.service');
1079
1080 my $root_free = PVE::Tools::df('/', 10);
5af851c5
TL
1081 log_warn("Less than 5 GB free space on root file system.")
1082 if defined($root_free) && $root_free->{avail} < 5 * 1000*1000*1000;
855e0adb
TL
1083
1084 log_info("Checking for running guests..");
1085 my $running_guests = 0;
1086
1087 my $vms = eval { PVE::API2::Qemu->vmlist({ node => $nodename }) };
1088 log_warn("Failed to retrieve information about this node's VMs - $@") if $@;
1089 $running_guests += grep { $_->{status} eq 'running' } @$vms if defined($vms);
1090
1091 my $cts = eval { PVE::API2::LXC->vmlist({ node => $nodename }) };
1092 log_warn("Failed to retrieve information about this node's CTs - $@") if $@;
1093 $running_guests += grep { $_->{status} eq 'running' } @$cts if defined($cts);
1094
1095 if ($running_guests > 0) {
1096 log_warn("$running_guests running guest(s) detected - consider migrating or stopping them.")
1097 } else {
1098 log_pass("no running guest detected.")
1099 }
1100
1101 log_info("Checking if the local node's hostname '$nodename' is resolvable..");
1102 my $local_ip = eval { PVE::Network::get_ip_from_hostname($nodename) };
1103 if ($@) {
1104 log_warn("Failed to resolve hostname '$nodename' to IP - $@");
1105 } else {
1106 log_info("Checking if resolved IP is configured on local node..");
1107 my $cidr = Net::IP::ip_is_ipv6($local_ip) ? "$local_ip/128" : "$local_ip/32";
1108 my $configured_ips = PVE::Network::get_local_ip_from_cidr($cidr);
1109 my $ip_count = scalar(@$configured_ips);
1110
1111 if ($ip_count <= 0) {
1112 log_fail("Resolved node IP '$local_ip' not configured or active for '$nodename'");
1113 } elsif ($ip_count > 1) {
1114 log_warn("Resolved node IP '$local_ip' active on multiple ($ip_count) interfaces!");
1115 } else {
1116 log_pass("Resolved node IP '$local_ip' configured and active on single interface.");
1117 }
1118 }
1119
1120 log_info("Check node certificate's RSA key size");
1121 my $certs = PVE::API2::Certificates->info({ node => $nodename });
1122 my $certs_check = {
1123 'rsaEncryption' => {
1124 minsize => 2048,
1125 name => 'RSA',
1126 },
1127 'id-ecPublicKey' => {
1128 minsize => 224,
1129 name => 'ECC',
1130 },
1131 };
1132
1133 my $certs_check_failed = 0;
1134 foreach my $cert (@$certs) {
1135 my ($type, $size, $fn) = $cert->@{qw(public-key-type public-key-bits filename)};
1136
1137 if (!defined($type) || !defined($size)) {
1138 log_warn("'$fn': cannot check certificate, failed to get it's type or size!");
1139 }
1140
1141 my $check = $certs_check->{$type};
1142 if (!defined($check)) {
82bbcfad 1143 log_warn("'$fn': certificate's public key type '$type' unknown!");
855e0adb
TL
1144 next;
1145 }
1146
1147 if ($size < $check->{minsize}) {
1148 log_fail("'$fn', certificate's $check->{name} public key size is less than 2048 bit");
1149 $certs_check_failed = 1;
1150 } else {
82bbcfad 1151 log_pass("Certificate '$fn' passed Debian Busters (and newer) security level for TLS connections ($size >= 2048)");
855e0adb
TL
1152 }
1153 }
1154
1155 check_backup_retention_settings();
1156 check_cifs_credential_location();
1157 check_custom_pool_roles();
1158 check_node_and_guest_configurations();
64fa63b7 1159 check_apt_repos();
855e0adb
TL
1160}
1161
1f4a4dbe
TL
1162my sub colored_if {
1163 my ($str, $color, $condition) = @_;
1164 return "". ($condition ? colored($str, $color) : $str);
1165}
1166
855e0adb
TL
1167__PACKAGE__->register_method ({
1168 name => 'checklist',
1169 path => 'checklist',
1170 method => 'GET',
1171 description => 'Check (pre-/post-)upgrade conditions.',
1172 parameters => {
1173 additionalProperties => 0,
1174 properties => {
1175 full => {
1176 description => 'perform additional, expensive checks.',
1177 type => 'boolean',
1178 optional => 1,
1179 default => 0,
1180 },
1181 },
1182 },
1183 returns => { type => 'null' },
1184 code => sub {
1185 my ($param) = @_;
1186
1187 my $kernel_cli = PVE::Tools::file_get_contents('/proc/cmdline');
1188 if ($kernel_cli =~ /systemd.unified_cgroup_hierarchy=0/){
1189 $forced_legacy_cgroup = 1;
1190 }
1191
1192 check_pve_packages();
1193 check_cluster_corosync();
1194 check_ceph();
1195 check_storage_health();
1196 check_misc();
1197
1198 if ($param->{full}) {
1199 check_containers_cgroup_compat();
1200 } else {
1201 log_skip("NOTE: Expensive checks, like CT cgroupv2 compat, not performed without '--full' parameter");
1202 }
1203
1204 print_header("SUMMARY");
1205
1206 my $total = 0;
1207 $total += $_ for values %$counters;
1208
1209 print "TOTAL: $total\n";
1210 print colored("PASSED: $counters->{pass}\n", 'green');
1211 print "SKIPPED: $counters->{skip}\n";
1f4a4dbe
TL
1212 print colored_if("WARNINGS: $counters->{warn}\n", 'yellow', $counters->{warn} > 0);
1213 print colored_if("FAILURES: $counters->{fail}\n", 'red', $counters->{fail} > 0);
855e0adb
TL
1214
1215 if ($counters->{warn} > 0 || $counters->{fail} > 0) {
1216 my $color = $counters->{fail} > 0 ? 'red' : 'yellow';
1217 print colored("\nATTENTION: Please check the output for detailed information!\n", $color);
1218 print colored("Try to solve the problems one at a time and then run this checklist tool again.\n", $color) if $counters->{fail} > 0;
1219 }
1220
1221 return undef;
1222 }});
1223
1224our $cmddef = [ __PACKAGE__, 'checklist', [], {}];
1225
12261;