mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-11-26 20:32:17 +00:00
Merge pull request #7954 from VersatusHPC/backport-7904-to-2.19
[Backport 2.19] feat(genimage): opt-in package signature checks for EL images
This commit is contained in:
@@ -19,6 +19,20 @@ Before packing the diskless image, you have the opportunity to change any files
|
||||
|
||||
However it's recommended that all changes to the image are made via post install scripts so that it's easily repeatable. Refer to :doc:`/guides/admin-guides/manage_clusters/ppc64le/diskless/customize_image/pre_post_script` for more details.
|
||||
|
||||
Verify Package Signatures
|
||||
-------------------------
|
||||
|
||||
By default ``genimage`` does not check package signatures for Red Hat family images. Set ``gpgcheck`` on the osimage to verify every package installed from the ``pkgdir``, ``kerneldir`` and ``otherpkgdir`` repositories: ::
|
||||
|
||||
chdef -t osimage rhels8.5.0-ppc64le-netboot-compute gpgcheck=yes
|
||||
|
||||
``genimage`` trusts the RPM signing keys imported on the management node, the same keys ``rpm -q gpg-pubkey`` lists. Import the key of each repository the image uses before running ``genimage``, including the distribution key when the image release differs from the management node and the keys of third-party ``otherpkgdir`` repositories such as EPEL: ::
|
||||
|
||||
rpm --import /install/rhels8.5.0/ppc64le/RPM-GPG-KEY-redhat-release
|
||||
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8
|
||||
|
||||
A package signed by a key that is not imported, or not signed at all, makes ``genimage`` fail.
|
||||
|
||||
|
||||
Pack Diskless Image
|
||||
===================
|
||||
|
||||
@@ -19,7 +19,7 @@ SYNOPSIS
|
||||
********
|
||||
|
||||
|
||||
\ **linuximage Attributes:**\ \ *imagename*\ , \ *template*\ , \ *boottarget*\ , \ *addkcmdline*\ , \ *pkglist*\ , \ *pkgdir*\ , \ *otherpkglist*\ , \ *otherpkgdir*\ , \ *exlist*\ , \ *postinstall*\ , \ *rootimgdir*\ , \ *kerneldir*\ , \ *nodebootif*\ , \ *otherifce*\ , \ *netdrivers*\ , \ *kernelver*\ , \ *krpmver*\ , \ *permission*\ , \ *dump*\ , \ *crashkernelsize*\ , \ *partitionfile*\ , \ *driverupdatesrc*\ , \ *comments*\ , \ *disable*\
|
||||
\ **linuximage Attributes:**\ \ *imagename*\ , \ *template*\ , \ *boottarget*\ , \ *addkcmdline*\ , \ *pkglist*\ , \ *pkgdir*\ , \ *otherpkglist*\ , \ *otherpkgdir*\ , \ *exlist*\ , \ *postinstall*\ , \ *rootimgdir*\ , \ *kerneldir*\ , \ *nodebootif*\ , \ *otherifce*\ , \ *netdrivers*\ , \ *kernelver*\ , \ *krpmver*\ , \ *permission*\ , \ *dump*\ , \ *crashkernelsize*\ , \ *partitionfile*\ , \ *driverupdatesrc*\ , \ *gpgcheck*\ , \ *comments*\ , \ *disable*\
|
||||
|
||||
|
||||
***********
|
||||
@@ -189,6 +189,12 @@ linuximage Attributes:
|
||||
|
||||
|
||||
|
||||
\ **gpgcheck**\
|
||||
|
||||
Diskless Red Hat family images only. Set to 'yes' or '1' to have genimage verify the signature of every package it installs from the pkgdir, kerneldir and otherpkgdir repositories. The trusted keys are the RPM signing keys imported on the node that runs genimage (rpm -q gpg-pubkey), so import the key of every repository first, for example rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-9. The default is no verification.
|
||||
|
||||
|
||||
|
||||
\ **comments**\
|
||||
|
||||
Any user-written notes.
|
||||
|
||||
@@ -19,7 +19,7 @@ SYNOPSIS
|
||||
********
|
||||
|
||||
|
||||
\ **osimage Attributes:**\ \ *addkcmdline*\ , \ *boottarget*\ , \ *bosinst_data*\ , \ *cfmdir*\ , \ *configdump*\ , \ *crashkernelsize*\ , \ *description*\ , \ *driverupdatesrc*\ , \ *dump*\ , \ *environvar*\ , \ *exlist*\ , \ *fb_script*\ , \ *groups*\ , \ *home*\ , \ *image_data*\ , \ *imagename*\ , \ *imagetype*\ , \ *installp_bundle*\ , \ *installto*\ , \ *isdeletable*\ , \ *kerneldir*\ , \ *kernelver*\ , \ *kitcomponents*\ , \ *krpmver*\ , \ *lpp_source*\ , \ *mksysb*\ , \ *netdrivers*\ , \ *nfsrootopts*\ , \ *nimmethod*\ , \ *nimtype*\ , \ *nodebootif*\ , \ *osarch*\ , \ *osdistroname*\ , \ *osname*\ , \ *osupdatename*\ , \ *osvers*\ , \ *otherifce*\ , \ *otherpkgdir*\ , \ *otherpkglist*\ , \ *otherpkgs*\ , \ *paging*\ , \ *partitionfile*\ , \ *permission*\ , \ *pkgdir*\ , \ *pkglist*\ , \ *postbootscripts*\ , \ *postinstall*\ , \ *postscripts*\ , \ *profile*\ , \ *provmethod*\ , \ *resolv_conf*\ , \ *root*\ , \ *rootfstype*\ , \ *rootimgdir*\ , \ *script*\ , \ *serverrole*\ , \ *shared_home*\ , \ *shared_root*\ , \ *spot*\ , \ *synclists*\ , \ *template*\ , \ *tmp*\ , \ *usercomment*\ , \ *winpepath*
|
||||
\ **osimage Attributes:**\ \ *addkcmdline*\ , \ *boottarget*\ , \ *bosinst_data*\ , \ *cfmdir*\ , \ *configdump*\ , \ *crashkernelsize*\ , \ *description*\ , \ *driverupdatesrc*\ , \ *dump*\ , \ *environvar*\ , \ *exlist*\ , \ *fb_script*\ , \ *gpgcheck*\ , \ *groups*\ , \ *home*\ , \ *image_data*\ , \ *imagename*\ , \ *imagetype*\ , \ *installp_bundle*\ , \ *installto*\ , \ *isdeletable*\ , \ *kerneldir*\ , \ *kernelver*\ , \ *kitcomponents*\ , \ *krpmver*\ , \ *lpp_source*\ , \ *mksysb*\ , \ *netdrivers*\ , \ *nfsrootopts*\ , \ *nimmethod*\ , \ *nimtype*\ , \ *nodebootif*\ , \ *osarch*\ , \ *osdistroname*\ , \ *osname*\ , \ *osupdatename*\ , \ *osvers*\ , \ *otherifce*\ , \ *otherpkgdir*\ , \ *otherpkglist*\ , \ *otherpkgs*\ , \ *paging*\ , \ *partitionfile*\ , \ *permission*\ , \ *pkgdir*\ , \ *pkglist*\ , \ *postbootscripts*\ , \ *postinstall*\ , \ *postscripts*\ , \ *profile*\ , \ *provmethod*\ , \ *resolv_conf*\ , \ *root*\ , \ *rootfstype*\ , \ *rootimgdir*\ , \ *script*\ , \ *serverrole*\ , \ *shared_home*\ , \ *shared_root*\ , \ *spot*\ , \ *synclists*\ , \ *template*\ , \ *tmp*\ , \ *usercomment*\ , \ *winpepath*
|
||||
|
||||
|
||||
***********
|
||||
@@ -115,6 +115,12 @@ osimage Attributes:
|
||||
|
||||
|
||||
|
||||
\ **gpgcheck**\ (linuximage.gpgcheck)
|
||||
|
||||
Diskless Red Hat family images only. Set to 'yes' or '1' to have genimage verify the signature of every package it installs from the pkgdir, kerneldir and otherpkgdir repositories. The trusted keys are the RPM signing keys imported on the node that runs genimage (rpm -q gpg-pubkey), so import the key of every repository first, for example rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-9. The default is no verification.
|
||||
|
||||
|
||||
|
||||
\ **groups**\ (osimage.groups)
|
||||
|
||||
A comma-delimited list of image groups of which this image is a member. Image groups can be used in the litefile and litetree table instead of a single image name. Group names are arbitrary.
|
||||
|
||||
@@ -808,7 +808,7 @@ passed as argument rather than by table value',
|
||||
},
|
||||
},
|
||||
linuximage => {
|
||||
cols => [qw(imagename template boottarget addkcmdline pkglist pkgdir otherpkglist otherpkgdir exlist postinstall rootimgdir kerneldir nodebootif otherifce netdrivers kernelver krpmver permission dump crashkernelsize partitionfile driverupdatesrc comments disable)],
|
||||
cols => [qw(imagename template boottarget addkcmdline pkglist pkgdir otherpkglist otherpkgdir exlist postinstall rootimgdir kerneldir nodebootif otherifce netdrivers kernelver krpmver permission dump crashkernelsize partitionfile driverupdatesrc gpgcheck comments disable)],
|
||||
keys => [qw(imagename)],
|
||||
tablespace => 'XCATTBS32K',
|
||||
table_desc => 'Information about a Linux operating system image that can be used to deploy cluster nodes.',
|
||||
@@ -853,6 +853,7 @@ passed as argument rather than by table value',
|
||||
"s:c:<the absolute path of the additional pressed config script>": only available for ubuntu osimages, runs in pressed/early_command and set the preseed values with "debconf-set". The multiple values should be delimited with comma ","
|
||||
',
|
||||
driverupdatesrc => 'The source of the drivers which need to be loaded during the boot. Two types of driver update source are supported: Driver update disk and Driver rpm package. The value for this attribute should be comma separated sources. Each source should be the format tab:full_path_of_source_file. The tab keyword can be: dud (for Driver update disk) and rpm (for driver rpm). If missing the tab, the rpm format is the default. e.g. dud:/install/dud/dd.img,rpm:/install/rpm/d.rpm',
|
||||
gpgcheck => "Diskless Red Hat family images only. Set to 'yes' or '1' to have genimage verify the signature of every package it installs from the pkgdir, kerneldir and otherpkgdir repositories. The trusted keys are the RPM signing keys imported on the node that runs genimage (rpm -q gpg-pubkey), so import the key of every repository first, for example rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-9. The default is no verification.",
|
||||
comments => 'Any user-written notes.',
|
||||
disable => "Set to 'yes' or '1' to comment out this row.",
|
||||
},
|
||||
@@ -3309,6 +3310,11 @@ push(@{ $defspec{node}->{'attrs'} }, @nodeattrs);
|
||||
tabentry => 'linuximage.otherpkgdir',
|
||||
access_tabentry => 'linuximage.imagename=attr:imagename',
|
||||
},
|
||||
{ attr_name => 'gpgcheck',
|
||||
only_if => 'imagetype=linux',
|
||||
tabentry => 'linuximage.gpgcheck',
|
||||
access_tabentry => 'linuximage.imagename=attr:imagename',
|
||||
},
|
||||
{ attr_name => 'exlist',
|
||||
only_if => 'imagetype=linux',
|
||||
tabentry => 'linuximage.exlist',
|
||||
|
||||
@@ -13,6 +13,7 @@ use xCAT::Table;
|
||||
#use Data::Dumper;
|
||||
use File::Path;
|
||||
use File::Copy;
|
||||
use Cwd qw(realpath);
|
||||
use Getopt::Long;
|
||||
Getopt::Long::Configure("bundling");
|
||||
Getopt::Long::Configure("pass_through");
|
||||
@@ -74,6 +75,7 @@ sub process_request {
|
||||
my $ignorekernelchk;
|
||||
my $noupdate;
|
||||
my $envar;
|
||||
my $gpgcheck;
|
||||
|
||||
GetOptions(
|
||||
'a=s' => \$arch,
|
||||
@@ -145,7 +147,7 @@ sub process_request {
|
||||
return 1;
|
||||
}
|
||||
|
||||
(my $ref_linuximage_tab) = $linuximagetab->getAttribs({ imagename => $imagename }, 'pkglist', 'pkgdir', 'otherpkglist', 'otherpkgdir', 'postinstall', 'rootimgdir', 'kerneldir', 'krpmver', 'nodebootif', 'otherifce', 'kernelver', 'netdrivers', 'permission', 'driverupdatesrc');
|
||||
(my $ref_linuximage_tab) = $linuximagetab->getAttribs({ imagename => $imagename }, 'pkglist', 'pkgdir', 'otherpkglist', 'otherpkgdir', 'postinstall', 'rootimgdir', 'kerneldir', 'krpmver', 'nodebootif', 'otherifce', 'kernelver', 'netdrivers', 'permission', 'driverupdatesrc', 'gpgcheck');
|
||||
unless ($ref_linuximage_tab) {
|
||||
$callback->({ error => ["Cannot find $imagename from the linuximage table."], errorcode => [1] });
|
||||
return 1;
|
||||
@@ -207,6 +209,14 @@ sub process_request {
|
||||
$rootimg_dir = $ref_linuximage_tab->{'rootimgdir'};
|
||||
$driverupdatesrc = $ref_linuximage_tab->{'driverupdatesrc'};
|
||||
|
||||
my $gpgcheck_value = $ref_linuximage_tab->{'gpgcheck'};
|
||||
if (defined($gpgcheck_value) && $gpgcheck_value =~ /^(?:1|yes)$/i) {
|
||||
$gpgcheck = 1;
|
||||
} elsif (defined($gpgcheck_value) && $gpgcheck_value !~ /^(?:0|no)?$/i) {
|
||||
$callback->({ error => ["Invalid linuximage.gpgcheck value \'$gpgcheck_value\' for image \'$imagename\'. Valid values are 1, yes, 0 or no."], errorcode => [1] });
|
||||
return 1;
|
||||
}
|
||||
|
||||
# TODO: how can we do if the user specifies one wrong value to the following attributes?
|
||||
# currently, one message is output to indicate the users there will be some updates
|
||||
|
||||
@@ -308,6 +318,12 @@ sub process_request {
|
||||
return 1;
|
||||
}
|
||||
|
||||
# Only the shared RPM image builder (rh/genimage) implements gpgcheck.
|
||||
if ($gpgcheck && realpath("$profDir/genimage") ne realpath("$::XCATROOT/share/xcat/netboot/rh/genimage")) {
|
||||
$callback->({ error => ["linuximage.gpgcheck is not supported for $osver diskless images."], errorcode => [1] });
|
||||
return 1;
|
||||
}
|
||||
|
||||
my $cmd = "cd $profDir; ./genimage";
|
||||
if ($arch) { $cmd .= " -a $arch"; }
|
||||
if ($osver) { $cmd .= " -o $osver"; }
|
||||
@@ -338,6 +354,7 @@ sub process_request {
|
||||
if ($driverupdatesrc) { $cmd .= " --driverupdatesrc $driverupdatesrc"; }
|
||||
if ($ignorekernelchk) { $cmd .= " --ignorekernelchk $ignorekernelchk"; }
|
||||
if ($noupdate) { $cmd .= " --noupdate $noupdate"; }
|
||||
if ($gpgcheck) { $cmd .= " --gpgcheck"; }
|
||||
|
||||
if ($osfamily eq "sles") {
|
||||
my @entries = xCAT::TableUtils->get_site_attribute("timezone");
|
||||
|
||||
@@ -48,6 +48,39 @@ sub rpm_installroot_command {
|
||||
return $cmd;
|
||||
}
|
||||
|
||||
sub rpm_trusted_keys {
|
||||
open(my $rpm, '-|', 'rpm', '-qa', '--qf', "%{DESCRIPTION}\n", 'gpg-pubkey*')
|
||||
or die "Cannot read trusted RPM keys: $!\n";
|
||||
local $/;
|
||||
my $keys = <$rpm>;
|
||||
close($rpm) or die "Cannot read trusted RPM keys\n";
|
||||
die "No trusted RPM signing keys are installed\n" unless defined($keys) && length($keys);
|
||||
return $keys;
|
||||
}
|
||||
|
||||
sub rpm_repository_config {
|
||||
my ($osver, $id, $url, $gpgkey) = @_;
|
||||
my $config = "[$id]\nname=$id\nbaseurl=$url\n";
|
||||
if (defined($gpgkey) && length($gpgkey)) {
|
||||
# RPM images verify signatures only when the caller opts in
|
||||
# by supplying the trusted keys (linuximage.gpgcheck).
|
||||
$config .= "gpgcheck=1\ngpgkey=$gpgkey\nskip_if_unavailable=True\n\n";
|
||||
} else {
|
||||
$config .= "gpgcheck=0\nskip_if_unavailable=True\n\n";
|
||||
}
|
||||
return $config;
|
||||
}
|
||||
|
||||
sub otherpkgs_repository_urls {
|
||||
my ($subdir, $local_dir, @urls) = @_;
|
||||
my @repos = @urls;
|
||||
|
||||
# Without a local otherpkgdir there is no local repository to add; a
|
||||
# file:///<subdir> entry would only produce a metadata download failure.
|
||||
push @repos, "file://$local_dir/$subdir" if defined($local_dir) && length($local_dir);
|
||||
return @repos;
|
||||
}
|
||||
|
||||
sub varsubinline{
|
||||
my $line=shift;
|
||||
my $refvardict=shift;
|
||||
|
||||
@@ -15,7 +15,7 @@ use File::Copy qw/copy cp mv move/;
|
||||
use File::Find;
|
||||
use Getopt::Long;
|
||||
use Cwd qw(realpath);
|
||||
use File::Temp qw/mkdtemp/;
|
||||
use File::Temp qw/mkdtemp tempfile/;
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../imgutils";
|
||||
use imgutils;
|
||||
@@ -70,6 +70,7 @@ my $ignorekernelchk;
|
||||
my $noupdate;
|
||||
my $lock;
|
||||
my $envar;
|
||||
my $gpgcheck;
|
||||
|
||||
|
||||
sub xdie {
|
||||
@@ -192,6 +193,7 @@ GetOptions(
|
||||
'onlyinitrd' => \$onlyinitrd,
|
||||
'ignorekernelchk' => \$ignorekernelchk,
|
||||
'noupdate' => \$noupdate,
|
||||
'gpgcheck' => \$gpgcheck, #internal flag
|
||||
'env=s' => \$envar,
|
||||
);
|
||||
|
||||
@@ -343,12 +345,19 @@ if($onlyinitrd){
|
||||
}
|
||||
|
||||
my $repnum = 0;
|
||||
my $gpgkey;
|
||||
if ($gpgcheck) {
|
||||
my ($keyfh, $keyfile) = tempfile('genimage-rpm-keys.XXXXXX', DIR => '/tmp', UNLINK => 1);
|
||||
print $keyfh imgutils::rpm_trusted_keys() or die "Cannot write RPM signing keys: $!\n";
|
||||
close($keyfh) or die "Cannot close RPM signing keys: $!\n";
|
||||
$gpgkey = "file://$keyfile";
|
||||
}
|
||||
foreach $srcdir (@yumdirs) {
|
||||
print $yumconfig "[$osver-$arch-$repnum]\nname=$osver-$arch-$repnum\nbaseurl=file://$srcdir\ngpgcheck=0\nskip_if_unavailable=True\n\n";
|
||||
print $yumconfig imgutils::rpm_repository_config($osver, "$osver-$arch-$repnum", "file://$srcdir", $gpgkey);
|
||||
$repnum += 1;
|
||||
}
|
||||
foreach $srcdir (@pkgdir_internet) {
|
||||
print $yumconfig "[$osver-$arch-$repnum]\nname=$osver-$arch-$repnum\nbaseurl=$srcdir\ngpgcheck=0\nskip_if_unavailable=True\n\n";
|
||||
print $yumconfig imgutils::rpm_repository_config($osver, "$osver-$arch-$repnum", $srcdir, $gpgkey);
|
||||
$repnum += 1;
|
||||
}
|
||||
$repnum -= 1;
|
||||
@@ -517,15 +526,11 @@ if($onlyinitrd){
|
||||
}
|
||||
|
||||
if (($_ eq "PRE_REMOVE") || ($_ eq "POST_REMOVE") || ($_ eq "ENVLIST")) { next; }
|
||||
foreach(@otherpkgdir_url){
|
||||
print $yumconfig "[otherpkgs$index]\nname=otherpkgs$index\nbaseurl=$_\ngpgcheck=0\nskip_if_unavailable=True\n\n";
|
||||
foreach my $url (imgutils::otherpkgs_repository_urls($_, $srcdir_otherpkgs_local, @otherpkgdir_url)) {
|
||||
print $yumconfig imgutils::rpm_repository_config($osver, "otherpkgs$index", $url, $gpgkey);
|
||||
$repohash{$pass}{$index} = 1;
|
||||
$index++;
|
||||
}
|
||||
|
||||
print $yumconfig "[otherpkgs$index]\nname=otherpkgs$index\nbaseurl=file://$srcdir_otherpkgs_local/$_\ngpgcheck=0\nskip_if_unavailable=True\n\n";
|
||||
$repohash{$pass}{$index} = 1;
|
||||
$index++;
|
||||
my $pa = $extra_hash{$pass}{$_};
|
||||
$extrapkgnames{$pass} .= " " . join(' ', @$pa);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
#!/usr/bin/env perl
|
||||
use strict;
|
||||
use warnings;
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use lib "$FindBin::Bin/../../perl-xCAT";
|
||||
use lib "$FindBin::Bin/../../xCAT-server/lib/perl";
|
||||
use lib "$FindBin::Bin/../../xCAT-server/share/xcat/netboot/imgutils";
|
||||
use File::Slurper qw(read_text write_text);
|
||||
use File::Temp qw(tempdir);
|
||||
use Storable qw(nstore retrieve);
|
||||
use Test::More;
|
||||
use XCAT::Test::File qw(repo_path slurp_repo_file);
|
||||
use imgutils;
|
||||
use xCAT::Schema;
|
||||
|
||||
my $key = 'file:///tmp/genimage-rpm-keys.abc123';
|
||||
|
||||
is(imgutils::rpm_repository_config('rocky9.6', 'rocky9.6-x86_64-0', 'file:///install/rocky9.6/x86_64'),
|
||||
"[rocky9.6-x86_64-0]\nname=rocky9.6-x86_64-0\nbaseurl=file:///install/rocky9.6/x86_64\n" .
|
||||
"gpgcheck=0\nskip_if_unavailable=True\n\n",
|
||||
'EL repositories stay unverified by default');
|
||||
is(imgutils::rpm_repository_config('rocky9.6', 'otherpkgs1', 'https://repo.example/epel/9/', ''),
|
||||
"[otherpkgs1]\nname=otherpkgs1\nbaseurl=https://repo.example/epel/9/\n" .
|
||||
"gpgcheck=0\nskip_if_unavailable=True\n\n",
|
||||
'an empty key set does not enable EL verification');
|
||||
is(imgutils::rpm_repository_config('rocky9.6', 'otherpkgs1', 'https://repo.example/epel/9/', $key),
|
||||
"[otherpkgs1]\nname=otherpkgs1\nbaseurl=https://repo.example/epel/9/\n" .
|
||||
"gpgcheck=1\ngpgkey=$key\nskip_if_unavailable=True\n\n",
|
||||
'EL repositories verify against the supplied trusted keys');
|
||||
|
||||
my @urls = ('https://repo.example/epel/9/', 'https://repo.example/ohpc/3/');
|
||||
is_deeply([imgutils::otherpkgs_repository_urls('.', undef, @urls)], \@urls,
|
||||
'URL-only otherpkgdir does not add a file:/// repository');
|
||||
is_deeply([imgutils::otherpkgs_repository_urls('xcat', '', @urls)], \@urls,
|
||||
'an empty local otherpkgdir does not add a file:/// repository');
|
||||
is_deeply([imgutils::otherpkgs_repository_urls('xcat', '/install/post/otherpkgs/rocky9.6/x86_64', @urls)],
|
||||
[@urls, 'file:///install/post/otherpkgs/rocky9.6/x86_64/xcat'],
|
||||
'a local otherpkgdir adds its subdirectory after the URLs');
|
||||
is_deeply([imgutils::otherpkgs_repository_urls('.', '/install/post/otherpkgs/rocky9.6/x86_64')],
|
||||
['file:///install/post/otherpkgs/rocky9.6/x86_64/.'],
|
||||
'a local-only otherpkgdir keeps its repository');
|
||||
|
||||
ok(scalar(grep { $_ eq 'gpgcheck' } @{ $xCAT::Schema::tabspec{linuximage}->{cols} }),
|
||||
'linuximage table includes gpgcheck');
|
||||
ok(length($xCAT::Schema::tabspec{linuximage}->{descriptions}->{gpgcheck} // ''),
|
||||
'linuximage.gpgcheck is described');
|
||||
is($xCAT::Schema::defspec{osimage}->{attrhash}->{gpgcheck}->{tabentry}, 'linuximage.gpgcheck',
|
||||
'osimage object exposes gpgcheck');
|
||||
|
||||
$ENV{XCATROOT} = repo_path('xCAT-server');
|
||||
require(repo_path('xCAT-server/lib/xcat/plugins/genimage.pm'));
|
||||
my $pkgdir = tempdir(CLEANUP => 1);
|
||||
write_text("$pkgdir/compute.pkglist", "bash\n");
|
||||
|
||||
sub dispatch {
|
||||
my ($os, $gpgcheck) = @_;
|
||||
my $dir = tempdir(CLEANUP => 1);
|
||||
my $out = "$dir/command";
|
||||
my %rows = (
|
||||
osimage => { osvers => $os, osarch => 'x86_64', profile => 'compute', provmethod => 'netboot' },
|
||||
linuximage => { pkglist => "$pkgdir/compute.pkglist", otherpkglist => '', postinstall => '',
|
||||
rootimgdir => "$dir/image", (defined($gpgcheck) ? (gpgcheck => $gpgcheck) : ()) },
|
||||
);
|
||||
my $pid = fork();
|
||||
die "fork: $!" unless defined($pid);
|
||||
if (!$pid) {
|
||||
my @responses;
|
||||
no warnings qw(redefine once);
|
||||
local *xCAT::Table::new = sub {
|
||||
my ($class, $table) = @_;
|
||||
die "Unexpected table $table" unless $rows{$table};
|
||||
return bless { row => $rows{$table} }, 'Local::ImageTable';
|
||||
};
|
||||
local *Local::ImageTable::getAttribs = sub { return { %{ $_[0]{row} } }; };
|
||||
local *xCAT::TableUtils::getInstallDir = sub { return '/install'; };
|
||||
local *xCAT::TableUtils::get_site_attribute = sub { return (); };
|
||||
local *xCAT::Utils::runcmd = sub { die 'Dry run attempted to execute an image build'; };
|
||||
xCAT_plugin::genimage::process_request({ command => ['genimage'], arg => [
|
||||
'--dryrun', '--tempfile', $out, 'testimage',
|
||||
] }, sub { push @responses, @_ }, sub { die 'Dry run attempted a database update'; });
|
||||
nstore(\@responses, "$dir/responses");
|
||||
exit 0;
|
||||
}
|
||||
waitpid($pid, 0);
|
||||
die "Plugin child failed: $?" if $?;
|
||||
return (retrieve("$dir/responses"), -f $out ? read_text($out) : '');
|
||||
}
|
||||
|
||||
for my $value (undef, '', '0', 'no') {
|
||||
my $label = defined($value) ? "'$value'" : 'unset';
|
||||
my ($responses, $out) = dispatch('rocky9.6', $value);
|
||||
ok(!grep({ $_->{error} } @$responses), "gpgcheck $label builds the image");
|
||||
like($out, qr{netboot/rocky; ./genimage .* testimage\n}, "gpgcheck $label uses the EL builder");
|
||||
unlike($out, qr/--gpgcheck/, "gpgcheck $label leaves verification off");
|
||||
}
|
||||
for my $value ('1', 'yes', 'YES') {
|
||||
my ($responses, $out) = dispatch('rocky9.6', $value);
|
||||
ok(!grep({ $_->{error} } @$responses), "gpgcheck '$value' builds the image");
|
||||
like($out, qr{netboot/rocky; ./genimage .* --gpgcheck testimage\n}, "gpgcheck '$value' enables verification");
|
||||
}
|
||||
{
|
||||
my ($responses, $out) = dispatch('rocky9.6', 'maybe');
|
||||
is_deeply([map { @{ $_->{error} // [] } } @$responses],
|
||||
["Invalid linuximage.gpgcheck value 'maybe' for image 'testimage'. Valid values are 1, yes, 0 or no."],
|
||||
'an invalid gpgcheck value is rejected');
|
||||
is($out, '', 'an invalid gpgcheck value does not produce a build command');
|
||||
}
|
||||
{
|
||||
my ($responses, $out) = dispatch('sles15.6', 'yes');
|
||||
is_deeply([map { @{ $_->{error} // [] } } @$responses],
|
||||
['linuximage.gpgcheck is not supported for sles15.6 diskless images.'],
|
||||
'a builder without gpgcheck support does not silently skip verification');
|
||||
is($out, '', 'an unsupported gpgcheck image does not produce a build command');
|
||||
}
|
||||
|
||||
my $builder = slurp_repo_file('xCAT-server/share/xcat/netboot/rh/genimage');
|
||||
like($builder, qr/'gpgcheck'\s*=>\s*\\\$gpgcheck/, 'the RPM builder accepts --gpgcheck');
|
||||
like($builder, qr/if \(\$gpgcheck\) \{/,
|
||||
'the RPM builder exports the trusted keys when verification is requested');
|
||||
like($builder, qr/imgutils::otherpkgs_repository_urls\(/, 'the RPM builder uses the shared otherpkgs repository list');
|
||||
|
||||
done_testing();
|
||||
Reference in New Issue
Block a user