- name: Gather the package facts
package_facts:
manager: auto
tags:
- DISA-STIG-OL08-00-010570
- NIST-800-53-AC-6 - NIST-800-53-AC-6(1)
- NIST-800-53-CM-6(a)
- NIST-800-53-CM-7(a)
- NIST-800-53-CM-7(b)
- NIST-800-53-MP-7
- configure_strategy
- high_disruption
- low_complexity
- medium_severity
- mount_option_home_nosuid
- no_reboot_needed
- name: Add nosuid Option to /home - Initialize variables
ansible.builtin.set_fact:
non_allowed_partitions:
- /
- /lib
- /opt
- /usr
- /bin
- /sbin
- /boot
- /dev
- /proc
home_directories: []
allowed_mount_point: []
fstab_mount_point_info: []
when: ( not ( "kernel" in ansible_facts.packages and "rpm-ostree" in ansible_facts.packages
and "bootc" in ansible_facts.packages ) and not ( ansible_virtualization_type
in ["docker", "lxc", "openvz", "podman", "container"] ) )
tags:
- DISA-STIG-OL08-00-010570
- NIST-800-53-AC-6
- NIST-800-53-AC-6(1)
- NIST-800-53-CM-6(a)
- NIST-800-53-CM-7(a)
- NIST-800-53-CM-7(b)
- NIST-800-53-MP-7
- configure_strategy
- high_disruption
- low_complexity
- medium_severity
- mount_option_home_nosuid
- no_reboot_needed
- name: Add nosuid Option to /home - Get home directories from passwd
ansible.builtin.getent:
database: passwd
when: ( not ( "kernel" in ansible_facts.packages and "rpm-ostree" in ansible_facts.packages
and "bootc" in ansible_facts.packages ) and not ( ansible_virtualization_type
in ["docker", "lxc", "openvz", "podman", "container"] ) )
tags:
- DISA-STIG-OL08-00-010570
- NIST-800-53-AC-6
- NIST-800-53-AC-6(1)
- NIST-800-53-CM-6(a)
- NIST-800-53-CM-7(a)
- NIST-800-53-CM-7(b)
- NIST-800-53-MP-7
- configure_strategy
- high_disruption
- low_complexity
- medium_severity
- mount_option_home_nosuid
- no_reboot_needed
- name: Add nosuid Option to /home - Filter home directories based on UID range
ansible.builtin.set_fact:
home_directories: '{{ home_directories + [item.data[4]] }}'
when:
- ( not ( "kernel" in ansible_facts.packages and "rpm-ostree" in ansible_facts.packages
and "bootc" in ansible_facts.packages ) and not ( ansible_virtualization_type
in ["docker", "lxc", "openvz", "podman", "container"] ) )
- item.data[4] is defined
- item.data[2]|int >= 1000
- item.data[2]|int != 65534
- item.data[4] not in non_allowed_partitions
with_items: '{{ ansible_facts.getent_passwd | dict2items(key_name=''user'', value_name=''data'')}}'
tags:
- DISA-STIG-OL08-00-010570
- NIST-800-53-AC-6
- NIST-800-53-AC-6(1)
- NIST-800-53-CM-6(a)
- NIST-800-53-CM-7(a)
- NIST-800-53-CM-7(b)
- NIST-800-53-MP-7
- configure_strategy
- high_disruption
- low_complexity
- medium_severity
- mount_option_home_nosuid
- no_reboot_needed
- name: Add nosuid Option to /home - Gather mount points
ansible.builtin.setup:
filter: ansible_mounts
when: ( not ( "kernel" in ansible_facts.packages and "rpm-ostree" in ansible_facts.packages
and "bootc" in ansible_facts.packages ) and not ( ansible_virtualization_type
in ["docker", "lxc", "openvz", "podman", "container"] ) )
tags:
- DISA-STIG-OL08-00-010570
- NIST-800-53-AC-6
- NIST-800-53-AC-6(1)
- NIST-800-53-CM-6(a)
- NIST-800-53-CM-7(a)
- NIST-800-53-CM-7(b)
- NIST-800-53-MP-7
- configure_strategy
- high_disruption
- low_complexity
- medium_severity
- mount_option_home_nosuid
- no_reboot_needed
- name: Add nosuid Option to /home - Ensure mount options for home directories
block:
- name: ' Add nosuid Option to /home - Obtain mount point using df and shell'
ansible.builtin.shell: |
df {{ item }} | awk '/^\/dev/ {print $6}'
register: df_output
with_items: '{{ home_directories }}'
- name: Add nosuid Option to /home - Set mount point for each home directory
ansible.builtin.set_fact:
allowed_mount_point: '{{ allowed_mount_point + [item.stdout_lines[0]] }}'
with_items: '{{ df_output.results }}'
when:
- item.stdout_lines is defined
- item.stdout_lines | length > 0
- item.stdout_lines[0] != ""
- name: Add nosuid Option to /home - Obtain full mount information for allowed mount
point
ansible.builtin.set_fact:
fstab_mount_point_info: '{{ fstab_mount_point_info + [ ansible_mounts | selectattr(''mount'',
''equalto'', item) | first ]}}'
with_items: '{{ allowed_mount_point }}'
when: allowed_mount_point is defined
- name: Add nosuid Option to /home - Ensure mount option nosuid is in fstab for
allowed mount point
ansible.builtin.mount:
path: '{{ item.mount }}'
src: '{{ item.device }}'
opts: '{{ item.options }},nosuid'
state: mounted
fstype: '{{ item.fstype }}'
with_items: '{{ fstab_mount_point_info }}'
when:
- allowed_mount_point is defined
- item.mount not in non_allowed_partitions
- '''nosuid'' not in item.options'
when: ( not ( "kernel" in ansible_facts.packages and "rpm-ostree" in ansible_facts.packages
and "bootc" in ansible_facts.packages ) and not ( ansible_virtualization_type
in ["docker", "lxc", "openvz", "podman", "container"] ) )
tags:
- DISA-STIG-OL08-00-010570
- NIST-800-53-AC-6
- NIST-800-53-AC-6(1)
- NIST-800-53-CM-6(a)
- NIST-800-53-CM-7(a)
- NIST-800-53-CM-7(b)
- NIST-800-53-MP-7
- configure_strategy
- high_disruption
- low_complexity
- medium_severity
- mount_option_home_nosuid
- no_reboot_needed