From 52605e39591cfb8a037cc90940f05382fa657e18 Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Thu, 15 Oct 2026 02:27:38 -0300 Subject: [PATCH] test(xcat-core): capture the missing image-build domain The image build creates an operating system tree, so it writes and relabels files of every type the packages own. xcat_t holds that authority today, and the same domain listens on the xcatd port. xcat_selinux_package.t now asserts a second domain for the build: the xcat_image_t declaration, its permissive line, the entrypoint, the transition from xcat_t with the three inherited process permissions, the role statements for system_r and unconfined_r, and the file contexts of the two genimage programs. One check holds the security property of the split: only xcat_image_t may manage or relabel every file type, and the daemon domain gets no filesystem-wide grant. 9 of the 74 checks fail on this commit. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-test/unit/xcat_selinux_package.t | 35 +++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/xCAT-test/unit/xcat_selinux_package.t b/xCAT-test/unit/xcat_selinux_package.t index dfbd6b86bd..8077b17cad 100644 --- a/xCAT-test/unit/xcat_selinux_package.t +++ b/xCAT-test/unit/xcat_selinux_package.t @@ -4,6 +4,7 @@ use warnings; use FindBin; use File::Slurper qw(read_lines); +use List::Util (); use Test::More; # The spec files and the file context list are the artifacts: rpmbuild and @@ -236,6 +237,40 @@ foreach my $domain (qw(user_t staff_t sysadm_t guest_t xguest_t)) { unlike($te, qr/\b\Q$domain\E\b/, "$domain gets no rule in xcat.te"); } +######################################## +# +# The image-build domain +# + +like($te, qr/^type xcat_image_t;$/m, 'xcat.te declares a domain for the image build'); +like($te, qr/^permissive xcat_image_t;$/m, '... which is permissive too'); +like($te, qr/^application_domain\(xcat_image_t, xcat_image_exec_t\)$/m, + 'genimage is the entrypoint of that domain'); +like($te, qr/^domtrans_pattern\(xcat_t, xcat_image_exec_t, xcat_image_t\)$/m, + 'xcatd running genimage enters it'); +like($te, qr/^allow xcat_t xcat_image_t:process \{[^}]*\bnoatsecure\b/m, + '... and hands the child the three inherited process permissions'); + +# The transition from a system service computes system_u:system_r:xcat_image_t. +# application_domain does not authorize a role, and without the statement the +# context is invalid: EACCES, reported as SELINUX_ERR and not as an AVC. +like($te, qr/^role system_r types xcat_image_t;$/m, 'system_r is authorized for xcat_image_t'); +like($te, qr/^\s*role unconfined_r types xcat_image_t;$/m, + '... and so is unconfined_r, for an administrator who runs genimage'); + +is_deeply([ grep { fc_type($_) eq 'xcat_image_exec_t' } sort keys %fc ], + [ '/opt/xcat/bin/genimage', '/opt/xcat/share/xcat/netboot/[^/]+/genimage' ], + 'the two genimage programs carry the entrypoint, and nothing else does'); + +# THE SECURITY PROPERTY OF THE SPLIT. The image build writes and relabels files +# of every type, because it creates an operating system tree. The daemon that +# listens on the network must not hold that authority. +my @wide = $te =~ /^allow (\w+) file_type:\w+ \w+;$/mg; +is_deeply([ sort(List::Util::uniq(@wide)) ], [ 'xcat_image_t' ], + 'only the image domain may manage and relabel every file type'); +unlike($te, qr/^files_(manage|relabel)_all_files\(xcat_t\)$/m, + 'the daemon domain gets no filesystem-wide grant by interface either'); + # A management node or a service node with the targeted policy installs the module. foreach my $pkg (qw(xCAT-server xCATsn)) { my @lines = lines_of("$root/$pkg/$pkg.spec");