From 40805772bca05c11ceb440eaacfa00706269c9fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Wed, 21 Oct 2026 15:47:41 -0300 Subject: [PATCH 1/2] fix(build): refresh RPM metadata after signing RPM signing can change bytes without changing the file size or whole-second modification time used by the metadata cache. Rebuild binary and source indexes after signing so their checksums describe the final RPMs. Keep incremental indexing for unsigned builds. --- buildrpms.pl | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/buildrpms.pl b/buildrpms.pl index 3cdec4d62e..eff22a94d2 100755 --- a/buildrpms.pl +++ b/buildrpms.pl @@ -676,9 +676,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"); } @@ -689,7 +690,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 @@ -705,9 +706,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 { @@ -755,8 +756,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") : ())) { From d90c9e6f53f5bba37a1640500e5853c0de8e5beb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Wed, 21 Oct 2026 15:48:39 -0300 Subject: [PATCH 2/2] test(build): verify signed repository package checksums --- xCAT-test/native/README.md | 11 ++-- .../native/fixtures/rpmsign-preserve-mtime.sh | 23 ++++++++ xCAT-test/native/release_repository.t | 59 +++++++++++++++---- 3 files changed, 75 insertions(+), 18 deletions(-) create mode 100644 xCAT-test/native/fixtures/rpmsign-preserve-mtime.sh diff --git a/xCAT-test/native/README.md b/xCAT-test/native/README.md index 71401eaa8c..d3089e6ff3 100644 --- a/xCAT-test/native/README.md +++ b/xCAT-test/native/README.md @@ -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 diff --git a/xCAT-test/native/fixtures/rpmsign-preserve-mtime.sh b/xCAT-test/native/fixtures/rpmsign-preserve-mtime.sh new file mode 100644 index 0000000000..1366afe4d6 --- /dev/null +++ b/xCAT-test/native/fixtures/rpmsign-preserve-mtime.sh @@ -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 diff --git a/xCAT-test/native/release_repository.t b/xCAT-test/native/release_repository.t index dc131a98e5..a1e072eb57 100644 --- a/xCAT-test/native/release_repository.t +++ b/xCAT-test/native/release_repository.t @@ -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"); } }