From 210b8b893b3152d2abe9bc69a964e0e79cfa1534 Mon Sep 17 00:00:00 2001 From: Vickey Brown Date: Fri, 8 May 2026 11:47:59 -0500 Subject: [PATCH] fixed rule to allow kubelet to kubelet to be unconfined --- controls/nist_rhcos4.yml | 12 ++---- .../oval/rhcos4.xml | 35 +++++++++++++++++ .../tests/kubelet_unconfined.rhcos4.pass.sh | 38 +++++++++++++++++++ .../tests/no_unconfined_daemons.pass.sh | 5 ++- .../tests/unconfined_daemon.fail.sh | 16 ++++++-- 5 files changed, 93 insertions(+), 13 deletions(-) create mode 100644 linux_os/guide/system/selinux/selinux_confinement_of_daemons/oval/rhcos4.xml create mode 100644 linux_os/guide/system/selinux/selinux_confinement_of_daemons/tests/kubelet_unconfined.rhcos4.pass.sh diff --git a/controls/nist_rhcos4.yml b/controls/nist_rhcos4.yml index b152c281059e..f361f62461f8 100644 --- a/controls/nist_rhcos4.yml +++ b/controls/nist_rhcos4.yml @@ -480,8 +480,7 @@ controls: rules: - var_selinux_policy_name=targeted - selinux_policytype - # (jhrozek): Disabled because of https://issues.redhat.com/browse/OCPBUGS-6968 - #- selinux_confinement_of_daemons + - selinux_confinement_of_daemons - var_selinux_state=enforcing - selinux_state - coreos_enable_selinux_kernel_argument @@ -822,8 +821,7 @@ controls: https://issues.redhat.com/browse/CMP-115 rules: - # (jhrozek): Disabled because of https://issues.redhat.com/browse/OCPBUGS-6968 - #- selinux_confinement_of_daemons + - selinux_confinement_of_daemons - no_shelllogin_for_systemaccounts - sysctl_kernel_perf_event_paranoid - sysctl_kernel_unprivileged_bpf_disabled @@ -4919,8 +4917,7 @@ controls: - audit_rules_privileged_commands_userhelper - audit_rules_networkconfig_modification - audit_rules_etc_shadow_openat - # (jhrozek): Disabled because of https://issues.redhat.com/browse/OCPBUGS-6968 - #- selinux_confinement_of_daemons + - selinux_confinement_of_daemons - audit_rules_etc_gshadow_open_by_handle_at - audit_rules_etc_gshadow_open - var_auditd_space_left_action=syslog @@ -5166,8 +5163,7 @@ controls: - service_bluetooth_disabled - kernel_module_tipc_disabled - sysctl_net_ipv6_conf_all_accept_redirects - # (jhrozek): Disabled because of https://issues.redhat.com/browse/OCPBUGS-6968 - #- selinux_confinement_of_daemons + - selinux_confinement_of_daemons - sysctl_net_ipv4_tcp_syncookies - sysctl_net_ipv4_icmp_ignore_bogus_error_responses - coreos_vsyscall_kernel_argument diff --git a/linux_os/guide/system/selinux/selinux_confinement_of_daemons/oval/rhcos4.xml b/linux_os/guide/system/selinux/selinux_confinement_of_daemons/oval/rhcos4.xml new file mode 100644 index 000000000000..bed366c3f6ae --- /dev/null +++ b/linux_os/guide/system/selinux/selinux_confinement_of_daemons/oval/rhcos4.xml @@ -0,0 +1,35 @@ + + + {{{ oval_metadata("All pids in /proc should be assigned an SELinux security context other than 'unconfined_service_t' (kubelet excluded).", rule_title=rule_title) }}} + + + + + + + + + + + + + + + + + + + + + + /proc + ^[0-9]+$ + + + + + unconfined_service_t + + diff --git a/linux_os/guide/system/selinux/selinux_confinement_of_daemons/tests/kubelet_unconfined.rhcos4.pass.sh b/linux_os/guide/system/selinux/selinux_confinement_of_daemons/tests/kubelet_unconfined.rhcos4.pass.sh new file mode 100644 index 000000000000..cd03564e3493 --- /dev/null +++ b/linux_os/guide/system/selinux/selinux_confinement_of_daemons/tests/kubelet_unconfined.rhcos4.pass.sh @@ -0,0 +1,38 @@ +#!/bin/bash +# +# This test verifies that kubelet is allowed to run with unconfined_service_t on RHCOS4. +# On RHCOS4, kubelet is explicitly allowed to be unconfined. + +# Create a mock kubelet binary with unconfined_service_t +# The binary name must be "kubelet" to match the OVAL pattern +cat > /usr/local/bin/kubelet << 'EOF' +#!/bin/bash + +while true; do + sleep 60 +done +EOF +chmod +x /usr/local/bin/kubelet + +cat > /etc/systemd/system/mock-kubelet.service << 'EOF' +[Unit] +Description=Mock kubelet for testing + +[Service] +Type=simple +ExecStart=/usr/local/bin/kubelet +SELinuxContext=system_u:system_r:unconfined_service_t:s0 +Restart=no + +[Install] +WantedBy=multi-user.target +EOF + +systemctl daemon-reload +systemctl start mock-kubelet.service + +# Wait for service to start +sleep 2 + +# Exit cleanly - the OVAL check should allow kubelet to be unconfined and pass +exit 0 diff --git a/linux_os/guide/system/selinux/selinux_confinement_of_daemons/tests/no_unconfined_daemons.pass.sh b/linux_os/guide/system/selinux/selinux_confinement_of_daemons/tests/no_unconfined_daemons.pass.sh index 7a180adf73b8..f510a831cb34 100644 --- a/linux_os/guide/system/selinux/selinux_confinement_of_daemons/tests/no_unconfined_daemons.pass.sh +++ b/linux_os/guide/system/selinux/selinux_confinement_of_daemons/tests/no_unconfined_daemons.pass.sh @@ -2,4 +2,7 @@ # sshd should be running and should have specific rules in SELinux policy # so it should not be detected as unconfined_service_t. -systemctl status sshd.service +systemctl start sshd.service 2>/dev/null || true + +# Exit cleanly - the OVAL check should find no unconfined_service_t processes +exit 0 diff --git a/linux_os/guide/system/selinux/selinux_confinement_of_daemons/tests/unconfined_daemon.fail.sh b/linux_os/guide/system/selinux/selinux_confinement_of_daemons/tests/unconfined_daemon.fail.sh index 8639fc6f9d96..f6bab0b6f3c0 100644 --- a/linux_os/guide/system/selinux/selinux_confinement_of_daemons/tests/unconfined_daemon.fail.sh +++ b/linux_os/guide/system/selinux/selinux_confinement_of_daemons/tests/unconfined_daemon.fail.sh @@ -2,7 +2,7 @@ # # remediation = none -cat > /usr/bin/dummydaemon.sh << EOF +cat > /usr/bin/dummydaemon.sh << 'EOF' #!/bin/bash while true; do @@ -12,17 +12,25 @@ done EOF chmod +x /usr/bin/dummydaemon.sh -cat > /etc/systemd/system/dummydaemon.service << EOF +cat > /etc/systemd/system/dummydaemon.service << 'EOF' [Unit] Description=Dummy daemon [Service] +Type=simple ExecStart=/usr/bin/dummydaemon.sh -Restart=on-failure +SELinuxContext=system_u:system_r:unconfined_service_t:s0 +Restart=no [Install] WantedBy=multi-user.target EOF +systemctl daemon-reload systemctl start dummydaemon.service -systemctl status dummydaemon.service + +# Wait a moment for service to start +sleep 2 + +# Exit cleanly - the OVAL check should detect an unconfined daemon and fail +exit 0