Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions controls/nist_rhcos4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<def-group>
<definition class="compliance" id="selinux_confinement_of_daemons" version="2">
{{{ oval_metadata("All pids in /proc should be assigned an SELinux security context other than 'unconfined_service_t' (kubelet excluded).", rule_title=rule_title) }}}
<criteria operator="OR">
<criterion comment="no unconfined_service_t processes exist" test_ref="test_no_unconfined_service_t_processes" />
<criterion comment="at most one unconfined_service_t process" test_ref="test_at_most_one_unconfined_process" />
</criteria>
</definition>

<!-- Test 1: Check if NO processes have unconfined_service_t -->
<linux:selinuxsecuritycontext_test check="none satisfy" check_existence="any_exist"
comment="no processes with unconfined_service_t" id="test_no_unconfined_service_t_processes" version="1">
<linux:object object_ref="object_selinux_confinement_of_daemons" />
<linux:state state_ref="state_unconfined_service_t" />
</linux:selinuxsecuritycontext_test>

<!-- Test 2: Check that at most one process has unconfined_service_t (assumed to be kubelet) -->
<linux:selinuxsecuritycontext_test check="all" check_existence="only_one_exists"
comment="at most one process with unconfined_service_t" id="test_at_most_one_unconfined_process" version="1">
<linux:object object_ref="object_selinux_confinement_of_daemons" />
<linux:state state_ref="state_unconfined_service_t" />
</linux:selinuxsecuritycontext_test>

<!-- Object: Find all processes in /proc -->
<linux:selinuxsecuritycontext_object comment="find all processes in /proc" id="object_selinux_confinement_of_daemons" version="2">
<linux:behaviors max_depth="1" recurse_direction="down" />
<linux:path>/proc</linux:path>
<linux:filename operation="pattern match">^[0-9]+$</linux:filename>
</linux:selinuxsecuritycontext_object>

<!-- State: Match unconfined_service_t type -->
<linux:selinuxsecuritycontext_state comment="state unconfined_service_t" id="state_unconfined_service_t" version="1">
<linux:type datatype="string" operation="equals">unconfined_service_t</linux:type>
</linux:selinuxsecuritycontext_state>
</def-group>
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# remediation = none

cat > /usr/bin/dummydaemon.sh << EOF
cat > /usr/bin/dummydaemon.sh << 'EOF'
#!/bin/bash

while true; do
Expand All @@ -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
Loading