From 2efdce66b9daf53c426cee9224a89c410575b79e Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Wed, 14 Oct 2026 16:52:43 -0300 Subject: [PATCH] test(xcat-core): capture the missing xcat_t domain xCAT ships no process domain. xcatd runs in unconfined_service_t, and a client command runs in the domain of its caller, so no rule in the policy module reaches either of them. xcat_selinux_package.t now asserts the domain, the two entrypoint types, the file contexts of the three entrypoints, the transition from systemd and the transition from unconfined_t, and that no confined user domain gets a transition. 9 of its 59 checks fail on this commit. selinux_xcatd_domain asserts the live context of xcatd and its workers, and the new selinux_client_domain case asserts the entrypoint labels and the transition rules the loaded policy holds. The two no-denial cases now count only the denials the kernel enforced, because xcat_t is permissive and each access it needs is recorded. They also pass --input-logs: on EL10 audit 4.0.3 ausearch reads the journal rather than the file auditd.conf names, and answered "" on a node whose log held 1032 denials. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-test/autotest/testcase/selinux/cases0 | 57 +++++++++++++++++----- xCAT-test/unit/xcat_selinux_package.t | 46 +++++++++++++++++ 2 files changed, 90 insertions(+), 13 deletions(-) diff --git a/xCAT-test/autotest/testcase/selinux/cases0 b/xCAT-test/autotest/testcase/selinux/cases0 index ca37c7c01c..649f542986 100644 --- a/xCAT-test/autotest/testcase/selinux/cases0 +++ b/xCAT-test/autotest/testcase/selinux/cases0 @@ -1,20 +1,47 @@ start:selinux_xcatd_domain -description:on an enforcing management node, xcatd and its workers run in unconfined_service_t +description:on an enforcing management node, xcatd and its workers run in xcat_t label:mn_only,selinux cmd:getenforce check:rc==0 check:output=~^Enforcing$ cmd:ps -o label= -p "$(cat /run/xcatd.pid)" check:rc==0 -check:output=~:unconfined_service_t: +check:output=~:xcat_t: cmd:ps -eo label,args | grep '[x]catd:' check:rc==0 -check:output=~:unconfined_service_t: +check:output=~:xcat_t: check:output!~initrc_t +check:output!~unconfined_service_t +end + +start:selinux_client_domain +description:on an enforcing management node, a client command entered through xcatclient runs in xcat_t +label:mn_only,selinux +cmd:getenforce +check:rc==0 +check:output=~^Enforcing$ +cmd:ls -Z /opt/xcat/bin/xcatclient +check:rc==0 +check:output=~:xcat_client_exec_t: +cmd:ls -Z /opt/xcat/sbin/xcatd +check:rc==0 +check:output=~:xcatd_exec_t: +cmd:sh -c 'rpm -q setools-console || dnf install -y setools-console' +check:rc==0 +cmd:sesearch -T -s init_t -t xcatd_exec_t -c process +check:rc==0 +check:output=~xcat_t +cmd:sesearch -T -s unconfined_t -t xcat_client_exec_t -c process +check:rc==0 +check:output=~xcat_t +cmd:sesearch -T -s unconfined_t -t bin_t -c process +check:output!~xcat_t +cmd:lsxcatd -v +check:rc==0 end start:selinux_mn_labels -description:on an enforcing management node, xCAT-selinux labels /install, httpd serves /install and /tftpboot, and SELinux denies nothing +description:on an enforcing management node, xCAT-selinux labels /install, httpd serves /install and /tftpboot, and no denial is enforced label:mn_only,selinux cmd:getenforce check:rc==0 @@ -52,14 +79,16 @@ check:rc==0 check:output=~^xcat-selinux-probe-ok$ cmd:rm -f /tftpboot/xcat/selinux_mn_labels.probe check:rc==0 -cmd:sh -c 'ausearch -m AVC,USER_AVC -ts $(cat /tmp/selinux_mn_labels.start)' -check:rc==1 -check:output=~ -cmd:rm -f /tmp/selinux_mn_labels.start +cmd:sh -c 'ausearch --input-logs -m AVC,USER_AVC -ts "$(cat /tmp/selinux_mn_labels.start)" > /tmp/selinux_mn_labels.avc 2>&1; grep -q -e "^type=" -e "no matches" /tmp/selinux_mn_labels.avc' +check:rc==0 +cmd:sh -c 'grep -F "permissive=0" /tmp/selinux_mn_labels.avc | wc -l' +check:rc==0 +check:output=~^0$ +cmd:rm -f /tmp/selinux_mn_labels.start /tmp/selinux_mn_labels.avc end start:selinux_restapi_avc -description:on an enforcing management node, xcatws.cgi reaches xcatd and SELinux denies nothing +description:on an enforcing management node, xcatws.cgi reaches xcatd and no denial is enforced label:mn_only,selinux,restapi cmd:getenforce check:rc==0 @@ -75,8 +104,10 @@ check:rc==0 cmd:username=__GETTABLEVALUE(key,system,username,passwd)__;password=__GETTABLEVALUE(key,system,password,passwd)__;curl -k -s -f "https://localhost/xcatws/globalconf/attrs/master?userName=$username&userPW=$password" check:rc==0 check:output=~clustersite -cmd:sh -c 'ausearch -m AVC,USER_AVC -ts $(cat /tmp/selinux_restapi_avc.start)' -check:rc==1 -check:output=~ -cmd:rm -f /tmp/selinux_restapi_avc.start +cmd:sh -c 'ausearch --input-logs -m AVC,USER_AVC -ts "$(cat /tmp/selinux_restapi_avc.start)" > /tmp/selinux_restapi_avc.avc 2>&1; grep -q -e "^type=" -e "no matches" /tmp/selinux_restapi_avc.avc' +check:rc==0 +cmd:sh -c 'grep -F "permissive=0" /tmp/selinux_restapi_avc.avc | wc -l' +check:rc==0 +check:output=~^0$ +cmd:rm -f /tmp/selinux_restapi_avc.start /tmp/selinux_restapi_avc.avc end diff --git a/xCAT-test/unit/xcat_selinux_package.t b/xCAT-test/unit/xcat_selinux_package.t index d98b64d5ad..478d426592 100644 --- a/xCAT-test/unit/xcat_selinux_package.t +++ b/xCAT-test/unit/xcat_selinux_package.t @@ -110,6 +110,22 @@ is($fc{'/install/netboot/[^/]+/[^/]+/[^/]+/rootimg-statelite(/.*)?'}, '<>' '... and a statelite rootimg too'); ok(!(grep { m{^/tftpboot} } keys %fc), '/tftpboot keeps the stock tftpdir_t'); +# The type of an fc entry, dropping the file-type flag that executables carry. +sub fc_type { + my ($path) = @_; + my $spec = $fc{$path} // return undef; + return $spec =~ /gen_context\(system_u:object_r:(\w+),s0\)/ ? $1 : $spec; +} + +# restorecon labels the file that execve resolves to. /usr/sbin/xcatd is a +# symlink, and a symlink is never an entrypoint. +is(fc_type('/opt/xcat/sbin/xcatd'), 'xcatd_exec_t', 'xcatd is the entrypoint of the daemon'); +ok(!exists $fc{'/usr/sbin/xcatd'}, '... and the symlink to it carries no context'); +foreach my $client (qw(xcatclient xcatclientnnr)) { + is(fc_type("/opt/xcat/bin/$client"), 'xcat_client_exec_t', + "$client is the entrypoint of the client commands"); +} + # The module source is the artifact: checkmodule compiles this text as written. # Each rule here is justified by a measured denial; see # docs/source/advanced/selinux/index.rst and the policy campaign REASONING.md. @@ -171,6 +187,36 @@ is_deeply([ grep { /^kernel_t / } @rules ], [], 'no rule grants kernel_t anything'); +######################################## +# +# The xcat_t domain +# + +like($te, qr/^type xcat_t;$/m, 'xcat.te declares one domain for xcatd and the clients'); +like($te, qr/^permissive xcat_t;$/m, + '... which is permissive while the CI collects the accesses it needs'); +unlike($te, qr/^permissive (?!xcat_t\b)/m, '... and no other domain is made permissive'); + +like($te, qr/^init_daemon_domain\(xcat_t, xcatd_exec_t\)$/m, + 'systemd starts xcatd in xcat_t'); +like($te, qr/^application_domain\(xcat_t, xcat_client_exec_t\)$/m, + 'a client command entered through xcatclient runs in xcat_t'); + +# xcatd and xcatclient are Perl scripts. The kernel labels the new process from +# the script, then the domain runs the interpreter named in the shebang. +like($te, qr/^corecmd_exec_bin\(xcat_t\)$/m, 'xcat_t runs the interpreter of its own script'); + +# Collects the source domains that xcat.te gives an automatic transition. +my @domtrans = $te =~ /^\s*domtrans_pattern\((\w+), xcat_client_exec_t, xcat_t\)$/mg; +is_deeply(\@domtrans, ['unconfined_t'], + 'only the unconfined domain transitions into xcat_t'); + +# A confined user domain that entered a permissive xcat_t would leave its own +# confinement, so the module gives it no transition. +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"); +} + # 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");