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 01/18] 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 02/18] 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"); } } From 33fee7bb0d98efedc3fa83621ccfa4324e492191 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 17:39:28 -0300 Subject: [PATCH 03/18] test(netboot): resolve the shell mount target in profile tests Older bubblewrap releases reject a symlink mount destination. Bind Bash over the resolved shell path without changing the profile cases. --- xCAT-test/native/netboot_profile_riscv64.t | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xCAT-test/native/netboot_profile_riscv64.t b/xCAT-test/native/netboot_profile_riscv64.t index be5109d4c9..9d92e00e01 100644 --- a/xCAT-test/native/netboot_profile_riscv64.t +++ b/xCAT-test/native/netboot_profile_riscv64.t @@ -4,6 +4,8 @@ use warnings; ## no critic (Modules::RequireFilenameMatchesPackage) use FindBin; +use Cwd qw(abs_path); +use File::Basename qw(basename); use lib "$FindBin::Bin/../lib"; use lib "$FindBin::Bin/../../perl-xCAT"; use lib "$FindBin::Bin/../../xCAT-server/lib/perl"; @@ -80,7 +82,7 @@ for my $family (@families) { for my $pass (1, 2) { # EL uses Bash as /bin/sh for these postinstall scripts. my ($status, $output) = sandbox_run($root, - {read_only => {repo_path('.') => repo_path('.'), '/bin/bash' => '/bin/sh'}}, + {read_only => {repo_path('.') => repo_path('.'), '/bin/bash' => '/bin/' . basename(abs_path('/bin/sh'))}}, $postinstall, '/target', $osver, 'riscv64', $profile); is($status, 0, "pass $pass executes the selected script") or diag($output); is(read_text("$root/etc/fstab"), "host fstab\n", "pass $pass leaves the host fstab unchanged"); From ce335ba3b3c8b10106808c3ced5ecd077dd05cc0 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 17:39:47 -0300 Subject: [PATCH 04/18] fix(netboot): correct SELinux assignments in postinstall profiles Match the complete enforcing or permissive setting. Preserve comments and whitespace, and do not change unrelated lines or create a missing policy file. --- .../share/xcat/netboot/rh/compute.rhels10.aarch64.postinstall | 2 +- .../share/xcat/netboot/rh/compute.rhels10.ppc64le.postinstall | 2 +- .../share/xcat/netboot/rh/compute.rhels10.x86_64.postinstall | 2 +- .../share/xcat/netboot/rh/compute.rhels7.ppc64.postinstall | 2 +- .../share/xcat/netboot/rh/compute.rhels7.x86_64.postinstall | 2 +- .../share/xcat/netboot/rh/compute.rhels8.ppc64le.postinstall | 2 +- .../share/xcat/netboot/rh/compute.rhels8.x86_64.postinstall | 2 +- .../share/xcat/netboot/rh/compute.rhels9.ppc64le.postinstall | 2 +- .../share/xcat/netboot/rh/compute.rhels9.x86_64.postinstall | 2 +- xCAT-server/share/xcat/netboot/rh/service.postinstall | 2 +- .../xcat/netboot/rocky/compute.rocky10.riscv64.postinstall | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/xCAT-server/share/xcat/netboot/rh/compute.rhels10.aarch64.postinstall b/xCAT-server/share/xcat/netboot/rh/compute.rhels10.aarch64.postinstall index 2ad53bb406..c5fcc45dfa 100755 --- a/xCAT-server/share/xcat/netboot/rh/compute.rhels10.aarch64.postinstall +++ b/xCAT-server/share/xcat/netboot/rh/compute.rhels10.aarch64.postinstall @@ -37,7 +37,7 @@ END #-- Need to disable selinux, otherwise, the booting will hang on "Loading selinux policy" if [ -f "$installroot/etc/selinux/config" ] then - sed -i 's/SELINUX=enforcing\|permissive/SELINUX=disabled/' $installroot/etc/selinux/config + sed -i 's/^\([[:blank:]]*SELINUX=\)\(enforcing\|permissive\)\([[:blank:]]*\(#.*\)\{0,1\}\)$/\1disabled\3/' "$installroot/etc/selinux/config" fi #--for redhat 8 and 8.1 #-- Need to disable firewalld, otherwise, the remoteshell script will not able to get all the SSH keys diff --git a/xCAT-server/share/xcat/netboot/rh/compute.rhels10.ppc64le.postinstall b/xCAT-server/share/xcat/netboot/rh/compute.rhels10.ppc64le.postinstall index dd2576c8f7..9028a7b75b 100755 --- a/xCAT-server/share/xcat/netboot/rh/compute.rhels10.ppc64le.postinstall +++ b/xCAT-server/share/xcat/netboot/rh/compute.rhels10.ppc64le.postinstall @@ -37,7 +37,7 @@ echo "co:2345:respawn:/sbin/agetty -L 38400 console" >> $installroot/etc/inittab #-- Need to disable selinux, otherwise, the booting will hang on "Loading selinux policy" if [ -f "$installroot/etc/selinux/config" ] then - sed -i 's/SELINUX=enforcing\|permissive/SELINUX=disabled/' $installroot/etc/selinux/config + sed -i 's/^\([[:blank:]]*SELINUX=\)\(enforcing\|permissive\)\([[:blank:]]*\(#.*\)\{0,1\}\)$/\1disabled\3/' "$installroot/etc/selinux/config" fi #--for redhat 8 and 8.1 diff --git a/xCAT-server/share/xcat/netboot/rh/compute.rhels10.x86_64.postinstall b/xCAT-server/share/xcat/netboot/rh/compute.rhels10.x86_64.postinstall index 2ad53bb406..c5fcc45dfa 100755 --- a/xCAT-server/share/xcat/netboot/rh/compute.rhels10.x86_64.postinstall +++ b/xCAT-server/share/xcat/netboot/rh/compute.rhels10.x86_64.postinstall @@ -37,7 +37,7 @@ END #-- Need to disable selinux, otherwise, the booting will hang on "Loading selinux policy" if [ -f "$installroot/etc/selinux/config" ] then - sed -i 's/SELINUX=enforcing\|permissive/SELINUX=disabled/' $installroot/etc/selinux/config + sed -i 's/^\([[:blank:]]*SELINUX=\)\(enforcing\|permissive\)\([[:blank:]]*\(#.*\)\{0,1\}\)$/\1disabled\3/' "$installroot/etc/selinux/config" fi #--for redhat 8 and 8.1 #-- Need to disable firewalld, otherwise, the remoteshell script will not able to get all the SSH keys diff --git a/xCAT-server/share/xcat/netboot/rh/compute.rhels7.ppc64.postinstall b/xCAT-server/share/xcat/netboot/rh/compute.rhels7.ppc64.postinstall index eac5a8f4d8..fa1737a632 100755 --- a/xCAT-server/share/xcat/netboot/rh/compute.rhels7.ppc64.postinstall +++ b/xCAT-server/share/xcat/netboot/rh/compute.rhels7.ppc64.postinstall @@ -37,7 +37,7 @@ echo "co:2345:respawn:/sbin/agetty -L 38400 console" >> $installroot/etc/inittab #-- Need to disable selinux, otherwise, the booting will hang on "Loading selinux policy" if [ -f "$installroot/etc/selinux/config" ] then - sed -i 's/SELINUX=enforcing\|permissive/SELINUX=disabled/' $installroot/etc/selinux/config + sed -i 's/^\([[:blank:]]*SELINUX=\)\(enforcing\|permissive\)\([[:blank:]]*\(#.*\)\{0,1\}\)$/\1disabled\3/' "$installroot/etc/selinux/config" fi #-- Example of booted image versioning diff --git a/xCAT-server/share/xcat/netboot/rh/compute.rhels7.x86_64.postinstall b/xCAT-server/share/xcat/netboot/rh/compute.rhels7.x86_64.postinstall index 366e3d1df4..1787b10290 100755 --- a/xCAT-server/share/xcat/netboot/rh/compute.rhels7.x86_64.postinstall +++ b/xCAT-server/share/xcat/netboot/rh/compute.rhels7.x86_64.postinstall @@ -37,7 +37,7 @@ END #-- Need to disable selinux, otherwise, the booting will hang on "Loading selinux policy" if [ -f "$installroot/etc/selinux/config" ] then - sed -i 's/SELINUX=enforcing\|permissive/SELINUX=disabled/' $installroot/etc/selinux/config + sed -i 's/^\([[:blank:]]*SELINUX=\)\(enforcing\|permissive\)\([[:blank:]]*\(#.*\)\{0,1\}\)$/\1disabled\3/' "$installroot/etc/selinux/config" fi #-- Example of booted image versioning diff --git a/xCAT-server/share/xcat/netboot/rh/compute.rhels8.ppc64le.postinstall b/xCAT-server/share/xcat/netboot/rh/compute.rhels8.ppc64le.postinstall index dd2576c8f7..9028a7b75b 100755 --- a/xCAT-server/share/xcat/netboot/rh/compute.rhels8.ppc64le.postinstall +++ b/xCAT-server/share/xcat/netboot/rh/compute.rhels8.ppc64le.postinstall @@ -37,7 +37,7 @@ echo "co:2345:respawn:/sbin/agetty -L 38400 console" >> $installroot/etc/inittab #-- Need to disable selinux, otherwise, the booting will hang on "Loading selinux policy" if [ -f "$installroot/etc/selinux/config" ] then - sed -i 's/SELINUX=enforcing\|permissive/SELINUX=disabled/' $installroot/etc/selinux/config + sed -i 's/^\([[:blank:]]*SELINUX=\)\(enforcing\|permissive\)\([[:blank:]]*\(#.*\)\{0,1\}\)$/\1disabled\3/' "$installroot/etc/selinux/config" fi #--for redhat 8 and 8.1 diff --git a/xCAT-server/share/xcat/netboot/rh/compute.rhels8.x86_64.postinstall b/xCAT-server/share/xcat/netboot/rh/compute.rhels8.x86_64.postinstall index 2ad53bb406..c5fcc45dfa 100755 --- a/xCAT-server/share/xcat/netboot/rh/compute.rhels8.x86_64.postinstall +++ b/xCAT-server/share/xcat/netboot/rh/compute.rhels8.x86_64.postinstall @@ -37,7 +37,7 @@ END #-- Need to disable selinux, otherwise, the booting will hang on "Loading selinux policy" if [ -f "$installroot/etc/selinux/config" ] then - sed -i 's/SELINUX=enforcing\|permissive/SELINUX=disabled/' $installroot/etc/selinux/config + sed -i 's/^\([[:blank:]]*SELINUX=\)\(enforcing\|permissive\)\([[:blank:]]*\(#.*\)\{0,1\}\)$/\1disabled\3/' "$installroot/etc/selinux/config" fi #--for redhat 8 and 8.1 #-- Need to disable firewalld, otherwise, the remoteshell script will not able to get all the SSH keys diff --git a/xCAT-server/share/xcat/netboot/rh/compute.rhels9.ppc64le.postinstall b/xCAT-server/share/xcat/netboot/rh/compute.rhels9.ppc64le.postinstall index dd2576c8f7..9028a7b75b 100755 --- a/xCAT-server/share/xcat/netboot/rh/compute.rhels9.ppc64le.postinstall +++ b/xCAT-server/share/xcat/netboot/rh/compute.rhels9.ppc64le.postinstall @@ -37,7 +37,7 @@ echo "co:2345:respawn:/sbin/agetty -L 38400 console" >> $installroot/etc/inittab #-- Need to disable selinux, otherwise, the booting will hang on "Loading selinux policy" if [ -f "$installroot/etc/selinux/config" ] then - sed -i 's/SELINUX=enforcing\|permissive/SELINUX=disabled/' $installroot/etc/selinux/config + sed -i 's/^\([[:blank:]]*SELINUX=\)\(enforcing\|permissive\)\([[:blank:]]*\(#.*\)\{0,1\}\)$/\1disabled\3/' "$installroot/etc/selinux/config" fi #--for redhat 8 and 8.1 diff --git a/xCAT-server/share/xcat/netboot/rh/compute.rhels9.x86_64.postinstall b/xCAT-server/share/xcat/netboot/rh/compute.rhels9.x86_64.postinstall index 2ad53bb406..c5fcc45dfa 100755 --- a/xCAT-server/share/xcat/netboot/rh/compute.rhels9.x86_64.postinstall +++ b/xCAT-server/share/xcat/netboot/rh/compute.rhels9.x86_64.postinstall @@ -37,7 +37,7 @@ END #-- Need to disable selinux, otherwise, the booting will hang on "Loading selinux policy" if [ -f "$installroot/etc/selinux/config" ] then - sed -i 's/SELINUX=enforcing\|permissive/SELINUX=disabled/' $installroot/etc/selinux/config + sed -i 's/^\([[:blank:]]*SELINUX=\)\(enforcing\|permissive\)\([[:blank:]]*\(#.*\)\{0,1\}\)$/\1disabled\3/' "$installroot/etc/selinux/config" fi #--for redhat 8 and 8.1 #-- Need to disable firewalld, otherwise, the remoteshell script will not able to get all the SSH keys diff --git a/xCAT-server/share/xcat/netboot/rh/service.postinstall b/xCAT-server/share/xcat/netboot/rh/service.postinstall index e410490db4..a0707a17b5 100755 --- a/xCAT-server/share/xcat/netboot/rh/service.postinstall +++ b/xCAT-server/share/xcat/netboot/rh/service.postinstall @@ -41,7 +41,7 @@ echo "co:2345:respawn:/sbin/agetty -L 38400 console" >> $installroot/etc/inittab #-- Need to disable selinux, otherwise, the booting will hang on "Loading selinux policy" if [ -f "$installroot/etc/selinux/config" ] then - sed -i 's/SELINUX=enforcing\|permissive/SELINUX=disabled/' $installroot/etc/selinux/config + sed -i 's/^\([[:blank:]]*SELINUX=\)\(enforcing\|permissive\)\([[:blank:]]*\(#.*\)\{0,1\}\)$/\1disabled\3/' "$installroot/etc/selinux/config" fi #-- Example of booted image versioning diff --git a/xCAT-server/share/xcat/netboot/rocky/compute.rocky10.riscv64.postinstall b/xCAT-server/share/xcat/netboot/rocky/compute.rocky10.riscv64.postinstall index 015cfec0f9..c69a051426 100755 --- a/xCAT-server/share/xcat/netboot/rocky/compute.rocky10.riscv64.postinstall +++ b/xCAT-server/share/xcat/netboot/rocky/compute.rocky10.riscv64.postinstall @@ -37,7 +37,7 @@ END #-- Need to disable selinux, otherwise, the booting will hang on "Loading selinux policy" if [ -f "$installroot/etc/selinux/config" ] then - sed -i 's/SELINUX=enforcing\|permissive/SELINUX=disabled/' $installroot/etc/selinux/config + sed -i 's/^\([[:blank:]]*SELINUX=\)\(enforcing\|permissive\)\([[:blank:]]*\(#.*\)\{0,1\}\)$/\1disabled\3/' "$installroot/etc/selinux/config" fi #--for redhat 8 and 8.1 #-- Need to disable firewalld, otherwise, the remoteshell script will not able to get all the SSH keys From 402f398bb17504034ade8e8b4042fb41d3b1ead0 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 17:41:31 -0300 Subject: [PATCH 05/18] test(netboot): cover SELinux settings across postinstall profiles Execute all affected owners and their aliases in isolated image roots. Check policy contents and metadata, missing files, repeated runs and host sentinels. Run the cases in Ubuntu and EL CI. --- .github/workflows/xcat_test.yml | 5 +- xCAT-test/native/README.md | 12 ++- .../native/netboot_profile_postinstall.t | 99 +++++++++++++++++++ xCAT-test/native/netboot_profile_riscv64.t | 2 - 4 files changed, 112 insertions(+), 6 deletions(-) create mode 100644 xCAT-test/native/netboot_profile_postinstall.t diff --git a/.github/workflows/xcat_test.yml b/.github/workflows/xcat_test.yml index 629fc208f0..f95d697dd3 100644 --- a/.github/workflows/xcat_test.yml +++ b/.github/workflows/xcat_test.yml @@ -102,7 +102,7 @@ jobs: run: | log=$(mktemp) trap 'rm -f -- "$log"' EXIT - prove -v xCAT-test/native/install_profile_riscv64.t xCAT-test/native/netboot_profile_riscv64.t xCAT-test/native/builddebs_riscv64.t xCAT-test/native/ubuntu_subiquity_template.t | tee "$log" + prove -v xCAT-test/native/install_profile_riscv64.t xCAT-test/native/netboot_profile_riscv64.t xCAT-test/native/netboot_profile_postinstall.t xCAT-test/native/builddebs_riscv64.t xCAT-test/native/ubuntu_subiquity_template.t | tee "$log" ! grep -qi skipped "$log" rpm_lifecycle_test: runs-on: ubuntu-24.04 @@ -131,3 +131,6 @@ jobs: - name: Test FIPS package artifacts if: ${{ !cancelled() }} run: su -s /bin/sh nobody -c 'prove -v xCAT-test/native/fips_package_payload.t' + - name: Test netboot postinstall profiles + if: ${{ !cancelled() }} + run: su -s /bin/sh nobody -c 'prove -v xCAT-test/native/netboot_profile_postinstall.t' diff --git a/xCAT-test/native/README.md b/xCAT-test/native/README.md index 71401eaa8c..000481f3ca 100644 --- a/xCAT-test/native/README.md +++ b/xCAT-test/native/README.md @@ -374,6 +374,7 @@ user with Bubblewrap and unprivileged user namespaces enabled: ``` prove xCAT-test/native/install_profile_riscv64.t \ xCAT-test/native/netboot_profile_riscv64.t \ + xCAT-test/native/netboot_profile_postinstall.t \ xCAT-test/native/builddebs_riscv64.t \ xCAT-test/native/ubuntu_subiquity_template.t ``` @@ -386,13 +387,18 @@ The Debian case needs debhelper, devscripts, fakeroot, and reprepro, and skips on non-Debian hosts. Each case creates its own temporary files and database. The temporary directory must allow execution; set TMPDIR if /tmp is noexec. Sandbox commands require GNU timeout and have a 45-second limit. -Pull-request CI runs these cases and rejects whole-file skips. The permissive -SELinux case records an existing postinstall defect as TODO, without changing -production behavior. +Pull-request CI runs these cases and rejects whole-file skips. The netboot case executes the selected postinstall file directly. Its private /bin/sh uses Bash, as on EL, including when the test host uses another shell. +`netboot_profile_postinstall.t` runs the affected EL postinstall owners and +their distro and service aliases. It checks the resulting SELinux settings, +missing files, comments, repeated execution, permissions, ownership and host +sentinels. It uses the same sandbox and Perl dependencies. CI runs it on +Ubuntu, EL8 and EL10. It executes host tools against private image roots; +it does not boot the target architecture or verify kernel SELinux state. + The Subiquity case replaces downloads and external commands, and uses a loopback install-monitor peer. It does not install an operating system. Architecture names in these fixtures do not qualify native firmware or boot diff --git a/xCAT-test/native/netboot_profile_postinstall.t b/xCAT-test/native/netboot_profile_postinstall.t new file mode 100644 index 0000000000..aa1a8f2dc9 --- /dev/null +++ b/xCAT-test/native/netboot_profile_postinstall.t @@ -0,0 +1,99 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +use FindBin; +use lib "$FindBin::Bin/../lib"; +use Cwd qw(abs_path); +use File::Basename qw(basename); +use File::Find qw(find); +use File::Path qw(make_path); +use File::Slurper qw(read_text write_text); +use Test::More; +use XCAT::Test::File qw(repo_path); +use XCAT::Test::Sandbox qw(sandbox_root sandbox_run); + +plan skip_all => 'postinstall execution requires Linux' unless $^O eq 'linux'; +my $netboot = repo_path('xCAT-server/share/xcat/netboot'); +my @owners = qw( + rh/compute.rhels7.ppc64.postinstall + rh/compute.rhels7.x86_64.postinstall + rh/compute.rhels8.ppc64le.postinstall + rh/compute.rhels8.x86_64.postinstall + rh/compute.rhels9.ppc64le.postinstall + rh/compute.rhels9.x86_64.postinstall + rh/compute.rhels10.aarch64.postinstall + rh/compute.rhels10.ppc64le.postinstall + rh/compute.rhels10.x86_64.postinstall + rh/service.postinstall + rocky/compute.rocky10.riscv64.postinstall +); +my %owners; +for my $owner (@owners) { + ok(-x "$netboot/$owner", "$owner is executable"); + $owners{abs_path("$netboot/$owner")} = 1; +} +my @aliases; +find({no_chdir => 1, wanted => sub { + return unless -l $_ && /[.]postinstall$/; + my $target = abs_path($_); + push @aliases, substr($_, length($netboot) + 1) if defined $target && $owners{$target}; +}}, $netboot); +ok(@aliases, 'finds profile aliases for the affected owners'); + +my $unchanged = "# SELINUX=enforcing or permissive\nSELINUXTYPE=targeted\n" . + "OTHER_SELINUX=permissive\n#SELINUX=permissive\n"; +my @cases = ( + ['enforcing', "SELINUX=enforcing\n", "SELINUX=disabled\n"], + ['permissive', "SELINUX=permissive\n", "SELINUX=disabled\n"], + ['disabled', "SELINUX=disabled\n", "SELINUX=disabled\n"], + ['absent', undef, undef], + ['no assignment', '', ''], + ['whitespace and comments', "\tSELINUX=permissive \t# image policy\n", + "\tSELINUX=disabled \t# image policy\n"], + ['enforcing comment', "SELINUX=enforcing # image policy\n", + "SELINUX=disabled # image policy\n"], +); + +for my $relative (@owners, sort @aliases) { + my @selected = -l "$netboot/$relative" ? ($cases[1]) : @cases; + for my $case (@selected) { + my ($label, $input, $expected) = @$case; + subtest "$relative: $label" => sub { + my $root = sandbox_root(); + my $image = "$root/target"; + make_path("$image/etc/selinux", "$root/etc/selinux"); + my $host_policy = "SELINUX=enforcing\n# host policy\n"; + write_text("$root/etc/selinux/config", $host_policy); + write_text("$root/etc/fstab", "host fstab\n"); + write_text("$root/etc/inittab", "host inittab\n"); + my $config = "$image/etc/selinux/config"; + if (defined $input) { + write_text($config, $input . $unchanged); + chmod 0640, $config or die "chmod $config: $!"; + } + my @metadata = defined $input ? (stat($config))[2, 4, 5] : (); + my ($profile, $osver, $arch) = split /[.]/, basename($relative); + for my $pass (1, 2) { + my ($status, $output) = sandbox_run($root, + {read_only => {repo_path('.') => repo_path('.'), '/bin/bash' => '/bin/' . basename(abs_path('/bin/sh'))}}, + "$netboot/$relative", '/target', $osver, $arch // '', $profile); + is($status, 0, "pass $pass executes the profile") or diag($output); + is($output, '', "pass $pass has no shell errors"); + is(read_text("$root/etc/selinux/config"), $host_policy, 'host policy is unchanged'); + is(read_text("$root/etc/fstab"), "host fstab\n", 'host fstab is unchanged'); + is(read_text("$root/etc/inittab"), "host inittab\n", 'host inittab is unchanged'); + if (defined $input) { + is(read_text($config), $expected . $unchanged, + "pass $pass changes only the active SELinux mode"); + is_deeply([(stat($config))[2, 4, 5]], \@metadata, + 'policy permissions and ownership are preserved'); + } else { + ok(!-e $config, 'absent policy remains absent'); + } + } + }; + } +} + +done_testing(); diff --git a/xCAT-test/native/netboot_profile_riscv64.t b/xCAT-test/native/netboot_profile_riscv64.t index 9d92e00e01..d993577a22 100644 --- a/xCAT-test/native/netboot_profile_riscv64.t +++ b/xCAT-test/native/netboot_profile_riscv64.t @@ -90,8 +90,6 @@ for my $family (@families) { if ($mode eq 'absent') { ok(!-e "$image/etc/selinux/config", "pass $pass leaves absent SELinux configuration absent"); } else { - local $TODO = 'The existing postinstall duplicates SELINUX= for permissive mode' - if $mode eq 'permissive'; is(read_text("$image/etc/selinux/config"), "SELINUX=disabled\nSELINUXTYPE=targeted\n", "pass $pass disables SELinux without changing the policy type"); } From 88915f34cf2f52e9968eef23ce515f3ba44c5078 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 17:42:30 -0300 Subject: [PATCH 06/18] fix(netboot): use POSIX firewalld checks in postinstall profiles Use separate test commands under /bin/sh. Remove regular files and symlinks, including dangling links, while retaining absent entries and directories. --- .../xcat/netboot/rh/compute.rhels10.aarch64.postinstall | 8 ++++---- .../xcat/netboot/rh/compute.rhels10.ppc64le.postinstall | 8 ++++---- .../xcat/netboot/rh/compute.rhels10.x86_64.postinstall | 8 ++++---- .../xcat/netboot/rh/compute.rhels8.ppc64le.postinstall | 8 ++++---- .../xcat/netboot/rh/compute.rhels8.x86_64.postinstall | 8 ++++---- .../xcat/netboot/rh/compute.rhels9.ppc64le.postinstall | 8 ++++---- .../xcat/netboot/rh/compute.rhels9.x86_64.postinstall | 8 ++++---- .../netboot/rocky/compute.rocky10.riscv64.postinstall | 8 ++++---- 8 files changed, 32 insertions(+), 32 deletions(-) diff --git a/xCAT-server/share/xcat/netboot/rh/compute.rhels10.aarch64.postinstall b/xCAT-server/share/xcat/netboot/rh/compute.rhels10.aarch64.postinstall index c5fcc45dfa..be42313772 100755 --- a/xCAT-server/share/xcat/netboot/rh/compute.rhels10.aarch64.postinstall +++ b/xCAT-server/share/xcat/netboot/rh/compute.rhels10.aarch64.postinstall @@ -42,14 +42,14 @@ fi #--for redhat 8 and 8.1 #-- Need to disable firewalld, otherwise, the remoteshell script will not able to get all the SSH keys FIREWALLD="$installroot/etc/systemd/system/multi-user.target.wants/firewalld.service" -if [[ -f "$FIREWALLD" || -L "$FIREWALLD" ]] +if [ -f "$FIREWALLD" ] || [ -L "$FIREWALLD" ] then - rm -f $FIREWALLD + rm -f "$FIREWALLD" fi FIREWALLD1="$installroot/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service" -if [[ -f "$FIREWALLD1" || -L "$FIREWALLD1" ]] +if [ -f "$FIREWALLD1" ] || [ -L "$FIREWALLD1" ] then - rm -f $FIREWALLD1 + rm -f "$FIREWALLD1" fi diff --git a/xCAT-server/share/xcat/netboot/rh/compute.rhels10.ppc64le.postinstall b/xCAT-server/share/xcat/netboot/rh/compute.rhels10.ppc64le.postinstall index 9028a7b75b..ba8f22b6ae 100755 --- a/xCAT-server/share/xcat/netboot/rh/compute.rhels10.ppc64le.postinstall +++ b/xCAT-server/share/xcat/netboot/rh/compute.rhels10.ppc64le.postinstall @@ -43,14 +43,14 @@ fi #--for redhat 8 and 8.1 #-- Need to disable firewalld, otherwise, the remoteshell script will not able to get all the SSH keys FIREWALLD="$installroot/etc/systemd/system/multi-user.target.wants/firewalld.service" -if [[ -f "$FIREWALLD" || -L "$FIREWALLD" ]] +if [ -f "$FIREWALLD" ] || [ -L "$FIREWALLD" ] then - rm -f $FIREWALLD + rm -f "$FIREWALLD" fi FIREWALLD1="$installroot/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service" -if [[ -f "$FIREWALLD1" || -L "$FIREWALLD1" ]] +if [ -f "$FIREWALLD1" ] || [ -L "$FIREWALLD1" ] then - rm -f $FIREWALLD1 + rm -f "$FIREWALLD1" fi diff --git a/xCAT-server/share/xcat/netboot/rh/compute.rhels10.x86_64.postinstall b/xCAT-server/share/xcat/netboot/rh/compute.rhels10.x86_64.postinstall index c5fcc45dfa..be42313772 100755 --- a/xCAT-server/share/xcat/netboot/rh/compute.rhels10.x86_64.postinstall +++ b/xCAT-server/share/xcat/netboot/rh/compute.rhels10.x86_64.postinstall @@ -42,14 +42,14 @@ fi #--for redhat 8 and 8.1 #-- Need to disable firewalld, otherwise, the remoteshell script will not able to get all the SSH keys FIREWALLD="$installroot/etc/systemd/system/multi-user.target.wants/firewalld.service" -if [[ -f "$FIREWALLD" || -L "$FIREWALLD" ]] +if [ -f "$FIREWALLD" ] || [ -L "$FIREWALLD" ] then - rm -f $FIREWALLD + rm -f "$FIREWALLD" fi FIREWALLD1="$installroot/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service" -if [[ -f "$FIREWALLD1" || -L "$FIREWALLD1" ]] +if [ -f "$FIREWALLD1" ] || [ -L "$FIREWALLD1" ] then - rm -f $FIREWALLD1 + rm -f "$FIREWALLD1" fi diff --git a/xCAT-server/share/xcat/netboot/rh/compute.rhels8.ppc64le.postinstall b/xCAT-server/share/xcat/netboot/rh/compute.rhels8.ppc64le.postinstall index 9028a7b75b..ba8f22b6ae 100755 --- a/xCAT-server/share/xcat/netboot/rh/compute.rhels8.ppc64le.postinstall +++ b/xCAT-server/share/xcat/netboot/rh/compute.rhels8.ppc64le.postinstall @@ -43,14 +43,14 @@ fi #--for redhat 8 and 8.1 #-- Need to disable firewalld, otherwise, the remoteshell script will not able to get all the SSH keys FIREWALLD="$installroot/etc/systemd/system/multi-user.target.wants/firewalld.service" -if [[ -f "$FIREWALLD" || -L "$FIREWALLD" ]] +if [ -f "$FIREWALLD" ] || [ -L "$FIREWALLD" ] then - rm -f $FIREWALLD + rm -f "$FIREWALLD" fi FIREWALLD1="$installroot/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service" -if [[ -f "$FIREWALLD1" || -L "$FIREWALLD1" ]] +if [ -f "$FIREWALLD1" ] || [ -L "$FIREWALLD1" ] then - rm -f $FIREWALLD1 + rm -f "$FIREWALLD1" fi diff --git a/xCAT-server/share/xcat/netboot/rh/compute.rhels8.x86_64.postinstall b/xCAT-server/share/xcat/netboot/rh/compute.rhels8.x86_64.postinstall index c5fcc45dfa..be42313772 100755 --- a/xCAT-server/share/xcat/netboot/rh/compute.rhels8.x86_64.postinstall +++ b/xCAT-server/share/xcat/netboot/rh/compute.rhels8.x86_64.postinstall @@ -42,14 +42,14 @@ fi #--for redhat 8 and 8.1 #-- Need to disable firewalld, otherwise, the remoteshell script will not able to get all the SSH keys FIREWALLD="$installroot/etc/systemd/system/multi-user.target.wants/firewalld.service" -if [[ -f "$FIREWALLD" || -L "$FIREWALLD" ]] +if [ -f "$FIREWALLD" ] || [ -L "$FIREWALLD" ] then - rm -f $FIREWALLD + rm -f "$FIREWALLD" fi FIREWALLD1="$installroot/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service" -if [[ -f "$FIREWALLD1" || -L "$FIREWALLD1" ]] +if [ -f "$FIREWALLD1" ] || [ -L "$FIREWALLD1" ] then - rm -f $FIREWALLD1 + rm -f "$FIREWALLD1" fi diff --git a/xCAT-server/share/xcat/netboot/rh/compute.rhels9.ppc64le.postinstall b/xCAT-server/share/xcat/netboot/rh/compute.rhels9.ppc64le.postinstall index 9028a7b75b..ba8f22b6ae 100755 --- a/xCAT-server/share/xcat/netboot/rh/compute.rhels9.ppc64le.postinstall +++ b/xCAT-server/share/xcat/netboot/rh/compute.rhels9.ppc64le.postinstall @@ -43,14 +43,14 @@ fi #--for redhat 8 and 8.1 #-- Need to disable firewalld, otherwise, the remoteshell script will not able to get all the SSH keys FIREWALLD="$installroot/etc/systemd/system/multi-user.target.wants/firewalld.service" -if [[ -f "$FIREWALLD" || -L "$FIREWALLD" ]] +if [ -f "$FIREWALLD" ] || [ -L "$FIREWALLD" ] then - rm -f $FIREWALLD + rm -f "$FIREWALLD" fi FIREWALLD1="$installroot/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service" -if [[ -f "$FIREWALLD1" || -L "$FIREWALLD1" ]] +if [ -f "$FIREWALLD1" ] || [ -L "$FIREWALLD1" ] then - rm -f $FIREWALLD1 + rm -f "$FIREWALLD1" fi diff --git a/xCAT-server/share/xcat/netboot/rh/compute.rhels9.x86_64.postinstall b/xCAT-server/share/xcat/netboot/rh/compute.rhels9.x86_64.postinstall index c5fcc45dfa..be42313772 100755 --- a/xCAT-server/share/xcat/netboot/rh/compute.rhels9.x86_64.postinstall +++ b/xCAT-server/share/xcat/netboot/rh/compute.rhels9.x86_64.postinstall @@ -42,14 +42,14 @@ fi #--for redhat 8 and 8.1 #-- Need to disable firewalld, otherwise, the remoteshell script will not able to get all the SSH keys FIREWALLD="$installroot/etc/systemd/system/multi-user.target.wants/firewalld.service" -if [[ -f "$FIREWALLD" || -L "$FIREWALLD" ]] +if [ -f "$FIREWALLD" ] || [ -L "$FIREWALLD" ] then - rm -f $FIREWALLD + rm -f "$FIREWALLD" fi FIREWALLD1="$installroot/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service" -if [[ -f "$FIREWALLD1" || -L "$FIREWALLD1" ]] +if [ -f "$FIREWALLD1" ] || [ -L "$FIREWALLD1" ] then - rm -f $FIREWALLD1 + rm -f "$FIREWALLD1" fi diff --git a/xCAT-server/share/xcat/netboot/rocky/compute.rocky10.riscv64.postinstall b/xCAT-server/share/xcat/netboot/rocky/compute.rocky10.riscv64.postinstall index c69a051426..1e7ea3d54e 100755 --- a/xCAT-server/share/xcat/netboot/rocky/compute.rocky10.riscv64.postinstall +++ b/xCAT-server/share/xcat/netboot/rocky/compute.rocky10.riscv64.postinstall @@ -42,14 +42,14 @@ fi #--for redhat 8 and 8.1 #-- Need to disable firewalld, otherwise, the remoteshell script will not able to get all the SSH keys FIREWALLD="$installroot/etc/systemd/system/multi-user.target.wants/firewalld.service" -if [[ -f "$FIREWALLD" || -L "$FIREWALLD" ]] +if [ -f "$FIREWALLD" ] || [ -L "$FIREWALLD" ] then - rm -f $FIREWALLD + rm -f "$FIREWALLD" fi FIREWALLD1="$installroot/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service" -if [[ -f "$FIREWALLD1" || -L "$FIREWALLD1" ]] +if [ -f "$FIREWALLD1" ] || [ -L "$FIREWALLD1" ] then - rm -f $FIREWALLD1 + rm -f "$FIREWALLD1" fi From 8c6ba3b2c028c90c2ddfc16a5651e4068384537f 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 17:44:10 -0300 Subject: [PATCH 07/18] test(netboot): exercise firewalld cleanup with Bash and dash Execute each profile through /bin/sh. Check both firewalld entries as regular files, valid links, dangling links, directories and missing paths. Preserve unit targets, unrelated links and the older profiles without this cleanup. --- .github/workflows/xcat_test.yml | 2 +- xCAT-test/native/README.md | 3 + .../native/netboot_profile_postinstall.t | 228 +++++++++++++----- 3 files changed, 169 insertions(+), 64 deletions(-) diff --git a/.github/workflows/xcat_test.yml b/.github/workflows/xcat_test.yml index f95d697dd3..99a69a413c 100644 --- a/.github/workflows/xcat_test.yml +++ b/.github/workflows/xcat_test.yml @@ -123,7 +123,7 @@ jobs: - name: Install lifecycle test dependencies run: | dnf install -y epel-release - dnf --enablerepo=${{ matrix.repository }} install -y perl perl-Capture-Tiny perl-File-Slurper perl-Test-Simple perl-DBI perl-DBD-SQLite perl-JSON perl-XML-Simple rpm-build bubblewrap systemd chkconfig initscripts tar gzip bzip2 which diffutils httpd curl procps-ng openssl + dnf --enablerepo=${{ matrix.repository }} install -y perl perl-Capture-Tiny perl-File-Slurper perl-Test-Simple perl-DBI perl-DBD-SQLite perl-JSON perl-XML-Simple rpm-build bubblewrap dash systemd chkconfig initscripts tar gzip bzip2 which diffutils httpd curl procps-ng openssl - name: Enable lifecycle test namespaces run: sysctl -w kernel.apparmor_restrict_unprivileged_userns=0 - name: Test RPM package lifecycle diff --git a/xCAT-test/native/README.md b/xCAT-test/native/README.md index 000481f3ca..e05949b662 100644 --- a/xCAT-test/native/README.md +++ b/xCAT-test/native/README.md @@ -398,6 +398,9 @@ missing files, comments, repeated execution, permissions, ownership and host sentinels. It uses the same sandbox and Perl dependencies. CI runs it on Ubuntu, EL8 and EL10. It executes host tools against private image roots; it does not boot the target architecture or verify kernel SELinux state. +Both Bash and dash are required. The firewalld cases cover regular files, +valid and dangling symlinks, absent entries and directories under both shells. +The unit files, unrelated links and host entries must remain unchanged. The Subiquity case replaces downloads and external commands, and uses a loopback install-monitor peer. It does not install an operating system. diff --git a/xCAT-test/native/netboot_profile_postinstall.t b/xCAT-test/native/netboot_profile_postinstall.t index aa1a8f2dc9..b481b4ecea 100644 --- a/xCAT-test/native/netboot_profile_postinstall.t +++ b/xCAT-test/native/netboot_profile_postinstall.t @@ -4,18 +4,19 @@ use warnings; use FindBin; use lib "$FindBin::Bin/../lib"; -use Cwd qw(abs_path); -use File::Basename qw(basename); -use File::Find qw(find); -use File::Path qw(make_path); -use File::Slurper qw(read_text write_text); +use Cwd qw(abs_path); +use File::Basename qw(basename dirname); +use File::Find qw(find); +use File::Path qw(make_path); +use File::Slurper qw(read_text write_text); +use File::Spec; use Test::More; -use XCAT::Test::File qw(repo_path); +use XCAT::Test::File qw(repo_path); use XCAT::Test::Sandbox qw(sandbox_root sandbox_run); plan skip_all => 'postinstall execution requires Linux' unless $^O eq 'linux'; my $netboot = repo_path('xCAT-server/share/xcat/netboot'); -my @owners = qw( +my @owners = qw( rh/compute.rhels7.ppc64.postinstall rh/compute.rhels7.x86_64.postinstall rh/compute.rhels8.ppc64le.postinstall @@ -29,70 +30,171 @@ my @owners = qw( rocky/compute.rocky10.riscv64.postinstall ); my %owners; + for my $owner (@owners) { - ok(-x "$netboot/$owner", "$owner is executable"); - $owners{abs_path("$netboot/$owner")} = 1; + ok( -x "$netboot/$owner", "$owner is executable" ); + $owners{ abs_path("$netboot/$owner") } = 1; } my @aliases; -find({no_chdir => 1, wanted => sub { - return unless -l $_ && /[.]postinstall$/; - my $target = abs_path($_); - push @aliases, substr($_, length($netboot) + 1) if defined $target && $owners{$target}; -}}, $netboot); -ok(@aliases, 'finds profile aliases for the affected owners'); +find( + { + no_chdir => 1, + wanted => sub { + return unless -l $_ && /[.]postinstall$/; + my $target = abs_path($_); + push @aliases, substr( $_, length($netboot) + 1 ) if defined $target && $owners{$target}; + } + }, + $netboot +); +ok( @aliases, 'finds profile aliases for the affected owners' ); +my %firewalld = map { abs_path("$netboot/$_") => 1 } qw( + rh/compute.rhels8.ppc64le.postinstall + rh/compute.rhels8.x86_64.postinstall + rh/compute.rhels9.ppc64le.postinstall + rh/compute.rhels9.x86_64.postinstall + rh/compute.rhels10.aarch64.postinstall + rh/compute.rhels10.ppc64le.postinstall + rh/compute.rhels10.x86_64.postinstall + rocky/compute.rocky10.riscv64.postinstall +); +my @shells = qw(/bin/bash /bin/dash); -my $unchanged = "# SELINUX=enforcing or permissive\nSELINUXTYPE=targeted\n" . - "OTHER_SELINUX=permissive\n#SELINUX=permissive\n"; +sub shell_options { + my ($shell) = @_; + return { read_only => { repo_path('.') => repo_path('.'), $shell => '/bin/' . basename( abs_path('/bin/sh') ) } }; +} + +for my $shell (@shells) { + BAIL_OUT("Install $shell to run this test") unless -x $shell; + my $root = sandbox_root(); + write_text( "$root/bin/shell-probe", "#!/bin/sh\nprintf '%s\\n' \"\${BASH_VERSION:+bash}\"\n" ); + chmod 0755, "$root/bin/shell-probe" or die "chmod shell probe: $!"; + my ( $status, $output ) = sandbox_run( $root, shell_options($shell), '/fixture/bin/shell-probe' ); + my $expected = $shell eq '/bin/bash' ? "bash\n" : "\n"; + is( $status, 0, "$shell probe executes through its shebang" ) or diag($output); + is( $output, $expected, "/bin/sh runs the selected $shell" ); + BAIL_OUT("The sandbox did not select $shell") if $status || $output ne $expected; +} + +sub run_profile { + my ( $root, $relative, $shell ) = @_; + my ( $profile, $osver, $arch ) = split /[.]/, basename($relative); + return sandbox_run( $root, shell_options($shell), "$netboot/$relative", '/target', $osver, $arch // '', $profile ); +} + +my $unchanged = + "# SELINUX=enforcing or permissive\nSELINUXTYPE=targeted\n" . "OTHER_SELINUX=permissive\n#SELINUX=permissive\n"; my @cases = ( - ['enforcing', "SELINUX=enforcing\n", "SELINUX=disabled\n"], - ['permissive', "SELINUX=permissive\n", "SELINUX=disabled\n"], - ['disabled', "SELINUX=disabled\n", "SELINUX=disabled\n"], - ['absent', undef, undef], - ['no assignment', '', ''], - ['whitespace and comments', "\tSELINUX=permissive \t# image policy\n", - "\tSELINUX=disabled \t# image policy\n"], - ['enforcing comment', "SELINUX=enforcing # image policy\n", - "SELINUX=disabled # image policy\n"], + [ 'enforcing', "SELINUX=enforcing\n", "SELINUX=disabled\n" ], + [ 'permissive', "SELINUX=permissive\n", "SELINUX=disabled\n" ], + [ 'disabled', "SELINUX=disabled\n", "SELINUX=disabled\n" ], + [ 'absent', undef, undef ], + [ 'no assignment', '', '' ], + [ 'whitespace and comments', "\tSELINUX=permissive \t# image policy\n", "\tSELINUX=disabled \t# image policy\n" ], + [ 'enforcing comment', "SELINUX=enforcing # image policy\n", "SELINUX=disabled # image policy\n" ], ); -for my $relative (@owners, sort @aliases) { - my @selected = -l "$netboot/$relative" ? ($cases[1]) : @cases; - for my $case (@selected) { - my ($label, $input, $expected) = @$case; - subtest "$relative: $label" => sub { - my $root = sandbox_root(); - my $image = "$root/target"; - make_path("$image/etc/selinux", "$root/etc/selinux"); - my $host_policy = "SELINUX=enforcing\n# host policy\n"; - write_text("$root/etc/selinux/config", $host_policy); - write_text("$root/etc/fstab", "host fstab\n"); - write_text("$root/etc/inittab", "host inittab\n"); - my $config = "$image/etc/selinux/config"; - if (defined $input) { - write_text($config, $input . $unchanged); - chmod 0640, $config or die "chmod $config: $!"; - } - my @metadata = defined $input ? (stat($config))[2, 4, 5] : (); - my ($profile, $osver, $arch) = split /[.]/, basename($relative); - for my $pass (1, 2) { - my ($status, $output) = sandbox_run($root, - {read_only => {repo_path('.') => repo_path('.'), '/bin/bash' => '/bin/' . basename(abs_path('/bin/sh'))}}, - "$netboot/$relative", '/target', $osver, $arch // '', $profile); - is($status, 0, "pass $pass executes the profile") or diag($output); - is($output, '', "pass $pass has no shell errors"); - is(read_text("$root/etc/selinux/config"), $host_policy, 'host policy is unchanged'); - is(read_text("$root/etc/fstab"), "host fstab\n", 'host fstab is unchanged'); - is(read_text("$root/etc/inittab"), "host inittab\n", 'host inittab is unchanged'); - if (defined $input) { - is(read_text($config), $expected . $unchanged, - "pass $pass changes only the active SELinux mode"); - is_deeply([(stat($config))[2, 4, 5]], \@metadata, - 'policy permissions and ownership are preserved'); - } else { - ok(!-e $config, 'absent policy remains absent'); +for my $shell (@shells) { + for my $relative ( @owners, sort @aliases ) { + my @selected = -l "$netboot/$relative" ? ( $cases[1] ) : @cases; + for my $case (@selected) { + my ( $label, $input, $expected ) = @$case; + subtest "$relative: $shell SELinux $label" => sub { + my $root = sandbox_root(); + my $image = "$root/target"; + make_path( "$image/etc/selinux", "$root/etc/selinux" ); + my $host_policy = "SELINUX=enforcing\n# host policy\n"; + write_text( "$root/etc/selinux/config", $host_policy ); + write_text( "$root/etc/fstab", "host fstab\n" ); + write_text( "$root/etc/inittab", "host inittab\n" ); + my $config = "$image/etc/selinux/config"; + + if ( defined $input ) { + write_text( $config, $input . $unchanged ); + chmod 0640, $config or die "chmod $config: $!"; } - } - }; + my @metadata = defined $input ? ( stat($config) )[ 2, 4, 5 ] : (); + for my $pass ( 1, 2 ) { + my ( $status, $output ) = run_profile( $root, $relative, $shell ); + is( $status, 0, "pass $pass executes the profile" ) or diag($output); + is( $output, '', "pass $pass has no shell errors" ); + is( read_text("$root/etc/selinux/config"), $host_policy, 'host policy is unchanged' ); + is( read_text("$root/etc/fstab"), "host fstab\n", 'host fstab is unchanged' ); + is( read_text("$root/etc/inittab"), "host inittab\n", 'host inittab is unchanged' ); + if ( defined $input ) { + is( + read_text($config), + $expected . $unchanged, + "pass $pass changes only the active SELinux mode" + ); + is_deeply( [ ( stat($config) )[ 2, 4, 5 ] ], + \@metadata, 'policy permissions and ownership are preserved' ); + } + else { + ok( !-e $config, 'absent policy remains absent' ); + } + } + }; + } + + my @kinds = -l "$netboot/$relative" ? ('dangling') : qw(regular symlink dangling absent directory); + for my $kind (@kinds) { + subtest "$relative: $shell firewalld $kind" => sub { + my $root = sandbox_root(); + my $image = "$root/target"; + my $unit = "$image/usr/lib/systemd/system/firewalld.service"; + make_path( dirname($unit) ); + write_text( $unit, "[Service]\nExecStart=/usr/bin/true\n" ); + my @links = qw(etc/systemd/system/multi-user.target.wants/firewalld.service + etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service); + my %targets; + + for my $relative_link (@links) { + my $link = "$image/$relative_link"; + make_path( dirname($link), dirname("$root/$relative_link") ); + write_text( "$root/$relative_link", "host firewalld\n" ); + $targets{$link} = + File::Spec->abs2rel( $unit . ( $kind eq 'dangling' ? '.missing' : '' ), dirname($link) ); + if ( $kind eq 'regular' ) { + write_text( $link, "image firewalld\n" ); + } + elsif ( $kind eq 'symlink' || $kind eq 'dangling' ) { + symlink( $targets{$link}, $link ) or die "symlink $link: $!"; + } + elsif ( $kind eq 'directory' ) { + make_path($link); + write_text( "$link/keep", "directory contents\n" ); + } + symlink( $targets{$link}, "$link.unrelated" ) or die "symlink: $!"; + } + for my $pass ( 1, 2 ) { + my ( $status, $output ) = run_profile( $root, $relative, $shell ); + is( $status, 0, "pass $pass executes the profile" ) or diag($output); + is( $output, '', 'both shell conditions execute without errors' ); + for my $relative_link (@links) { + my $link = "$image/$relative_link"; + if ( ( $firewalld{ abs_path("$netboot/$relative") } && $kind ne 'directory' ) + || $kind eq 'absent' ) + { + ok( !-e $link && !-l $link, 'firewalld entry is absent' ); + } + elsif ( $kind eq 'regular' ) { + is( read_text($link), "image firewalld\n", 'older profile retains the entry' ); + } + elsif ( $kind eq 'directory' ) { + is( read_text("$link/keep"), "directory contents\n", 'directory contents are retained' ); + } + else { + is( readlink($link), $targets{$link}, 'older profile retains the link' ); + } + is( readlink("$link.unrelated"), $targets{$link}, 'unrelated link is unchanged' ); + is( read_text("$root/$relative_link"), "host firewalld\n", 'host entry is unchanged' ); + } + is( read_text($unit), "[Service]\nExecStart=/usr/bin/true\n", 'unit target is unchanged' ); + } + }; + } } } From 34ea500af702d7828c0225467c7067af0aab01c9 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 20:09:17 -0300 Subject: [PATCH 08/18] fix(syncfiles): retain the client name when node lookup fails Keep the original client name for the rejection diagnostic. Use the resolved node only for dispatch, without changing identity or copy-command handling. --- xCAT-server/lib/xcat/plugins/syncfiles.pm | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/syncfiles.pm b/xCAT-server/lib/xcat/plugins/syncfiles.pm index 66a7e0b4c1..ddabf4dc8d 100644 --- a/xCAT-server/lib/xcat/plugins/syncfiles.pm +++ b/xCAT-server/lib/xcat/plugins/syncfiles.pm @@ -73,14 +73,15 @@ sub process_request $::RCP=$options{'node-rcp'}; } - if ($client) { ($client) = noderange($client) } - unless ($client) { #Not able to do identify the host in question + my $node; + if ($client) { ($node) = noderange($client) } + unless ($node) { #Not able to do identify the host in question xCAT::MsgUtils->message("S", "Received syncfiles from $client, which couldn't be correlated to a node (domain mismatch?)"); return; } require xCAT::Postage; - &syncfiles($client, $callback, $subreq); + &syncfiles($node, $callback, $subreq); } From 7f77e90308959394b35dc4f56fe8f30bef153d17 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 20:42:13 -0300 Subject: [PATCH 09/18] test(syncfiles): check unresolved client names and rejection Check the original hostname in the unresolved-node diagnostic. Keep blank and missing-client rejection covered without sending a copy request. --- xCAT-test/unit/syncfiles_xdcp_identity.t | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/xCAT-test/unit/syncfiles_xdcp_identity.t b/xCAT-test/unit/syncfiles_xdcp_identity.t index e281e88ddc..7db1906fe9 100644 --- a/xCAT-test/unit/syncfiles_xdcp_identity.t +++ b/xCAT-test/unit/syncfiles_xdcp_identity.t @@ -183,9 +183,25 @@ push @cases, args => [], synclist => { node1 => '/install/custom/sync-a' }, expected => [], - messages => [ qr/couldn't be correlated to a node/ ], + messages => [ qr/\AReceived syncfiles from unknown\.example\.test, which couldn't be correlated to a node \(domain mismatch\?\)\z/ ], }; +for my $client ( 'other.example.test', '', undef ) { + my $name = defined($client) ? $client : ''; + my $label = !defined($client) ? 'missing' : length($client) ? $client : 'blank'; + push @cases, { + name => "unresolved client '$label' retains its diagnostic and sends no request", + request => { + command => ['syncfiles'], + arg => [], + ( defined($client) ? ( _xcat_clienthost => [$client] ) : () ), + }, + synclist => { node1 => '/install/custom/sync-a' }, + expected => [], + messages => [ qr/\AReceived syncfiles from \Q$name\E, which couldn't be correlated to a node \(domain mismatch\?\)\z/ ], + }; +} + for my $case (@cases) { subtest $case->{name} => sub { local $RCP; From 090deae902154d74d61d516615006160ccec2171 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 20:42:14 -0300 Subject: [PATCH 10/18] test(syncfiles): exercise copy consumer identity precedence Drive the real xdsh and DSHCLI parser from syncfiles and updatenode. Capture only the external copy boundary and preserve inherited identity behavior. --- xCAT-test/unit/syncfiles_consumer_identity.t | 124 +++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 xCAT-test/unit/syncfiles_consumer_identity.t diff --git a/xCAT-test/unit/syncfiles_consumer_identity.t b/xCAT-test/unit/syncfiles_consumer_identity.t new file mode 100644 index 0000000000..d49fad012a --- /dev/null +++ b/xCAT-test/unit/syncfiles_consumer_identity.t @@ -0,0 +1,124 @@ +#!/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 File::Path qw(make_path); +use File::Slurper qw(write_text); +use File::Temp qw(tempdir); +use Storable qw(dclone); +use Test::More; +use XCAT::Test::File qw(repo_path); + +my $work = tempdir(CLEANUP => 1); +make_path("$work/db"); +local $ENV{XCATROOT} = $work; +local $ENV{XCATCFG} = "SQLite:$work/db"; +for my $mapping ( + [ xCAT_plugin => 'xCAT-server/lib/xcat/plugins' ], + [ xCAT_monitoring => 'xCAT-server/lib/xcat/monitoring' ], +) { + symlink(repo_path($mapping->[1]), "$work/$mapping->[0]") or die $!; +} +unshift @INC, $work; +require xCAT_plugin::syncfiles; +require xCAT_plugin::xdsh; +require xCAT_plugin::updatenode; + +my $source = "$work/payload"; +my $list = "$work/synclist"; +write_text($source, "identity fixture\n"); +write_text($list, "$source -> /tmp/syncfiles-identity/payload\n"); + +sub exercise { + my ($producer, $case) = @_; + local %ENV = %ENV; + delete @ENV{grep { /\A(?:DSH_|DCP_|RSYNC)/ } keys %ENV}; + @ENV{keys %{$case->{inherited}}} = values %{$case->{inherited}}; + no warnings qw(once redefine); + local $::RCP; + local $::USER; + local $::fanout; + local $::timeout; + local $::REPORTSTATUS = 'N'; + local @::SUCCESSFULLNODES; + local @::FAILEDNODES; + local @ARGV; + local *xCAT::Utils::isServiceNode = sub { return 0; }; + local *xCAT::Utils::isMN = sub { return 0; }; + local *xCAT::TableUtils::get_site_attribute = sub { return; }; + local *xCAT::SvrUtils::getsynclistfile = sub { return {node1 => $list}; }; + local *xCAT_plugin::syncfiles::noderange = sub { return 'node1'; }; + my (@executions, @responses, @requests); + local *xCAT::DSHCLI::execute_dcp = sub { + my ($class, $options) = @_; + push @executions, { + options => dclone($options), + from => $ENV{DSH_FROM_USERID}, + to => $ENV{DSH_TO_USERID}, + }; + return 0; + }; + my $callback = sub { push @responses, dclone($_[0]); }; + my $dispatch = sub { + my ($request, $response) = @_; + push @requests, dclone($request); + xCAT_plugin::xdsh::process_request($request, $response, sub { die 'Unexpected nested request'; }); + }; + my $request = { + command => [$producer], node => ['node1'], arg => [], + username => ['operator'], _xcat_clienthost => ['node1.example.test'], + environment => $case->{environment} || [], + SNFileSyncing => ['no'], FileSyncing => ['yes'], + }; + if ($producer eq 'syncfiles') { + xCAT_plugin::syncfiles::process_request($request, $callback, $dispatch); + } else { + xCAT_plugin::updatenode::updatenodesyncfiles($request, $dispatch, $callback); + } + is(scalar @executions, 1, 'one parsed copy reaches the execution boundary'); + is(scalar @requests, 1, 'one producer request reaches the real xdsh plugin'); + my $copy = $executions[0] || {options => {}}; + is($copy->{from}, $case->{from}, 'consumer preserves the expected sending identity'); + is($copy->{to}, $case->{to}, 'consumer preserves the expected receiving identity'); + is($copy->{options}->{user}, $case->{from}, 'xdcp selects the sending identity for its copy user'); + is($copy->{options}->{nodes}, 'node1', 'copy targets the resolved node'); + is_deeply( + $copy->{options}->{destDir_srcFile}, + {node1 => {'/tmp/syncfiles-identity' => {same_dest_name => [$source]}}}, + 'the real synclist parser supplies the payload and destination', + ); + is_deeply($requests[0]->{username}, [$producer eq 'syncfiles' ? 'root' : 'operator'], + 'the producer retains its request identity contract'); + my @errors = grep { + $_->{error} || grep { $_ } ref($_->{errorcode}) eq 'ARRAY' + ? @{$_->{errorcode}} : ($_->{errorcode} || 0) + } @responses; + is_deeply(\@errors, [], 'the request has no consumer error'); + return; +} + +for my $case ( + {name => 'unset', inherited => {}, from => 'root', to => 'root'}, + {name => 'empty', inherited => {DSH_FROM_USERID => '', DSH_TO_USERID => ''}, from => 'root', to => 'root'}, + {name => 'sending identity only', inherited => {DSH_FROM_USERID => 'sender'}, from => 'sender', to => 'root'}, + {name => 'receiving identity only', inherited => {DSH_TO_USERID => 'receiver'}, from => 'root', to => 'receiver'}, + {name => 'both inherited', inherited => {DSH_FROM_USERID => 'sender', DSH_TO_USERID => 'receiver'}, from => 'sender', to => 'receiver'}, +) { + subtest "syncfiles: $case->{name}" => sub { exercise('syncfiles', $case); }; +} + +for my $case ( + {name => 'certificate identity', inherited => {}, from => 'operator', to => 'operator'}, + {name => 'certificate overrides inherited sender', inherited => {DSH_FROM_USERID => 'sender', DSH_TO_USERID => 'receiver'}, from => 'operator', to => 'receiver'}, + {name => 'explicit sending identity', inherited => {}, environment => ['DSH_FROM_USERID=sender'], from => 'sender', to => 'operator'}, + {name => 'first explicit sender wins', inherited => {}, environment => ['DSH_FROM_USERID=sender', 'DSH_FROM_USERID=other'], from => 'sender', to => 'operator'}, + {name => 'empty explicit sender falls back at consumer', inherited => {DSH_FROM_USERID => 'sender'}, environment => ['DSH_FROM_USERID='], from => 'operator', to => 'operator'}, +) { + subtest "updatenode: $case->{name}" => sub { exercise('updatenode', $case); }; +} + +done_testing(); From ff2ec0d4acaa480fe6b71caca81f18af6954fb89 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 20:42:14 -0300 Subject: [PATCH 11/18] test(syncfiles): verify authenticated hierarchy delivery Exercise certificate policy and real SSH copies in a disposable MN/SN/node fixture. This test is opt-in and skips in ordinary CI without XCAT_SYNCFILES_LIVE_CONFIG. --- .../autotest/testcase/integration/cases0 | 2 +- .../integration/fixtures/syncfiles-request.pl | 29 +++ xCAT-test/integration/syncfiles_delivery.t | 173 ++++++++++++++++++ 3 files changed, 203 insertions(+), 1 deletion(-) create mode 100644 xCAT-test/integration/fixtures/syncfiles-request.pl create mode 100644 xCAT-test/integration/syncfiles_delivery.t diff --git a/xCAT-test/autotest/testcase/integration/cases0 b/xCAT-test/autotest/testcase/integration/cases0 index 907e458372..aba39450ed 100644 --- a/xCAT-test/autotest/testcase/integration/cases0 +++ b/xCAT-test/autotest/testcase/integration/cases0 @@ -4,7 +4,7 @@ os:Linux label:mn_only,ci_test,integration cmd:prove -I/opt/xcat/lib/perl -I/opt/xcat/lib/perl/xCAT -r /opt/xcat/share/xcat/tools/autotest/integration check:rc==0 -check:output=~Files=10, +check:output=~Files=11, end start:xcatd_dispatch_redaction diff --git a/xCAT-test/integration/fixtures/syncfiles-request.pl b/xCAT-test/integration/fixtures/syncfiles-request.pl new file mode 100644 index 0000000000..92a5c5672b --- /dev/null +++ b/xCAT-test/integration/fixtures/syncfiles-request.pl @@ -0,0 +1,29 @@ +use strict; +use warnings; +use File::Slurper qw(read_text); +use JSON::PP qw(decode_json encode_json); +use xCAT::Client; + +my ($input) = @ARGV; +my $case = decode_json(read_text($input)); +my @responses; +my $callback = sub { push @responses, $_[0]; }; +delete $ENV{XCATBYPASS}; +local $SIG{ALRM} = sub { die "Syncfiles request timed out\n"; }; +alarm 60; +if ($case->{consumer}) { + require xCAT_plugin::syncfiles; + require xCAT_plugin::xdsh; + delete @ENV{qw(DSH_FROM_USERID DSH_TO_USERID)}; + @ENV{keys %{$case->{inherited}}} = values %{$case->{inherited}}; + xCAT_plugin::syncfiles::process_request($case->{request}, $callback, sub { + my ($request, $response) = @_; + xCAT_plugin::xdsh::preprocess_request($request, $response, sub { die 'Unexpected remote dispatch'; }); + }); +} else { + $ENV{XCATHOST} = $case->{endpoint}; + xCAT::Client::submit_request($case->{request}, $callback, + $case->{credential}, $case->{credential}, $case->{ca}); +} +alarm 0; +print encode_json(\@responses), "\n"; diff --git a/xCAT-test/integration/syncfiles_delivery.t b/xCAT-test/integration/syncfiles_delivery.t new file mode 100644 index 0000000000..ff0ca9763d --- /dev/null +++ b/xCAT-test/integration/syncfiles_delivery.t @@ -0,0 +1,173 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use FindBin; +use lib '/opt/xcat/lib/perl'; +use File::Path qw(remove_tree); +use File::Slurper qw(read_text write_text); +use JSON::PP qw(decode_json encode_json); +use Test::More; + +plan skip_all => 'set XCAT_SYNCFILES_LIVE_CONFIG for a disposable MN/SN/node lab' + unless $ENV{XCAT_SYNCFILES_LIVE_CONFIG}; +require Capture::Tiny; +die 'Run as root on the disposable management node' unless $> == 0; +my $config = decode_json(read_text($ENV{XCAT_SYNCFILES_LIVE_CONFIG})); +my ($node, $service, $work, $cache) = @{$config}{qw(node service work cache)}; +die 'Unsafe fixture path' unless $work =~ m{\A/tmp/xcat-syncfiles-[A-Za-z0-9]+\z}; +die 'Unsafe cache path' unless $cache =~ m{\A/[A-Za-z0-9/_-]+\z} && $cache ne '/'; +for ($node, $service, $config->{management}) { die 'Unsafe host name' unless /\A[A-Za-z0-9][A-Za-z0-9.-]*\z/; } +die 'Fixture hosts must be distinct' if $node eq $service || $node eq $config->{management} || $service eq $config->{management}; +for my $key (qw(operator denied ca)) { + die "Unsafe $key credential path" unless $config->{$key} =~ m{\A/[A-Za-z0-9/_.-]+\z}; +} +require xCAT::SvrUtils; +my $lists = xCAT::SvrUtils->getsynclistfile([$node]); +die 'The fixture node must use only the fixture synclist' + unless $lists->{$node} eq "$work/synclist"; + +sub command { + my (@args) = @_; + my ($out, $err, $status) = Capture::Tiny::capture(sub { system('timeout', '90', @args) }); + die "Command failed (@args): $status\n$out$err" if $status; + return $out; +} +sub remote { + my ($host, @args) = @_; + return command('ssh', '-oBatchMode=yes', "root\@$host", @args); +} +sub copy_to { + my ($host, $file, $target) = @_; + command('scp', '-q', $file, "root\@$host:$target"); + return; +} +my %created; +END { + my $status = $?; + my $failed = 0; + for my $host (grep { $_ ne 'local' } keys %created) { + eval { remote($host, 'rm', '-rf', '--', $work, "$cache$work"); 1 } + or do { warn "Fixture cleanup failed on $host: $@"; $failed = 1; }; + } + if ($created{local}) { + remove_tree($work, {error => \my $errors}); + if (@$errors) { warn "Local fixture cleanup failed\n"; $failed = 1; } + } + $? = $status || $failed; +} +die 'Fixture path already exists locally' if -e $work; +for my $host ($node, $service) { + remote($host, 'test', '!', '-e', $work); + remote($host, 'test', '!', '-e', "$cache$work"); +} +mkdir($work, 0700) or die "Cannot create $work: $!"; +$created{local} = 1; +for my $host ($node, $service) { + remote($host, 'mkdir', '-m', '0755', $work); + $created{$host} = 1; + copy_to($host, "$FindBin::Bin/fixtures/syncfiles-request.pl", "$work/request.pl"); +} +my $payload = "$work/payload"; +my $destination = "$work/delivered/payload"; +write_text("$work/synclist", "$payload -> $destination\n"); + +sub request { + my ($host, $case) = @_; + write_text("$work/request.json", encode_json($case)); + copy_to($host, "$work/request.json", "$work/request.json"); + my $out = remote($host, 'perl', '-I/opt/xcat/lib/perl', "$work/request.pl", "$work/request.json"); + return decode_json($out); +} +sub errors { + my ($responses) = @_; + my @errors; + for my $response (@$responses) { + my $codes = $response->{errorcode}; + $codes = [$codes] unless ref($codes) eq 'ARRAY'; + push @errors, $response if $response->{error} || + grep { defined($_) && $_ ne '0' && length($_) } @$codes; + } + return \@errors; +} +sub authenticated { + my ($endpoint, $principal, $request) = @_; + return request($node, { + endpoint => "$endpoint:3001", credential => $config->{$principal}, + ca => $config->{ca}, request => $request, + }); +} +sub delivered { + my ($text, $user) = @_; + is(remote($node, 'cat', $destination), $text, 'destination has the new payload'); + is(remote($node, 'stat', '-c', '%U', $destination), "$user\n", 'destination ownership matches the copy identity'); + return; +} +sub prepare_destination { + my ($user) = @_; + remote($node, 'mkdir', '-p', "$work/delivered"); + remote($node, 'rm', '-f', $destination); + remote($node, 'chown', $user, "$work/delivered"); + return; +} + +subtest 'authenticated node request traverses the MN/SN hierarchy' => sub { + write_text($payload, "hierarchy payload\n"); + prepare_destination('root'); + my $responses = authenticated($config->{management}, 'operator', {command => ['syncfiles'], arg => [], username => ['denied']}); + is_deeply(errors($responses), [], 'the authorized certificate is accepted despite the supplied username'); + delivered("hierarchy payload\n", 'root'); + is(remote($service, 'cat', "$cache$payload"), "hierarchy payload\n", 'the service node receives the staged payload'); +}; + +subtest 'authenticated node request consumes the service-node cache' => sub { + write_text($payload, "service cache payload\n"); + copy_to($service, $payload, "$cache$payload"); + prepare_destination('root'); + my $responses = authenticated($service, 'operator', {command => ['syncfiles'], arg => []}); + is_deeply(errors($responses), [], 'the service node accepts the certificate'); + delivered("service cache payload\n", 'root'); +}; + +subtest 'unauthorized certificate cannot trigger a copy' => sub { + write_text($payload, "must not be delivered\n"); + copy_to($service, $payload, "$cache$payload"); + my $responses = authenticated($service, 'denied', {command => ['syncfiles'], arg => [], username => ['root']}); + my @denials = map { @{$_->{error} || []} } @{errors($responses)}; + ok(scalar(grep { $_ eq 'Permission denied for request' } @denials), + 'authorization rejects the certificate despite the supplied root username'); + delivered("service cache payload\n", 'root'); +}; + +for my $case ( + ['unset', {}, 'root'], + ['empty', {DSH_FROM_USERID => '', DSH_TO_USERID => ''}, 'root'], + ['sender only', {DSH_FROM_USERID => 'sender'}, 'sender'], + ['receiver only', {DSH_TO_USERID => 'receiver'}, 'root'], + ['both', {DSH_FROM_USERID => 'sender', DSH_TO_USERID => 'receiver'}, 'sender'], +) { + my ($name, $inherited, $user) = @$case; + subtest "real copy consumer with $name inherited" => sub { + my $text = "consumer $name\n"; + write_text($payload, $text); + copy_to($service, $payload, "$cache$payload"); + prepare_destination($user); + my $responses = request($service, { + consumer => 1, inherited => $inherited, + request => {command => ['syncfiles'], arg => [], _xcat_clienthost => [$node]}, + }); + is_deeply(errors($responses), [], 'the real copy consumer reports no error'); + delivered($text, $user); + }; +} + +subtest 'updatenode preserves the authenticated non-root identity across the hierarchy' => sub { + write_text($payload, "updatenode payload\n"); + prepare_destination('operator'); + my $responses = authenticated($config->{management}, 'operator', { + command => ['updatenode'], noderange => [$node], arg => ['-F'], username => ['root'], + }); + is_deeply(errors($responses), [], 'updatenode completes without an earlier error being hidden'); + delivered("updatenode payload\n", 'operator'); +}; + +done_testing(); From 66a8b7786bbe064f9ff1b7fd0c0b7f0645123144 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 20:42:14 -0300 Subject: [PATCH 12/18] docs(syncfiles): describe the isolated delivery fixture Document the restricted certificate policy, required tools and cleanup limits. Distinguish the fixture from the default certificate-free postscript path. --- xCAT-test/integration/README.md | 79 ++++++++++++++++++++++++++++++++- xCAT-test/unit/README.md | 5 +++ 2 files changed, 82 insertions(+), 2 deletions(-) diff --git a/xCAT-test/integration/README.md b/xCAT-test/integration/README.md index eec8664c99..151e9e1f77 100644 --- a/xCAT-test/integration/README.md +++ b/xCAT-test/integration/README.md @@ -27,8 +27,8 @@ against it. Note the `-I` flags: unlike the unit tests these run from the installed location, so they pick up xCAT modules from `/opt/xcat/lib/perl` rather than from a source tree. -The case checks `rc==0` and `output=~Files=10,`. The file count checks that `prove` -found all ten files, which catches a packaging regression or a test renamed away from +The case checks `rc==0` and `output=~Files=11,`. The file count checks that `prove` +found all eleven files, which catches a packaging regression or a test renamed away from `.t` without updating the count. It does not prove that environment-gated cases ran; inspect the TAP output for skips. **Add to that number when you add a test.** A missing directory is already caught by `rc==0` -- `prove -r` on a path that does not exist exits @@ -55,6 +55,7 @@ A test belongs in `integration/` when it needs something the checkout cannot pro | `html_form_runtime_dependency.t` | the installed `HTML::Form` module | | `openeuler_package_postscripts.t` | Linux root, private mount namespaces and DNF; tests complete package postscripts with command doubles and an isolated repository directory | | `openeuler_postscript_repositories.t` | Linux root, private mount namespaces, DNF and RPM signing tools; tests actual signed repository transactions in isolated install roots | +| `syncfiles_delivery.t` | a disposable management node, service node and compute node, certificate policies and SSH copy access; opt-in | | `wsapi_apache_access.t` | an Apache binary and its modules; reads `xcat-ws.conf` from the source tree, so `github_action_xcat_test.pl` runs it from the checkout and the installed copy skips | | `xcatd_dispatch_redaction.sh` | a live `xcatd`, syslog delivery to `/var/log/xcat/cluster.log`, and root | @@ -96,6 +97,80 @@ plan skip_all => 'set XCAT_KEA_LIVE_SMOKE=1 to run live Kea daemon smoke test' It starts real Kea daemons, so it stays off unless asked for. Do not enable it on a node whose DHCP service is in use. +## Syncfiles delivery lab + +Run `syncfiles_delivery.t` only in a disposable three-node lab. It sends real +`syncfiles` and `updatenode -F` requests, and runs real SSH/rsync copies. Do not +point it at a shared or production cluster. + +Prepare the lab before enabling the test: + +- Install xCAT on the management and service nodes, and the xCAT Perl client + modules on the compute node. Install Perl `File::Slurper`, `Capture::Tiny`, + `JSON::PP`, `timeout`, SSH/SFTP and rsync. The management and service nodes + must have the normal `updatenode` postscript files and reachability tools. +- Configure name resolution and route the compute node through the service node + in `noderes.servicenode` and `noderes.xcatmaster`. Give the compute node a + dedicated osimage with exactly one synclist: `/synclist`. +- Configure the service-node cache prefix in the test to match + `site.SNsyncfiledir` (default `/var/xcat/syncfiles`). Keep the daemon environment + free of `DSH_*`, `DCP_*` and `RSYNC*` overrides. +- Use a lab CA and valid client certificates for `operator` and `denied`. + Allow `operator` to run `syncfiles`, `updatenode` and `xdcp`. Leave `denied` + unauthorized. On both the management and service nodes, remove the default + unnamed `syncfiles` allow rule and any other rule that allows `denied`. + This certificate-only fixture intentionally differs from the default policy, + which allows the certificate-free `startsyncfiles` postscript request. + Configure the normal trusted MN/SN certificate relationship. + Store the client credentials and CA on the compute node; the test does not + create certificates or change policy. +- Create the `operator`, `sender` and `receiver` Unix accounts. Give the + management node root SSH access to the service and compute nodes, and give + the service node SSH copy access to the compute node as `root`, `operator` + and `sender`. Use lab-only keys and pinned host keys. Do not enable password + authentication for this test. + +Create a JSON configuration on the management node. For example: + +```json +{ + "management": "mn", + "service": "sn", + "node": "cn", + "work": "/tmp/xcat-syncfiles-fixture1", + "cache": "/var/xcat/syncfiles", + "operator": "/root/lab-certs/operator.pem", + "denied": "/root/lab-certs/denied.pem", + "ca": "/root/lab-certs/ca.pem" +} +``` + +Each client PEM contains its certificate and private key. Keep the credentials +private. The three host names must be distinct. The work path must be a new +directory directly under `/tmp`, named `xcat-syncfiles-` followed by letters or +digits. The test refuses existing work and cache paths, removes its request and +payload directories on exit, and fails if that cleanup fails. xCAT can retain +cache parent directories and generated `/tmp/rsync_*` command files outside +those directories. Remove the disposable nodes and credentials after testing. + +Run as root on the management node: + +```sh +XCAT_SYNCFILES_LIVE_CONFIG=/root/syncfiles-lab.json \ + prove -v xCAT-test/integration/syncfiles_delivery.t +``` + +The certificate cases check authorization under that restricted policy, MN/SN +staging, delivered bytes and file ownership. `syncfiles` requests root copies +regardless of the authenticated user; `updatenode` retains the authenticated +user unless its environment overrides the sender. The inherited-environment +cases call the real copy consumer on the service node without TLS; they test +copy identity precedence, not authentication. The unit test +`syncfiles_consumer_identity.t` checks both parsed identity variables and rejects +changes that overwrite nonempty inherited values. + +This fixture does not cover the default certificate-free `startsyncfiles` path. + ## What does not belong here Anything that only needs the checkout. Those go in [`../unit`](../unit/README.md) and diff --git a/xCAT-test/unit/README.md b/xCAT-test/unit/README.md index 2a5b5ed111..abd70e1771 100644 --- a/xCAT-test/unit/README.md +++ b/xCAT-test/unit/README.md @@ -38,6 +38,11 @@ skip. The CI takes a copy of the checkout before the build for this reason; see ## Running commands from Perl tests +`syncfiles_consumer_identity.t` also requires `/usr/bin/rsync` on Linux. The +real copy parser checks that executable before the test intercepts copy +execution. Install rsync with the test dependencies; this test does not run it +or connect to another node. The CI management-node install already includes it. + Use `XCAT::Test::Process` when a test needs a command's exit code and combined standard output and standard error: From cc206d5f1ced3f2f6632d2c93e74a09233451e59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Thu, 22 Oct 2026 14:12:14 -0300 Subject: [PATCH 13/18] fix(route): retain the device for IPv6 link-local gateways Scope generic Linux route lookup and updates to the supplied interface for link-local next hops. Retain the device in SLES routes, legacy Red Hat route6 records and Debian interface commands. Remove matching saved records without matching neighboring interface names, and migrate older unscoped records when adding routes. Keep global gateways, connected routes and NetworkManager policy unchanged. --- xCAT/postscripts/routeop | 77 ++++++++++++++++++++++++++++++++-------- 1 file changed, 62 insertions(+), 15 deletions(-) diff --git a/xCAT/postscripts/routeop b/xCAT/postscripts/routeop index 5add370d08..626a45aa52 100755 --- a/xCAT/postscripts/routeop +++ b/xCAT/postscripts/routeop @@ -143,7 +143,7 @@ route_exists() # ipv6 if is_ipv6_route "$route_net" then - result=`ip -6 route show $route_net/$route_mask` + result=`ip -6 route show $route_net/$route_mask ${gateway_device:+via $route_gw dev $gateway_device}` if [ $? -ne 0 ] || [ -z "$result" ] then ret=0 @@ -449,6 +449,15 @@ nmcli_persistent_route() fi } +remove_route_record() +{ + local filename=$1 + local pattern + [ -f "$filename" ] || return 0 + pattern=$(printf '%s\n' "$2" | sed 's/[][\\.^$*#]/\\&/g') + sed -i "\#^[[:space:]]*${pattern}[[:space:]]*\$#d" "$filename" +} + # handle the route replace operation that adding the setting to configuration file replace_persistent_route() { @@ -491,8 +500,8 @@ replace_persistent_route() route="$net/$mask :: - $ifname" route1="$net\/$mask :: - $ifname"; else - route="$net/$mask $gw - -" - route1="$net\/$mask $gw - -"; + route="$net/$mask $gw - ${gateway_device:--}" + route1="$net\/$mask $gw - ${gateway_device:--}"; fi else # for ipv4 @@ -549,8 +558,8 @@ replace_persistent_route() route="$net/$mask dev $ifname" route1="$net\/$mask dev $ifname" else - route="$net/$mask via $gw" - route1="$net\/$mask via $gw" + route="$net/$mask via $gw${gateway_device:+ dev $gateway_device}" + route1="$net\/$mask via $gw${gateway_device:+ dev $gateway_device}" fi else # ipv4 @@ -696,8 +705,8 @@ add_persistent_route() route="$net/$mask :: - $ifname" route1="$net\/$mask :: - $ifname"; else - route="$net/$mask $gw - -" - route1="$net\/$mask $gw - -"; + route="$net/$mask $gw - ${gateway_device:--}" + route1="$net\/$mask $gw - ${gateway_device:--}"; fi else if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then @@ -728,8 +737,13 @@ add_persistent_route() fi fi fi + local match_flags= + if is_ipv6_route "$net" && [ -n "$gateway_device" ]; then + remove_route_record "$filename" "$net/$mask $gw - -" || return $? + match_flags=-Fx + fi if [ -f $filename ]; then - grep "$route" $filename 2>&1 1>/dev/null + grep $match_flags "$route" $filename 2>&1 1>/dev/null if [ $? -ne 0 ]; then #route does not exist grep "$xcat_config_start" $filename 2>&1 1>/dev/null if [ $? -ne 0 ]; then #no xCAT section @@ -782,6 +796,11 @@ add_persistent_route() fi fi + if [ -n "$gateway_device" ] && [ "$v6flag" -eq 1 ]; then + remove_route_record "$filename" "up route -A inet6 add $net/$mask gw $gw" || return $? + remove_route_record "$filename" "down route -A inet6 del $net/$mask gw $gw" || return $? + remove_route_record "$filename" "post-up ip -6 route replace $net/$mask via $gw" || return $? + fi grep "$matchstr" $filename 2>&1 1>/dev/null if [ $? -ne 0 ];then foundflag=0 @@ -796,8 +815,8 @@ add_persistent_route() echo " up route -A inet6 add $net/$mask dev $ifname" >> $tempfile echo " down route -A inet6 del $net/$mask dev $ifname" >> $tempfile else - echo " up route -A inet6 add $net/$mask gw $gw" >> $tempfile - echo " down route -A inet6 del $net/$mask gw $gw" >> $tempfile + echo " up route -A inet6 add $net/$mask gw $gw${gateway_device:+ dev $gateway_device}" >> $tempfile + echo " down route -A inet6 del $net/$mask gw $gw${gateway_device:+ dev $gateway_device}" >> $tempfile fi else if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then @@ -824,8 +843,8 @@ add_persistent_route() echo " up route -A inet6 add $net/$mask dev $ifname" >> $tempfile echo " down route -A inet6 del $net/$mask dev $ifname" >> $tempfile else - echo " up route -A inet6 add $net/$mask gw $gw" >> $tempfile - echo " down route -A inet6 del $net/$mask gw $gw" >> $tempfile + echo " up route -A inet6 add $net/$mask gw $gw${gateway_device:+ dev $gateway_device}" >> $tempfile + echo " down route -A inet6 del $net/$mask gw $gw${gateway_device:+ dev $gateway_device}" >> $tempfile fi else if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then @@ -924,6 +943,11 @@ rm_persistent_route() sles) #echo "sles" filename="/etc/sysconfig/network/routes"; + if is_ipv6_route "$net" && [ -n "$gateway_device" ]; then + remove_route_record "$filename" "$net/$mask $gw - $gateway_device" || return $? + remove_route_record "$filename" "$net/$mask $gw - -" + return $? + fi # ipv6 net if is_ipv6_route "$net" then @@ -984,6 +1008,15 @@ rm_persistent_route() fi fi + if [ -n "$gateway_device" ] && [ "$v6flag" -eq 1 ]; then + local device_suffix + for device_suffix in " dev $gateway_device" ""; do + remove_route_record "$filename" "up route -A inet6 add $net/$mask gw $gw$device_suffix" || return $? + remove_route_record "$filename" "down route -A inet6 del $net/$mask gw $gw$device_suffix" || return $? + remove_route_record "$filename" "post-up ip -6 route replace $net/$mask via $gw$device_suffix" || return $? + done + return 0 + fi grep "$matchstr" $filename if [ $? -eq 0 ];then sed -i -e "/$matchstr/d" $filename @@ -998,6 +1031,13 @@ rm_persistent_route() nmcli_persistent_route delete "$net" "$mask" "$gw" "$ifname" return $? fi + if is_ipv6_route "$net" && [ -n "$gateway_device" ]; then + filename="/etc/sysconfig/network-scripts/route6-$ifname" + remove_route_record "$filename" "$net/$mask via $gw dev $gateway_device" || return $? + remove_route_record "$filename" "$net/$mask via $gw" || return $? + remove_route_record /etc/sysconfig/static-routes-ipv6 "$ifname $net/$mask $gw" + return $? + fi #ipv6 if is_ipv6_route "$net" then @@ -1048,6 +1088,13 @@ rm_persistent_route() +gateway_device= +if [ "$(uname -s)" = "Linux" ]; then + case "$gw" in + [fF][eE][89aAbB][[:xdigit:]]:*) gateway_device=$ifname ;; + esac +fi + if command -v xcat_is_openeuler >/dev/null 2>&1 && xcat_is_openeuler "$OSVER"; then case "$op" in add|delete|replace) @@ -1071,7 +1118,7 @@ if [ "$op" = "add" ]; then if [ "$gw" = "" -o "$gw" = "::" ] ; then cmd="ip -6 route add $net/$mask dev $ifname" else - cmd="ip -6 route add $net/$mask via $gw" + cmd="ip -6 route add $net/$mask via $gw${gateway_device:+ dev $gateway_device}" fi else # AIX TODO @@ -1127,7 +1174,7 @@ elif [ "$op" = "delete" ]; then if [ "$gw" = "" -o "$gw" = "::" ] ; then cmd="ip -6 route delete $net/$mask dev $ifname" else - cmd="ip -6 route delete $net/$mask via $gw" + cmd="ip -6 route delete $net/$mask via $gw${gateway_device:+ dev $gateway_device}" fi else # AIX TODO @@ -1183,7 +1230,7 @@ elif [ "$op" = "replace" ]; then if [ "$net" = "default" ]; then cmd="ip -6 route replace default via $gw" else - cmd="ip -6 route replace $net/$mask via $gw" + cmd="ip -6 route replace $net/$mask via $gw${gateway_device:+ dev $gateway_device}" fi fi fi From d42f3e3150df63d4c5989a23cfcd61f2215df1d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Thu, 22 Oct 2026 14:12:14 -0300 Subject: [PATCH 14/18] test(route): exercise link-local gateways in network namespaces Run routeop against real kernel routes. Cover repeated add, replacement, deletion, another device, expanded addresses and failure preservation. Check SLES, legacy Red Hat and Debian persistent records, including unscoped records and neighboring interface names. Keep global-gateway and connected-route controls. --- xCAT-test/bats/README.md | 5 + xCAT-test/bats/routeop_linklocal.bats | 179 ++++++++++++++++++++++++++ 2 files changed, 184 insertions(+) create mode 100644 xCAT-test/bats/routeop_linklocal.bats diff --git a/xCAT-test/bats/README.md b/xCAT-test/bats/README.md index 4e70ec6f2c..de452fe90e 100644 --- a/xCAT-test/bats/README.md +++ b/xCAT-test/bats/README.md @@ -28,6 +28,11 @@ fixtures. They require Bubblewrap, Bash, GNU core utilities, grep, sed, and permission to create user namespaces. The CI workflow installs Bubblewrap and enables those namespaces. +`routeop_linklocal.bats` also needs iproute2 and kernel support for dummy +network interfaces. It maps root and grants `CAP_NET_ADMIN` only inside a +new user and network namespace. It runs as an ordinary user and changes +real kernel routes only in that private network namespace. + Missing prerequisites fail these tests without stopping unrelated test files. Non-Linux hosts report a skip. Set `TMPDIR` to a writable, executable filesystem if the default temporary directory is mounted with `noexec`. diff --git a/xCAT-test/bats/routeop_linklocal.bats b/xCAT-test/bats/routeop_linklocal.bats new file mode 100644 index 0000000000..8be31330a8 --- /dev/null +++ b/xCAT-test/bats/routeop_linklocal.bats @@ -0,0 +1,179 @@ +#!/usr/bin/env bats + +load 'helpers/script_sandbox' + +setup() +{ + setup_script_sandbox cat dirname grep sed tr uname logger awk cut head rm touch mkdir mv + local ip_binary + ip_binary=$(PATH=/usr/sbin:/sbin:/usr/bin:/bin type -P ip) || return 1 + cp -L "$ip_binary" "$fixture/bin/ip" + mkdir -p "$fixture/etc/sysconfig/network" + printf '%s\n' SLE VERSION=15 >"$fixture/etc/SUSE-brand" + sandbox+=(--ro-bind "$(repo_path xCAT/postscripts)" /tmp/postscripts + --setenv OSVER sles15 --uid 0 --gid 0 --cap-add CAP_NET_ADMIN) + cat >"$fixture/bin/route-test" <<'SH' +#!/bin/bash +set -eu +ip link set lo up +for dev in test0 test1; do + ip link add "$dev" type dummy + ip link set "$dev" up + ip -6 address add fe80::2/64 dev "$dev" nodad + ip -6 address add 2001:db8:1::2/64 dev "$dev" nodad +done +exec /bin/bash -eu -c "$1" +SH + chmod +x "$fixture/bin/route-test" +} + +run_routes() +{ + run "${sandbox[@]}" /bin/bash /bin/route-test "$1" + [ "$status" -eq 0 ] +} + +@test 'routeop installs and repeats a link-local gateway route on its device' { + run_routes ' + for pass in 1 2; do + /tmp/postscripts/routeop add 2001:db8:2:: 64 fe80::1 test0 + ip -6 route show 2001:db8:2::/64 | + grep -q "2001:db8:2::/64 via fe80::1 dev test0" + done + test "$(grep -c "^2001:db8:2::/64 fe80::1 - test0$" /etc/sysconfig/network/routes)" = 1 + ' +} + +@test 'routeop does not confuse a link-local route on another device' { + run_routes ' + ip -6 route add 2001:db8:2::/64 via fe80::1 dev test1 metric 2000 + /tmp/postscripts/routeop add 2001:db8:2:: 64 fe80::1 test0 + ip -6 route show 2001:db8:2::/64 | grep -q "2001:db8:2::/64 via fe80::1 dev test0" + ip -6 route show 2001:db8:2::/64 | grep -q "2001:db8:2::/64 via fe80::1 dev test1" + ' +} + +@test 'routeop replaces and deletes the scoped gateway without deleting a neighbor' { + run_routes ' + /tmp/postscripts/routeop replace 2001:db8:2:: 64 fe80::1 test0 + ip -6 route show 2001:db8:2::/64 | grep -q "2001:db8:2::/64 via fe80::1 dev test0" + /tmp/postscripts/routeop replace 2001:db8:2:: 64 fe80::3 test0 + ip -6 route show 2001:db8:2::/64 | grep -q "2001:db8:2::/64 via fe80::3 dev test0" + grep -qx "2001:db8:2::/64 fe80::3 - test0" /etc/sysconfig/network/routes + ip -6 route add 2001:db8:2::/64 via fe80::3 dev test1 metric 512 + /tmp/postscripts/routeop delete 2001:db8:2:: 64 fe80::3 test0 + test -z "$(ip -6 route show 2001:db8:2::/64 via fe80::3 dev test0)" + ip -6 route show 2001:db8:2::/64 | grep -q "2001:db8:2::/64 via fe80::3 dev test1" + test -z "$(sed "/^[[:space:]]*$/d" /etc/sysconfig/network/routes)" + ' +} + +@test 'routeop scopes expanded and upper-case link-local gateways' { + run_routes ' + /tmp/postscripts/routeop replace 2001:db8:2:: 64 FE80:0000:0000:0000:0000:0000:0000:0001 test0 + ip -6 route show 2001:db8:2::/64 | grep -q "2001:db8:2::/64 via fe80::1 dev test0" + grep -qx "2001:db8:2::/64 FE80:0000:0000:0000:0000:0000:0000:0001 - test0" /etc/sysconfig/network/routes + ' +} + +@test 'routeop leaves persistence unchanged when a scoped replacement fails' { + run_routes ' + echo "2001:db8:2::/64 fe80::1 - test0" >/etc/sysconfig/network/routes + if /tmp/postscripts/routeop replace 2001:db8:2:: 64 fe80::3 missing0; then exit 1; fi + grep -qx "2001:db8:2::/64 fe80::1 - test0" /etc/sysconfig/network/routes + test -z "$(ip -6 route show 2001:db8:2::/64)" + ' +} + +@test 'routeop retains global-gateway and connected-route behavior' { + run_routes ' + /tmp/postscripts/routeop replace 2001:db8:2:: 64 2001:db8:1::1 test0 + ip -6 route show 2001:db8:2::/64 | grep -q "via 2001:db8:1::1" + grep -qx "2001:db8:2::/64 2001:db8:1::1 - -" /etc/sysconfig/network/routes + /tmp/postscripts/routeop replace 2001:db8:3:: 64 :: test0 + ip -6 route show 2001:db8:3::/64 | grep -q "dev test0" + grep -qx "2001:db8:3::/64 :: - test0" /etc/sysconfig/network/routes + ' +} + +@test 'routeop deletes exact SLES records and older unscoped entries' { + run_routes ' + printf "%s\n" "2001:db8:2::/64 fe80::1 - test0" \ + "2001:db8:2::/64 fe80::1 - test01" \ + "2001:db8:3::/64 fe80::1 - -" >/etc/sysconfig/network/routes + /tmp/postscripts/routeop delete 2001:db8:2:: 64 fe80::1 test0 + /tmp/postscripts/routeop delete 2001:db8:3:: 64 fe80::1 test0 + test "$(cat /etc/sysconfig/network/routes)" = "2001:db8:2::/64 fe80::1 - test01" + ' +} + +@test 'routeop replaces an unscoped SLES entry without matching another device' { + run_routes ' + printf "%s\n" "2001:db8:2::/64 fe80::1 - -" \ + "2001:db8:2::/64 fe80::1 - test01" >/etc/sysconfig/network/routes + /tmp/postscripts/routeop add 2001:db8:2:: 64 fe80::1 test0 + test "$(grep -c "^2001:db8:2::/64 fe80::1 - test0$" /etc/sysconfig/network/routes)" = 1 + grep -qx "2001:db8:2::/64 fe80::1 - test01" /etc/sysconfig/network/routes + test "$(grep -c " - -$" /etc/sysconfig/network/routes)" = 0 + ' +} + +@test 'routeop treats dotted interface names literally in saved routes' { + run_routes ' + ip link add test0.1 type dummy + ip link set test0.1 up + printf "%s\n" "2001:db8:2::/64 fe80::1 - test0x1" >/etc/sysconfig/network/routes + /tmp/postscripts/routeop add 2001:db8:2:: 64 fe80::1 test0.1 + grep -Fqx "2001:db8:2::/64 fe80::1 - test0.1" /etc/sysconfig/network/routes + /tmp/postscripts/routeop delete 2001:db8:2:: 64 fe80::1 test0.1 + test "$(sed "/^#/d;/^$/d" /etc/sysconfig/network/routes)" = "2001:db8:2::/64 fe80::1 - test0x1" + ' +} + +@test 'routeop retains the device in legacy Red Hat route6 files' { + run_routes ' + rm /etc/SUSE-brand + touch /etc/redhat-release + mkdir -p /etc/sysconfig/network-scripts + export OSVER=rhels8 + /tmp/postscripts/routeop replace 2001:db8:2:: 64 fe80::1 test0 + test "$(cat /etc/sysconfig/network-scripts/route6-test0)" = "2001:db8:2::/64 via fe80::1 dev test0" + ip -6 route show 2001:db8:2::/64 | grep -q "via fe80::1 dev test0" + printf "%s\n" "test0 2001:db8:2::/64 fe80::1" "test01 2001:db8:2::/64 fe80::1" >/etc/sysconfig/static-routes-ipv6 + /tmp/postscripts/routeop delete 2001:db8:2:: 64 fe80::1 test0 + test ! -s /etc/sysconfig/network-scripts/route6-test0 + test "$(cat /etc/sysconfig/static-routes-ipv6)" = "test01 2001:db8:2::/64 fe80::1" + test -z "$(ip -6 route show 2001:db8:2::/64)" + echo "2001:db8:2::/64 via fe80::1" >/etc/sysconfig/network-scripts/route6-test0 + /tmp/postscripts/routeop delete 2001:db8:2:: 64 fe80::1 test0 + test ! -s /etc/sysconfig/network-scripts/route6-test0 + ' +} + +@test 'routeop scopes Debian interface up and down gateway commands' { + run_routes ' + rm /etc/SUSE-brand + touch /etc/debian_version + mkdir -p /etc/network/interfaces.d + printf "%s\n" "#XCAT_CONFIG" "source /etc/network/interfaces.d/*" >/etc/network/interfaces + export OSVER=ubuntu24.04 + for layout in last middle; do + printf "%s\n" "auto test0" "iface test0 inet manual" >/etc/network/interfaces.d/test0 + printf "%s\n" " up route -A inet6 add 2001:db8:2::/64 gw fe80::1" \ + " down route -A inet6 del 2001:db8:2::/64 gw fe80::1" \ + "post-up ip -6 route replace 2001:db8:2::/64 via fe80::1" >>/etc/network/interfaces.d/test0 + if [ "$layout" = middle ]; then echo "iface test1 inet manual" >>/etc/network/interfaces.d/test0; fi + /tmp/postscripts/routeop add 2001:db8:2:: 64 fe80::1 test0 + grep -Fxq " up route -A inet6 add 2001:db8:2::/64 gw fe80::1 dev test0" /etc/network/interfaces.d/test0 + grep -Fxq " down route -A inet6 del 2001:db8:2::/64 gw fe80::1 dev test0" /etc/network/interfaces.d/test0 + if grep -Fxq "post-up ip -6 route replace 2001:db8:2::/64 via fe80::1" /etc/network/interfaces.d/test0; then exit 1; fi + /tmp/postscripts/routeop delete 2001:db8:2:: 64 fe80::1 test0 + test "$(grep -c "2001:db8:2::" /etc/network/interfaces.d/test0)" = 0 + /tmp/postscripts/routeop replace 2001:db8:2:: 64 fe80::1 test0 + grep -Fxq "post-up ip -6 route replace 2001:db8:2::/64 via fe80::1 dev test0" /etc/network/interfaces.d/test0 + ip -6 route show 2001:db8:2::/64 | grep -q "via fe80::1 dev test0" + /tmp/postscripts/routeop delete 2001:db8:2:: 64 fe80::1 test0 + test "$(grep -c "2001:db8:2::" /etc/network/interfaces.d/test0)" = 0 + done + ' +} From 60beaecead4e8b1008dcb2fc0a202f57bd58c1c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Thu, 22 Oct 2026 14:18:03 -0300 Subject: [PATCH 15/18] fix(syslog): create the local log directory before setting its owner Create missing Debian-family log directories before assigning their owner. Use mode 0750 for syslog-owned directories. In the legacy reference-owner path, copy the parent directory mode so group-writing daemons retain access. Preserve existing directory modes, log files and forwarding policy. Stop with an error before restarting syslog if the directory cannot be created. Keep existing ownership-command failures nonfatal. --- xCAT/postscripts/syslog | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/xCAT/postscripts/syslog b/xCAT/postscripts/syslog index b0acfedd35..7840b3b763 100755 --- a/xCAT/postscripts/syslog +++ b/xCAT/postscripts/syslog @@ -83,6 +83,14 @@ is_lsb_ubuntu () # failure (not Ubuntu), which is the correct outcome. } +set_log_directory_owner() +{ + local mode=$1 + shift + mkdir -p -m "$mode" /var/log/xcat || exit $? + chown "$@" /var/log/xcat +} + config_Rsyslog_C3() { isReceiving=0 @@ -127,7 +135,7 @@ config_Rsyslog_C3() touch /var/log/messages chown syslog:adm /var/log/messages sed -i 's/\$PrivDropToGroup syslog/\$PrivDropToGroup adm/' $2 - chown syslog:adm /var/log/xcat + set_log_directory_owner 0750 syslog:adm fi else sed -i 's/^\(\*\..*\)/\#\1/; @@ -286,7 +294,7 @@ config_rsyslog_V8() if ( pmatch $OSVER "ubuntu*" ) || ( is_lsb_ubuntu ) || ( pmatch $OSVER "debian*" ); then chown syslog:adm /var/log/messages sed -i 's/\$PrivDropToGroup syslog/\$PrivDropToGroup adm/' $conf_file - chown syslog:adm /var/log/xcat + set_log_directory_owner 0750 syslog:adm fi # Mark the start of xCAT section @@ -523,7 +531,7 @@ else touch /var/log/messages if ( pmatch $OSVER "ubuntu*" ) || ( is_lsb_ubuntu ) || ( pmatch $OSVER "debian*" ); then chown --reference=/var/log /var/log/messages - chown --reference=/var/log /var/log/xcat + set_log_directory_owner "$(stat -c %a /var/log)" --reference=/var/log fi if [ $ng -eq 0 ]; then if [ ! -f $conf_file.XCATORIG ]; then From ea4738a5cee041d3876050de6760afe3ccfe6983 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Thu, 22 Oct 2026 14:18:03 -0300 Subject: [PATCH 16/18] test(syslog): verify directory setup and native log delivery Execute the complete postscript and check the daemon UID before real UDP log delivery. Cover fresh and repeated MN/SN setup, restricted directories, legacy ownership and modes, and a blocked directory path. Keep the upgrade wrapper and forwarding cases as compatibility controls. Select older configuration branches through their version-report boundary; use the installed daemon, without claiming old-daemon qualification. Run the isolated native cases in CI. --- .github/workflows/xcat_test.yml | 1 + xCAT-test/native/syslog_log_directory.bats | 197 +++++++++++++++++++++ 2 files changed, 198 insertions(+) create mode 100644 xCAT-test/native/syslog_log_directory.bats diff --git a/.github/workflows/xcat_test.yml b/.github/workflows/xcat_test.yml index 629fc208f0..93af942c58 100644 --- a/.github/workflows/xcat_test.yml +++ b/.github/workflows/xcat_test.yml @@ -49,6 +49,7 @@ jobs: sudo cp -R xCAT-test xCAT-server perl-xCAT xCAT "$workdir/" status=0 sudo sh -c 'cd "$1" && bats xCAT-test/native/getinstdisk_selection.bats' sh "$workdir" || status=1 + sudo sh -c 'cd "$1" && bats xCAT-test/native/syslog_log_directory.bats' sh "$workdir" || status=1 sudo sh -c 'cd "$1" && prove -v xCAT-test/native/getinstdisk_installer.t xCAT-test/native/enablekdump_per_node.t xCAT-test/native/sudoer_password_source.t xCAT-test/native/remoteshell_credentials.t' sh "$workdir" || status=1 exit "$status" - name: Prepare xCAT syslog directory diff --git a/xCAT-test/native/syslog_log_directory.bats b/xCAT-test/native/syslog_log_directory.bats new file mode 100644 index 0000000000..c58dba70fb --- /dev/null +++ b/xCAT-test/native/syslog_log_directory.bats @@ -0,0 +1,197 @@ +#!/usr/bin/env bats + +load '../bats/helpers/script_sandbox' + +setup() +{ + [ "$(id -u)" -eq 0 ] || skip 'native syslog ownership checks require root' + setup_script_sandbox cat cp dirname grep egrep sed tr uname awk cut head touch mkdir \ + chown chmod stat id sleep logger rm date mktemp + local index daemon + # Keep real account IDs so rsyslog can drop its privileges. + for index in "${!sandbox[@]}"; do + if [ "${sandbox[$index]}" = --unshare-all ]; then + sandbox[$index]=--unshare-pid + fi + done + sandbox+=(--unshare-net --unshare-ipc --unshare-uts + --ro-bind "$(repo_path xCAT/postscripts)" /tmp/postscripts + --ro-bind "$(repo_path xCAT/xcat-upgrade-functions.sh)" /tmp/upgrade.sh) + daemon=$(PATH=/usr/sbin:/sbin:/usr/bin:/bin type -P rsyslogd) || return 1 + cp -L "$daemon" "$fixture/bin/rsyslogd-real" + daemon=$(PATH=/usr/sbin:/sbin:/usr/bin:/bin type -P ip) || return 1 + cp -L "$daemon" "$fixture/bin/ip" + cp /etc/passwd /etc/group /etc/nsswitch.conf "$fixture/etc/" + id syslog >/dev/null || return 1 + mkdir -p "$fixture/etc/rsyslog.d" "$fixture/etc/default" \ + "$fixture/etc/systemd/system" "$fixture/var/log" "$fixture/var/lib/rsyslog" + touch "$fixture/etc/systemd/system/rsyslog.service" + cat >"$fixture/etc/rsyslog.conf" <<'CONF' +$PrivDropToUser syslog +$PrivDropToGroup syslog +module(load="imudp") +input(type="imudp" address="127.0.0.1" port="1514") +local4.* /var/log/xcat/cluster.log +$IncludeConfig /etc/rsyslog.d/*.conf +CONF + cat >"$fixture/bin/rsyslogd" <<'SH' +#!/bin/sh +if [ "$1" = -v ] && [ "$SYSLOG_TEST_VERSION" != 8 ]; then + echo "rsyslogd $SYSLOG_TEST_VERSION.0" +else + exec /bin/rsyslogd-real "$@" +fi +SH + cat >"$fixture/bin/systemctl" <<'SH' +#!/bin/bash +set -eu +[ "$*" = 'restart rsyslog' ] +if [ -s /run/rsyslog.pid ]; then + previous=$(cat /run/rsyslog.pid) + kill "$previous" + for ((i=0; i<100; i++)); do + [ -d "/proc/$previous" ] || break + sleep .02 + done + [ ! -d "/proc/$previous" ] + rm -f /run/rsyslog.pid +fi +/bin/rsyslogd-real -n -i /run/rsyslog.pid -f /etc/rsyslog.conf >>/run/daemon.log 2>&1 "$fixture/bin/check-delivery" <<'SH' +#!/bin/bash +set -eu +uid=$(id -u syslog) +expected="^Uid:[[:space:]]+$uid[[:space:]]+$uid[[:space:]]+$uid[[:space:]]+$uid$" +for ((i=0; i<100; i++)); do + if grep -Eq "$expected" /proc/$(cat /run/rsyslog.pid)/status; then break; fi + sleep .02 +done +grep -Eq "$expected" /proc/$(cat /run/rsyslog.pid)/status +logger -n 127.0.0.1 -P 1514 -d -p local4.info "$1" +for ((i=0; i<100; i++)); do + if grep -q "$1" /var/log/xcat/cluster.log; then break; fi + sleep .02 +done +grep -q "$1" /var/log/xcat/cluster.log +SH + cat >"$fixture/bin/log-test" <<'SH' +#!/bin/bash +set -eu +ip link set lo up +rm -f /run/rsyslog.pid +if [ "$SYSLOG_TEST_ROLE" = mn ]; then touch /etc/xCATMN; fi +if [ "$SYSLOG_TEST_VERSION" = 3 ]; then + echo 'SYSLOGD_OPTIONS="-c 3"' >/etc/default/rsyslog +fi +case "$SYSLOG_TEST_DIRECTORY" in + absent) ;; + blocked) touch /var/log/xcat ;; + *) + mkdir -m "$SYSLOG_TEST_DIRECTORY" /var/log/xcat + echo preserved >/var/log/xcat/old.log + chmod 0600 /var/log/xcat/old.log + ;; +esac +exec /bin/bash -eu -c "$1" +SH + chmod +x "$fixture/bin/rsyslogd" "$fixture/bin/systemctl" \ + "$fixture/bin/log-test" "$fixture/bin/check-delivery" +} + +run_syslog() +{ + local role=$1 directory=$2 version=$3 osver=$4 code=$5 + run "${sandbox[@]}" --setenv OSVER "$osver" --setenv SYSLOG '' \ + --setenv NTYPE service --setenv SVLOGLOCAL "$([ "$role" = forward ] && echo 0 || echo 1)" \ + --setenv MASTER 127.0.0.1:1515 --setenv SYSLOG_TEST_ROLE "$role" \ + --setenv SYSLOG_TEST_DIRECTORY "$directory" --setenv SYSLOG_TEST_VERSION "$version" \ + /bin/bash /bin/log-test "$code" + if [ "$status" -ne 0 ]; then + cat "$fixture/run/daemon.log" >&2 + return 1 + fi +} + +@test 'syslog creates a local log directory and delivers as syslog on MN and SN' { + local role osver + for role in mn sn; do + for osver in ubuntu24.04 debian12; do + run_syslog "$role" absent 8 "$osver" ' + for pass in 1 2; do + /tmp/postscripts/syslog + test "$(stat -c %U:%G:%a /var/log/xcat)" = syslog:adm:750 + check-delivery "directory-test-$pass" + done + ' + rm -rf "$fixture/var/log/xcat" + rm -f "$fixture/etc/xCATMN" + done + done +} + +@test 'syslog preserves existing directory modes and log file ownership' { + local mode + for mode in 0700 0750; do + run_syslog mn "$mode" 8 ubuntu24.04 ' + before=$(stat -c %u:%g:%a /var/log/xcat/old.log) + /tmp/postscripts/syslog + test "$(stat -c %a /var/log/xcat)" = "${SYSLOG_TEST_DIRECTORY#0}" + test "$(stat -c %U:%G /var/log/xcat)" = syslog:adm + test "$(stat -c %u:%g:%a /var/log/xcat/old.log)" = "$before" + test "$(cat /var/log/xcat/old.log)" = preserved + check-delivery restricted-directory-test + ' + rm -rf "$fixture/var/log/xcat" + done +} + +@test 'syslog prepares the log directory after the real upgrade wrapper' { + run_syslog mn absent 8 ubuntu24.04 ' + . /tmp/upgrade.sh + xcat_run_upgrade /tmp/postscripts/syslog + test "$(stat -c %U:%G /var/log/xcat)" = syslog:adm + test -s /var/log/xcat/upgrade.log + check-delivery upgrade-directory-test + ' +} + +@test 'syslog retains rsyslog compatibility-mode directory ownership' { + run_syslog mn absent 3 ubuntu24.04 ' + /tmp/postscripts/syslog + test "$(stat -c %U:%G:%a /var/log/xcat)" = syslog:adm:750 + check-delivery compatibility-directory-test + ' +} + +@test 'syslog retains the legacy reference-directory ownership' { + run_syslog mn absent 5 ubuntu24.04 ' + chown root:syslog /var/log + chmod 0775 /var/log + /tmp/postscripts/syslog + test "$(stat -c %u:%g /var/log/xcat)" = "$(stat -c %u:%g /var/log)" + test "$(stat -c %a /var/log/xcat)" = 775 + check-delivery legacy-directory-test + ' +} + +@test 'syslog does not create a local directory on forwarding nodes' { + run_syslog forward absent 8 ubuntu24.04 ' + /tmp/postscripts/syslog + test ! -e /var/log/xcat + grep -qx "\*\.\* @127.0.0.1:1515" /etc/rsyslog.d/remote.conf + ' +} + +@test 'syslog reports failure when the directory path is a file' { + run_syslog mn blocked 8 ubuntu24.04 ' + if /tmp/postscripts/syslog; then exit 1; fi + test -f /var/log/xcat + test ! -e /run/rsyslog.pid + ' +} From 169f3d54eb4de9e78cc7b30e4561b16bac501084 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Thu, 22 Oct 2026 22:11:35 -0300 Subject: [PATCH 17/18] fix(grub2): give aarch64 nodes a boot file name ending in .efi Some aarch64 UEFI firmware ignores a DHCP boot file name that does not end in .efi and requests grubaa64.efi from the TFTP root instead. xCAT names grub2-, so these nodes stop with a TFTP error before grub2 runs. For an aarch64 node, nodeset now links grub2-.efi to grub2.aarch64 beside grub2-. Both DHCP backends name the .efi link once it exists in the node's TFTP directory (noderes.tftpdir, or the site one). A node set by an older xCAT keeps grub2- until its next nodeset, so makedhcp after an upgrade does not name a missing file. With site.sharedtftp off, every server that runs nodeset for the node creates both links. This relies on service nodes running the same xCAT version as the management node, which xCAT requires. The old link stays for DHCP configurations that makedhcp did not write. The boot and offline states remove both links. Other architectures keep grub2-. --- perl-xCAT/xCAT/DHCP/BootPolicy.pm | 15 +++++++++++++++ xCAT-server/lib/xcat/plugins/dhcp.pm | 14 +++++++++----- xCAT-server/lib/xcat/plugins/grub2.pm | 16 ++++++++++++---- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/perl-xCAT/xCAT/DHCP/BootPolicy.pm b/perl-xCAT/xCAT/DHCP/BootPolicy.pm index bf47dbb4f1..3d730ab155 100644 --- a/perl-xCAT/xCAT/DHCP/BootPolicy.pm +++ b/perl-xCAT/xCAT/DHCP/BootPolicy.pm @@ -890,6 +890,21 @@ sub x86_san_loader_present { return ( -f "$tftpdir/undionly.kpxe" || -f "$tftpdir/$loader->{bios}" ) ? 1 : 0; } +# Some aarch64 UEFI firmware ignores a boot file name without the .efi suffix and requests grubaa64.efi. +my %GRUB2_NODE_LOADER_SUFFIX = ( aarch64 => '.efi' ); + +# The file in boot/grub2 that DHCP names as the boot file of a grub2 node. With tftpdir, the name is +# grub2- until nodeset creates the suffixed link there: a node set by an older xCAT has only that. +sub grub2_node_loader { + my ( $class, %opts ) = @_; + + my $loader = "grub2-$opts{node}"; + my $suffix = $GRUB2_NODE_LOADER_SUFFIX{ $opts{arch} // '' } // ''; + return $loader if $suffix eq ''; + return $loader if defined $opts{tftpdir} && !-e "$opts{tftpdir}/boot/grub2/$loader$suffix"; + return "$loader$suffix"; +} + # The ISC host statements that choose the boot file of a node with netboot ipxe, xnba or pxe. They # reach dhcpd through omshell, so their quotes are escaped. sub isc_node_boot_statements { diff --git a/xCAT-server/lib/xcat/plugins/dhcp.pm b/xCAT-server/lib/xcat/plugins/dhcp.pm index 5ab5d04a41..815dcf2dc9 100644 --- a/xCAT-server/lib/xcat/plugins/dhcp.pm +++ b/xCAT-server/lib/xcat/plugins/dhcp.pm @@ -1251,7 +1251,9 @@ sub addnode } elsif ($nrent and $nrent->{netboot} and $nrent->{netboot} eq 'yaboot') { $lstatements = 'filename = \"/yb/node/yaboot-' . $node . '\";' . $lstatements; } elsif ($nrent and $nrent->{netboot} and $nrent->{netboot} =~ /^grub2[-]?.*$/) { - $lstatements = 'filename = \"/boot/grub2/grub2-' . $node . '\";' . $lstatements; + my $loader = xCAT::DHCP::BootPolicy->grub2_node_loader(node => $node, arch => $ntent && $ntent->{arch}, + tftpdir => ($nrent->{tftpdir} || $tftpdir)); + $lstatements = 'filename = \"/boot/grub2/' . $loader . '\";' . $lstatements; } elsif ($nrent and $nrent->{netboot} and $nrent->{netboot} eq 'petitboot') { $lstatements = 'option conf-file \"http://' . $nxtsrv . $portsuffix . '/tftpboot/petitboot/' . $node . '\";' . $lstatements; } elsif ($nrent and $nrent->{netboot} and $nrent->{netboot} eq 'onie') { @@ -2621,11 +2623,11 @@ sub process_request } else { $chainents = undef; } - $nrhash = $nrtab->getNodesAttribs($req->{node}, [ 'tftpserver', 'netboot', 'proxydhcp', 'xcatmaster', 'servicenode']); + $nrhash = $nrtab->getNodesAttribs($req->{node}, [ 'tftpserver', 'netboot', 'proxydhcp', 'xcatmaster', 'servicenode', 'tftpdir']); my $nodetypetab; $nodetypetab = xCAT::Table->new('nodetype', -create => 0); if ($nodetypetab) { - $nodetypeents = $nodetypetab->getNodesAttribs($req->{node}, [qw(os provmethod)]); + $nodetypeents = $nodetypetab->getNodesAttribs($req->{node}, [qw(os provmethod arch)]); } my $iscsitab = xCAT::Table->new('iscsi', -create => 0); if ($iscsitab) { @@ -3708,7 +3710,7 @@ sub kea_build_node_reservations my $mactab = xCAT::Table->new('mac'); $chainents = $chaintab ? $chaintab->getNodesAttribs($nodes, ['currstate']) : undef; - $nrhash = $nrtab->getNodesAttribs($nodes, [ 'tftpserver', 'netboot', 'proxydhcp', 'xcatmaster', 'servicenode' ]); + $nrhash = $nrtab->getNodesAttribs($nodes, [ 'tftpserver', 'netboot', 'proxydhcp', 'xcatmaster', 'servicenode', 'tftpdir' ]); $nodetypeents = $nodetypetab ? $nodetypetab->getNodesAttribs($nodes, [qw(os provmethod arch)]) : undef; $iscsients = $iscsitab ? $iscsitab->getNodesAttribs($nodes, [qw(server target lun iname)]) : undef; $machash = $mactab ? $mactab->getNodesAttribs($nodes, ['mac']) : undef; @@ -4408,7 +4410,9 @@ sub kea_boot_for_node } elsif ($netboot and $netboot eq 'yaboot') { $boot{'boot-file-name'} = "/yb/node/yaboot-$node"; } elsif ($netboot and $netboot =~ /^grub2[-]?.*$/) { - $boot{'boot-file-name'} = "/boot/grub2/grub2-$node"; + $boot{'boot-file-name'} = '/boot/grub2/' + . xCAT::DHCP::BootPolicy->grub2_node_loader( node => $node, arch => $ntent && $ntent->{arch}, + tftpdir => ( $nrent->{tftpdir} || $tftpdir ) ); } elsif ($netboot and $netboot eq 'nimol') { $boot{'boot-file-name'} = "/vios/nodes/$node"; } elsif ($netboot and $netboot eq 'petitboot') { diff --git a/xCAT-server/lib/xcat/plugins/grub2.pm b/xCAT-server/lib/xcat/plugins/grub2.pm index 17e48e3b4d..ba048ff348 100644 --- a/xCAT-server/lib/xcat/plugins/grub2.pm +++ b/xCAT-server/lib/xcat/plugins/grub2.pm @@ -5,6 +5,7 @@ use Sys::Syslog; use xCAT::Scope; use xCAT::Utils; use xCAT::TableUtils; +use xCAT::DHCP::BootPolicy; use xCAT::ServiceNodeUtils; use xCAT::NetworkUtils; use xCAT::MsgUtils; @@ -311,9 +312,14 @@ sub setstate { return (1, "Stop grub2 configuration for this node, \"$grub2bin\" does not exits."); } + # grub2- stays for DHCP configurations that makedhcp did not write. + my @loaders = ("grub2-$node"); + my $dhcp_loader = xCAT::DHCP::BootPolicy->grub2_node_loader(node => $node, arch => $nodearch); + push @loaders, $dhcp_loader if ($dhcp_loader ne $loaders[0]); + chdir("$bootloader_root"); if ($cref->{currstate} eq "offline" or $cref->{currstate} eq "boot") { - unlink("grub2-$node"); + unlink(@loaders); } elsif ($cref->{currstate} eq "standby" and $nodeos =~ /^sle/i) { my $os_version = $nodeos; $os_version =~ s/sles//i; # Strip sles if there @@ -321,10 +327,12 @@ sub setstate { if ($os_version >= "15") { # Make sure for SLES15 or higher can still boot # from disk in "standby" state - unlink("grub2-$node"); + unlink(@loaders); + } + } else { + foreach my $loader (grep { !-e $_ } @loaders) { + symlink("grub2." . $nodearch, $loader); } - } elsif (! -e "grub2-$node") { - symlink("grub2." . $nodearch, "grub2-$node"); } my $ip = xCAT::NetworkUtils->getipaddr($node); From 8bb6f4ef91bdee143219166482192879aeef1665 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Thu, 22 Oct 2026 22:15:53 -0300 Subject: [PATCH 18/18] test(grub2): cover the aarch64 boot file name and node loader links Drive the Kea reservation builder and the ISC makedhcp path for grub2 nodes of each architecture. Place the loader links in the site TFTP directory or in noderes.tftpdir. An aarch64 node with only grub2- keeps that name. The table stub returns only the requested columns, so a missing nodetype.arch or noderes.tftpdir read fails the aarch64 cases. Drive grub2 setstate for the node loader links: both names for an aarch64 node and one for the others. Cover a repeated nodeset, a node with only the old link, and removal in the boot, offline and SLES 15 standby states. --- xCAT-test/unit/dhcp_grub2_node_loader.t | 209 +++++++++++++++++++++++ xCAT-test/unit/grub2_node_loader_links.t | 110 ++++++++++++ 2 files changed, 319 insertions(+) create mode 100644 xCAT-test/unit/dhcp_grub2_node_loader.t create mode 100644 xCAT-test/unit/grub2_node_loader_links.t diff --git a/xCAT-test/unit/dhcp_grub2_node_loader.t b/xCAT-test/unit/dhcp_grub2_node_loader.t new file mode 100644 index 0000000000..01f389cd67 --- /dev/null +++ b/xCAT-test/unit/dhcp_grub2_node_loader.t @@ -0,0 +1,209 @@ +#!/usr/bin/env perl +# The boot file both DHCP backends name for a grub2 node. An aarch64 node gets a name that ends in +# .efi once nodeset has created it: some aarch64 UEFI firmware ignores any other name and requests +# grubaa64.efi instead. +use strict; +use warnings; +## no critic (TestingAndDebugging::ProhibitNoWarnings) +no warnings 'once'; + +use FindBin; +use lib "$FindBin::Bin/../lib"; +use lib "$FindBin::Bin/../../xCAT-server/lib"; +use lib "$FindBin::Bin/../../xCAT-server/lib/perl"; +use lib "$FindBin::Bin/../../perl-xCAT"; + +use File::Path qw(make_path); +use File::Temp qw(tempdir); +use Test::More; +use XCAT::Test::File qw(repo_path); + +BEGIN { + $ENV{XCATROOT} = repo_path('xCAT-server'); + $ENV{XCATCFG} = 'SQLite:' . tempdir( CLEANUP => 1 ); +} + +use xCAT::DHCP::BootPolicy; +use xCAT::TableUtils; + +# dhcp.pm reads the site TFTP directory once, when it loads. noderes.tftpdir moves one node elsewhere. +my $site_tftp = tempdir( CLEANUP => 1 ); +my $node_tftp = tempdir( CLEANUP => 1 ); +{ + no warnings 'redefine'; + *xCAT::TableUtils::getTftpDir = sub { return $site_tftp; }; +} +require( repo_path('xCAT-server/lib/xcat/plugins/dhcp.pm') ); + +for my $dir ( $site_tftp, $node_tftp ) { + make_path("$dir/boot/grub2"); + open( my $loader, '>', "$dir/boot/grub2/grub2.aarch64" ) or die "Cannot create the loader: $!"; + close($loader) or die "Cannot close the loader: $!"; +} + +# The node loader links in a TFTP directory, as a nodeset left them. +sub publish { + my ( $dir, @names ) = @_; + unlink( glob("$dir/boot/grub2/grub2-cn1*") ); + for my $name (@names) { + symlink( 'grub2.aarch64', "$dir/boot/grub2/$name" ) or die "Cannot create $dir/boot/grub2/$name: $!"; + } + return; +} + +# A table returns only the columns the plugin asks for, like the real one. +{ + package GrubLoaderTable; + + our %rows; + sub new { my ( $class, $name ) = @_; return bless { name => $name }, $class; } + + sub getNodesAttribs { + my ( $self, $nodes, $cols ) = @_; + my %out; + for my $node (@$nodes) { + my $row = $rows{ $self->{name} }{$node} or next; + $out{$node} = [ { map { exists $row->{$_} ? ( $_ => $row->{$_} ) : () } @$cols } ]; + } + return \%out; + } + sub getNodeAttribs { return; } + sub getAllAttribs { return; } + sub getAttribs { return { username => 'xcat_key', password => 'dGVzdA==' }; } + sub close { return; } + + package GrubLoaderISCBackend; + sub name { return 'isc'; } + + package GrubLoaderKeaBackend; + sub subnet_id_for_ip { return 1; } +} + +sub node_rows { + my ( $arch, $netboot, $tftpdir ) = @_; + return ( + noderes => { cn1 => { netboot => $netboot, tftpserver => '192.0.2.1', ( $tftpdir ? ( tftpdir => $tftpdir ) : () ) } }, + chain => { cn1 => { currstate => 'install' } }, + mac => { cn1 => { mac => '02:00:00:00:00:11' } }, + nodetype => { cn1 => { os => 'rhels9.4', provmethod => 'install', ( defined $arch ? ( arch => $arch ) : () ) } }, + ); +} + +my @errors; +no warnings 'redefine'; +local *xCAT::Table::new = sub { return GrubLoaderTable->new( $_[1] ); }; +local *xCAT::TableUtils::get_site_attribute = sub { return; }; +local *xCAT::MsgUtils::trace = sub { return; }; +local *xCAT_plugin::dhcp::getipaddr = sub { return '192.0.2.11'; }; +local *xCAT::NetworkUtils::getipaddr = sub { return '192.0.2.11'; }; +local *xCAT_plugin::dhcp::ipIsDynamic = sub { return 0; }; +local $xCAT_plugin::dhcp::callback = sub { push @errors, @{ $_[0]->{error} || [] }; }; +use warnings 'redefine'; + +# The boot file of the reservation the Kea backend builds for cn1. +sub kea_boot_file { + my ( $arch, $netboot, $tftpdir ) = @_; + local %GrubLoaderTable::rows = node_rows( $arch, $netboot, $tftpdir ); + my $reservations = xCAT_plugin::dhcp::kea_build_node_reservations( bless( {}, 'GrubLoaderKeaBackend' ), {}, ['cn1'] ); + return [ map { $_->{'boot-file-name'} } @$reservations ]; +} + +my $dir = tempdir( CLEANUP => 1 ); +my $conf = "$dir/dhcpd.conf"; +open( my $fh, '>', $conf ) or die "Cannot create $conf: $!"; +print {$fh} "#xCAT generated dhcp configuration\n", + "option space gpxe;\n", + @{ xCAT::DHCP::BootPolicy->isc_ipxe_feature_option_lines() }, + "subnet 192.0.2.0 netmask 255.255.255.0 {\n", + "} # 192.0.2.0/255.255.255.0 subnet_end\n"; +close($fh) or die "Cannot close $conf: $!"; + +# The boot file of every host that makedhcp creates for cn1 through OMAPI. +sub isc_boot_files { + my ( $arch, $netboot, $tftpdir ) = @_; + local %GrubLoaderTable::rows = node_rows( $arch, $netboot, $tftpdir ); + my $commands = ''; + no warnings 'redefine'; + local *xCAT::DHCP::Backend::new_backend = sub { return bless {}, 'GrubLoaderISCBackend'; }; + local *xCAT::Utils::isServiceNode = sub { return 0; }; + local *xCAT::Utils::isLinux = sub { return 1; }; + local *xCAT::Utils::isFIPS = sub { return 0; }; + local *xCAT::Utils::checkservicestatus = sub { return 0; }; + local *xCAT::NetworkUtils::determinehostname = sub { return ('mn'); }; + local *xCAT::NetworkUtils::nodeonmynet = sub { return 1; }; + local *xCAT::DBobjUtils::getnodetype = sub { return {}; }; + local *xCAT::DBobjUtils::getNetwkInfo = sub { return ( cn1 => { mgtifname => 'eth0' } ); }; + local *xCAT_plugin::dhcp::addnic = sub { return; }; + local *xCAT_plugin::dhcp::addnet = sub { return; }; + local *xCAT_plugin::dhcp::addnet6 = sub { return; }; + local *xCAT_plugin::dhcp::writeout = sub { return; }; + local *xCAT_plugin::dhcp::_open_omshell_writer = sub { + open( my $out, '>', \$commands ) or die "Cannot open an omshell buffer: $!"; + return $out; + }; + local *xCAT_plugin::dhcp::_close_omshell_writer = sub { return; }; + local $::XCATSITEVALS{externaldhcpservers}; + local $xCAT_plugin::dhcp::dhcpconffile = $conf; + local $xCAT_plugin::dhcp::distro = 'rhels9.4'; + use warnings 'redefine'; + + open( my $printed, '>', \my $text ) or die "Cannot open an output buffer: $!"; + my $selected = select($printed); + my $died; + eval { + xCAT_plugin::dhcp::process_request( { _xcatpreprocessed => [1], node => ['cn1'], arg => [] }, + sub { push @errors, @{ $_[0]->{error} || [] }; } ); + 1; + } or $died = $@; + select($selected); + die "makedhcp died: $died" if $died; + + return [ map { /filename = \\"([^\\"]*)\\"/g } $commands =~ /^set statements = "(.*)"$/mg ]; +} + +my @both = qw(grub2-cn1 grub2-cn1.efi); +my @old = qw(grub2-cn1); + +# Architecture, links in the site TFTP directory, links in the node's own one (none: no noderes.tftpdir), +# the boot file DHCP names, and the case. +my @cases = ( + [ 'aarch64', \@both, undef, '/boot/grub2/grub2-cn1.efi', 'after nodeset' ], + [ 'aarch64', \@old, undef, '/boot/grub2/grub2-cn1', 'set by an older nodeset' ], + [ 'aarch64', [], undef, '/boot/grub2/grub2-cn1', 'without loader links' ], + [ 'aarch64', \@old, \@both, '/boot/grub2/grub2-cn1.efi', 'after nodeset in its own TFTP directory' ], + [ 'aarch64', \@both, \@old, '/boot/grub2/grub2-cn1', 'set by an older nodeset in its own TFTP directory' ], + [ 'x86_64', \@old, undef, '/boot/grub2/grub2-cn1', 'after nodeset' ], + [ 'x86_64', \@both, undef, '/boot/grub2/grub2-cn1', 'with a stray .efi link' ], + [ 'riscv64', \@old, undef, '/boot/grub2/grub2-cn1', 'after nodeset' ], + [ 'ppc64', \@old, undef, '/boot/grub2/grub2-cn1', 'after nodeset' ], + [ 'ppc64le', \@old, undef, '/boot/grub2/grub2-cn1', 'after nodeset' ], + [ '', \@both, undef, '/boot/grub2/grub2-cn1', 'with a .efi link' ], + [ undef, \@both, undef, '/boot/grub2/grub2-cn1', 'with a .efi link' ], +); + +for my $case (@cases) { + my ( $arch, $site_links, $node_links, $expected, $state ) = @$case; + my $label = ( defined $arch ? ( $arch eq '' ? 'a blank arch' : $arch ) : 'no arch' ) . " $state"; + publish( $site_tftp, @$site_links ); + publish( $node_tftp, @{ $node_links || [] } ); + my $tftpdir = $node_links ? $node_tftp : undef; + + for my $netboot (qw(grub2 grub2-tftp grub2-http)) { + @errors = (); + is_deeply( kea_boot_file( $arch, $netboot, $tftpdir ), [$expected], "Kea: $netboot node with $label" ) + or diag("errors: @errors"); + } + @errors = (); + is_deeply( isc_boot_files( $arch, 'grub2', $tftpdir ), [$expected], "ISC: grub2 node with $label" ) + or diag("errors: @errors"); +} + +publish( $site_tftp, @both ); +is( xCAT_plugin::dhcp::kea_boot_for_node( 'cn1', { netboot => 'grub2' }, undef, undef, undef, '192.0.2.1' )->{'boot-file-name'}, + '/boot/grub2/grub2-cn1', 'Kea: grub2 node without a nodetype entry' ); +is( xCAT_plugin::dhcp::kea_boot_for_node( + 'cn1', { netboot => 'grub2' }, { currstate => 'boot' }, { arch => 'aarch64' }, undef, '192.0.2.1' + )->{'boot-file-name'}, + '', 'Kea: aarch64 grub2 node in boot state still gets no boot file' ); + +done_testing(); diff --git a/xCAT-test/unit/grub2_node_loader_links.t b/xCAT-test/unit/grub2_node_loader_links.t new file mode 100644 index 0000000000..6572d979e4 --- /dev/null +++ b/xCAT-test/unit/grub2_node_loader_links.t @@ -0,0 +1,110 @@ +#!/usr/bin/env perl +# The per-node loader links nodeset publishes in boot/grub2. An aarch64 node also gets +# grub2-.efi, the name DHCP hands it, and grub2- stays for DHCP that makedhcp did not write. +use strict; +use warnings; +no warnings 'once'; + +use Cwd qw(getcwd); +use File::Path qw(make_path); +use File::Slurper qw(write_text); +use File::Temp qw(tempdir); +use FindBin; +use Test::More; +use lib "$FindBin::Bin/../lib"; +use lib "$FindBin::Bin/../../perl-xCAT"; +use lib "$FindBin::Bin/../../xCAT-server/lib/perl"; +use XCAT::Test::File qw(repo_path); + +my $root = tempdir(CLEANUP => 1); +local $ENV{XCATROOT} = repo_path('xCAT-server'); +local $ENV{XCATCFG} = "$root/config"; +make_path($ENV{XCATCFG}); +local %::XCATSITEVALS = (tftpdir => "$root/tftpboot", xcatdebugmode => 0); +require xCAT::Table; +require xCAT::NetworkUtils; + +no warnings 'redefine'; +local *xCAT::Table::new = sub { die 'Unexpected database access'; }; +local *xCAT::NetworkUtils::getipaddr = sub { + my ($class, $host) = @_; + return '192.0.2.1' if $host eq 'server'; + return '192.0.2.2' if $host eq 'node'; + die "Unexpected hostname: $host"; +}; +use warnings 'redefine'; + +require(repo_path('xCAT-server/lib/xcat/plugins/grub2.pm')); + +sub new_bootdir { + my ($arch) = @_; + my $tftpdir = tempdir(DIR => $root, CLEANUP => 1); + make_path("$tftpdir/boot/grub2"); + write_text("$tftpdir/boot/grub2/grub2.$arch", "fixture loader\n"); + return $tftpdir; +} + +sub nodeset { + my ($tftpdir, $arch, $currstate, $os) = @_; + my $cwd = getcwd(); + my @result = xCAT_plugin::grub2::setstate( + 'node', + {node => [{kernel => 'images/vmlinuz', initrd => 'images/initrd.img', kcmdline => 'quiet'}]}, + {node => [{currstate => $currstate}]}, + {node => [{mac => '02:00:00:00:00:02'}]}, + $tftpdir, {node => [{tftpserver => 'server', netboot => 'grub2'}]}, {}, $arch, $os // 'rhels9.4', + ); + chdir($cwd) or die "Cannot restore working directory: $!"; + is_deeply(\@result, [0, ''], "nodeset $currstate succeeds"); + return; +} + +sub links { + my ($tftpdir) = @_; + opendir(my $dh, "$tftpdir/boot/grub2") or die "Cannot read $tftpdir/boot/grub2: $!"; + my %links = map { $_ => readlink("$tftpdir/boot/grub2/$_") } grep { -l "$tftpdir/boot/grub2/$_" } readdir($dh); + closedir($dh); + return \%links; +} + +for my $case (['aarch64', 'aarch64'], ['x86_64', 'x86_64'], ['riscv64', 'riscv64'], ['ppc64', 'ppc']) { + my ($arch, $loader_arch) = @$case; + subtest "$arch: install" => sub { + my $tftpdir = new_bootdir($loader_arch); + nodeset($tftpdir, $arch, 'install'); + my %expected = ('grub2-node' => "grub2.$loader_arch"); + $expected{'grub2-node.efi'} = 'grub2.aarch64' if $arch eq 'aarch64'; + is_deeply(links($tftpdir), \%expected, 'the node loader links point at the architecture loader'); + + nodeset($tftpdir, $arch, 'install'); + is_deeply(links($tftpdir), \%expected, 'a second nodeset leaves the same links'); + }; +} + +subtest 'aarch64: install after an older nodeset' => sub { + my $tftpdir = new_bootdir('aarch64'); + symlink('grub2.aarch64', "$tftpdir/boot/grub2/grub2-node") or die "Cannot create the old link: $!"; + nodeset($tftpdir, 'aarch64', 'install'); + is_deeply(links($tftpdir), {'grub2-node' => 'grub2.aarch64', 'grub2-node.efi' => 'grub2.aarch64'}, + 'the .efi link is added beside the old one'); +}; + +for my $case (['boot'], ['offline'], ['standby', 'sles15.5']) { + my ($state, $os) = @$case; + subtest "aarch64: $state after install" . ($os ? " on $os" : '') => sub { + my $tftpdir = new_bootdir('aarch64'); + nodeset($tftpdir, 'aarch64', 'install', $os); + nodeset($tftpdir, 'aarch64', $state, $os); + is_deeply(links($tftpdir), {}, 'both node loader links are removed'); + }; +} + +subtest 'aarch64: standby on an older SLES keeps both links' => sub { + my $tftpdir = new_bootdir('aarch64'); + nodeset($tftpdir, 'aarch64', 'install', 'sles12.5'); + nodeset($tftpdir, 'aarch64', 'standby', 'sles12.5'); + is_deeply(links($tftpdir), {'grub2-node' => 'grub2.aarch64', 'grub2-node.efi' => 'grub2.aarch64'}, + 'the node loader links stay'); +}; + +done_testing();