From d52b2d463bf774a353ed64a0727ff905c8ec4ed0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Mon, 2 Nov 2026 22:50:57 -0300 Subject: [PATCH 1/2] fix(install): run the SELinux relabel after the EL post scripts post.rhels8 and post.rhels10 end with exit 0. The kickstart templates include them inline in the %post script, so the exit ends that script before #SELINUXRELABEL#, and restorecon never runs on an enforcing or permissive node. Both scripts now end with their last command, so the templates reach the relabel after the xCAT post scripts wrote their files. --- xCAT-server/share/xcat/install/scripts/post.rhels10 | 2 -- xCAT-server/share/xcat/install/scripts/post.rhels8 | 2 -- 2 files changed, 4 deletions(-) diff --git a/xCAT-server/share/xcat/install/scripts/post.rhels10 b/xCAT-server/share/xcat/install/scripts/post.rhels10 index 75e8647476..42158dc8c7 100644 --- a/xCAT-server/share/xcat/install/scripts/post.rhels10 +++ b/xCAT-server/share/xcat/install/scripts/post.rhels10 @@ -16,5 +16,3 @@ do sed -i -e 's/^[[:space:]]*enabled[[:space:]]*=[[:space:]]*1/enabled=0/' /etc/yum.repos.d/$repo_file fi done - -exit 0 diff --git a/xCAT-server/share/xcat/install/scripts/post.rhels8 b/xCAT-server/share/xcat/install/scripts/post.rhels8 index e396315c4b..11d185a198 100644 --- a/xCAT-server/share/xcat/install/scripts/post.rhels8 +++ b/xCAT-server/share/xcat/install/scripts/post.rhels8 @@ -41,5 +41,3 @@ do sed -i -e 's/^[[:space:]]*enabled[[:space:]]*=[[:space:]]*1/enabled=0/' /etc/yum.repos.d/$repo_file fi done - -exit 0 From 2770ff0840decef2318e3e8957ef083669ddef27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Mon, 2 Nov 2026 22:51:02 -0300 Subject: [PATCH 2/2] test(install): run the SELinux relabel after the EL post scripts Each kickstart template with #SELINUXRELABEL#, rendered for an enforcing node and run in a sandbox through its downloaded postscript, must call restorecon once, after the postscript ran and post.rhels8 or post.rhels10 disabled the vendor repository. A disabled node must get no relabel. --- .github/workflows/xcat_test.yml | 2 +- xCAT-test/native/selinux_kickstart_relabel.t | 100 +++++++++++++++++++ 2 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 xCAT-test/native/selinux_kickstart_relabel.t diff --git a/.github/workflows/xcat_test.yml b/.github/workflows/xcat_test.yml index 6034769ca7..319399beeb 100644 --- a/.github/workflows/xcat_test.yml +++ b/.github/workflows/xcat_test.yml @@ -110,7 +110,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/netboot_profile_postinstall.t xCAT-test/native/kdump_condition_systemd.t xCAT-test/native/openeuler_post_kdump.t xCAT-test/native/builddebs_riscv64.t xCAT-test/native/ubuntu_subiquity_template.t xCAT-test/native/ubuntu_subiquity_install_disk.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/selinux_kickstart_relabel.t xCAT-test/native/kdump_condition_systemd.t xCAT-test/native/openeuler_post_kdump.t xCAT-test/native/builddebs_riscv64.t xCAT-test/native/ubuntu_subiquity_template.t xCAT-test/native/ubuntu_subiquity_install_disk.t | tee "$log" ! grep -qi skipped "$log" rpm_lifecycle_test: runs-on: ubuntu-24.04 diff --git a/xCAT-test/native/selinux_kickstart_relabel.t b/xCAT-test/native/selinux_kickstart_relabel.t new file mode 100644 index 0000000000..f7ed776282 --- /dev/null +++ b/xCAT-test/native/selinux_kickstart_relabel.t @@ -0,0 +1,100 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +use File::Copy qw(copy); +use File::Path qw(make_path); +use File::Slurper qw(read_text write_text); +use FindBin; +use lib "$FindBin::Bin/../lib"; +use lib "$FindBin::Bin/../../perl-xCAT", "$FindBin::Bin/../../xCAT-server/lib/perl"; +use Test::More; + +use XCAT::Test::File qw(repo_path); +use XCAT::Test::Sandbox qw(sandbox_root sandbox_run); +use XCAT::Test::Template qw(template_database set_row render_template); + +plan skip_all => 'kickstart %post execution requires Linux' unless $^O eq 'linux'; +my $database = template_database(); +set_row('passwd', {key => 'system', username => 'root'}, {password => '$6$fixture$encrypted'}); + +my $install = repo_path('xCAT-server/share/xcat/install'); +my @templates = ( + ['rh/compute.rhels8.tmpl', 'rocky8.10', 'x86_64', 'rh'], + ['rh/compute.rhels9.tmpl', 'alma9.6', 'x86_64', 'rh'], + ['rh/compute.rhels10.tmpl', 'rhels10.0', 'x86_64', 'rh'], + ['rh/compute.rhels10.riscv64.tmpl', 'rhels10.0', 'riscv64', 'rh'], + ['rocky/service.rocky10.riscv64.tmpl', 'rocky10.2', 'riscv64', 'rocky'], + ['openeuler/compute.openeuler.tmpl', 'openeuler24.03sp3', 'x86_64', 'openeuler'], +); + +# The stand-in records what the xCAT post scripts had done when the relabel ran. +my $restorecon = <<'SH'; +#!/bin/sh +{ + printf 'args=%s\n' "$*" + [ -e /fixture/postscript-ran ] && echo 'postscript=ran' + grep -q '^enabled=0$' /etc/yum.repos.d/rocky.repo && echo 'vendor-repository=disabled' +} >>/fixture/restorecon.calls +SH + +sub post_root { + my $root = sandbox_root(); + make_path("$root/sbin", "$root/etc/systemd/system", "$root/etc/yum.repos.d", "$root/boot/efi/EFI/BOOT"); + write_text("$root/sbin/restorecon", $restorecon); + chmod 0755, "$root/sbin/restorecon" or die $!; + write_text("$root/etc/yum.repos.d/rocky.repo", "[baseos]\nname=BaseOS\nenabled=1\n"); + write_text("$root/boot/efi/EFI/BOOT/BOOTRISCV64.EFI", "loader\n"); + write_text("$root/tmp/pre-install.log", "pre-install fixture diagnostic\n"); + copy(repo_path('xCAT/postscripts/xcatlib.sh'), "$root/xcatlib.sh") or die $!; + write_text("$root/mypostscript.node", "#!/bin/bash\nMASTER=192.0.2.1\ntouch /fixture/postscript-ran\n"); + for my $name (qw(curl logger sleep updateflag.awk nmcli openssl)) { + copy(repo_path('xCAT-test/fixtures/install-profile/command'), "$root/bin/$name") or die $!; + chmod 0755, "$root/bin/$name" or die $!; + } + return $root; +} + +for my $case (@templates) { + my ($template, $os, $arch, $platform) = @$case; + for my $mode (qw(enforcing disabled)) { + subtest "$template $mode" => sub { + set_row('nodetype', {node => 'node'}, {os => $os, arch => $arch, provmethod => 'install'}); + set_row('noderes', {node => 'node'}, {selinux => $mode}); + (my $pkglist = "$install/$template") =~ s/\.tmpl$/.pkglist/; + my $output = "$database/ks"; + render_template($database, "$install/$template", $output, 'node', (-r $pkglist ? $pkglist : ''), + '/install/media', $platform, undef, {xcatmaster => '192.0.2.1'}); + my $rendered = read_text($output); + my @posts; + while ($rendered =~ /^%post([^\n]*)\n(.*?)^%end/msg) { + push @posts, [$1, $2]; + } + ok(@posts, 'renders a %post section'); + + my $root = post_root(); + my $index = 0; + for my $post (@posts) { + my ($interpreter) = $post->[0] =~ /--interpreter=(\S+)/; + write_text("$root/post.sh", $post->[1]); + my ($rc, $log) = sandbox_run($root, {read_only => {"$root/sbin" => '/usr/sbin'}}, + 'timeout', '30', $interpreter // '/bin/sh', '/fixture/post.sh'); + is($rc, 0, '%post section ' . ++$index . ' completes') + or diag($log, read_text("$root/log/xcat/xcat.log")); + } + ok(-e "$root/postscript-ran", 'runs the rendered sequence through the downloaded postscript'); + ok(!-e "$root/unexpected-command", 'external fixtures accept the requested operations'); + is(read_text("$root/etc/yum.repos.d/rocky.repo"), "[baseos]\nname=BaseOS\nenabled=0\n", + 'disables the installed vendor repository'); + my $calls = -e "$root/restorecon.calls" ? read_text("$root/restorecon.calls") : undef; + if ($mode eq 'disabled') { + is($calls, undef, 'does not relabel a disabled node'); + } else { + is($calls, "args=-RF /xcatpost /opt/xcat /etc /root /var/log\npostscript=ran\nvendor-repository=disabled\n", + 'relabels once, after the xCAT post scripts wrote their files'); + } + }; + } +} + +done_testing();