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