diff --git a/linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/ansible/shared.yml b/linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/ansible/shared.yml index f2d8077b6027..0666adcc2c63 100644 --- a/linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/ansible/shared.yml +++ b/linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/ansible/shared.yml @@ -8,7 +8,7 @@ setup: gather_subset: mounts -- name: Ensure non-root local partitions are mounted with nodev option +- name: "{{{ rule_title }}}: Ensure non-root local partitions are mounted with nodev option" mount: path: "{{ item.mount }}" src: "{{ item.device }}" @@ -20,3 +20,9 @@ - "item.options is not search('nodev')" with_items: - "{{ ansible_facts.mounts }}" + +- name: "{{{ rule_title }}}: Ensure non-root local partitions are present with nodev option in /etc/fstab" + ansible.builtin.replace: + path: /etc/fstab + regexp: '^\s*(?!#)(/dev/\S+|UUID=\S+)\s+(/\w\S*)\s+(\S+)\s+(?!nodev)(\S+)(.*)$' + replace: '\1 \2 \3 \4,nodev \5' diff --git a/linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/bash/shared.sh b/linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/bash/shared.sh index 2d877170be9b..73c4974a2d97 100644 --- a/linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/bash/shared.sh +++ b/linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/bash/shared.sh @@ -23,3 +23,6 @@ for partition_record in "${partitions_records[@]}"; do {{{ bash_ensure_partition_is_mounted("$mount_point") | indent(8)}}} fi done + +# Remediate unmounted /etc/fstab entries +sed -i -E '/nodev/! s;^\s*(/dev/\S+|UUID=\S+)\s+(/\w\S*)\s+(\S+)\s+(\S+)(.*)$;\1 \2 \3 \4,nodev \5;' /etc/fstab diff --git a/linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/oval/shared.xml b/linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/oval/shared.xml index 24432b7adc6c..84d84120b3b0 100644 --- a/linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/oval/shared.xml +++ b/linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/oval/shared.xml @@ -6,9 +6,11 @@ should exist in the /dev directory on the root partition or within chroot jails built for system services. All other locations should not allow character and block devices.") }}} - + + - - ^/\w.*$ + + ^/(?!boot|efi)\w.*$ state_local_nodev @@ -28,4 +30,21 @@ nodev + + + + + + + /etc/fstab + ^\s*(?!#)(?:/dev/\S+|UUID=\S+)\s+/\w\S*\s+\S+\s+(\S+) + 1 + + + 1 + nodev + diff --git a/linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/tests/complex.fail.sh b/linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/tests/complex.fail.sh new file mode 100644 index 000000000000..825436aa2c13 --- /dev/null +++ b/linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/tests/complex.fail.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +cat >/etc/fstab < /etc/fstab +# Remount all partitions. (--all option can't be used because it doesn't +# mount e.g. /boot partition +declare -a partitions=( $(awk '{print $2}' /etc/fstab | grep "^/\w") ) +for partition in ${partitions[@]}; do + mount -o remount "$partition" +done + +# partition intentionally not mounted to test /etc/fstab detection +PARTITION="/dev/new_partition1"; create_partition +make_fstab_given_partition_line "/tmp/partition1" ext2 defaults + +# partition intentionally not mounted to test /etc/fstab detection +PARTITION="/dev/new_partition2"; create_partition +make_fstab_given_partition_line "/tmp/partition2" ext2 defaults