From d3739aa512421528f3b97e596c6d64692c9d344b Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Wed, 14 Oct 2026 17:33:39 -0300 Subject: [PATCH] test(xcat-core): capture the labels the erase of xCAT-selinux leaves behind Removing the package removes the module, so xcatd_exec_t and xcat_client_exec_t leave the policy and each file that carried one becomes unlabeled_t. Measured on xcat162-mn-tmp-286 after dnf remove: system_u:object_r:unlabeled_t:s0 /opt/xcat/sbin/xcatd system_u:object_r:unlabeled_t:s0 /opt/xcat/bin/xcatclient system_u:object_r:unlabeled_t:s0 /opt/xcat/bin/xcatclientnnr restorecon -n reported all three as pending, and /install kept public_content_t, which the stock policy does not define for it. xcat_selinux_package.t asserts the %preun snapshot and the %postun relabel that an erase needs, guarded for the erase only. 3 of its 64 checks fail on this commit. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-test/unit/xcat_selinux_package.t | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/xCAT-test/unit/xcat_selinux_package.t b/xCAT-test/unit/xcat_selinux_package.t index e59621d7bd..dfbd6b86bd 100644 --- a/xCAT-test/unit/xcat_selinux_package.t +++ b/xCAT-test/unit/xcat_selinux_package.t @@ -91,11 +91,22 @@ like(join("\n", @{ $spec->{post} || [] }), '%post installs the module'); like(join("\n", @{ $spec->{postun} || [] }), qr/^%selinux_modules_uninstall -s targeted xcat$/m, '%postun removes the module'); +# On an erase the module leaves the policy, so each file labelled with one of +# its types becomes unlabeled_t. %preun takes the snapshot that %postun needs +# to relabel them, because %pre does not run on an erase. +like(join("\n", @{ $spec->{preun} || [] }), qr/^%selinux_relabel_pre -s targeted$/m, + '%preun saves the file contexts before the module leaves the policy'); +my $postun = join("\n", @{ $spec->{postun} || [] }); +like($postun, qr/^%selinux_relabel_post -s targeted$/m, + '%postun relabels the files the removed module had labelled'); +like($postun, qr/\[ \$1 -eq 0 \]/, + '... on an erase only, so an upgrade keeps the labels'); + my $posttrans = join("\n", @{ $spec->{posttrans} || [] }); like($posttrans, qr/^%selinux_relabel_post -s targeted$/m, '%posttrans relabels the files whose context changed'); like($posttrans, qr{\brestorecon -R /install\b}, '... and relabels /install'); -foreach my $section (qw(pre post postun posttrans)) { +foreach my $section (qw(pre preun post postun posttrans)) { unlike(join("\n", @{ $spec->{$section} || [] }), qr/\bsetenforce\b|\/etc\/selinux\/config/, "%$section does not change the SELinux mode"); }