From 4487162ff6a0148effec373e507d8d633bb93bd3 Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Wed, 21 Oct 2026 16:37:00 -0300 Subject: [PATCH] test(xcat-core): no case has an image root called rootimg The file contexts exclude a guest tree by the name rootimg at any depth under /install. The native lookup case has no image whose profile is rootimg, so nothing measured what happens when the image root itself carries that name. Add three images: a profile called rootimg, one called rootimg-statelite and one whose name only contains rootimg. Each contributes its guest files and its published files, so the case asks for both answers on the same path depth. Record the choice for a rootimg component inside an image root, which is ambiguous, and add four guest files whose own names are published names. 54 of the 224 checks fail against the file contexts before the next commit. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-test/native/selinux_file_contexts.t | 31 +++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/xCAT-test/native/selinux_file_contexts.t b/xCAT-test/native/selinux_file_contexts.t index c0e15681b0..a54b5ce09b 100644 --- a/xCAT-test/native/selinux_file_contexts.t +++ b/xCAT-test/native/selinux_file_contexts.t @@ -81,12 +81,20 @@ sub lookup { install_module(); +# The last component of an image root is the profile, and a profile may be +# called rootimg. The guest tree is then <...>/rootimg/rootimg and the +# published kernel is <...>/rootimg/kernel, so a rule that matches the name +# rootimg anywhere in the path takes the kernel with it. my @images = ( '/install/netboot/rhels9/x86_64/compute', + '/install/netboot/rhels9/x86_64/rootimg', + '/install/netboot/rhels9/x86_64/rootimg-statelite', + '/install/netboot/rhels9/x86_64/rootimg-custom', '/install/netboot/custom-image', '/install/custom/images/rhels9-compute', ); -my @guest = map { ("$_/rootimg/etc/shadow", "$_/rootimg-statelite/etc/shadow") } @images; +my @guest = map { ("$_/rootimg/etc/shadow", "$_/rootimg/etc/passwd", + "$_/rootimg-statelite/etc/shadow") } @images; my @published = map { my $dir = $_; map { "$dir/$_" } qw(kernel initrd-stateless.gz initrd-statelite.gz rootimg.cpio.gz @@ -101,6 +109,27 @@ foreach my $path (@published, '/install', '/install/postscripts/xcatdsklspost') is(lookup($path), 'public_content_t', "$path is public_content_t"); } +# rootimgdir is any path under /install, so a component called rootimg in the +# MIDDLE of an image root cannot be told from a guest tree rooted there: +# /install/netboot/rootimg/a/b/kernel is either a published kernel below an +# image root called .../rootimg/a/b, or a file inside a guest tree rooted at +# /install/netboot/rootimg. The rules keep the guest labels, which leaves the +# first reading unlabelled. Hold that choice down, so a change of direction +# fails here instead of silently relabelling a guest. +foreach my $path ('/install/netboot/rootimg/rhels9/x86_64/compute/kernel', + '/install/netboot/rootimg/rhels9/x86_64/compute/rootimg/etc/shadow') { + is(lookup($path), '<>', + "a rootimg component inside an image root keeps $path out of the relabel"); +} + +# A guest file whose own name is a published name keeps its label: the rules +# name the component directly below rootimg, not a name at any depth. +foreach my $path (map { "/install/netboot/rhels9/x86_64/$_" } + qw(compute/rootimg/usr/src/kernel rootimg/rootimg/usr/src/kernel + rootimg/rootimg/boot/initrd.img rootimg/rootimg/var/lib/rootimg.sfs)) { + is(lookup($path), '<>', "a guest file at $path keeps its own label"); +} + # A management node: each guest file keeps the label of its own operating # system, and each published file starts with the label it had before the # package was installed.