|
1 | 1 | <def-group> |
2 | | - <definition class="compliance" id="selinux_confinement_of_daemons" version="1"> |
3 | | - {{{ oval_metadata("All pids in /proc should be assigned an SELinux security context other than 'unconfined_service_t'.", rule_title=rule_title) }}} |
4 | | - <criteria> |
5 | | - <criterion comment="no unconfined_service_t in /proc" test_ref="test_selinux_confinement_of_daemons" /> |
| 2 | + <definition class="compliance" id="selinux_confinement_of_daemons" version="2"> |
| 3 | + {{{ oval_metadata("All pids in /proc should be assigned an SELinux security context other than 'unconfined_service_t' (kubelet excluded).", rule_title=rule_title) }}} |
| 4 | + <criteria operator="OR"> |
| 5 | + <criterion comment="no unconfined_service_t processes exist" test_ref="test_no_unconfined_service_t_processes" /> |
| 6 | + <criterion comment="only kubelet has unconfined_service_t" test_ref="test_only_kubelet_unconfined" /> |
6 | 7 | </criteria> |
7 | 8 | </definition> |
8 | | - <linux:selinuxsecuritycontext_test check="none satisfy" check_existence="any_exist" comment="none satisfy unconfined_service_t in /proc" id="test_selinux_confinement_of_daemons" version="2"> |
| 9 | + |
| 10 | + <!-- Test 1: Check if NO processes have unconfined_service_t --> |
| 11 | + <linux:selinuxsecuritycontext_test check="none satisfy" check_existence="any_exist" |
| 12 | + comment="no processes with unconfined_service_t" id="test_no_unconfined_service_t_processes" version="1"> |
9 | 13 | <linux:object object_ref="object_selinux_confinement_of_daemons" /> |
10 | | - <linux:state state_ref="state_selinux_confinement_of_daemons" /> |
| 14 | + <linux:state state_ref="state_unconfined_service_t" /> |
11 | 15 | </linux:selinuxsecuritycontext_test> |
12 | | - <linux:selinuxsecuritycontext_object comment="find unconfined_service_t in /proc" id="object_selinux_confinement_of_daemons" version="1"> |
| 16 | + |
| 17 | + <!-- Test 2: Check that all unconfined_service_t processes are kubelet --> |
| 18 | + <ind:textfilecontent54_test check="all" check_existence="all_exist" |
| 19 | + comment="all unconfined_service_t processes are kubelet" id="test_only_kubelet_unconfined" version="1"> |
| 20 | + <ind:object object_ref="object_unconfined_service_t_cmdlines" /> |
| 21 | + <ind:state state_ref="state_cmdline_is_kubelet" /> |
| 22 | + </ind:textfilecontent54_test> |
| 23 | + |
| 24 | + <!-- Object: Find all processes in /proc --> |
| 25 | + <linux:selinuxsecuritycontext_object comment="find all processes in /proc" id="object_selinux_confinement_of_daemons" version="2"> |
13 | 26 | <linux:behaviors max_depth="1" recurse_direction="down" /> |
14 | 27 | <linux:path>/proc</linux:path> |
15 | | - <linux:filename operation="pattern match">^.*$</linux:filename> |
16 | | - <filter action="include">state_selinux_confinement_of_daemons</filter> |
| 28 | + <linux:filename operation="pattern match">^[0-9]+$</linux:filename> |
17 | 29 | </linux:selinuxsecuritycontext_object> |
18 | | - <linux:selinuxsecuritycontext_state comment="state unconfined_service_t" id="state_selinux_confinement_of_daemons" version="1"> |
| 30 | + |
| 31 | + <!-- Object: Read cmdline for processes with unconfined_service_t --> |
| 32 | + <ind:textfilecontent54_object comment="cmdline of unconfined_service_t processes" id="object_unconfined_service_t_cmdlines" version="1"> |
| 33 | + <ind:filepath operation="equals" var_ref="var_unconfined_cmdline_paths" var_check="at least one"/> |
| 34 | + <ind:pattern operation="pattern match">^(.*)$</ind:pattern> |
| 35 | + <ind:instance datatype="int" operation="equals">1</ind:instance> |
| 36 | + </ind:textfilecontent54_object> |
| 37 | + |
| 38 | + <!-- Variable: Build /proc/PID/cmdline paths for unconfined processes --> |
| 39 | + <local_variable id="var_unconfined_cmdline_paths" datatype="string" comment="cmdline paths for unconfined_service_t PIDs" version="1"> |
| 40 | + <concat> |
| 41 | + <literal_component>/proc/</literal_component> |
| 42 | + <object_component object_ref="object_unconfined_selinux_contexts" item_field="pid"/> |
| 43 | + <literal_component>/cmdline</literal_component> |
| 44 | + </concat> |
| 45 | + </local_variable> |
| 46 | + |
| 47 | + <!-- Object: SELinux contexts filtered to unconfined_service_t --> |
| 48 | + <linux:selinuxsecuritycontext_object comment="unconfined_service_t contexts" id="object_unconfined_selinux_contexts" version="1"> |
| 49 | + <linux:behaviors max_depth="1" recurse_direction="down" /> |
| 50 | + <linux:path>/proc</linux:path> |
| 51 | + <linux:filename operation="pattern match">^[0-9]+$</linux:filename> |
| 52 | + <filter action="include">state_unconfined_service_t</filter> |
| 53 | + </linux:selinuxsecuritycontext_object> |
| 54 | + |
| 55 | + <!-- State: Match unconfined_service_t type --> |
| 56 | + <linux:selinuxsecuritycontext_state comment="state unconfined_service_t" id="state_unconfined_service_t" version="1"> |
19 | 57 | <linux:type datatype="string" operation="equals">unconfined_service_t</linux:type> |
20 | 58 | </linux:selinuxsecuritycontext_state> |
| 59 | + |
| 60 | + <!-- State: Match kubelet in cmdline --> |
| 61 | + <ind:textfilecontent54_state comment="kubelet cmdline" id="state_cmdline_is_kubelet" version="1"> |
| 62 | + <ind:subexpression operation="pattern match">.*kubelet.*</ind:subexpression> |
| 63 | + </ind:textfilecontent54_state> |
21 | 64 | </def-group> |
0 commit comments