mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-11-28 13:22:16 +00:00
fix(xcat-test): every AVC check in the selinux cases searches an empty window
The cases marked the start of their window with date "+%x %T" and gave it to ausearch. audit 4.0.3 takes a bare HH:MM:SS and rejects that format: it prints nothing and exits 0. Measured on an enforcing AlmaLinux 10.2 management node, with the raw log holding 4197 records: "-ts 10/21/2026 20:59:08" returned 0 records, "-ts 20:59:08" returned 22 and "-ts today" returned 4006. So selinux_avc_check.sh searched nothing and reported XCAT_AVC=0 whatever the node did. The positive control of selinux_mn_labels is what found it. The case mislabels /install/postscripts/xcatdsklspost, shows httpd answering 403 and requires the check to report XCAT_AVC=[1-9]; it reported SEARCHED=0 AVC=0 XCAT_AVC=0 and the case failed on an enforcing el10 node. The four cases now write date "+%H:%M:%S". selinux_avc_check.sh refuses a window that holds no audit record at all, because that is not a credible answer on a running node, and names the format in the message. selinux_avc_check.bats fails its ninth check against the unguarded script. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
This commit is contained in:
@@ -14,6 +14,12 @@
|
||||
# no audit records, so --input-logs is not optional: without it the search returns 0
|
||||
# records and every answer is "clean".
|
||||
#
|
||||
# audit 4.0.3 takes a bare HH:MM:SS and rejects the output of date "+%x %T". It prints
|
||||
# nothing and exits 0, so a window that holds records reads as empty. Measured on an
|
||||
# enforcing el10 node: "-ts 10/21/2026 20:59:08" returned 0 records, "-ts 20:59:08"
|
||||
# returned 22 and "-ts today" returned 4006. A window with no audit record at all is not a
|
||||
# credible answer on a running node, so SEARCHED=0 is a usage error and not a clean result.
|
||||
#
|
||||
# Usage:
|
||||
# selinux_avc_check.sh <ausearch -ts value> search and report
|
||||
# selinux_avc_check.sh --classify read raw records on stdin
|
||||
@@ -37,6 +43,11 @@ selinux_avc_report()
|
||||
[ -n "$since" ] || return 2
|
||||
|
||||
searched=$(ausearch --input-logs -ts "$since" --raw 2>/dev/null | grep -c '^type=')
|
||||
if [ "$searched" -eq 0 ]; then
|
||||
echo "SEARCHED=0 AVC=0 XCAT_AVC=0"
|
||||
echo "no audit record since '$since'. ausearch takes a bare HH:MM:SS." >&2
|
||||
return 2
|
||||
fi
|
||||
denials=$(ausearch --input-logs -m AVC,USER_AVC -ts "$since" --raw 2>/dev/null)
|
||||
all=$(printf '%s\n' "$denials" | grep -c '^type=')
|
||||
kept=$(printf '%s\n' "$denials" | selinux_avc_classify)
|
||||
|
||||
@@ -58,7 +58,7 @@ label:mn_only,selinux
|
||||
cmd:getenforce
|
||||
check:rc==0
|
||||
check:output=~^Enforcing$
|
||||
cmd:sh -c 'rm -f /tmp/selinux_mn_labels.ck; ausearch --input-logs -m AVC,USER_AVC --checkpoint /tmp/selinux_mn_labels.ck -ts today > /dev/null 2>&1; date "+%x %T" > /tmp/selinux_mn_labels.start; true'
|
||||
cmd:sh -c 'rm -f /tmp/selinux_mn_labels.ck; ausearch --input-logs -m AVC,USER_AVC --checkpoint /tmp/selinux_mn_labels.ck -ts today > /dev/null 2>&1; date "+%H:%M:%S" > /tmp/selinux_mn_labels.start; true'
|
||||
check:rc==0
|
||||
cmd:rpm -q xCAT-selinux
|
||||
check:rc==0
|
||||
@@ -99,7 +99,7 @@ check:output=~^0$
|
||||
cmd:sh -c '/opt/xcat/share/xcat/tools/autotest/testcase/commoncmd/selinux_avc_check.sh "$(cat /tmp/selinux_mn_labels.start)"'
|
||||
check:rc==0
|
||||
check:output=~XCAT_AVC=0
|
||||
cmd:sh -c 'date "+%x %T" > /tmp/selinux_mn_control.start; sleep 1; chcon -t shadow_t /install/postscripts/xcatdsklspost'
|
||||
cmd:sh -c 'date "+%H:%M:%S" > /tmp/selinux_mn_control.start; sleep 1; chcon -t shadow_t /install/postscripts/xcatdsklspost'
|
||||
check:rc==0
|
||||
cmd:sh -c 'curl -s -o /dev/null -w "%{http_code}" http://localhost/install/postscripts/xcatdsklspost'
|
||||
check:rc==0
|
||||
@@ -123,7 +123,7 @@ label:mn_only,selinux,restapi
|
||||
cmd:getenforce
|
||||
check:rc==0
|
||||
check:output=~^Enforcing$
|
||||
cmd:sh -c 'rm -f /tmp/selinux_restapi_avc.ck; ausearch --input-logs -m AVC,USER_AVC --checkpoint /tmp/selinux_restapi_avc.ck -ts today > /dev/null 2>&1; date "+%x %T" > /tmp/selinux_restapi_avc.start; true'
|
||||
cmd:sh -c 'rm -f /tmp/selinux_restapi_avc.ck; ausearch --input-logs -m AVC,USER_AVC --checkpoint /tmp/selinux_restapi_avc.ck -ts today > /dev/null 2>&1; date "+%H:%M:%S" > /tmp/selinux_restapi_avc.start; true'
|
||||
check:rc==0
|
||||
cmd:sh -c 'rpm -q mod_ssl || dnf install -y mod_ssl'
|
||||
check:rc==0
|
||||
|
||||
@@ -5,7 +5,7 @@ os:Linux
|
||||
cmd:getenforce
|
||||
check:rc==0
|
||||
check:output=~^Enforcing$
|
||||
cmd:sh -c 'date "+%x %T" > /tmp/selinux_cn_diskful.start'
|
||||
cmd:sh -c 'date "+%H:%M:%S" > /tmp/selinux_cn_diskful.start'
|
||||
check:rc==0
|
||||
cmd:chdef -t node -o $$CN selinux=enforcing
|
||||
check:rc==0
|
||||
|
||||
@@ -76,3 +76,10 @@ SSH_RECORD='type=AVC msg=audit(1759000002.333:444): avc: denied { siginh } for
|
||||
run "$(repo_path 'xCAT-test/autotest/testcase/commoncmd/selinux_avc_check.sh')"
|
||||
[ "$status" -eq 2 ]
|
||||
}
|
||||
|
||||
@test "a window with no audit record is a usage error, not a clean answer" {
|
||||
run selinux_avc_report "01/01/1970 00:00:00"
|
||||
[ "$status" -eq 2 ]
|
||||
[[ "$output" == *"SEARCHED=0"* ]]
|
||||
[[ "$output" == *"bare HH:MM:SS"* ]]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user