Skip to content

Commit a8bb68c

Browse files
Enable sle16 specific checks and remediations for mount_option_tmp_noexec
1 parent 6ede348 commit a8bb68c

3 files changed

Lines changed: 69 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# platform = SUSE Linux Enterprise 16
2+
# reboot = true
3+
# strategy = configure
4+
# complexity = low
5+
# disruption = low
6+
7+
- name: '{{{ rule_title }}} - Check if noexec options is configured in /usr/lib/systemd/system/tmp.mount'
8+
ansible.builtin.lineinfile:
9+
path: /usr/lib/systemd/system/tmp.mount
10+
regexp: ^[\s]*Options=[\s]*.*noexec.*$
11+
state: absent
12+
check_mode: true
13+
register: noexec_match
14+
15+
# if no match, collect current options and add noexec
16+
- name: '{{{ rule_title }}} - Collect previously configured options'
17+
ansible.builtin.shell:
18+
cmd: sed -n 's/^[\s]*Options=[\s]*\(.*\)$/\1/p' /usr/lib/systemd/system/tmp.mount
19+
register: current_options
20+
when:
21+
- noexec_match is defined and noexec_match.found == 0
22+
23+
24+
- name: '{{{ rule_title }}} - Add noexec option to previously configured options'
25+
ansible.builtin.shell:
26+
cmd: sed -i "s/^Options=.*/Options={{ current_options.stdout }},noexec/g" /usr/lib/systemd/system/tmp.mount
27+
when:
28+
- noexec_match.found == 0 and current_options is defined
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# platform = SUSE Linux Enterprise 16
2+
# reboot = true
3+
# strategy = configure
4+
# complexity = low
5+
# disruption = low
6+
7+
tmp_mount_file="/usr/lib/systemd/system/tmp.mount"
8+
9+
# if already set, skip
10+
if grep -qE '^[\s]*Options=[\s]*.*noexec.*$' ${tmp_mount_file}; then
11+
echo "noexec option already present, skipping remediation"
12+
exit 0
13+
fi
14+
15+
# no options set, add it
16+
if ! grep -qE '^[\s]*Options=[\s]*.*$' ${tmp_mount_file}; then
17+
echo "Options=noexec" >> ${tmp_mount_file}
18+
else
19+
# collect currently set options
20+
current_options=$(sed -n 's/^[\s]*Options=[\s]*\(.*\)$/\1/p' ${tmp_mount_file})
21+
# add noexec to current options and replace
22+
sed -i "s/^Options=.*/Options=${current_options},noexec/g" ${tmp_mount_file}
23+
fi
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<def-group>
2+
<definition class="compliance" id="mount_option_tmp_noexec" version="1">
3+
{{{ oval_metadata("ensure tmp.mount services has noexec option configured.") }}}
4+
<criteria>
5+
<criterion comment="check noexec is set in Options in /usr/lib/systemd/system/tmp.mount" test_ref="test_tmp_mount_noexec_option" />
6+
</criteria>
7+
</definition>
8+
9+
<ind:textfilecontent54_test check="all" check_existence="all_exist" comment="check noexec is set in Options in /usr/lib/systemd/system/tmp.mount" id="test_tmp_mount_noexec_option" version="1">
10+
<ind:object object_ref="object_tmp_mount_noexec_option" />
11+
</ind:textfilecontent54_test>
12+
<ind:textfilecontent54_object id="object_tmp_mount_noexec_option" comment="Options has noexec set in /usr/lib/systemd/system/tmp.mount" version="1">
13+
<ind:filepath>/usr/lib/systemd/system/tmp.mount</ind:filepath>
14+
<ind:pattern operation="pattern match">^[\s]*Options=.*noexec.*$</ind:pattern>
15+
<ind:instance datatype="int" operation="equals">1</ind:instance>
16+
</ind:textfilecontent54_object>
17+
18+
</def-group>

0 commit comments

Comments
 (0)