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"); }