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

Merge pull request #7968 from VersatusHPC/fix/release-metadata-checksums

fix(build): refresh RPM metadata after signing
This commit is contained in:
Daniel Hilst
2026-10-23 10:55:14 -03:00
committed by GitHub
4 changed files with 83 additions and 25 deletions
+8 -7
View File
@@ -677,9 +677,10 @@ sub setup_local_repos {
#
# Nothing this project ships reads the sqlite metadata. dnf on el8+ and zypper both read the XML.
sub createrepo_dir {
my ($dir, $extra) = @_;
my ($dir, $extra, $fresh) = @_;
$extra //= '';
sh_or_die(qq(createrepo_c --update )
my $update = $fresh ? '' : '--update';
sh_or_die(qq(createrepo_c $update )
. qq(--revision "$SOURCE_DATE_EPOCH" --set-timestamp-to-revision $extra "$dir"),
"Failed to createrepo_c $dir\n");
}
@@ -690,7 +691,7 @@ sub createrepo_dir {
# top-level strays; then index the binaries EXCLUDING the SRPMS/ subdir so no
# src.rpm enters the binary repomd, and index the SRPMS repo separately.
sub index_repo {
my ($repodir) = @_;
my ($repodir, $fresh) = @_;
my $alias = "$repodir/xCAT-release-latest.noarch.rpm";
# The stable bootstrap filename is a direct-download convenience, not a
@@ -706,9 +707,9 @@ sub index_repo {
# replace good metadata with metadata for an empty repo -- publishing a repo that
# resolves nothing. Leave it exactly as the last binary build left it and index
# only the srpms.
createrepo_dir($repodir, "--excludes 'SRPMS/*' --excludes '*.src.rpm'")
createrepo_dir($repodir, "--excludes 'SRPMS/*' --excludes '*.src.rpm'", $fresh)
unless $opts{source_only};
createrepo_dir("$repodir/SRPMS") if -d "$repodir/SRPMS";
createrepo_dir("$repodir/SRPMS", '', $fresh) if -d "$repodir/SRPMS";
}
sub update_repo {
@@ -756,8 +757,8 @@ sub sign_repo_dir {
"Failed to sign SRPMs in $repodir/SRPMS");
}
# Regenerate both indexes (binary + SRPMS) after signing, before signing repomd.
index_repo($repodir);
# Signing can change RPM bytes without changing the size or timestamp used by the metadata cache.
index_repo($repodir, 1);
for my $rd ("$repodir/repodata",
(-d "$repodir/SRPMS/repodata" ? ("$repodir/SRPMS/repodata") : ())) {
+6 -5
View File
@@ -56,11 +56,12 @@ prove xCAT-test/native/probe_package_payload.t \
They need RPM build/query tools, cpio, createrepo_c, zstd, rsync, GnuPG, Python 3
with RPM bindings, user/mount namespaces, and the Perl modules Capture::Tiny,
File::Slurper, Parallel::ForkManager and XML::LibXML. The probe command also
needs `which`. The release test uses an ephemeral signing key and removes its
agent. These checks inspect real packages and repository output; they do not
qualify package installation on every target architecture. On EL8, install both
`python36` and `python3-rpm` to provide the interpreter and its RPM bindings.
Digest::SHA, File::Slurper, Parallel::ForkManager and XML::LibXML. The probe
command also needs `which`. The release test uses an ephemeral signing key and
removes its agent. These checks inspect real packages and repository output;
they do not qualify package installation on every target architecture. On EL8,
install both `python36` and `python3-rpm` to provide the interpreter and its RPM
bindings.
The Debian probe permission test has a separate pull-request CI step. It needs
Debian build tools, BATS, bubblewrap, fakeroot, reprepro and
@@ -0,0 +1,23 @@
#!/bin/sh
set -eu
# Preserve timestamps so checksum coverage does not depend on signing within one clock tick.
timestamps=$(mktemp -d)
trap 'rm -rf -- "$timestamps"' EXIT
index=0
for package do
if [ -f "$package" ]; then
touch -r "$package" "$timestamps/$index"
fi
index=$((index + 1))
done
"$XCAT_TEST_RPMSIGN" "$@"
index=0
for package do
if [ -f "$timestamps/$index" ]; then
touch -r "$timestamps/$index" "$package"
fi
index=$((index + 1))
done
+46 -13
View File
@@ -1,6 +1,7 @@
#!/usr/bin/env perl
use strict;
use warnings;
use Digest::SHA qw(sha256_hex);
use File::Basename qw(dirname);
use File::Copy qw(copy);
use File::Path qw(make_path);
@@ -55,13 +56,26 @@ copy("$root/RPMS/noarch/$rpm", "$root/input/$rpm") or die $!;
copy("$root/SRPMS/$srpm", "$root/input/SRPMS/$srpm") or die $!;
copy("$root/RPMS/noarch/$rpm", "$root/input/xCAT-release-latest.noarch.rpm") or die $!;
my $rpmsign = command($root, 'sh', '-c', 'command -v rpmsign');
chomp $rpmsign;
make_path("$root/bin");
copy(repo_path('xCAT-test/native/fixtures/rpmsign-preserve-mtime.sh'), "$root/bin/rpmsign") or die $!;
chmod 0755, "$root/bin/rpmsign" or die $!;
local $ENV{XCAT_TEST_RPMSIGN} = $rpmsign;
local $ENV{PATH} = "$root/bin:$ENV{PATH}";
for my $signed (0, 1) {
for my $attempt (1, 2) {
my $before = $signed && $attempt == 1 ? package_stats("$root/input") : undef;
command("$root/work", $^X, 'buildrpms.pl', '--merge-core-repos',
'--target', 'alma+epel-10-x86_64', '--release', '1',
'--output-dir', "$root/output", '--input-core-repos', "$root/input",
$signed ? ('--gpg-sign', '--gpg-key-name', 'package@example.test') : ());
check_repository("$root/output", $signed, "merge signed=$signed run=$attempt");
check_repository("$root/output", $signed, "merge signed=$signed run=$attempt", $before);
if ($signed) {
copy("$root/output/$rpm", "$root/input/$rpm") or die $!;
copy("$root/output/SRPMS/$srpm", "$root/input/SRPMS/$srpm") or die $!;
}
}
}
@@ -74,12 +88,15 @@ command($root, 'cp', '-a', repo_path('xCAT-release'), "$root/work/xCAT-release")
write_text("$root/mock/xCAT-release-$target.cfg", "# cached build\n");
write_text("$root/os-release", "ID=almalinux\nVERSION_ID=10\n");
local $ENV{BUILD_FIXTURE} = $root;
command("$root/work", 'unshare', '--user', '--map-root-user', '--mount',
'bash', repo_path('xCAT-test/native/fixtures/buildrpms-namespace.sh'),
'sh', '-c', 'trap \'gpgconf --homedir "$GNUPGHOME" --kill gpg-agent\' EXIT; "$@"', 'sign-test',
$^X, 'buildrpms.pl', '--package', 'xCAT-release', '--target', $target,
'--release', '1', '--nproc', '1', '--gpg-sign', '--gpg-key-name', 'package@example.test');
check_repository($cached, 1, 'cached build finalization');
for my $attempt (1, 2) {
my $before = $attempt == 1 ? package_stats($cached) : undef;
command("$root/work", 'unshare', '--user', '--map-root-user', '--mount',
'bash', repo_path('xCAT-test/native/fixtures/buildrpms-namespace.sh'),
'sh', '-c', 'trap \'gpgconf --homedir "$GNUPGHOME" --kill gpg-agent\' EXIT; "$@"', 'sign-test',
$^X, 'buildrpms.pl', '--package', 'xCAT-release', '--target', $target,
'--release', '1', '--nproc', '1', '--gpg-sign', '--gpg-key-name', 'package@example.test');
check_repository($cached, 1, "cached build finalization run=$attempt", $before);
}
write_text("$root/work/schedule.pl", <<'PERL');
BEGIN {
@@ -134,17 +151,31 @@ sub primary_packages {
return XML::LibXML->load_xml(string => $xml)->findnodes('//*[local-name()="package"]');
}
sub package_stats {
my ($directory) = @_;
return {map { $_ => [(stat("$directory/$_"))[7, 9]] } ($rpm, "SRPMS/$srpm")};
}
sub check_repository {
my ($directory, $signed, $label) = @_;
my ($directory, $signed, $label, $before) = @_;
is_deeply(package_stats($directory), $before, "$label signing preserves package sizes and mtimes")
if $before;
my $alias = "$directory/xCAT-release-latest.noarch.rpm";
ok(-f $alias, "$label publishes the alias") or die('missing bootstrap alias');
is(read_binary($alias), read_binary("$directory/$rpm"), "$label alias has final RPM bytes");
is((stat($alias))[2] & 0777, 0644, "$label alias is readable");
my @packages = primary_packages($directory);
is(scalar(@packages), 1, "$label indexes the release package once");
for my $package (@packages) {
my ($location) = $package->findnodes('./*[local-name()="location"]');
is($location->getAttribute('href'), $rpm, "$label indexes the versioned filename only");
for my $entry ([$directory, $rpm], ["$directory/SRPMS", $srpm]) {
my ($repo, $filename) = @$entry;
my @indexed = primary_packages($repo);
is(scalar(@indexed), 1, "$label indexes one $filename");
for my $package (@indexed) {
my ($location) = $package->findnodes('./*[local-name()="location"]');
is($location->getAttribute('href'), $filename, "$label locates $filename");
my ($checksum) = $package->findnodes('./*[local-name()="checksum"]');
is($checksum->getAttribute('type'), 'sha256', "$label uses SHA256 for $filename");
is($checksum->textContent, sha256_hex(read_binary("$repo/$filename")),
"$label metadata matches final $filename bytes");
}
}
if ($signed) {
for my $repo ($directory, "$directory/SRPMS") {
@@ -153,5 +184,7 @@ sub check_repository {
my $signature = command($root, 'rpm', '-qp', '--qf', '%{RSAHEADER:pgpsig}', $alias);
like($signature, qr/RSA.*Key ID/i, "$label alias carries the package signature");
isnt(read_binary($alias), read_binary("$root/RPMS/noarch/$rpm"), "$label signing changed the unsigned RPM");
isnt(read_binary("$directory/SRPMS/$srpm"), read_binary("$root/SRPMS/$srpm"),
"$label signing changed the unsigned SRPM");
}
}