Skip to content

Commit

Permalink
Rewriting tasks for rule 1.1.2.x according to this issue: https://cod…
Browse files Browse the repository at this point in the history
  • Loading branch information
DianaMariaDDM committed Jan 29, 2024
1 parent 6328cf2 commit 05c2a5a
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 52 deletions.
34 changes: 34 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,43 @@
---
- name: Writing the tmp file | tmp_systemd
ansible.builtin.template:
src: etc/systemd/system/tmp.mount.j2
dest: /etc/systemd/system/tmp.mount
owner: root
group: root
mode: '0644'
with_items:
- "{{ ansible_facts.mounts }}"
loop_control:
label: "{{ item.device }}"
when:
- "'/tmp' in mount_names"
- item.mount == "/tmp"
- tmp_mnt_type == 'tmp_systemd'
listen: Writing and remounting tmp

- name: Writing the tmp file | fstab
ansible.posix.mount:
path: /tmp
src: "{{ item.device }}"
state: present
fstype: "{{ item.fstype }}"
opts: defaults,{{ tmp_partition_mount_options | unique | join(',') }}
with_items:
- "{{ ansible_facts.mounts }}"
loop_control:
label: "{{ item.device }}"
when:
- "'/tmp' in mount_names"
- tmp_mnt_type == 'fstab'
- item.mount == "/tmp"
listen: Writing and remounting tmp

- name: Remount tmp
ansible.posix.mount:
path: /tmp
state: remounted
listen: Writing and remounting tmp

- name: Remount var
ansible.posix.mount:
Expand Down
17 changes: 17 additions & 0 deletions tasks/prelim.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,23 @@
tags:
- always

- name: Initialize the mount options variable
block:
- name: Initializing the var if there is no /tmp mount
ansible.builtin.set_fact:
tmp_partition_mount_options: []
when: "'/tmp' not in mount_names"

- name: Initializing the var if there is a /tmp mount
ansible.builtin.set_fact:
tmp_partition_mount_options: "{{ item.options }}"
loop: "{{ ansible_facts.mounts }}"
when:
- item.mount == "/tmp"
- "'/tmp' in mount_names"
tags:
-always

- name: "PRELIM | Run apt update"
ansible.builtin.package:
update_cache: true
Expand Down
75 changes: 24 additions & 51 deletions tasks/section_1/cis_1.1.2.x.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,68 +23,41 @@
- rule_1.1.2.1
- tmp

- name: |
"1.1.2.2 | PATCH | Ensure nodev option set on /tmp partition | tmp_systemd"
"1.1.2.3 | PATCH | Ensure noexec option set on /tmp partition | tmp_systemd"
"1.1.2.4 | PATCH | Ensure nosuid option set on /tmp partition | tmp_systemd"
ansible.builtin.template:
src: etc/systemd/system/tmp.mount.j2
dest: /etc/systemd/system/tmp.mount
owner: root
group: root
mode: '0644'
notify: Remount tmp
with_items:
- "{{ ansible_facts.mounts }}"
loop_control:
label: "{{ item.device }}"
when:
- "'/tmp' in mount_names"
- item.mount == "/tmp"
- tmp_mnt_type == 'tmp_systemd'
- ubtu22cis_rule_1_1_2_2 or
ubtu22cis_rule_1_1_2_3 or
ubtu22cis_rule_1_1_2_4
tags:
- name: "1.1.2.2 | PATCH | Ensure nodev option set on /tmp partition"
ansible.builtin.set_fact:
tmp_partition_mount_options: "{{ tmp_partition_mount_options + [ 'nodev' ] }}"
notify: Writing and remounting tmp
when: ubtu22cis_rule_1_1_2_2
tags:
- level1-server
- level1-workstation
- automated
- patch
- rule_1.1.2.2
- rule_1.1.2.3
- rule_1.1.2.4
- tmp

- name: |
"1.1.2.2 | PATCH | Ensure nodev option set on /tmp partition | fstab"
"1.1.2.3 | PATCH | Ensure noexec option set on /tmp partition | fstab"
"1.1.2.4 | PATCH | Ensure nosuid option set on /tmp partition | fstab"
ansible.posix.mount:
path: /tmp
src: "{{ item.device }}"
state: present
fstype: "{{ item.fstype }}"
opts: defaults,{% if ubtu22cis_rule_1_1_2_2 %}nodev,{% endif %}{% if ubtu22cis_rule_1_1_2_3 %}noexec,{% endif %}{% if ubtu22cis_rule_1_1_2_4 %}nosuid{% endif %}
notify: remount tmp
with_items:
- "{{ ansible_facts.mounts }}"
loop_control:
label: "{{ item.device }}"
when:
- "'/tmp' in mount_names"
- tmp_mnt_type == 'fstab'
- item.mount == "/tmp"
- ubtu22cis_rule_1_1_2_1 or
ubtu22cis_rule_1_1_2_2 or
ubtu22cis_rule_1_1_2_3 or
ubtu22cis_rule_1_1_2_4
tags:
- name: "1.1.2.3 | PATCH | Ensure noexec option set on /tmp partition"
ansible.builtin.set_fact:
tmp_partition_mount_options: "{{ tmp_partition_mount_options + [ 'noexec' ] }}"
notify: Writing and remounting tmp
when: ubtu22cis_rule_1_1_2_3
tags:
- level1-server
- level1-workstation
- automated
- patch
- rule_1.1.2.2
- rule_1.1.2.2
- rule_1.1.2.3
- tmp

- name: "1.1.2.4 | PATCH | Ensure nosuid option set on /tmp partition"
ansible.builtin.set_fact:
tmp_partition_mount_options: "{{ tmp_partition_mount_options + [ 'nosuid' ] }}"
notify: Writing and remounting tmp
when: ubtu22cis_rule_1_1_2_4
tags:
- level1-server
- level1-workstation
- automated
- patch
- rule_1.1.2.4
- tmp
2 changes: 1 addition & 1 deletion templates/etc/systemd/system/tmp.mount.j2
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ After=swap.target
What=tmpfs
Where=/tmp
Type=tmpfs
Options: {% if ubtu22cis_rule_1_1_2_2 %}nodev,{% endif %}{% if ubtu22cis_rule_1_1_2_3 %}noexec,{% endif %}{% if ubtu22cis_rule_1_1_2_4 %}nosuid{% endif %}
Options: {{ tmp_partition_mount_options | unique | join(',') }}

[Install]
WantedBy=local-fs.target

0 comments on commit 05c2a5a

Please sign in to comment.