2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-11-19 17:02:15 +00:00

fix(kvm): a KVM node cannot ask for EFI without Secure Boot

vm.othersettings firmware: accepted only efi, which leaves Secure Boot to libvirt
firmware autoselection. Autoselection picks a descriptor by host policy, so on a
host whose best match enrolls keys the guest refuses an unsigned boot loader:

    NBP file downloaded successfully.
    BdsDxe: failed to load Boot0004 "UEFI PXEv6" : Access Denied

That decides whether a node can network boot over IPv6. A DHCPv6 bootfile-url is
written for a grub2 node alone, and the grub2 image under /tftpboot/boot/grub2 is
built with grub2-mkimage and is not signed, so a node with Secure Boot enforced
cannot start it and falls through to the next boot entry.

firmware: now also takes efi-secureboot and efi-insecure, and build_xmldesc adds
the <firmware> element that states the request. enrolled-keys follows secure-boot
because libvirt refuses a guest whose keys are enrolled while Secure Boot is off.
XML::Simple writes the firmware attribute of <os> and the element has the same
name, so the element is added to the rendered XML rather than to the hash.

firmware:efi keeps its behaviour and adds no element.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
This commit is contained in:
Daniel Hilst
2026-10-28 06:23:08 -03:00
parent a1a35fe3af
commit a91d0f783d
2 changed files with 83 additions and 4 deletions
+79 -3
View File
@@ -6,6 +6,7 @@ package xCAT::KVMUtils;
use strict;
use warnings;
use XML::LibXML;
#-------------------------------------------------------
@@ -130,7 +131,7 @@ sub guest_arch_profile {
$profile{bios} = 0;
$profile{sound} = 0;
}
if (defined($firmware) and $firmware eq 'efi' and not defined $profile{firmware}) {
if (defined($firmware) and $firmware =~ /^efi\b/ and not defined $profile{firmware}) {
$profile{firmware} = 'efi';
if ($profile{x86_features}) {
$profile{machine} = 'q35';
@@ -468,8 +469,83 @@ sub requested_firmware {
#-------------------------------------------------------
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);
return undef if $firmware eq 'efi' or defined secure_boot_request($firmware);
return "vm.othersettings firmware:$firmware names no firmware libvirt can select for $node."
. " Use firmware:efi, firmware:efi-secureboot or firmware:efi-insecure.";
}
#-------------------------------------------------------
=head3 secure_boot_request
Descriptions:
What the firmware: setting of a node asks of Secure Boot.
firmware:efi asks nothing and leaves the choice to libvirt firmware
autoselection, which picks a descriptor by host policy. A node that must load
the unsigned grub2 image xCAT serves asks for efi-insecure, and a node that
must enforce Secure Boot asks for efi-secureboot.
Arguments:
$firmware - the value from requested_firmware, or undef
Returns:
'yes', 'no', or undef when the node asks nothing
=cut
#-------------------------------------------------------
sub secure_boot_request {
my ($firmware) = @_;
return undef unless defined $firmware;
return 'yes' if $firmware eq 'efi-secureboot';
return 'no' if $firmware eq 'efi-insecure';
return undef;
}
#-------------------------------------------------------
=head3 with_firmware_features
Descriptions:
The guest XML with the <firmware> element that states what the node asks of
Secure Boot. A node that asks nothing, or a guest that does not ask for EFI,
gets its XML back unchanged.
enrolled-keys follows secure-boot: libvirt refuses a guest whose keys are
enrolled while Secure Boot is disabled.
Arguments:
$xml - the guest XML
$firmware - the value from requested_firmware, or undef
Returns:
the guest XML
=cut
#-------------------------------------------------------
sub with_firmware_features {
my ($xml, $firmware) = @_;
my $secure_boot = secure_boot_request($firmware);
return $xml unless defined $secure_boot;
my $doc = eval { XML::LibXML->load_xml(string => $xml) } or return $xml;
my ($os) = $doc->findnodes('/domain/os');
return $xml unless $os and $os->getAttribute('firmware');
foreach my $stale ($os->findnodes('./firmware')) {
$os->removeChild($stale);
}
my $element = $doc->createElement('firmware');
foreach my $name (qw(secure-boot enrolled-keys)) {
my $feature = $doc->createElement('feature');
$feature->setAttribute('enabled', $secure_boot);
$feature->setAttribute('name', $name);
$element->appendChild($feature);
}
$os->appendChild($element);
return $doc->toString();
}
#-------------------------------------------------------
+4 -1
View File
@@ -893,7 +893,10 @@ sub build_xmldesc {
$xtree{devices}->{console}->{type} = 'pty';
$xtree{devices}->{console}->{target}->{port} = '1';
return XMLout(\%xtree, RootName => "domain");
# XML::Simple writes the firmware attribute of <os>; the <firmware> element that states
# what the node asks of Secure Boot is a child of the same name, so it is added after.
return xCAT::KVMUtils::with_firmware_features(
XMLout(\%xtree, RootName => "domain"), $firmware);
}
sub refresh_vm {