From e3956e7a95b2609332a99ee5811aa4d377c7b439 Mon Sep 17 00:00:00 2001
From: Daniel Hilst <392820+dhilst@users.noreply.github.com>
Date: Wed, 21 Oct 2026 10:38:59 -0300
Subject: [PATCH 01/18] test(kvm): a node cannot ask for UEFI that verifies
what it boots
vm.othersettings firmware:efi asks libvirt for UEFI and states nothing
about Secure Boot. libvirt then takes the firmware descriptor of highest
priority that fits the guest, and that order belongs to the hypervisor.
The same node boots a firmware that verifies its kernel on one host and
one that does not on another, and the domain reports neither.
kvm_secureboot_firmware.t reads firmware:efi-secureboot through
requested_firmware, guest_arch_profile and guest_os. Six of its twelve
checks fail on this commit: the value is refused as unknown, so the node
keeps SeaBIOS and no reaches the domain.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
---
xCAT-test/unit/kvm_secureboot_firmware.t | 73 ++++++++++++++++++++++++
1 file changed, 73 insertions(+)
create mode 100644 xCAT-test/unit/kvm_secureboot_firmware.t
diff --git a/xCAT-test/unit/kvm_secureboot_firmware.t b/xCAT-test/unit/kvm_secureboot_firmware.t
new file mode 100644
index 0000000000..652d7b0a60
--- /dev/null
+++ b/xCAT-test/unit/kvm_secureboot_firmware.t
@@ -0,0 +1,73 @@
+#!/usr/bin/env perl
+# An x86_64 KVM guest asks libvirt for UEFI with Secure Boot on with vm.othersettings
+# "firmware:efi-secureboot".
+#
+# firmware:efi alone states no requirement about Secure Boot. libvirt then takes the firmware
+# descriptor of highest priority that fits the guest, and that order is host policy: the same
+# node boots with Secure Boot on on one hypervisor and off on another, and the domain reports
+# neither. A node that must boot signed binaries has to say so, so that a hypervisor without a
+# Secure Boot firmware refuses the domain instead of starting it unverified.
+#
+# is the requirement libvirt reads during firmware selection. Measured
+# with libvirt 11.10.0 on rome01: with that element resolves to
+# OVMF_CODE.secboot.fd and , and the same domain with
+# resolves to OVMF_CODE.fd.
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/../../perl-xCAT";
+use Test::More;
+
+require xCAT::KVMUtils;
+
+# The firmware and the profile that build_xmldesc reads for one x86_64 node.
+sub node_profile {
+ my ($othersettings) = @_;
+ my $confdata = {
+ vm => { cn1 => [ { host => 'hyp1', othersettings => $othersettings } ] },
+ nodetype => { cn1 => [ { arch => 'x86_64' } ] },
+ };
+ my $firmware =
+ xCAT::KVMUtils::requested_firmware( xCAT::KVMUtils::vm_othersettings( $confdata, 'cn1' ) );
+ return xCAT::KVMUtils::guest_arch_profile( 'x86_64', 'x86_64', $firmware );
+}
+
+sub os_of {
+ my ($profile) = @_;
+ return xCAT::KVMUtils::guest_os( $profile, hyp_cpumodel => 'x86_64' );
+}
+
+is( xCAT::KVMUtils::requested_firmware('firmware:efi-secureboot'),
+ 'efi-secureboot', 'firmware:efi-secureboot is read whole, not truncated to efi' );
+is( xCAT::KVMUtils::firmware_error( 'efi-secureboot', 'cn1' ),
+ undef, 'and it is a firmware libvirt can select, so it is not refused' );
+
+my $sb = node_profile('firmware:efi-secureboot');
+my $sb_os = os_of($sb);
+is( $sb_os->{firmware}, 'efi',
+ 'firmware:efi-secureboot puts firmware="efi" on , which starts the firmware selection' );
+is( $sb_os->{loader}->{secure}, 'yes',
+ 'and , which narrows that selection to a Secure Boot firmware' );
+is( $sb_os->{type}->{machine}, 'q35',
+ 'the Secure Boot node is placed on q35, the only machine type the x86_64 OVMF descriptors target' );
+is( $sb->{disk_model}, 'scsi', 'and its disks take the scsi bus, because q35 has no IDE controller' );
+is( $sb_os->{bios}->{useserial}, 'yes',
+ 'and it keeps , so its boot still reaches the serial console' );
+
+# firmware:efi must keep stating nothing about Secure Boot. A site that asked only for UEFI
+# gets the firmware its hypervisor prefers, as it did before.
+my $uefi_os = os_of( node_profile('firmware:efi') );
+is( $uefi_os->{firmware}, 'efi', 'firmware:efi still asks for UEFI' );
+is( $uefi_os->{loader}, undef, 'and states no Secure Boot requirement' );
+is( os_of( node_profile(undef) )->{loader},
+ undef, 'a node that asks for no firmware states no Secure Boot requirement either' );
+
+# A value libvirt cannot select is refused by name, and the refusal names both values a node
+# may ask for. A typo must not leave the node on a firmware it did not ask for.
+my $error = xCAT::KVMUtils::firmware_error( 'efi-secure', 'cn1' );
+like( $error, qr/firmware:efi-secure\b/, 'a value that is not a firmware is refused by name' );
+like( $error, qr/firmware:efi-secureboot/,
+ 'and the refusal names firmware:efi-secureboot, so the typo can be corrected from it' );
+
+done_testing();
From 772b2c656c65e1c2b30fc143d9da08757fa5fa2c Mon Sep 17 00:00:00 2001
From: Daniel Hilst <392820+dhilst@users.noreply.github.com>
Date: Wed, 21 Oct 2026 10:38:59 -0300
Subject: [PATCH 02/18] feat(kvm): ask libvirt for UEFI that verifies what it
boots
vm.othersettings now takes firmware:efi-secureboot. guest_os puts
on the domain beside firmware="efi". libvirt
reads that element while it selects the firmware and keeps only the
descriptors that carry secure-boot, so a hypervisor with no such
firmware refuses the domain instead of starting the node on a firmware
that verifies nothing.
firmware:efi keeps its meaning and states no requirement.
Measured with libvirt 11.10.0 on an x86_64 host: the domain resolves to
OVMF_CODE.secboot.fd with , and the same domain with
secure-boot asked off resolves to OVMF_CODE.fd.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
---
perl-xCAT/xCAT/KVMUtils.pm | 38 +++++++++++++++++++++--------
xCAT-server/lib/xcat/plugins/kvm.pm | 2 +-
2 files changed, 29 insertions(+), 11 deletions(-)
diff --git a/perl-xCAT/xCAT/KVMUtils.pm b/perl-xCAT/xCAT/KVMUtils.pm
index e1befd7493..e414c9a6f8 100644
--- a/perl-xCAT/xCAT/KVMUtils.pm
+++ b/perl-xCAT/xCAT/KVMUtils.pm
@@ -65,6 +65,10 @@ sub default_storagemodel {
An x86_64 guest that asks for efi moves to q35, because every x86_64 OVMF descriptor
targets pc-q35-* only. q35 has no IDE controller, so its disks and its optical drive
move to scsi.
+
+ efi-secureboot also sets secureboot, which guest_os turns into the requirement
+ libvirt reads. efi alone states no requirement, so libvirt takes the descriptor of
+ highest priority that fits the guest, and that order belongs to the hypervisor.
Arguments:
$guest_arch - nodetype.arch of the node, or undef
$hyp_cpumodel - the cpumodel of the hypervisor, or undef
@@ -82,6 +86,7 @@ sub guest_arch_profile {
arch => undef,
machine => undef,
firmware => undef,
+ secureboot => 0,
cpu_mode => undef,
cpu_model => undef,
pseries => 0,
@@ -130,12 +135,15 @@ sub guest_arch_profile {
$profile{bios} = 0;
$profile{sound} = 0;
}
- if (defined($firmware) and $firmware eq 'efi' and not defined $profile{firmware}) {
- $profile{firmware} = 'efi';
- if ($profile{x86_features}) {
- $profile{machine} = 'q35';
- $profile{disk_model} = 'scsi';
- $profile{cd_prefix} = 'sd';
+ if (defined($firmware) and $firmware =~ /^efi(?:-secureboot)?$/) {
+ $profile{secureboot} = 1 if $firmware eq 'efi-secureboot';
+ unless (defined $profile{firmware}) {
+ $profile{firmware} = 'efi';
+ if ($profile{x86_features}) {
+ $profile{machine} = 'q35';
+ $profile{disk_model} = 'scsi';
+ $profile{cd_prefix} = 'sd';
+ }
}
}
return \%profile;
@@ -433,6 +441,8 @@ sub vm_othersettings {
Descriptions:
The firmware a node asks for in vm.othersettings. No node asks by default, so an
existing guest keeps the firmware of its machine type.
+
+ efi asks for UEFI. efi-secureboot asks for UEFI that verifies what it boots.
Arguments:
$othersettings - vm.othersettings of the node, or undef
Returns:
@@ -456,20 +466,21 @@ sub requested_firmware {
Descriptions:
The refusal of a firmware value that libvirt cannot select. A node with a typo must
- not stay on SeaBIOS without a message.
+ not stay on SeaBIOS without a message, nor lose a Secure Boot requirement it asked
+ for.
Arguments:
$firmware - the value from requested_firmware, or undef
$node - the node name
Returns:
- the error message, or undef when the value is efi or undef
+ the error message, or undef when the value is efi, efi-secureboot or undef
=cut
#-------------------------------------------------------
sub firmware_error {
my ($firmware, $node) = @_;
- return undef if !defined($firmware) or $firmware eq 'efi';
- return "vm.othersettings firmware:$firmware names no firmware libvirt can select for $node. Use firmware:efi.";
+ return undef if !defined($firmware) or $firmware =~ /^efi(?:-secureboot)?$/;
+ return "vm.othersettings firmware:$firmware names no firmware libvirt can select for $node. Use firmware:efi or firmware:efi-secureboot.";
}
#-------------------------------------------------------
@@ -481,6 +492,12 @@ sub firmware_error {
A ppc64le hypervisor gets no . A profile without bios drops it too.
A machine type from vm.othersettings replaces the machine type of the profile.
+
+ A profile with secureboot states . libvirt reads it while it
+ selects the firmware and keeps only the descriptors that carry secure-boot, so a
+ hypervisor with no such firmware refuses the domain. Without the element the guest
+ takes whichever firmware the hypervisor prefers, and the domain says nothing about
+ whether that firmware verifies what it boots.
Arguments:
$profile - the hash reference from guest_arch_profile
%args - hyp_cpumodel: the cpumodel of the hypervisor; bootorder: vm.bootorder of the
@@ -508,6 +525,7 @@ sub guest_os {
$os{type}->{arch} = $profile->{arch} if defined $profile->{arch};
$os{type}->{machine} = $profile->{machine} if defined $profile->{machine};
$os{firmware} = $profile->{firmware} if defined $profile->{firmware};
+ $os{loader}->{secure} = 'yes' if $profile->{secureboot};
delete $os{bios} unless $profile->{bios};
$os{type}->{machine} = $args{machine} if defined $args{machine};
return \%os;
diff --git a/xCAT-server/lib/xcat/plugins/kvm.pm b/xCAT-server/lib/xcat/plugins/kvm.pm
index 73cefeaefe..ce0db53e47 100644
--- a/xCAT-server/lib/xcat/plugins/kvm.pm
+++ b/xCAT-server/lib/xcat/plugins/kvm.pm
@@ -642,7 +642,7 @@ sub build_xmldesc {
#memory binding: "membind:"
#cpu mode: "cpumode:"
#machine type: "machine:"
- #firmware: "firmware:efi"
+ #firmware: "firmware:efi" or "firmware:efi-secureboot"
if ($advsettings) {
my @tmp_array = split ";", $advsettings;
foreach (@tmp_array) {
From 687d2c15a6ef94a80e67f2cb32c6bdeba4f23e88 Mon Sep 17 00:00:00 2001
From: Daniel Hilst <392820+dhilst@users.noreply.github.com>
Date: Wed, 21 Oct 2026 16:37:04 -0300
Subject: [PATCH 03/18] test(xcattest): the harness tests stage one module by
name
xcattest_report_every_check.t and autotest_check_lines_are_understood.t
copy xcattest into a scratch tree and run it. Each copied
xCAT/Test/OS.pm by name, so a second module under xCAT-test/lib/xCAT
stops the copied xcattest before its first case, and the test reports
that as a harness error.
Both now copy every .pm under that directory.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
---
xCAT-test/unit/autotest_check_lines_are_understood.t | 9 +++++++--
xCAT-test/unit/xcattest_report_every_check.t | 9 +++++++--
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/xCAT-test/unit/autotest_check_lines_are_understood.t b/xCAT-test/unit/autotest_check_lines_are_understood.t
index 40b6ea3175..5d7a278a64 100644
--- a/xCAT-test/unit/autotest_check_lines_are_understood.t
+++ b/xCAT-test/unit/autotest_check_lines_are_understood.t
@@ -3,6 +3,7 @@ use strict;
use warnings;
use File::Copy qw(copy);
+use File::Basename qw(basename);
use File::Find qw(find);
use File::Path qw(make_path);
use File::Temp qw(tempdir);
@@ -57,8 +58,12 @@ my $root = tempdir(CLEANUP => 1);
make_path("$root/bin", "$root/cases", "$root/lib/perl/xCAT/Test");
copy($program, "$root/bin/xcattest") or die("copy xcattest: $!");
chmod 0755, "$root/bin/xcattest";
-copy("$FindBin::Bin/../lib/xCAT/Test/OS.pm", "$root/lib/perl/xCAT/Test/OS.pm")
- or die("copy xCAT/Test/OS.pm: $!");
+# Every module under xCAT-test/lib/xCAT, because xcattest loads them from lib/perl beside its
+# own directory and a missing one stops it before the first case.
+foreach my $module (glob("$FindBin::Bin/../lib/xCAT/Test/*.pm")) {
+ my $name = basename($module);
+ copy($module, "$root/lib/perl/xCAT/Test/$name") or die("copy xCAT/Test/$name: $!");
+}
open(my $fixture_fh, '>', "$root/cases/fixture") or die("write the fixture case: $!");
print $fixture_fh $fixture;
close($fixture_fh) or die("close the fixture case: $!");
diff --git a/xCAT-test/unit/xcattest_report_every_check.t b/xCAT-test/unit/xcattest_report_every_check.t
index 44372e9f4e..69336fcc71 100644
--- a/xCAT-test/unit/xcattest_report_every_check.t
+++ b/xCAT-test/unit/xcattest_report_every_check.t
@@ -4,6 +4,7 @@ use warnings;
use FindBin;
use File::Copy qw(copy);
+use File::Basename qw(basename);
use File::Path qw(make_path);
use File::Temp qw(tempdir);
use Test::More;
@@ -31,8 +32,12 @@ sub run_harness {
make_path("$root/bin", "$root/cases", "$root/lib/perl/xCAT/Test");
copy($program, "$root/bin/xcattest") or die("copy xcattest: $!");
chmod 0755, "$root/bin/xcattest";
- copy("$FindBin::Bin/../lib/xCAT/Test/OS.pm", "$root/lib/perl/xCAT/Test/OS.pm")
- or die("copy xCAT/Test/OS.pm: $!");
+ # Every module under xCAT-test/lib/xCAT, because xcattest loads them from lib/perl beside
+ # its own directory and a missing one stops it before the first case.
+ foreach my $module (glob("$FindBin::Bin/../lib/xCAT/Test/*.pm")) {
+ my $name = basename($module);
+ copy($module, "$root/lib/perl/xCAT/Test/$name") or die("copy xCAT/Test/$name: $!");
+ }
open(my $case_fh, '>', "$root/cases/fixture") or die("write the fixture case: $!");
print $case_fh $case_text;
From b5181574eaccc36966c47e686266bdf71c72baef Mon Sep 17 00:00:00 2001
From: Daniel Hilst <392820+dhilst@users.noreply.github.com>
Date: Wed, 21 Oct 2026 16:39:24 -0300
Subject: [PATCH 04/18] test(xcattest): a conf cannot set a vm.othersettings
with two settings
An [Object_*] line of an xcattest conf declares an xCAT node attribute.
vm.othersettings holds several settings separated by a semicolon, which
is the syntax the kvm plugin reads, and such a line reaches the node cut
at its first semicolon with no message. The reader drops the rest, and
the chdef that applies it runs through /bin/bash -c unquoted, so the
shell would read the semicolon as a command separator.
load_config_file read each line with a regular expression written inline
and built the chdef by concatenation, so neither could be measured
without a database. xCAT::Test::Conf now holds the three readers and the
command builder, and xcattest calls them. The routines keep the behaviour
they replace, and both packages install the module.
xcattest_conf_object_attr.t fails five of its nine checks on this commit:
the semicolon value, the quoting and the order of the assignments.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
---
xCAT-test/debian/install | 1 +
xCAT-test/lib/xCAT/Test/Conf.pm | 109 +++++++++++++++++++++
xCAT-test/unit/xcattest_conf_object_attr.t | 66 +++++++++++++
xCAT-test/xCAT-test.spec | 2 +
xCAT-test/xcattest | 19 ++--
5 files changed, 185 insertions(+), 12 deletions(-)
create mode 100644 xCAT-test/lib/xCAT/Test/Conf.pm
create mode 100644 xCAT-test/unit/xcattest_conf_object_attr.t
diff --git a/xCAT-test/debian/install b/xCAT-test/debian/install
index 14a97a1eba..5510397e7a 100644
--- a/xCAT-test/debian/install
+++ b/xCAT-test/debian/install
@@ -7,3 +7,4 @@ unit opt/xcat/share/xcat/tools/autotest
integration opt/xcat/share/xcat/tools/autotest
blackboxtest opt/xcat/share/xcat/tools/autotest
lib/xCAT/Test/OS.pm opt/xcat/lib/perl/xCAT/Test
+lib/xCAT/Test/Conf.pm opt/xcat/lib/perl/xCAT/Test
diff --git a/xCAT-test/lib/xCAT/Test/Conf.pm b/xCAT-test/lib/xCAT/Test/Conf.pm
new file mode 100644
index 0000000000..fc02d2bc06
--- /dev/null
+++ b/xCAT-test/lib/xCAT/Test/Conf.pm
@@ -0,0 +1,109 @@
+package xCAT::Test::Conf;
+
+use strict;
+use warnings;
+
+#-------------------------------------------------------------------------------
+
+=head1 NAME
+
+xCAT::Test::Conf - the lines and commands of an xcattest configuration file
+
+=head1 DESCRIPTION
+
+xcattest reads a configuration file and applies its [Object_*] and [Table_*] blocks to the
+xCAT database before the first case runs. The routines here read one line of such a block and
+build the command that applies it. Each one takes its input and returns its answer, so the
+reader and the command can be measured without a database.
+
+=cut
+
+#-------------------------------------------------------------------------------
+
+=head3 object_attr
+
+ Descriptions:
+ The attribute and value of one line of an [Object_*] block.
+ Arguments:
+ $line - the line, with or without leading whitespace
+ Returns:
+ ($attr, $value), or the empty list when the line holds no assignment
+
+=cut
+
+#-------------------------------------------------------------------------------
+sub object_attr {
+ my ($line) = @_;
+ return () unless defined $line;
+ return ($1, $2) if $line =~ /(\w+)\s*=\s*([:,\w\.\-\/]+)/;
+ return ();
+}
+
+#-------------------------------------------------------------------------------
+
+=head3 table_attr
+
+ Descriptions:
+ The attribute and value of one line of a [Table_*] block.
+ Arguments:
+ $line - the line, with or without leading whitespace
+ Returns:
+ ($attr, $value), or the empty list when the line holds no assignment
+
+=cut
+
+#-------------------------------------------------------------------------------
+sub table_attr {
+ my ($line) = @_;
+ return () unless defined $line;
+ return ($1, $2) if $line =~ /(\w+)\s*=\s*([\w\.\-]+)/;
+ return ();
+}
+
+#-------------------------------------------------------------------------------
+
+=head3 var_attr
+
+ Descriptions:
+ The name and value of one line of the [System] or [Custom] block.
+ Arguments:
+ $line - the line, with or without leading whitespace
+ Returns:
+ ($name, $value), or the empty list when the line holds no assignment
+
+=cut
+
+#-------------------------------------------------------------------------------
+sub var_attr {
+ my ($line) = @_;
+ return () unless defined $line;
+ return ($1, $2) if $line =~ /(\w+)\s*=\s*([\w\.\-\+\ \/:]+)/;
+ return ();
+}
+
+#-------------------------------------------------------------------------------
+
+=head3 chdef_command
+
+ Descriptions:
+ The chdef command that applies one object of an [Object_*] block.
+ Arguments:
+ $type - the object type, as the section name spells it
+ $name - the object name
+ $attrs - a hash reference of attribute to value
+ Returns:
+ the command
+
+=cut
+
+#-------------------------------------------------------------------------------
+sub chdef_command {
+ my ($type, $name, $attrs) = @_;
+ my $cmd = "chdef -t $type -o $name";
+ foreach my $attr (keys %$attrs) {
+ $cmd .= " $attr=$attrs->{$attr}";
+ }
+ return $cmd;
+}
+
+1;
diff --git a/xCAT-test/unit/xcattest_conf_object_attr.t b/xCAT-test/unit/xcattest_conf_object_attr.t
new file mode 100644
index 0000000000..f083536dfe
--- /dev/null
+++ b/xCAT-test/unit/xcattest_conf_object_attr.t
@@ -0,0 +1,66 @@
+#!/usr/bin/env perl
+# The [Object_*] blocks of an xcattest conf declare xCAT node attributes, and xcattest applies
+# them with chdef. vm.othersettings holds several settings separated by a semicolon, which is the
+# syntax the kvm plugin reads:
+#
+# vmothersetting=cpumode:host-passthrough;firmware:efi-secureboot
+#
+# Two things have to hold for that line to reach the node. The reader has to keep the whole
+# value, and the chdef command has to quote it, because xcattest runs every command through
+# /bin/bash -c and an unquoted semicolon ends the command there.
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/../lib";
+use Test::More;
+
+require xCAT::Test::Conf;
+
+# The reader keeps every setting of a multi-setting value.
+is_deeply(
+ [ xCAT::Test::Conf::object_attr(' vmothersetting=cpumode:host-passthrough;firmware:efi-secureboot') ],
+ [ 'vmothersetting', 'cpumode:host-passthrough;firmware:efi-secureboot' ],
+ 'an [Object_*] value keeps the settings after its first semicolon'
+);
+
+# The values the reader already took stay as they are.
+is_deeply(
+ [ xCAT::Test::Conf::object_attr(' vmnics=virbr-p147,virbr-p147,virbr-p147') ],
+ [ 'vmnics', 'virbr-p147,virbr-p147,virbr-p147' ],
+ 'a comma-separated value is unchanged'
+);
+is_deeply(
+ [ xCAT::Test::Conf::object_attr(' vmstorage=dir:///var/lib/libvirt/images/') ],
+ [ 'vmstorage', 'dir:///var/lib/libvirt/images/' ],
+ 'a value with a colon and slashes is unchanged'
+);
+is_deeply( [ xCAT::Test::Conf::object_attr('Name=xcat147-cn-tmp-243') ],
+ [ 'Name', 'xcat147-cn-tmp-243' ], 'the Name line is read like any other attribute' );
+is_deeply( [ xCAT::Test::Conf::object_attr('this line has no equals sign') ],
+ [], 'a line with no assignment yields no attribute' );
+
+# chdef runs under /bin/bash -c, so each assignment is quoted. Without the quoting the shell
+# reads the semicolon as a command separator and chdef gets half the value.
+my $cmd = xCAT::Test::Conf::chdef_command( 'node', 'cn1',
+ { vmothersetting => 'cpumode:host-passthrough;firmware:efi-secureboot' } );
+like( $cmd, qr/^chdef -t 'node' -o 'cn1' /, 'chdef_command names the type and the object' );
+like(
+ $cmd,
+ qr/'vmothersetting=cpumode:host-passthrough;firmware:efi-secureboot'/,
+ 'and quotes the assignment, so bash does not read the semicolon as a command separator'
+);
+
+# A single quote inside a value must not end the quoting.
+like(
+ xCAT::Test::Conf::chdef_command( 'node', 'cn1', { usercomment => "it's here" } ),
+ qr/'usercomment=it'\\''s here'/,
+ 'a single quote in a value is escaped inside the quoted assignment'
+);
+
+# The order of the assignments is fixed, so two runs of one conf build the same command.
+is( xCAT::Test::Conf::chdef_command( 'node', 'cn1', { b => '2', a => '1', c => '3' } ),
+ "chdef -t 'node' -o 'cn1' 'a=1' 'b=2' 'c=3'",
+ 'the assignments are sorted by attribute name' );
+
+done_testing();
diff --git a/xCAT-test/xCAT-test.spec b/xCAT-test/xCAT-test.spec
index 6c1d859820..abb562554f 100644
--- a/xCAT-test/xCAT-test.spec
+++ b/xCAT-test/xCAT-test.spec
@@ -63,7 +63,9 @@ cp xcattest $RPM_BUILD_ROOT/%{prefix}/bin
chmod 755 $RPM_BUILD_ROOT/%{prefix}/bin/*
cp lib/xCAT/Test/OS.pm $RPM_BUILD_ROOT/%{prefix}/lib/perl/xCAT/Test
+cp lib/xCAT/Test/Conf.pm $RPM_BUILD_ROOT/%{prefix}/lib/perl/xCAT/Test
chmod 644 $RPM_BUILD_ROOT/%{prefix}/lib/perl/xCAT/Test/OS.pm
+chmod 644 $RPM_BUILD_ROOT/%{prefix}/lib/perl/xCAT/Test/Conf.pm
cp restapitest $RPM_BUILD_ROOT/%{prefix}/sbin
chmod 755 $RPM_BUILD_ROOT/%{prefix}/sbin/*
diff --git a/xCAT-test/xcattest b/xCAT-test/xcattest
index a424ec6f1f..7a9d9da963 100755
--- a/xCAT-test/xcattest
+++ b/xCAT-test/xcattest
@@ -17,6 +17,7 @@ BEGIN
}
use lib "$::XCATROOT/lib/perl";
use xCAT::Test::OS;
+use xCAT::Test::Conf;
#--------------global attributes----------------
my $program_path = dirname(File::Spec->rel2abs(__FILE__));
@@ -814,9 +815,7 @@ sub load_config_file {
$type = "Varible";
} elsif ($type eq "Table") {
##TABLE BLOCK##
- if ($line =~ /(\w+)\s*=\s*([\w\.\-]+)/) {
- $attr = $1;
- $value = $2;
+ if ((($attr, $value) = xCAT::Test::Conf::table_attr($line)) == 2) {
if ($name && ($$config_ref{table}{$sub_type}{$name}{__KEY__} ne $attr)) {
$$config_ref{table}{$sub_type}{$name}{$attr} = $value;
} else {
@@ -826,9 +825,7 @@ sub load_config_file {
}
} elsif ($type eq "Object") {
##OBJECT BLOCK##
- if ($line =~ /(\w+)\s*=\s*([:,\w\.\-\/]+)/) {
- $attr = $1;
- $value = $2;
+ if ((($attr, $value) = xCAT::Test::Conf::object_attr($line)) == 2) {
if ($attr eq "Name") {
$name = $value;
} elsif (!defined($name)) {
@@ -851,8 +848,8 @@ sub load_config_file {
}
} elsif ($type eq "Varible") {
##NODE_BLOCK##
- if ($line =~ /(\w+)\s*=\s*([\w\.\-\+\ \/:]+)/) {
- $$config_ref{var}{$1} = $2;
+ if ((my ($var, $val) = xCAT::Test::Conf::var_attr($line)) == 2) {
+ $$config_ref{var}{$var} = $val;
}
}
}
@@ -1581,10 +1578,8 @@ sub setup_env_by_configure_file {
if (exists $$config_ref{object}) {
foreach my $type (keys %{ $$config_ref{object} }) {
foreach my $name (keys %{ $$config_ref{object}{$type} }) {
- $cmd = "chdef -t $type -o $name";
- foreach my $attr (keys %{ $$config_ref{object}{$type}{$name} }) {
- $cmd = $cmd . " $attr=$$config_ref{object}{$type}{$name}{$attr}";
- }
+ $cmd = xCAT::Test::Conf::chdef_command($type, $name,
+ $$config_ref{object}{$type}{$name});
log_this($running_log_fd, "$cmd");
runcmd($cmd);
if ($::RUNCMD_RC != 0) {
From 6e0b113edf41a287701558247639b0af960aca17 Mon Sep 17 00:00:00 2001
From: Daniel Hilst <392820+dhilst@users.noreply.github.com>
Date: Wed, 21 Oct 2026 16:39:25 -0300
Subject: [PATCH 05/18] fix(xcattest): an [Object_*] value stops at its first
semicolon
A conf that declares vmothersetting=cpumode:host-passthrough;firmware:efi
reaches the node as vmothersetting=cpumode:host-passthrough. The value
class of object_attr held no semicolon, so the reader kept the characters
up to it and dropped the rest without a message. vm.othersettings
separates its settings with a semicolon, so no conf could set two of them.
object_attr now keeps the semicolon, and chdef_command quotes every word
it takes from the conf. The quoting is what makes the semicolon safe:
xcattest runs each command through /bin/bash -c, where an unquoted
semicolon ends the command. chdef_command also sorts the assignments, so
one conf builds one command.
xcattest_conf_object_attr.t covers both halves.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
---
xCAT-test/lib/xCAT/Test/Conf.pm | 42 +++++++++++++++++++++++++++++----
1 file changed, 37 insertions(+), 5 deletions(-)
diff --git a/xCAT-test/lib/xCAT/Test/Conf.pm b/xCAT-test/lib/xCAT/Test/Conf.pm
index fc02d2bc06..ca56c42b73 100644
--- a/xCAT-test/lib/xCAT/Test/Conf.pm
+++ b/xCAT-test/lib/xCAT/Test/Conf.pm
@@ -24,6 +24,9 @@ reader and the command can be measured without a database.
Descriptions:
The attribute and value of one line of an [Object_*] block.
+
+ The semicolon is in the value, because vm.othersettings separates its settings with
+ one. chdef_command quotes what this routine returns.
Arguments:
$line - the line, with or without leading whitespace
Returns:
@@ -35,7 +38,7 @@ reader and the command can be measured without a database.
sub object_attr {
my ($line) = @_;
return () unless defined $line;
- return ($1, $2) if $line =~ /(\w+)\s*=\s*([:,\w\.\-\/]+)/;
+ return ($1, $2) if $line =~ /(\w+)\s*=\s*([:,;\w\.\-\/]+)/;
return ();
}
@@ -87,6 +90,11 @@ sub var_attr {
Descriptions:
The chdef command that applies one object of an [Object_*] block.
+
+ xcattest runs every command through /bin/bash -c, so each word is quoted. A
+ vm.othersettings value carries a semicolon, which bash reads as a command separator.
+
+ The assignments are sorted, so one conf builds one command.
Arguments:
$type - the object type, as the section name spells it
$name - the object name
@@ -99,11 +107,35 @@ sub var_attr {
#-------------------------------------------------------------------------------
sub chdef_command {
my ($type, $name, $attrs) = @_;
- my $cmd = "chdef -t $type -o $name";
- foreach my $attr (keys %$attrs) {
- $cmd .= " $attr=$attrs->{$attr}";
+ my @words = ($type, $name);
+ foreach my $attr (sort keys %$attrs) {
+ my $value = defined $attrs->{$attr} ? $attrs->{$attr} : '';
+ push @words, "$attr=$value";
}
- return $cmd;
+ my ($qtype, $qname, @qattrs) = map { _quote($_) } @words;
+ return join ' ', 'chdef', '-t', $qtype, '-o', $qname, @qattrs;
+}
+
+#-------------------------------------------------------------------------------
+
+=head3 _quote
+
+ Descriptions:
+ One word of a command for /bin/bash -c. Single quotes stop the shell from reading any
+ character of the word, and a single quote inside the word closes and reopens them.
+ Arguments:
+ $word - the word
+ Returns:
+ the quoted word
+
+=cut
+
+#-------------------------------------------------------------------------------
+sub _quote {
+ my ($word) = @_;
+ $word = '' unless defined $word;
+ $word =~ s/'/'\\''/g;
+ return "'$word'";
}
1;
From 86f437d47549227b8e68ff24738982ad8be0fe0f Mon Sep 17 00:00:00 2001
From: Daniel Hilst <392820+dhilst@users.noreply.github.com>
Date: Wed, 21 Oct 2026 17:10:28 -0300
Subject: [PATCH 06/18] fix(copycds): the web server cannot read the EFI
binaries of the media
A node with netboot=ipxe and Secure Boot on fetches the shim of its
install source over HTTP, and the server answers 403. EL media ships the
EFI binaries of its boot loader mode 0700, copycds copies the media with
the modes the media carries, and xCAT serves the install directory over
HTTP. Measured on an AlmaLinux 10 tree: EFI/BOOT/grub.cfg is 0444 and
answers 200, and BOOTX64.EFI, grubx64.efi and mmx64.efi are 0700 and
answer 403. The node reports "Verification failed: Security Policy
Violation" for its kernel and then "Operation not permitted" for the
shim, and boots nothing.
copycd gave the top directory of the copy mode 0755 and left every path
under it as the media had it. Both copycd plugins now call
xCAT::MediaPerms::make_readable on the copied tree, which adds read
permission for the group and for others, and search permission on a
directory. It adds no write permission, it adds no execute permission to
a file, and it leaves a path that is already group and other readable
alone, so a second call changes nothing.
On the same AlmaLinux 10 tree it walks 5850 paths, 5835 files and 15
directories, and changes 3 of them: the three files above, each from 0700
to 0744. An install tree that is already copied keeps its modes until
copycds runs again for that osimage, so an operator with an existing tree
re-runs copycds or gives those files read permission.
media_perms_readable.t covers the modes and the idempotence. Three
mutations of the module each turn it red.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
---
perl-xCAT/xCAT/MediaPerms.pm | 89 ++++++++++++++++++++++++
xCAT-server/lib/xcat/plugins/anaconda.pm | 6 ++
xCAT-server/lib/xcat/plugins/debian.pm | 5 ++
xCAT-test/unit/media_perms_readable.t | 67 ++++++++++++++++++
4 files changed, 167 insertions(+)
create mode 100644 perl-xCAT/xCAT/MediaPerms.pm
create mode 100644 xCAT-test/unit/media_perms_readable.t
diff --git a/perl-xCAT/xCAT/MediaPerms.pm b/perl-xCAT/xCAT/MediaPerms.pm
new file mode 100644
index 0000000000..ce3f06a278
--- /dev/null
+++ b/perl-xCAT/xCAT/MediaPerms.pm
@@ -0,0 +1,89 @@
+package xCAT::MediaPerms;
+
+use strict;
+use warnings;
+
+use File::Find ();
+
+#-------------------------------------------------------------------------------
+
+=head1 NAME
+
+xCAT::MediaPerms - the modes of a copied install tree
+
+=head1 DESCRIPTION
+
+xCAT serves the install directory over HTTP, and copycds copies the media with the modes the
+media carries. EL media ships the EFI binaries of its boot loader mode 0700, so the web server
+cannot read them and a node that fetches one over HTTP is answered 403.
+
+=cut
+
+#-------------------------------------------------------------------------------
+
+=head3 readable_mode
+
+ Descriptions:
+ The mode one path needs so that the web server can read it.
+
+ Read permission for the group and for others. A directory also needs search
+ permission, because a mode without it hides the files under it. No write permission,
+ and no execute permission on a file that has none.
+ Arguments:
+ $mode - the current mode, as stat reports it
+ $is_dir - true for a directory
+ Returns:
+ the new mode, or undef when the path needs no change
+
+=cut
+
+#-------------------------------------------------------------------------------
+sub readable_mode {
+ my ($mode, $is_dir) = @_;
+ return undef unless defined $mode;
+ $mode &= 07777;
+ my $wanted = $mode | 0044;
+ $wanted |= 0011 if $is_dir;
+ return undef if $wanted == $mode;
+ return $wanted;
+}
+
+#-------------------------------------------------------------------------------
+
+=head3 make_readable
+
+ Descriptions:
+ Give every path under one directory the mode readable_mode names. The directory
+ itself is included.
+ Arguments:
+ $dir - the directory, which need not exist
+ Returns:
+ the number of paths whose mode changed
+
+=cut
+
+#-------------------------------------------------------------------------------
+sub make_readable {
+ my ($dir) = @_;
+ return 0 unless defined($dir) and -d $dir;
+
+ my $changed = 0;
+ File::Find::find(
+ {
+ no_chdir => 1,
+ wanted => sub {
+ my $path = $File::Find::name;
+ # A symbolic link carries no mode of its own, and chmod would follow it out of
+ # the tree.
+ return if -l $path;
+ my @st = stat $path or return;
+ my $new = readable_mode($st[2], -d _) or return;
+ $changed++ if chmod $new, $path;
+ },
+ },
+ $dir
+ );
+ return $changed;
+}
+
+1;
diff --git a/xCAT-server/lib/xcat/plugins/anaconda.pm b/xCAT-server/lib/xcat/plugins/anaconda.pm
index 8057490eb2..9200a8b594 100644
--- a/xCAT-server/lib/xcat/plugins/anaconda.pm
+++ b/xCAT-server/lib/xcat/plugins/anaconda.pm
@@ -19,6 +19,7 @@ use xCAT::MsgUtils;
use xCAT::SvrUtils;
use xCAT::UFTP;
use xCAT::Yum;
+use xCAT::MediaPerms;
use Getopt::Long;
Getopt::Long::Configure("bundling");
@@ -2613,6 +2614,11 @@ sub copycd
#my $rc = system("cd $path;rsync -a . $installroot/$distname/$arch/");
chmod 0755, "$path";
+ # The media carries its own modes, and EL media ships the EFI binaries of its boot loader
+ # mode 0700. xCAT serves the install directory over HTTP, so the web server answers 403 for
+ # one, and a node with Secure Boot on cannot fetch the shim that verifies its kernel.
+ xCAT::MediaPerms::make_readable($path);
+
#append the fingerprint to the .fingerprint file to indicate that the os media has been copied in
unless ($disccopiedin)
{
diff --git a/xCAT-server/lib/xcat/plugins/debian.pm b/xCAT-server/lib/xcat/plugins/debian.pm
index 1b93307d0b..7145e63562 100644
--- a/xCAT-server/lib/xcat/plugins/debian.pm
+++ b/xCAT-server/lib/xcat/plugins/debian.pm
@@ -10,6 +10,7 @@ use Storable qw(dclone);
use Sys::Syslog;
use File::Temp qw/tempdir/;
use xCAT::Table;
+use xCAT::MediaPerms;
use xCAT::Utils;
use xCAT::SvrUtils;
use xCAT::UFTP;
@@ -673,6 +674,10 @@ sub copycd
# );
chmod 0755, "$installroot/$distname/$arch";
+ # The media carries its own modes. xCAT serves the install directory over HTTP, so a file
+ # the web server cannot read is answered 403 and the node that fetches it cannot boot.
+ xCAT::MediaPerms::make_readable("$installroot/$distname/$arch");
+
# Need to do this otherwise there will be warning about corrupt Packages file
# when installing a system
diff --git a/xCAT-test/unit/media_perms_readable.t b/xCAT-test/unit/media_perms_readable.t
new file mode 100644
index 0000000000..00a659acfd
--- /dev/null
+++ b/xCAT-test/unit/media_perms_readable.t
@@ -0,0 +1,67 @@
+#!/usr/bin/env perl
+# copycds copies the install media with the modes the media carries. EL media ships the EFI
+# binaries of its boot loader mode 0700, and xCAT serves /install over HTTP, so the web server
+# cannot read them. Measured on an AlmaLinux 10 tree copied by copycds: EFI/BOOT/grub.cfg is
+# 0444 and answers 200, EFI/BOOT/BOOTX64.EFI and EFI/BOOT/mmx64.efi are 0700 and answer 403.
+#
+# make_readable adds read permission for the group and for others, and search permission on a
+# directory. It never adds write permission, and it never adds execute permission to a file.
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/../../perl-xCAT";
+use File::Path qw(make_path);
+use File::Temp qw(tempdir);
+use Test::More;
+
+my %before = %INC;
+require xCAT::MediaPerms;
+my @xcat_loaded = sort grep { m{^xCAT} and !exists $before{$_} } keys %INC;
+is_deeply( \@xcat_loaded, ['xCAT/MediaPerms.pm'], 'xCAT::MediaPerms loads no other xCAT module' );
+
+sub mode_of {
+ my ($path) = @_;
+ return sprintf '%04o', ( ( stat $path )[2] & 07777 );
+}
+
+my $root = tempdir( CLEANUP => 1 );
+make_path("$root/EFI/BOOT/fonts");
+foreach my $file (qw(EFI/BOOT/BOOTX64.EFI EFI/BOOT/mmx64.efi EFI/BOOT/grub.cfg EFI/BOOT/fonts/unicode.pf2)) {
+ open my $fh, '>', "$root/$file" or die "write $file: $!";
+ print $fh 'x';
+ close $fh or die "close $file: $!";
+}
+chmod 0700, "$root/EFI/BOOT/BOOTX64.EFI", "$root/EFI/BOOT/mmx64.efi";
+chmod 0444, "$root/EFI/BOOT/grub.cfg";
+chmod 0600, "$root/EFI/BOOT/fonts/unicode.pf2";
+chmod 0700, "$root/EFI/BOOT/fonts";
+
+my $changed = xCAT::MediaPerms::make_readable("$root/EFI");
+
+is( mode_of("$root/EFI/BOOT/BOOTX64.EFI"), '0744',
+ 'a boot loader the media ships 0700 becomes readable, and keeps its owner execute bit' );
+is( mode_of("$root/EFI/BOOT/mmx64.efi"), '0744', 'and so does the MOK manager beside it' );
+is( mode_of("$root/EFI/BOOT/fonts/unicode.pf2"), '0644',
+ 'a file with no execute bit stays without one' );
+is( mode_of("$root/EFI/BOOT/fonts"), '0755',
+ 'a directory the media ships 0700 gains search permission, so the files under it can be read' );
+is( mode_of("$root/EFI/BOOT/grub.cfg"), '0444', 'a file that is already readable is left alone' );
+is( $changed, 4, 'make_readable reports the number of paths it changed' );
+
+is( xCAT::MediaPerms::make_readable("$root/EFI"), 0,
+ 'a second call changes nothing, so copycds can be re-run' );
+
+is( xCAT::MediaPerms::make_readable("$root/no-such-directory"), 0,
+ 'a directory that does not exist changes nothing' );
+
+# No write permission is ever added. /install holds the media of every osimage on the
+# management node.
+my $writable = tempdir( CLEANUP => 1 );
+open my $fh, '>', "$writable/kernel" or die "write kernel: $!";
+close $fh or die "close kernel: $!";
+chmod 0700, "$writable/kernel";
+xCAT::MediaPerms::make_readable($writable);
+is( mode_of("$writable/kernel"), '0744', 'the file is readable and writable by its owner alone' );
+
+done_testing();
From 242cff9c1c60c98b1b847b8e24f6f1d2f2a84cfa Mon Sep 17 00:00:00 2001
From: Daniel Hilst <392820+dhilst@users.noreply.github.com>
Date: Wed, 21 Oct 2026 17:55:15 -0300
Subject: [PATCH 07/18] fix(kvm): a machine type of vm.othersettings takes a
UEFI node to i440fx
guest_arch_profile moves an x86_64 node that asks for efi to q35, because
every x86_64 OVMF descriptor targets pc-q35-* only. guest_os then writes
a machine: setting of vm.othersettings over that machine type, so a node
with firmware:efi and machine:pc reaches libvirt asking for a UEFI
firmware on i440fx. libvirt answers "Unable to find 'efi' firmware that
is compatible with the current configuration" and names neither the node
nor either setting, and rpower boot fails with no way to see why.
firmware_machine_error refuses the pair, and build_xmldesc returns it
before the domain is built. The message names the node, both settings and
the machine type to use. A node that names no machine type, a q35 of any
version, and the machine types of another architecture are all unchanged.
kvm_secureboot_firmware.t covers the refusal and the five values that are
not refused.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
---
perl-xCAT/xCAT/KVMUtils.pm | 33 ++++++++++++++++++++++++
xCAT-server/lib/xcat/plugins/kvm.pm | 4 +++
xCAT-test/unit/kvm_secureboot_firmware.t | 23 +++++++++++++++++
3 files changed, 60 insertions(+)
diff --git a/perl-xCAT/xCAT/KVMUtils.pm b/perl-xCAT/xCAT/KVMUtils.pm
index e414c9a6f8..7e384078c5 100644
--- a/perl-xCAT/xCAT/KVMUtils.pm
+++ b/perl-xCAT/xCAT/KVMUtils.pm
@@ -485,6 +485,39 @@ sub firmware_error {
#-------------------------------------------------------
+=head3 firmware_machine_error
+
+ Descriptions:
+ The refusal of a machine type that cannot carry the firmware the node asks for.
+
+ Every x86_64 OVMF descriptor targets pc-q35-* only, and guest_os writes a machine:
+ setting of vm.othersettings over the machine type guest_arch_profile chose. Without
+ this refusal libvirt answers "Unable to find 'efi' firmware that is compatible with
+ the current configuration", which names neither the node nor either setting.
+
+ Only x86_64 is judged. Another architecture has one machine type for its firmware.
+ Arguments:
+ $firmware - the result of requested_firmware, or undef
+ $machine - the machine: setting of vm.othersettings, or undef
+ $arch - nodetype.arch of the node, or undef
+ $node - the node name
+ Returns:
+ the error message, or undef when the pair can boot
+
+=cut
+
+#-------------------------------------------------------
+sub firmware_machine_error {
+ my ($firmware, $machine, $arch, $node) = @_;
+ return undef unless defined($firmware) and defined($machine);
+ return undef unless defined($arch) and $arch eq 'x86_64';
+ return undef if $machine =~ /q35/;
+ return "vm.othersettings firmware:$firmware needs a q35 machine type, and $node names"
+ . " machine:$machine. Use machine:q35, or leave the machine type out.";
+}
+
+#-------------------------------------------------------
+
=head3 guest_os
Descriptions:
diff --git a/xCAT-server/lib/xcat/plugins/kvm.pm b/xCAT-server/lib/xcat/plugins/kvm.pm
index ce0db53e47..c7da387e00 100644
--- a/xCAT-server/lib/xcat/plugins/kvm.pm
+++ b/xCAT-server/lib/xcat/plugins/kvm.pm
@@ -674,6 +674,10 @@ sub build_xmldesc {
}
}
+ my $machine_error = xCAT::KVMUtils::firmware_machine_error($firmware, $machine_type,
+ $confdata->{nodetype}->{$node}->[0]->{arch}, $node);
+ return (-1, $machine_error) if $machine_error;
+
# Support VM machine types specified through vm.othersettings, e.g., q35, pseries-rhel7.4.0.
$xtree{os} = xCAT::KVMUtils::guest_os($profile,
hyp_cpumodel => $hypcpumodel,
diff --git a/xCAT-test/unit/kvm_secureboot_firmware.t b/xCAT-test/unit/kvm_secureboot_firmware.t
index 652d7b0a60..0cb9157e00 100644
--- a/xCAT-test/unit/kvm_secureboot_firmware.t
+++ b/xCAT-test/unit/kvm_secureboot_firmware.t
@@ -70,4 +70,27 @@ like( $error, qr/firmware:efi-secure\b/, 'a value that is not a firmware is refu
like( $error, qr/firmware:efi-secureboot/,
'and the refusal names firmware:efi-secureboot, so the typo can be corrected from it' );
+# vm.othersettings can name a machine type, and guest_os writes it over the one the profile
+# chose. An x86_64 node that asks for efi is moved to q35 by guest_arch_profile, because every
+# x86_64 OVMF descriptor targets pc-q35-* only, so a machine: setting naming i440fx takes the
+# node to a machine type no UEFI firmware fits. libvirt then answers "Unable to find 'efi'
+# firmware that is compatible with the current configuration", which names neither the node nor
+# either setting.
+my $conflict = xCAT::KVMUtils::firmware_machine_error( 'efi-secureboot', 'pc', 'x86_64', 'cn1' );
+like( $conflict, qr/\bcn1\b/, 'the refusal names the node' );
+like( $conflict, qr/firmware:efi-secureboot/, 'and the firmware the node asked for' );
+like( $conflict, qr/machine:pc\b/, 'and the machine type that cannot carry it' );
+like( $conflict, qr/q35/, 'and the machine type that can, so the conf can be corrected from it' );
+
+is( xCAT::KVMUtils::firmware_machine_error( 'efi-secureboot', 'q35', 'x86_64', 'cn1' ),
+ undef, 'q35 is not refused' );
+is( xCAT::KVMUtils::firmware_machine_error( 'efi', 'pc-q35-rhel9.4.0', 'x86_64', 'cn1' ),
+ undef, 'a versioned q35 is not refused' );
+is( xCAT::KVMUtils::firmware_machine_error( 'efi-secureboot', undef, 'x86_64', 'cn1' ),
+ undef, 'a node that names no machine type is not refused' );
+is( xCAT::KVMUtils::firmware_machine_error( undef, 'pc', 'x86_64', 'cn1' ),
+ undef, 'a node that asks for no firmware keeps i440fx' );
+is( xCAT::KVMUtils::firmware_machine_error( 'efi', 'virt', 'riscv64', 'cn1' ),
+ undef, 'the machine types of another architecture are not judged here' );
+
done_testing();
From 1ab2f68a32f386ea486dcddb5b256927ba578a40 Mon Sep 17 00:00:00 2001
From: Daniel Hilst <392820+dhilst@users.noreply.github.com>
Date: Wed, 21 Oct 2026 17:55:15 -0300
Subject: [PATCH 08/18] fix(xcattest): the diskless case takes a UEFI node to
i440fx
reg_linux_diskless_installation_flat asks vm_machine_type.sh for a valid
machine type, and the helper answers machine:pc for every x86_64 node. A
node with firmware:efi then cannot boot: libvirt refuses a UEFI firmware
on i440fx, rpower boot fails and the case reports a provision failure
that has nothing to do with provisioning.
vm_machine_type_for_arch now reads the vmothersetting it saved and
answers machine:q35 for an x86_64 node that asks for a UEFI firmware. An
x86_64 node without one still gets machine:pc.
vm_machine_type.bats covers both, and a mutation that answers machine:pc
for a UEFI node turns the two new tests red.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
---
.../testcase/commoncmd/vm_machine_type.sh | 12 +++++++++--
xCAT-test/bats/vm_machine_type.bats | 21 +++++++++++++++++++
2 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/xCAT-test/autotest/testcase/commoncmd/vm_machine_type.sh b/xCAT-test/autotest/testcase/commoncmd/vm_machine_type.sh
index 412a16c771..93b198aabd 100755
--- a/xCAT-test/autotest/testcase/commoncmd/vm_machine_type.sh
+++ b/xCAT-test/autotest/testcase/commoncmd/vm_machine_type.sh
@@ -33,11 +33,19 @@ vm_machine_type_private_dir()
fi
}
+# vm_machine_type_for_arch [] -- the machine type to apply.
+# An x86_64 node that asks for a UEFI firmware takes q35: every x86_64 OVMF descriptor targets
+# pc-q35-*, and libvirt refuses firmware efi on i440fx.
vm_machine_type_for_arch()
{
case "$1" in
ppc64*) echo 'machine:pseries-rhel7.6.0' ;;
- x86_64) echo 'machine:pc' ;;
+ x86_64)
+ case ";$2" in
+ *';firmware:efi'*) echo 'machine:q35' ;;
+ *) echo 'machine:pc' ;;
+ esac
+ ;;
riscv64) echo 'machine:virt' ;;
aarch64) echo 'machine:virt' ;;
*) return 1 ;;
@@ -109,7 +117,7 @@ vm_machine_type_apply()
chdef "$node" "vmothersetting=$original"
return
fi
- if ! machine="$(vm_machine_type_for_arch "$arch")"; then
+ if ! machine="$(vm_machine_type_for_arch "$arch" "$original")"; then
echo "vm_machine_type.sh: no machine type for arch '$arch'" >&2
return 1
fi
diff --git a/xCAT-test/bats/vm_machine_type.bats b/xCAT-test/bats/vm_machine_type.bats
index 22480c09ed..427393085e 100644
--- a/xCAT-test/bats/vm_machine_type.bats
+++ b/xCAT-test/bats/vm_machine_type.bats
@@ -79,6 +79,27 @@ assert_arch()
assert_arch x86_64 pc 'cpumode:host-passthrough'
}
+# An x86_64 node that asks for UEFI needs q35: every x86_64 OVMF descriptor targets pc-q35-*,
+# and libvirt refuses a domain that asks for firmware efi on i440fx with "Unable to find 'efi'
+# firmware that is compatible with the current configuration".
+@test "x86_64 with firmware:efi: the case sets and clears q35" {
+ assert_arch x86_64 q35 'firmware:efi'
+ assert_arch x86_64 q35 'cpumode:host-passthrough;firmware:efi'
+}
+
+@test "x86_64 with firmware:efi-secureboot: the case sets and clears q35" {
+ assert_arch x86_64 q35 'firmware:efi-secureboot'
+ assert_arch x86_64 q35 'cpumode:host-passthrough;firmware:efi-secureboot'
+}
+
+@test "x86_64 without a firmware: the case still sets pc" {
+ assert_arch x86_64 pc 'cpumode:host-passthrough'
+}
+
+@test "round trip: x86_64 with firmware:efi-secureboot" {
+ assert_round_trip x86_64 'cpumode:host-passthrough;firmware:efi-secureboot'
+}
+
@test "riscv64: the case sets and clears virt" {
assert_arch riscv64 virt ''
assert_arch riscv64 virt 'cpumode:host-passthrough'
From 1edcddab89261376cc5757775c40685a1d019d33 Mon Sep 17 00:00:00 2001
From: Daniel Hilst <392820+dhilst@users.noreply.github.com>
Date: Wed, 21 Oct 2026 19:14:19 -0300
Subject: [PATCH 09/18] fix(kvm): the firmware guard refuses a machine type
xCAT cannot judge
firmware_machine_error refused every machine type that did not contain
q35, so a node with firmware:efi and a machine type xCAT does not know
failed at mkvm. xCAT does not know which machine types a hypervisor
offers, and reg_linux_diskless_installation_flat relies on mkvm accepting
machine:invalid so that it can measure the provisioning failure that
follows. That case failed at the mkvm before it reached the measurement.
The guard now names the i440fx family alone: pc, pc-i440fx-* and
i440fx-*, whose descriptors carry no UEFI firmware. Any other value goes
to libvirt, which reports a machine type it cannot use.
kvm_secureboot_firmware.t covers both halves, and a mutation that
restores the q35 test turns the invalid-machine check red.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
---
perl-xCAT/xCAT/KVMUtils.pm | 6 ++++--
xCAT-test/unit/kvm_secureboot_firmware.t | 12 ++++++++++++
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/perl-xCAT/xCAT/KVMUtils.pm b/perl-xCAT/xCAT/KVMUtils.pm
index 7e384078c5..737dac1bf5 100644
--- a/perl-xCAT/xCAT/KVMUtils.pm
+++ b/perl-xCAT/xCAT/KVMUtils.pm
@@ -495,7 +495,9 @@ sub firmware_error {
this refusal libvirt answers "Unable to find 'efi' firmware that is compatible with
the current configuration", which names neither the node nor either setting.
- Only x86_64 is judged. Another architecture has one machine type for its firmware.
+ Only the i440fx family is judged, and only on x86_64. xCAT does not know which
+ machine types a hypervisor offers, so any other value goes to libvirt, which reports
+ a machine type it cannot use.
Arguments:
$firmware - the result of requested_firmware, or undef
$machine - the machine: setting of vm.othersettings, or undef
@@ -511,7 +513,7 @@ sub firmware_machine_error {
my ($firmware, $machine, $arch, $node) = @_;
return undef unless defined($firmware) and defined($machine);
return undef unless defined($arch) and $arch eq 'x86_64';
- return undef if $machine =~ /q35/;
+ return undef unless $machine eq 'pc' or $machine =~ /^(?:pc-)?i440fx/;
return "vm.othersettings firmware:$firmware needs a q35 machine type, and $node names"
. " machine:$machine. Use machine:q35, or leave the machine type out.";
}
diff --git a/xCAT-test/unit/kvm_secureboot_firmware.t b/xCAT-test/unit/kvm_secureboot_firmware.t
index 0cb9157e00..5ebe5e2ff6 100644
--- a/xCAT-test/unit/kvm_secureboot_firmware.t
+++ b/xCAT-test/unit/kvm_secureboot_firmware.t
@@ -82,8 +82,20 @@ like( $conflict, qr/firmware:efi-secureboot/, 'and the firmware the node asked f
like( $conflict, qr/machine:pc\b/, 'and the machine type that cannot carry it' );
like( $conflict, qr/q35/, 'and the machine type that can, so the conf can be corrected from it' );
+like( xCAT::KVMUtils::firmware_machine_error( 'efi', 'pc-i440fx-rhel10.0.0', 'x86_64', 'cn1' ),
+ qr/machine:pc-i440fx-rhel10\.0\.0/, 'a versioned i440fx is refused by name' );
+
is( xCAT::KVMUtils::firmware_machine_error( 'efi-secureboot', 'q35', 'x86_64', 'cn1' ),
undef, 'q35 is not refused' );
+
+# xCAT does not know which machine types a hypervisor offers, so it judges only the i440fx
+# family, whose descriptors carry no UEFI firmware. libvirt reports any other machine type it
+# cannot use, and reg_linux_diskless_installation_flat relies on mkvm accepting machine:invalid
+# so that it can measure the provisioning failure that follows.
+is( xCAT::KVMUtils::firmware_machine_error( 'efi-secureboot', 'invalid', 'x86_64', 'cn1' ),
+ undef, 'a machine type xCAT does not know is left to libvirt' );
+is( xCAT::KVMUtils::firmware_machine_error( 'efi', 'pc-q35-rhel10.2.0', 'x86_64', 'cn1' ),
+ undef, 'and so is a machine type that carries a UEFI firmware' );
is( xCAT::KVMUtils::firmware_machine_error( 'efi', 'pc-q35-rhel9.4.0', 'x86_64', 'cn1' ),
undef, 'a versioned q35 is not refused' );
is( xCAT::KVMUtils::firmware_machine_error( 'efi-secureboot', undef, 'x86_64', 'cn1' ),
From 789913b001c8901efef4e5cbd41d7afae6ca44d1 Mon Sep 17 00:00:00 2001
From: Daniel Hilst <392820+dhilst@users.noreply.github.com>
Date: Thu, 22 Oct 2026 06:52:12 -0300
Subject: [PATCH 10/18] docs(ipxe): say which kernels the ipxe path boots with
Secure Boot on
The Secure Boot chapter described the shim that each kind of node uses
and did not say which of them boots. A reader took the MOK paragraph for
a supported procedure, and an operator configuring discovery found
nothing about Secure Boot at all.
The chapter now states what the path supports: a node with netboot=ipxe
boots the kernel of a distribution with Secure Boot on, for a disk
installation and for a netboot image. Genesis requires Secure Boot off on
the node, because xCAT-genesis-base ships its kernel unsigned and a shim
verifies a kernel only against the signature database of the firmware or
a key in the MOK list. That covers discovery, the Genesis shell and the
standby and runcmd destinies. The section on clients without a node
definition names the same requirement and links to it.
A site may still sign the Genesis kernel with its own key and enroll it
with mokutil. xCAT ships no key and no signature.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
---
docs/source/advanced/ipxe/index.rst | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/docs/source/advanced/ipxe/index.rst b/docs/source/advanced/ipxe/index.rst
index 40df83bcb3..a77e4d70c8 100644
--- a/docs/source/advanced/ipxe/index.rst
+++ b/docs/source/advanced/ipxe/index.rst
@@ -36,6 +36,8 @@ An x86 client without a node definition, such as a node in discovery, gets the u
On a server that serves x86 discovery, ``makedhcp -n`` and ``makedhcp -a`` warn when an upstream loader file is missing from the local TFTP directory, or when ``xcat/ipxe/nets`` has no network boot script.
+A client in discovery boots the Genesis kernel, which carries no signature, so discovery requires Secure Boot off on the node. See `UEFI Secure Boot`_.
+
Move nodes to the ipxe method
-----------------------------
@@ -63,7 +65,14 @@ The signature database of the firmware does not hold the keys of a Linux distrib
iPXE fetches a shim only when it cannot load the kernel itself, so a node with Secure Boot off reads neither file.
-A shim also accepts a kernel that a MOK key signs. Nothing signs the Genesis kernel, so a node boots Genesis with Secure Boot on only after the site signs ``xcat/genesis.kernel.x86_64`` with its own key and enrolls that key with ``mokutil``. The discovery scripts under ``xcat/ipxe/nets`` name the shim of ``ipxe-xcat`` for that purpose.
+What this path supports
+~~~~~~~~~~~~~~~~~~~~~~~
+
+A node with ``netboot=ipxe`` boots the kernel of a distribution with Secure Boot on, for a disk installation and for a netboot image. The shim of the install source verifies that kernel.
+
+**Genesis requires Secure Boot off on the node.** ``xCAT-genesis-base`` ships ``xcat/genesis.kernel.x86_64`` unsigned, and a shim verifies a kernel only against the signature database of the firmware or a key in the MOK list. So a node that boots Genesis with Secure Boot on reports ``Verification failed: Security Policy Violation`` for the kernel, and the shim then stops in its own dialog. This covers node discovery, the Genesis shell, and the ``standby`` and ``runcmd`` destinies, which all boot that kernel. Turn Secure Boot off on a node for those tasks, and on again afterwards for a disk installation or a netboot image.
+
+A shim also accepts a kernel that a MOK key signs, so a site that signs ``xcat/genesis.kernel.x86_64`` with its own key and enrolls that key with ``mokutil`` boots Genesis with Secure Boot on. xCAT ships no key and no signature. The scripts under ``xcat/ipxe/nets`` name the shim of ``ipxe-xcat``, which reads the MOK list.
Two paths stay Secure Boot off. A kernel without an EFI stub boots through ``elilo-x64.efi``, and ESXi boots through ``esxboot-x64.efi``. No key signs either file. Boot these nodes with Secure Boot off.
From 94d2ce2cd595c4172e03daef0ae97be16826ba67 Mon Sep 17 00:00:00 2001
From: Daniel Hilst <392820+dhilst@users.noreply.github.com>
Date: Thu, 22 Oct 2026 10:11:49 -0300
Subject: [PATCH 11/18] fix(kvm): a Secure Boot domain can start on a firmware
with no enrolled keys
guest_os stated alone for a node with
vm.othersettings firmware:efi-secureboot. libvirt reads that element as
the secure-boot feature, and a firmware with secure-boot and an empty key
store boots an unsigned binary. The two x86_64 descriptors of an EL 10
host name the same OVMF_CODE.secboot.fd and differ in the nvram template,
OVMF_VARS.secboot.fd against OVMF_VARS.fd, so only descriptor priority
picked the one that holds keys. Commit 772b2c656 of this branch says that
element selects the descriptor with enrolled keys. It does not.
firmware_features names secure-boot and enrolled-keys for a Secure Boot
guest, and add_firmware_features writes them into the of the domain.
guest_os cannot carry the element: the firmware attribute of and the
child of are one key of one hash for XMLout, and the
attribute is the one that starts the selection. firmware:efi asks for no
feature and is unchanged.
Measured with libvirt 11.10.0 on an x86_64 host, with the enrolled
descriptor masked for one connection: the old XML starts on OVMF_VARS.fd
with enrolled-keys resolved to no, and the new XML is refused with
"Unable to find 'efi' firmware that is compatible with the current
configuration". virt-xml-validate accepts the new XML.
kvm_secureboot_firmware.t covers the features and the element. Two
mutations turn it red: dropping enrolled-keys from firmware_features, and
making add_firmware_features return its argument.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
---
perl-xCAT/xCAT/KVMUtils.pm | 84 ++++++++++++++++++++++--
xCAT-server/lib/xcat/plugins/kvm.pm | 3 +-
xCAT-test/unit/kvm_secureboot_firmware.t | 79 ++++++++++++++++++++--
3 files changed, 156 insertions(+), 10 deletions(-)
diff --git a/perl-xCAT/xCAT/KVMUtils.pm b/perl-xCAT/xCAT/KVMUtils.pm
index 737dac1bf5..6214737cb4 100644
--- a/perl-xCAT/xCAT/KVMUtils.pm
+++ b/perl-xCAT/xCAT/KVMUtils.pm
@@ -528,11 +528,12 @@ sub firmware_machine_error {
A ppc64le hypervisor gets no . A profile without bios drops it too.
A machine type from vm.othersettings replaces the machine type of the profile.
- A profile with secureboot states . libvirt reads it while it
- selects the firmware and keeps only the descriptors that carry secure-boot, so a
- hypervisor with no such firmware refuses the domain. Without the element the guest
- takes whichever firmware the hypervisor prefers, and the domain says nothing about
- whether that firmware verifies what it boots.
+ A profile with secureboot states . libvirt keeps only the
+ descriptors that carry the secure-boot feature while it selects the firmware, so a
+ hypervisor with no such firmware refuses the domain. The element says nothing about
+ the UEFI keys, so firmware_features asks for enrolled-keys beside it. Without the
+ element the guest takes whichever firmware the hypervisor prefers, and the domain
+ says nothing about whether that firmware verifies what it boots.
Arguments:
$profile - the hash reference from guest_arch_profile
%args - hyp_cpumodel: the cpumodel of the hypervisor; bootorder: vm.bootorder of the
@@ -568,6 +569,79 @@ sub guest_os {
#-------------------------------------------------------
+=head3 firmware_features
+
+ Descriptions:
+ The firmware autoselection features of one guest, in the form states them.
+
+ A guest with secureboot asks for secure-boot and for enrolled-keys. secure-boot names
+ a firmware that can verify what it boots. It does not name the UEFI keys that decide
+ what passes, and a firmware with secure-boot and no enrolled keys boots an unsigned
+ binary. The two x86_64 descriptors of an EL 10 host show the difference:
+ 30-edk2-ovmf-x64-sb-enrolled.json and 40-edk2-ovmf-x64-sb.json name the same
+ OVMF_CODE.secboot.fd and differ in the nvram template, OVMF_VARS.secboot.fd against
+ OVMF_VARS.fd. Only the first template holds keys.
+
+ libvirt reads as the secure-boot feature alone, and picks the
+ descriptor of highest priority that carries it. A host that ships the 40- descriptor
+ and not the 30- one satisfies that domain with an empty key store.
+ Arguments:
+ $profile - the hash reference from guest_arch_profile, or undef
+ Returns:
+ an array reference of { name, enabled } pairs, empty when the guest asks for none
+
+=cut
+
+#-------------------------------------------------------
+sub firmware_features {
+ my ($profile) = @_;
+ return [] unless ref($profile) eq 'HASH' and $profile->{secureboot};
+ return [
+ { name => 'secure-boot', enabled => 'yes' },
+ { name => 'enrolled-keys', enabled => 'yes' },
+ ];
+}
+
+#-------------------------------------------------------
+
+=head3 add_firmware_features
+
+ Descriptions:
+ Add with the features firmware_features names to the of one domain.
+
+ guest_os cannot carry this element. The firmware attribute of and the
+ child of are one key of one hash for XMLout, which writes a scalar as an
+ attribute and a reference as an element, so the hash holds one of the two. The
+ attribute is the one that starts the firmware selection.
+ Arguments:
+ $xml - the domain XML
+ $features - the array reference from firmware_features
+ Returns:
+ the new domain XML, or $xml when the guest asks for no feature
+
+=cut
+
+#-------------------------------------------------------
+sub add_firmware_features {
+ my ($xml, $features) = @_;
+ return $xml unless ref($features) eq 'ARRAY' and scalar(@$features);
+ require XML::LibXML;
+ my $domdesc = XML::LibXML->new()->parse_string($xml);
+ my ($os) = $domdesc->findnodes('/domain/os');
+ return $xml unless $os;
+ my $element = $domdesc->createElement('firmware');
+ foreach my $feature (@$features) {
+ my $child = $domdesc->createElement('feature');
+ $child->setAttribute('enabled', $feature->{enabled});
+ $child->setAttribute('name', $feature->{name});
+ $element->appendChild($child);
+ }
+ $os->appendChild($element);
+ return $domdesc->toString();
+}
+
+#-------------------------------------------------------
+
=head3 clock_offset
Descriptions:
diff --git a/xCAT-server/lib/xcat/plugins/kvm.pm b/xCAT-server/lib/xcat/plugins/kvm.pm
index c7da387e00..e0e70bff6e 100644
--- a/xCAT-server/lib/xcat/plugins/kvm.pm
+++ b/xCAT-server/lib/xcat/plugins/kvm.pm
@@ -889,7 +889,8 @@ sub build_xmldesc {
$xtree{devices}->{console}->{type} = 'pty';
$xtree{devices}->{console}->{target}->{port} = '1';
- return XMLout(\%xtree, RootName => "domain");
+ return xCAT::KVMUtils::add_firmware_features(XMLout(\%xtree, RootName => "domain"),
+ xCAT::KVMUtils::firmware_features($profile));
}
sub refresh_vm {
diff --git a/xCAT-test/unit/kvm_secureboot_firmware.t b/xCAT-test/unit/kvm_secureboot_firmware.t
index 5ebe5e2ff6..58de679aaf 100644
--- a/xCAT-test/unit/kvm_secureboot_firmware.t
+++ b/xCAT-test/unit/kvm_secureboot_firmware.t
@@ -8,16 +8,26 @@
# neither. A node that must boot signed binaries has to say so, so that a hypervisor without a
# Secure Boot firmware refuses the domain instead of starting it unverified.
#
-# is the requirement libvirt reads during firmware selection. Measured
-# with libvirt 11.10.0 on rome01: with that element resolves to
-# OVMF_CODE.secboot.fd and , and the same domain with
-# resolves to OVMF_CODE.fd.
+# is not that requirement on its own. libvirt reads it as the secure-boot
+# feature, and a firmware with secure-boot and an empty key store boots an unsigned binary. The
+# two x86_64 descriptors of an EL 10 host name the same OVMF_CODE.secboot.fd and differ in the
+# nvram template: 30-edk2-ovmf-x64-sb-enrolled.json takes OVMF_VARS.secboot.fd, which holds the
+# keys, and 40-edk2-ovmf-x64-sb.json takes OVMF_VARS.fd, which does not. Only descriptor
+# priority picks the first one, and priority is host policy.
+#
+# So the domain asks for enrolled-keys as well. Measured with libvirt 11.10.0 on rome01, with
+# the 30- descriptor masked for one connection: the domain that states
+# alone starts on OVMF_VARS.fd with enrolled-keys resolved to no, and the domain that asks for
+# enrolled-keys is refused with "Unable to find 'efi' firmware that is compatible with the
+# current configuration".
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../../perl-xCAT";
use Test::More;
+use XML::LibXML;
+use XML::Simple qw(XMLout);
require xCAT::KVMUtils;
@@ -105,4 +115,65 @@ is( xCAT::KVMUtils::firmware_machine_error( undef, 'pc', 'x86_64', 'cn1' ),
is( xCAT::KVMUtils::firmware_machine_error( 'efi', 'virt', 'riscv64', 'cn1' ),
undef, 'the machine types of another architecture are not judged here' );
+# carries the features libvirt filters the descriptors by. It is not in the hash
+# guest_os returns: the firmware attribute of and the child of are one key
+# of one hash for XMLout, and the attribute is the one that starts the selection. So
+# add_firmware_features adds the element to the domain XMLout wrote, which is what kvm.pm does.
+my $features = xCAT::KVMUtils::firmware_features($sb);
+is_deeply(
+ $features,
+ [ { name => 'secure-boot', enabled => 'yes' }, { name => 'enrolled-keys', enabled => 'yes' } ],
+ 'a Secure Boot node asks for secure-boot and for enrolled-keys'
+);
+is_deeply( xCAT::KVMUtils::firmware_features( node_profile('firmware:efi') ),
+ [], 'firmware:efi asks for no firmware feature' );
+is_deeply( xCAT::KVMUtils::firmware_features( node_profile(undef) ),
+ [], 'and neither does a node that asks for no firmware' );
+is_deeply( xCAT::KVMUtils::firmware_features(undef), [], 'and neither does an undefined profile' );
+
+# The domain as kvm.pm writes it: the of guest_os, then the features.
+sub domain_of {
+ my ($profile) = @_;
+ my $os = XMLout( os_of($profile), RootName => 'os' );
+ $os =~ s/^<\?xml[^>]*\?>\s*//;
+ return xCAT::KVMUtils::add_firmware_features( "\n$os\n\n",
+ xCAT::KVMUtils::firmware_features($profile) );
+}
+
+sub feature_enabled {
+ my ( $xml, $name ) = @_;
+ my ($node) =
+ XML::LibXML->load_xml( string => $xml )
+ ->findnodes("/domain/os/firmware/feature[\@name='$name']");
+ return defined($node) ? $node->getAttribute('enabled') : undef;
+}
+
+my $sb_domain = domain_of($sb);
+is( feature_enabled( $sb_domain, 'enrolled-keys' ),
+ 'yes', 'the domain of a Secure Boot node asks for a firmware whose keys are enrolled' );
+is( feature_enabled( $sb_domain, 'secure-boot' ),
+ 'yes', 'and for one that verifies what it boots' );
+is( XML::LibXML->load_xml( string => $sb_domain )->findnodes('/domain/os')->[0]
+ ->getAttribute('firmware'),
+ 'efi', 'and it keeps firmware="efi" on , which is what starts the firmware selection' );
+is( XML::LibXML->load_xml( string => $sb_domain )->findnodes('/domain/os/loader')->[0]
+ ->getAttribute('secure'),
+ 'yes', 'and keeps beside the features' );
+
+# A node that asked only for UEFI gets no , so it keeps taking the descriptor its
+# hypervisor prefers.
+foreach my $othersettings ( 'firmware:efi', undef ) {
+ my $name = defined($othersettings) ? $othersettings : 'no firmware';
+ my $domain = domain_of( node_profile($othersettings) );
+ is_deeply(
+ [ XML::LibXML->load_xml( string => $domain )->findnodes('/domain/os/firmware') ],
+ [], "$name states no firmware feature" );
+}
+
+is( xCAT::KVMUtils::add_firmware_features( "", [] ),
+ "",
+ 'a domain that asks for no feature is returned unchanged, not re-serialised' );
+is( xCAT::KVMUtils::add_firmware_features( "", $features ),
+ "", 'a domain with no is returned unchanged' );
+
done_testing();
From 832ca0b34688aec177b35845163bf17bed7d80d9 Mon Sep 17 00:00:00 2001
From: Daniel Hilst <392820+dhilst@users.noreply.github.com>
Date: Thu, 22 Oct 2026 10:12:07 -0300
Subject: [PATCH 12/18] fix(test): the count of changed media modes depends on
the umask of the caller
media_perms_readable.t asked make_path for two directories and then
counted the paths make_readable changed. make_path takes the mode from
the umask of the caller, so under umask 027 or 077 those two directories
need a mode change as well and the count is 6, not 4. The test failed
with "got '6', expected '4'" for anyone whose umask is not 022.
The fixture now sets the mode of both directories, so every mode the
count depends on is stated in the test.
Measured on the unfixed file: red under umask 027 and under umask 077.
The fixed file passes under 022, 027 and 077.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
---
xCAT-test/unit/media_perms_readable.t | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/xCAT-test/unit/media_perms_readable.t b/xCAT-test/unit/media_perms_readable.t
index 00a659acfd..27c8343c4a 100644
--- a/xCAT-test/unit/media_perms_readable.t
+++ b/xCAT-test/unit/media_perms_readable.t
@@ -32,6 +32,10 @@ foreach my $file (qw(EFI/BOOT/BOOTX64.EFI EFI/BOOT/mmx64.efi EFI/BOOT/grub.cfg E
print $fh 'x';
close $fh or die "close $file: $!";
}
+# make_path takes the mode of the umask of the caller, so the modes of the two directories it
+# creates are those of whoever runs the test. The count below is a count of the paths that
+# change, so every mode in the fixture is set here.
+chmod 0755, "$root/EFI", "$root/EFI/BOOT";
chmod 0700, "$root/EFI/BOOT/BOOTX64.EFI", "$root/EFI/BOOT/mmx64.efi";
chmod 0444, "$root/EFI/BOOT/grub.cfg";
chmod 0600, "$root/EFI/BOOT/fonts/unicode.pf2";
From 294f7c8f0e195616ef7dea16de96bd978ecaef74 Mon Sep 17 00:00:00 2001
From: Daniel Hilst <392820+dhilst@users.noreply.github.com>
Date: Thu, 22 Oct 2026 10:12:52 -0300
Subject: [PATCH 13/18] fix(test): five checks of the Secure Boot branch pass
without the code they name
Each of these five checks held with the behaviour it describes removed.
kvm_secureboot_firmware.t asked firmware_machine_error for machine virt
on riscv64 to measure the x86_64 guard. virt matches neither pc nor the
i440fx pattern, so the answer was undef with the guard removed as well.
The file now asks for pc and for a versioned i440fx on another
architecture, and for pc with nodetype.arch unset.
media_perms_readable.t asked make_readable for a directory that does not
exist to measure the -d test. File::Find returns without changing a path
there in either case, so only the warning it prints differs. The check
now also reads the warnings, which is what copycds shows the admin.
MediaPerms.pm skipped a symbolic link and nothing measured it, so the
fixture now holds one that names a file outside the tree.
vm_machine_type.bats kept two cases that a machine:pc answer for every
x86_64 node left green. "x86_64 without a firmware" repeats the second
line of test 2 and is deleted. assert_round_trip never read the machine
type apply wrote, so it now takes the expected machine type and the
Secure Boot round trip states q35.
Four mutations turn the three files red: the x86_64 guard, the -d test,
the symbolic-link test, and machine:pc for every x86_64 node.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
---
xCAT-test/bats/vm_machine_type.bats | 17 +++++++++--------
xCAT-test/unit/kvm_secureboot_firmware.t | 10 ++++++++++
xCAT-test/unit/media_perms_readable.t | 23 +++++++++++++++++++++--
3 files changed, 40 insertions(+), 10 deletions(-)
diff --git a/xCAT-test/bats/vm_machine_type.bats b/xCAT-test/bats/vm_machine_type.bats
index 427393085e..6be656567c 100644
--- a/xCAT-test/bats/vm_machine_type.bats
+++ b/xCAT-test/bats/vm_machine_type.bats
@@ -92,12 +92,8 @@ assert_arch()
assert_arch x86_64 q35 'cpumode:host-passthrough;firmware:efi-secureboot'
}
-@test "x86_64 without a firmware: the case still sets pc" {
- assert_arch x86_64 pc 'cpumode:host-passthrough'
-}
-
@test "round trip: x86_64 with firmware:efi-secureboot" {
- assert_round_trip x86_64 'cpumode:host-passthrough;firmware:efi-secureboot'
+ assert_round_trip x86_64 'cpumode:host-passthrough;firmware:efi-secureboot' q35
}
@test "riscv64: the case sets and clears virt" {
@@ -110,10 +106,11 @@ assert_arch()
assert_arch aarch64 virt 'cpumode:host-passthrough'
}
-# assert_round_trip -- the case ends with the exact value it started with.
+# assert_round_trip [] -- the case ends with the exact value it
+# started with. is the machine type apply is to have written, when the caller knows it.
assert_round_trip()
{
- local arch="$1" original="$2" machine
+ local arch="$1" original="$2" expected="$3" machine
set_vmother "$original"
vm_machine_type_main invalid cn1
@@ -122,6 +119,10 @@ assert_round_trip()
[ "$machine" = "machine:invalid" ]
vm_machine_type_main apply cn1 "$arch"
+ if [ -n "$expected" ]; then
+ machine="$(vmother | tr ';' '\n' | grep '^machine:' | tail -n 1)"
+ [ "$machine" = "machine:$expected" ]
+ fi
vm_machine_type_main restore cn1 "$arch"
[ "$(vmother)" = "$original" ]
[ -z "$(ls -A "$VM_MACHINE_TYPE_STATE_DIR")" ]
@@ -136,7 +137,7 @@ assert_round_trip()
}
@test "round trip: cpumode:host-passthrough" {
- assert_round_trip x86_64 'cpumode:host-passthrough'
+ assert_round_trip x86_64 'cpumode:host-passthrough' pc
}
@test "round trip: x86_64 with a versioned machine type" {
diff --git a/xCAT-test/unit/kvm_secureboot_firmware.t b/xCAT-test/unit/kvm_secureboot_firmware.t
index 58de679aaf..51e97d2140 100644
--- a/xCAT-test/unit/kvm_secureboot_firmware.t
+++ b/xCAT-test/unit/kvm_secureboot_firmware.t
@@ -112,6 +112,16 @@ is( xCAT::KVMUtils::firmware_machine_error( 'efi-secureboot', undef, 'x86_64', '
undef, 'a node that names no machine type is not refused' );
is( xCAT::KVMUtils::firmware_machine_error( undef, 'pc', 'x86_64', 'cn1' ),
undef, 'a node that asks for no firmware keeps i440fx' );
+# Only x86_64 is judged. The i440fx family and the q35 the refusal names belong to that
+# architecture, so a node of another one goes to libvirt whatever it names. The machine type
+# has to be one the x86_64 branch would refuse, or the test measures the i440fx match instead
+# of the architecture guard.
+is( xCAT::KVMUtils::firmware_machine_error( 'efi', 'pc', 'ppc64le', 'cn1' ),
+ undef, 'a machine type of the i440fx family is not judged on another architecture' );
+is( xCAT::KVMUtils::firmware_machine_error( 'efi', 'pc-i440fx-rhel10.0.0', 'aarch64', 'cn1' ),
+ undef, 'and neither is a versioned one' );
+is( xCAT::KVMUtils::firmware_machine_error( 'efi', 'pc', undef, 'cn1' ),
+ undef, 'a node whose nodetype.arch is unset is not judged either' );
is( xCAT::KVMUtils::firmware_machine_error( 'efi', 'virt', 'riscv64', 'cn1' ),
undef, 'the machine types of another architecture are not judged here' );
diff --git a/xCAT-test/unit/media_perms_readable.t b/xCAT-test/unit/media_perms_readable.t
index 27c8343c4a..472549cc1c 100644
--- a/xCAT-test/unit/media_perms_readable.t
+++ b/xCAT-test/unit/media_perms_readable.t
@@ -41,8 +41,19 @@ chmod 0444, "$root/EFI/BOOT/grub.cfg";
chmod 0600, "$root/EFI/BOOT/fonts/unicode.pf2";
chmod 0700, "$root/EFI/BOOT/fonts";
+# A symbolic link out of the tree. chmod follows a link, so make_readable has to skip it: the
+# install directory of one osimage must not change the mode of a path in another.
+my $outside = tempdir( CLEANUP => 1 );
+open my $out_fh, '>', "$outside/vmlinuz" or die "write vmlinuz: $!";
+close $out_fh or die "close vmlinuz: $!";
+chmod 0600, "$outside/vmlinuz";
+symlink "$outside/vmlinuz", "$root/EFI/BOOT/vmlinuz" or die "symlink: $!";
+
my $changed = xCAT::MediaPerms::make_readable("$root/EFI");
+is( mode_of("$outside/vmlinuz"), '0600',
+ 'a symbolic link is skipped, so the path it names outside the tree keeps its mode' );
+
is( mode_of("$root/EFI/BOOT/BOOTX64.EFI"), '0744',
'a boot loader the media ships 0700 becomes readable, and keeps its owner execute bit' );
is( mode_of("$root/EFI/BOOT/mmx64.efi"), '0744', 'and so does the MOK manager beside it' );
@@ -56,8 +67,16 @@ is( $changed, 4, 'make_readable reports the number of paths it changed' );
is( xCAT::MediaPerms::make_readable("$root/EFI"), 0,
'a second call changes nothing, so copycds can be re-run' );
-is( xCAT::MediaPerms::make_readable("$root/no-such-directory"), 0,
- 'a directory that does not exist changes nothing' );
+# An osimage whose media carries no EFI directory is the common case, and copycds calls
+# make_readable for it too. Without the -d test File::Find warns "Can't stat", which reaches
+# the output of copycds as an error the admin cannot act on.
+my @warnings;
+my $absent = do {
+ local $SIG{__WARN__} = sub { push @warnings, $_[0] };
+ xCAT::MediaPerms::make_readable("$root/no-such-directory");
+};
+is( $absent, 0, 'a directory that does not exist changes nothing' );
+is_deeply( \@warnings, [], 'and it is not reported, because copycds calls it for every osimage' );
# No write permission is ever added. /install holds the media of every osimage on the
# management node.
From 2cd5c70ae785ab0d93576154dec0b740cd7a3a1e Mon Sep 17 00:00:00 2001
From: Daniel Hilst <392820+dhilst@users.noreply.github.com>
Date: Thu, 22 Oct 2026 10:13:01 -0300
Subject: [PATCH 14/18] docs(kvm): the Secure Boot documentation omits the keys
and the rpower path
Two statements about this branch are narrower than the code.
Commit 1edcddab8 says a node with a machine type xCAT cannot judge
"failed at mkvm". firmware_machine_error is returned by build_xmldesc,
and makedom calls build_xmldesc for a node whose domain is not yet built,
so the refusal also reaches the rpower boot of that node. The POD of
firmware_machine_error now names both callers.
The Secure Boot section of the ipxe guide did not name
firmware:efi-secureboot at all. It now says what mkvm asks libvirt for,
why both the secure-boot feature and enrolled-keys are asked for, and
what a hypervisor without such a firmware answers.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
---
docs/source/advanced/ipxe/index.rst | 13 +++++++++++++
perl-xCAT/xCAT/KVMUtils.pm | 3 +++
2 files changed, 16 insertions(+)
diff --git a/docs/source/advanced/ipxe/index.rst b/docs/source/advanced/ipxe/index.rst
index a77e4d70c8..4800415b94 100644
--- a/docs/source/advanced/ipxe/index.rst
+++ b/docs/source/advanced/ipxe/index.rst
@@ -76,6 +76,19 @@ A shim also accepts a kernel that a MOK key signs, so a site that signs ``xcat/g
Two paths stay Secure Boot off. A kernel without an EFI stub boots through ``elilo-x64.efi``, and ESXi boots through ``esxboot-x64.efi``. No key signs either file. Boot these nodes with Secure Boot off.
+A KVM node takes Secure Boot from ``vm.othersettings``
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+``vm.othersettings`` of a KVM node takes ``firmware:efi-secureboot``. ``mkvm`` then asks libvirt for a firmware with the ``secure-boot`` feature and with the UEFI keys enrolled, and places the node on ``q35``, the only machine type the x86_64 OVMF descriptors target::
+
+ chdef cn1 vmothersetting=firmware:efi-secureboot
+
+Both features are asked for, because the two are separate. ``secure-boot`` names a firmware that can verify what it boots, and ``enrolled-keys`` names the key store that decides what passes. A firmware with ``secure-boot`` and an empty key store boots an unsigned binary. On an EL 10 host the descriptors ``30-edk2-ovmf-x64-sb-enrolled.json`` and ``40-edk2-ovmf-x64-sb.json`` name the same OVMF binary and differ only in that key store.
+
+A hypervisor that ships no such firmware refuses the domain with ``Unable to find 'efi' firmware that is compatible with the current configuration``, rather than starting the node on a firmware that verifies nothing.
+
+``firmware:efi`` keeps its meaning and asks for no feature, so a node that asks only for UEFI takes the firmware its hypervisor prefers.
+
Known limits of the upstream loader
-----------------------------------
diff --git a/perl-xCAT/xCAT/KVMUtils.pm b/perl-xCAT/xCAT/KVMUtils.pm
index 6214737cb4..d459b1453f 100644
--- a/perl-xCAT/xCAT/KVMUtils.pm
+++ b/perl-xCAT/xCAT/KVMUtils.pm
@@ -498,6 +498,9 @@ sub firmware_error {
Only the i440fx family is judged, and only on x86_64. xCAT does not know which
machine types a hypervisor offers, so any other value goes to libvirt, which reports
a machine type it cannot use.
+
+ build_xmldesc returns the message, and both mkvm and makedom call build_xmldesc, so
+ the refusal reaches mkvm and the rpower boot of a node whose domain is not yet built.
Arguments:
$firmware - the result of requested_firmware, or undef
$machine - the machine: setting of vm.othersettings, or undef
From 86b8bb96b43c23fd5c37adb237772a3506fc3430 Mon Sep 17 00:00:00 2001
From: Daniel Hilst <392820+dhilst@users.noreply.github.com>
Date: Thu, 22 Oct 2026 13:11:08 -0300
Subject: [PATCH 15/18] docs(ipxe): the Secure Boot chapter does not say which
distributions are supported
The chapter rules out ppc64le, aarch64 and riscv64, and says nothing about the
distribution. The shim chain is UEFI and distribution independent, so a reader
concludes that any distribution xCAT installs boots with Secure Boot on, and nothing
in the chapter contradicts it.
Operator decision, 2026-10-22: Secure Boot is Enterprise Linux and x86_64 for 2.20.
State it, and say what is measured rather than what is possible -- the mechanism does
work elsewhere, and that is exactly why the support claim has to be explicit.
The CI side carries the same scope: the Secure Boot case is named by the EL x86_64
leaves only, in xcat-core-ci-cd cells.tsv.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
---
docs/source/advanced/ipxe/index.rst | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/docs/source/advanced/ipxe/index.rst b/docs/source/advanced/ipxe/index.rst
index 4800415b94..6fb85c9666 100644
--- a/docs/source/advanced/ipxe/index.rst
+++ b/docs/source/advanced/ipxe/index.rst
@@ -15,6 +15,11 @@ line before the kernel, so the firmware verifies what it loads. A node with ``ne
does not: ``xnba.efi`` is unsigned, and no shim can chain to it. ``grub2`` and ``grub2-http``
nodes, which is every ppc64le, aarch64 and riscv64 node, are outside this chapter.
+xCAT 2.20 supports Secure Boot on Enterprise Linux and on ``x86_64``. The shim chain itself is
+UEFI and distribution independent, and a node of another distribution can boot through it, but no
+other distribution is measured and none is supported. The CI names the Secure Boot case on its EL
+``x86_64`` cells only.
+
New x86 nodes get ``netboot=ipxe``: node discovery, profile-based node definitions and the x86 node templates of ``mkdef --template`` set it.
The upstream loader
From 839117f9eff2712ccbcb5b15675790bd11c2d878 Mon Sep 17 00:00:00 2001
From: Daniel Hilst <392820+dhilst@users.noreply.github.com>
Date: Fri, 23 Oct 2026 11:26:22 -0300
Subject: [PATCH 16/18] fix(xcattest): a [Table_*] value stops at its first
colon or slash
xcattest applies a conf's [Table_*] blocks itself, once, before the first case
runs, so whatever table_attr returns is what reaches chtab. Its value class was
([\w\.\-]+), which stops at a colon or a slash and writes the truncated value
with no warning: on a management node provisioning over IPv6,
`net=2001:db8:176::/64` reached chtab as `net=2001`, and xcattest re-applied that
junk row on every run. [Table_site] value= has the same hole, so site.master
cannot be an IPv6 address either, and any table value holding a path or a
comma-separated list loses everything after the first slash or colon.
object_attr, beside it in the same module, already accepts ":,;/" -- which is
why an [Object_node] ip= carries an IPv6 address and a [Table_networks] net=
silently could not. table_attr now uses the same class. Both are faithful to
what they replaced: upstream xcattest still matches tables with ([\w\.\-]+) at
line 817 and objects with ([\w\.\-\+\ \/:]+) at line 854, and moving the pair
into xCAT::Test::Conf is what made the asymmetry visible and testable.
The class holds no whitespace and no '#', so a trailing inline comment is still
excluded -- asserted, because that is the behaviour a wider class could have
broken.
xcattest_conf_table_value_class.t covers one line per kind of value a table
holds. Seven of its 22 assertions fail without the fix, including the three IPv6
forms and the absolute path; xcattest_conf_object_attr.t stays green, which is
the control that colons were never meant to be refused.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
---
xCAT-test/lib/xCAT/Test/Conf.pm | 9 ++-
.../unit/xcattest_conf_table_value_class.t | 64 +++++++++++++++++++
2 files changed, 72 insertions(+), 1 deletion(-)
create mode 100644 xCAT-test/unit/xcattest_conf_table_value_class.t
diff --git a/xCAT-test/lib/xCAT/Test/Conf.pm b/xCAT-test/lib/xCAT/Test/Conf.pm
index ca56c42b73..a27ada92f7 100644
--- a/xCAT-test/lib/xCAT/Test/Conf.pm
+++ b/xCAT-test/lib/xCAT/Test/Conf.pm
@@ -59,7 +59,14 @@ sub object_attr {
sub table_attr {
my ($line) = @_;
return () unless defined $line;
- return ($1, $2) if $line =~ /(\w+)\s*=\s*([\w\.\-]+)/;
+ # The same value class as object_attr. A table value holds the same kinds of thing an object
+ # value does: an IPv6 prefix (2001:db8::/64), a path (/install), a comma-separated list of
+ # name servers. The narrower ([\w\.\-]+) this replaces stopped at the first colon or slash and
+ # wrote the truncated value, so `net=2001:db8:176::/64` reached chtab as `net=2001` and
+ # xcattest re-applied that row on every run. Nothing warned.
+ #
+ # The class holds no whitespace and no '#', so a trailing inline comment is still excluded.
+ return ($1, $2) if $line =~ /(\w+)\s*=\s*([:,;\w\.\-\/]+)/;
return ();
}
diff --git a/xCAT-test/unit/xcattest_conf_table_value_class.t b/xCAT-test/unit/xcattest_conf_table_value_class.t
new file mode 100644
index 0000000000..a1590085b9
--- /dev/null
+++ b/xCAT-test/unit/xcattest_conf_table_value_class.t
@@ -0,0 +1,64 @@
+#!/usr/bin/env perl
+# A [Table_*] VALUE MAY CONTAIN A COLON OR A SLASH. table_attr DROPS THE REST OF IT.
+#
+# xcattest applies a conf's [Table_*] blocks itself, once, before the first case runs
+# (setup_env_by_configure_file), so whatever table_attr returns is what reaches chtab. Its value
+# class is ([\w\.\-]+) while object_attr, beside it in the same module, already allows ":,;/" --
+# so an [Object_node] ip= carries an IPv6 address and a [Table_networks] net= silently cannot.
+#
+# The narrow class is faithful to what it replaced: upstream xcattest still matches tables with
+# ([\w\.\-]+) at line 817 and objects with ([\w\.\-\+\ \/:]+) at line 854. Moving the pair into
+# xCAT::Test::Conf is what made the asymmetry visible and testable.
+#
+# Measured 2026-10-23 on a management node provisioning over IPv6: `net=2001:db8:176::/64` reached
+# chtab as `net=2001`, and xcattest re-applied that junk row on every run. [Table_site] value= has
+# the same hole, so site.master cannot be an IPv6 address either. Nothing warns: the line parses,
+# the truncated value is written, and the case fails later for a reason that looks unrelated.
+#
+# The same hole swallows any path or time range a table value needs.
+use strict;
+use warnings;
+use Test::More;
+use FindBin;
+use lib "$FindBin::Bin/../lib";
+use xCAT::Test::Conf ();
+
+my $table = xCAT::Test::Conf->can('table_attr');
+ok($table, 'xCAT::Test::Conf provides table_attr') or die "nothing to test\n";
+
+# One pair per thing a table value legitimately holds. The value is what must come back WHOLE.
+my @cases = (
+ ['net=2001:db8:176::/64', 'net', '2001:db8:176::/64', 'an IPv6 prefix'],
+ [' gateway=2001:db8:176::1', 'gateway', '2001:db8:176::1', 'an IPv6 address'],
+ ['value=fd00::1', 'value', 'fd00::1', 'a unique-local address'],
+ ['master=192.168.201.76', 'master', '192.168.201.76', 'an IPv4 address, unchanged'],
+ ['installdir=/install', 'installdir', '/install', 'an absolute path'],
+ ['nameservers=2001:db8::1,2001:db8::2', 'nameservers', '2001:db8::1,2001:db8::2',
+ 'a comma-separated list'],
+ ['domain=xcat76.lab', 'domain', 'xcat76.lab', 'a dotted name, unchanged'],
+ ['key=system', 'key', 'system', 'a bare word, unchanged'],
+);
+for my $c (@cases) {
+ my ($line, $attr, $value, $what) = @$c;
+ my ($got_attr, $got_value) = $table->($line);
+ is($got_attr, $attr, "$what: the attribute is $attr");
+ is($got_value, $value, "$what: the value survives whole");
+}
+
+# A line with no assignment is still the empty list, and an inline comment is still excluded --
+# the class holds no whitespace and no '#', so widening it does not start swallowing comments.
+is_deeply([ $table->('# a comment') ], [], 'a comment line yields no assignment');
+is_deeply([ $table->('[Table_site]') ], [], 'a section header yields no assignment');
+my ($a, $v) = $table->('value=fd00::1 # the management address');
+is($v, 'fd00::1', 'an inline comment is not part of the value');
+
+# CONTROL: object_attr already accepts these, which is why the asymmetry is the defect rather
+# than the design. Without this a reader cannot tell whether colons were meant to be refused.
+my $object = xCAT::Test::Conf->can('object_attr');
+ok($object, 'and object_attr, for comparison');
+if ($object) {
+ my (undef, $ov) = $object->('ip=2001:db8:176::20');
+ is($ov, '2001:db8:176::20', 'control: an [Object_*] value already keeps an IPv6 address');
+}
+
+done_testing;
From e813f1eed002e8df300e91e0a155f29bca068d79 Mon Sep 17 00:00:00 2001
From: Daniel Hilst <392820+dhilst@users.noreply.github.com>
Date: Fri, 30 Oct 2026 10:01:15 -0300
Subject: [PATCH 17/18] fix(xcat-core): no test shows a [Table_*] semicolon
breaks the chtab command
xcattest builds the chtab command for a [Table_*] row with unquoted words and
runs it through /bin/bash -c. A [Table_vm] othersettings value such as
cpumode:host-passthrough;firmware:efi-secureboot ends the command at the
semicolon: chtab receives only the first setting, and bash runs the second as
a command, so the environment setup fails.
Move the command builder from setup_env_by_configure_file into
xCAT::Test::Conf::chtab_command, with the same output, so a test can read the
words chtab receives. xcattest_conf_chtab_command.t splits the command the way
the shell does. Three of its four checks fail on this commit.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
---
xCAT-test/lib/xCAT/Test/Conf.pm | 30 +++++++++
xCAT-test/unit/xcattest_conf_chtab_command.t | 64 ++++++++++++++++++++
xCAT-test/xcattest | 9 +--
3 files changed, 97 insertions(+), 6 deletions(-)
create mode 100644 xCAT-test/unit/xcattest_conf_chtab_command.t
diff --git a/xCAT-test/lib/xCAT/Test/Conf.pm b/xCAT-test/lib/xCAT/Test/Conf.pm
index a27ada92f7..8a9f649b60 100644
--- a/xCAT-test/lib/xCAT/Test/Conf.pm
+++ b/xCAT-test/lib/xCAT/Test/Conf.pm
@@ -125,6 +125,36 @@ sub chdef_command {
#-------------------------------------------------------------------------------
+=head3 chtab_command
+
+ Descriptions:
+ The chtab command that applies one row of a [Table_*] block.
+
+ The assignments are sorted, so one conf builds one command.
+ Arguments:
+ $table - the table name, as the section name spells it
+ $key - the key column of the row
+ $name - the value of the key column
+ $attrs - a hash reference of column to value
+ Returns:
+ the command
+
+=cut
+
+#-------------------------------------------------------------------------------
+sub chtab_command {
+ my ($table, $key, $name, $attrs) = @_;
+ my @words = ("$key=$name");
+ foreach my $attr (sort keys %$attrs) {
+ next if $attr eq '__KEY__';
+ my $value = defined $attrs->{$attr} ? $attrs->{$attr} : '';
+ push @words, "$table.$attr=$value";
+ }
+ return join ' ', 'chtab', @words;
+}
+
+#-------------------------------------------------------------------------------
+
=head3 _quote
Descriptions:
diff --git a/xCAT-test/unit/xcattest_conf_chtab_command.t b/xCAT-test/unit/xcattest_conf_chtab_command.t
new file mode 100644
index 0000000000..6fd3110593
--- /dev/null
+++ b/xCAT-test/unit/xcattest_conf_chtab_command.t
@@ -0,0 +1,64 @@
+#!/usr/bin/env perl
+# xcattest applies each row of a [Table_*] block with chtab, and runs the command through
+# /bin/bash -c. A vm.othersettings value separates its settings with a semicolon:
+#
+# othersettings=cpumode:host-passthrough;firmware:efi-secureboot
+#
+# Unquoted, bash ends the chtab command at the semicolon and runs the second setting as a
+# command. These checks split the command the way the shell does and look at the words chtab
+# receives.
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/../lib";
+use Test::More;
+use Text::ParseWords qw(parse_line);
+
+require xCAT::Test::Conf;
+
+# The words bash gives to chtab, or undef when the command holds an unquoted shell operator.
+sub chtab_words {
+ my ($cmd) = @_;
+ my @words = parse_line(qr/\s+/, 0, $cmd);
+ return undef if grep { !defined $_ } @words;
+ my @tokens = parse_line(qr/\s+/, 1, $cmd);
+ return undef if grep { !/^'.*'$/s && /[;&|<>`\$()*?\[\]]/ } @tokens;
+ return \@words;
+}
+
+my $cmd = xCAT::Test::Conf::chtab_command('vm', 'node', 'cn1',
+ { __KEY__ => 'node', othersettings => 'cpumode:host-passthrough;firmware:efi-secureboot' });
+is_deeply(
+ chtab_words($cmd),
+ [ 'chtab', 'node=cn1', 'vm.othersettings=cpumode:host-passthrough;firmware:efi-secureboot' ],
+ 'chtab receives both settings of a vm.othersettings value in one argument'
+);
+
+$cmd = xCAT::Test::Conf::chtab_command('site', 'key', 'domain name',
+ { __KEY__ => 'key', value => 'a&b' });
+is_deeply(
+ chtab_words($cmd),
+ [ 'chtab', 'key=domain name', 'site.value=a&b' ],
+ 'the row selector is quoted like the assignments'
+);
+
+$cmd = xCAT::Test::Conf::chtab_command('site', 'key', 'motd',
+ { __KEY__ => 'key', value => "it's here" });
+is_deeply(
+ chtab_words($cmd),
+ [ 'chtab', 'key=motd', "site.value=it's here" ],
+ 'a single quote in a value does not end the quoting'
+);
+
+# The values a table already held pass through unchanged.
+$cmd = xCAT::Test::Conf::chtab_command('networks', 'netname', 'prov6',
+ { __KEY__ => 'netname', net => '2001:db8:176::/64', mask => '/64', dynamicrange => 'a-b' });
+is_deeply(
+ chtab_words($cmd),
+ [ 'chtab', 'netname=prov6', 'networks.dynamicrange=a-b', 'networks.mask=/64',
+ 'networks.net=2001:db8:176::/64' ],
+ 'the key column is not written as an attribute, and the assignments are sorted'
+);
+
+done_testing();
diff --git a/xCAT-test/xcattest b/xCAT-test/xcattest
index 7a9d9da963..0f9f79512a 100755
--- a/xCAT-test/xcattest
+++ b/xCAT-test/xcattest
@@ -1593,12 +1593,9 @@ sub setup_env_by_configure_file {
if (exists $$config_ref{table}) {
foreach my $type (keys %{ $$config_ref{table} }) {
foreach my $name (keys %{ $$config_ref{table}{$type} }) {
- $cmd = "chtab $$config_ref{table}{$type}{$name}{__KEY__}=$name";
- foreach my $attr (keys %{ $$config_ref{table}{$type}{$name} }) {
- if ($attr ne '__KEY__') {
- $cmd = $cmd . " $type.$attr=$$config_ref{table}{$type}{$name}{$attr}";
- }
- }
+ $cmd = xCAT::Test::Conf::chtab_command($type,
+ $$config_ref{table}{$type}{$name}{__KEY__}, $name,
+ $$config_ref{table}{$type}{$name});
log_this($running_log_fd, "$cmd");
&runcmd($cmd);
if ($::RUNCMD_RC != 0) {
From 2107bd6069f6781cb7cf693bb9f4f1195b09aa53 Mon Sep 17 00:00:00 2001
From: Daniel Hilst <392820+dhilst@users.noreply.github.com>
Date: Fri, 30 Oct 2026 10:01:30 -0300
Subject: [PATCH 18/18] fix(xcat-core): chtab receives only the first setting
of a [Table_*] value
With [Table_vm] othersettings=cpumode:host-passthrough;firmware:efi-secureboot,
xcattest gives chtab only cpumode:host-passthrough, and bash runs
firmware:efi-secureboot as a command. The environment setup then fails.
chtab_command joined its words unquoted, and xcattest runs the command
through /bin/bash -c. chtab_command now quotes every word, the row selector
included, with the same _quote that chdef_command uses.
xcattest_conf_chtab_command.t passes with this change and fails 3 of 4
checks on the previous commit.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
---
xCAT-test/lib/xCAT/Test/Conf.pm | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/xCAT-test/lib/xCAT/Test/Conf.pm b/xCAT-test/lib/xCAT/Test/Conf.pm
index 8a9f649b60..b5e74e7177 100644
--- a/xCAT-test/lib/xCAT/Test/Conf.pm
+++ b/xCAT-test/lib/xCAT/Test/Conf.pm
@@ -130,6 +130,9 @@ sub chdef_command {
Descriptions:
The chtab command that applies one row of a [Table_*] block.
+ xcattest runs every command through /bin/bash -c, so each word is quoted, the row
+ selector too. A vm.othersettings value carries a semicolon.
+
The assignments are sorted, so one conf builds one command.
Arguments:
$table - the table name, as the section name spells it
@@ -150,7 +153,7 @@ sub chtab_command {
my $value = defined $attrs->{$attr} ? $attrs->{$attr} : '';
push @words, "$table.$attr=$value";
}
- return join ' ', 'chtab', @words;
+ return join ' ', 'chtab', map { _quote($_) } @words;
}
#-------------------------------------------------------------------------------