Blame SOURCES/scap-security-guide-0.1.55-update_nodev_nonroot_mount_option-PR_6606.patch

b5e178
From cbede36c7a4e35cb882c35892cff72f9f190cbf9 Mon Sep 17 00:00:00 2001
b5e178
From: Milan Lysonek <mlysonek@redhat.com>
b5e178
Date: Mon, 8 Feb 2021 15:57:43 +0100
b5e178
Subject: [PATCH 1/5] Add nodev,nosuid,noexec options to /boot in ANSSI
b5e178
 kickstart
b5e178
b5e178
---
b5e178
 rhel7/kickstart/ssg-rhel7-anssi_nt28_enhanced-ks.cfg     | 2 +-
b5e178
 rhel7/kickstart/ssg-rhel7-anssi_nt28_high-ks.cfg         | 2 +-
b5e178
 rhel7/kickstart/ssg-rhel7-anssi_nt28_intermediary-ks.cfg | 2 +-
b5e178
 rhel8/kickstart/ssg-rhel8-anssi_bp28_enhanced-ks.cfg     | 2 +-
b5e178
 rhel8/kickstart/ssg-rhel8-anssi_bp28_high-ks.cfg         | 2 +-
b5e178
 rhel8/kickstart/ssg-rhel8-anssi_bp28_intermediary-ks.cfg | 2 +-
b5e178
 6 files changed, 6 insertions(+), 6 deletions(-)
b5e178
b5e178
diff --git a/rhel7/kickstart/ssg-rhel7-anssi_nt28_enhanced-ks.cfg b/rhel7/kickstart/ssg-rhel7-anssi_nt28_enhanced-ks.cfg
b5e178
index 1d35bedb91..c381512476 100644
b5e178
--- a/rhel7/kickstart/ssg-rhel7-anssi_nt28_enhanced-ks.cfg
b5e178
+++ b/rhel7/kickstart/ssg-rhel7-anssi_nt28_enhanced-ks.cfg
b5e178
@@ -99,7 +99,7 @@ zerombr
b5e178
 clearpart --linux --initlabel
b5e178
 
b5e178
 # Create primary system partitions (required for installs)
b5e178
-part /boot --fstype=xfs --size=512
b5e178
+part /boot --fstype=xfs --size=512 --fsoptions="nodev,nosuid,noexec"
b5e178
 part pv.01 --grow --size=1
b5e178
 
b5e178
 # Create a Logical Volume Management (LVM) group (optional)
b5e178
diff --git a/rhel7/kickstart/ssg-rhel7-anssi_nt28_high-ks.cfg b/rhel7/kickstart/ssg-rhel7-anssi_nt28_high-ks.cfg
b5e178
index 73225c2fab..a672b38b83 100644
b5e178
--- a/rhel7/kickstart/ssg-rhel7-anssi_nt28_high-ks.cfg
b5e178
+++ b/rhel7/kickstart/ssg-rhel7-anssi_nt28_high-ks.cfg
b5e178
@@ -103,7 +103,7 @@ zerombr
b5e178
 clearpart --linux --initlabel
b5e178
 
b5e178
 # Create primary system partitions (required for installs)
b5e178
-part /boot --fstype=xfs --size=512
b5e178
+part /boot --fstype=xfs --size=512 --fsoptions="nodev,nosuid,noexec"
b5e178
 part pv.01 --grow --size=1
b5e178
 
b5e178
 # Create a Logical Volume Management (LVM) group (optional)
b5e178
diff --git a/rhel7/kickstart/ssg-rhel7-anssi_nt28_intermediary-ks.cfg b/rhel7/kickstart/ssg-rhel7-anssi_nt28_intermediary-ks.cfg
b5e178
index 20c4c59a78..88a7cee8ab 100644
b5e178
--- a/rhel7/kickstart/ssg-rhel7-anssi_nt28_intermediary-ks.cfg
b5e178
+++ b/rhel7/kickstart/ssg-rhel7-anssi_nt28_intermediary-ks.cfg
b5e178
@@ -99,7 +99,7 @@ zerombr
b5e178
 clearpart --linux --initlabel
b5e178
 
b5e178
 # Create primary system partitions (required for installs)
b5e178
-part /boot --fstype=xfs --size=512
b5e178
+part /boot --fstype=xfs --size=512 --fsoptions="nodev,nosuid,noexec"
b5e178
 part pv.01 --grow --size=1
b5e178
 
b5e178
 # Create a Logical Volume Management (LVM) group (optional)
b5e178
diff --git a/rhel8/kickstart/ssg-rhel8-anssi_bp28_enhanced-ks.cfg b/rhel8/kickstart/ssg-rhel8-anssi_bp28_enhanced-ks.cfg
b5e178
index 728946ecb7..6f66a3774b 100644
b5e178
--- a/rhel8/kickstart/ssg-rhel8-anssi_bp28_enhanced-ks.cfg
b5e178
+++ b/rhel8/kickstart/ssg-rhel8-anssi_bp28_enhanced-ks.cfg
b5e178
@@ -90,7 +90,7 @@ zerombr
b5e178
 clearpart --linux --initlabel
b5e178
 
b5e178
 # Create primary system partitions (required for installs)
b5e178
-part /boot --fstype=xfs --size=512
b5e178
+part /boot --fstype=xfs --size=512 --fsoptions="nodev,nosuid,noexec"
b5e178
 part pv.01 --grow --size=1
b5e178
 
b5e178
 # Create a Logical Volume Management (LVM) group (optional)
b5e178
diff --git a/rhel8/kickstart/ssg-rhel8-anssi_bp28_high-ks.cfg b/rhel8/kickstart/ssg-rhel8-anssi_bp28_high-ks.cfg
b5e178
index cd0eff2625..b5c09253a5 100644
b5e178
--- a/rhel8/kickstart/ssg-rhel8-anssi_bp28_high-ks.cfg
b5e178
+++ b/rhel8/kickstart/ssg-rhel8-anssi_bp28_high-ks.cfg
b5e178
@@ -94,7 +94,7 @@ zerombr
b5e178
 clearpart --linux --initlabel
b5e178
 
b5e178
 # Create primary system partitions (required for installs)
b5e178
-part /boot --fstype=xfs --size=512
b5e178
+part /boot --fstype=xfs --size=512 --fsoptions="nodev,nosuid,noexec"
b5e178
 part pv.01 --grow --size=1
b5e178
 
b5e178
 # Create a Logical Volume Management (LVM) group (optional)
b5e178
diff --git a/rhel8/kickstart/ssg-rhel8-anssi_bp28_intermediary-ks.cfg b/rhel8/kickstart/ssg-rhel8-anssi_bp28_intermediary-ks.cfg
b5e178
index 3a241b06f4..fb785e0c11 100644
b5e178
--- a/rhel8/kickstart/ssg-rhel8-anssi_bp28_intermediary-ks.cfg
b5e178
+++ b/rhel8/kickstart/ssg-rhel8-anssi_bp28_intermediary-ks.cfg
b5e178
@@ -90,7 +90,7 @@ zerombr
b5e178
 clearpart --linux --initlabel
b5e178
 
b5e178
 # Create primary system partitions (required for installs)
b5e178
-part /boot --fstype=xfs --size=512
b5e178
+part /boot --fstype=xfs --size=512 --fsoptions="nodev,nosuid,noexec"
b5e178
 part pv.01 --grow --size=1
b5e178
 
b5e178
 # Create a Logical Volume Management (LVM) group (optional)
b5e178
b5e178
From 15be64cc2d6c21b0351bb8d3d1b55b1924be99ca Mon Sep 17 00:00:00 2001
b5e178
From: Milan Lysonek <mlysonek@redhat.com>
b5e178
Date: Tue, 9 Feb 2021 12:45:34 +0100
b5e178
Subject: [PATCH 2/5] Add mount_option_nodev_nonroot_local_partitions bash
b5e178
 remediation
b5e178
b5e178
---
b5e178
 .../bash/shared.sh                             | 18 ++++++++++++++++++
b5e178
 1 file changed, 18 insertions(+)
b5e178
 create mode 100644 linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/bash/shared.sh
b5e178
b5e178
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
b5e178
new file mode 100644
b5e178
index 0000000000..7e2b3bd76b
b5e178
--- /dev/null
b5e178
+++ b/linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/bash/shared.sh
b5e178
@@ -0,0 +1,18 @@
b5e178
+# platform = multi_platform_all
b5e178
+. /usr/share/scap-security-guide/remediation_functions
b5e178
+
b5e178
+include_mount_options_functions
b5e178
+
b5e178
+MOUNT_OPTION="nodev"
b5e178
+# Create array of local non-root partitions
b5e178
+readarray -t partitions_records < <(findmnt --mtab --raw --evaluate | grep "^/\w" | grep "\s/dev/\w")
b5e178
+
b5e178
+for partition_record in "${partitions_records[@]}"; do
b5e178
+    # Get all important information for fstab
b5e178
+    mount_point="$(echo ${partition_record} | cut -d " " -f1)"
b5e178
+    device="$(echo ${partition_record} | cut -d " " -f2)"
b5e178
+    device_type="$(echo ${partition_record} | cut -d " " -f3)"
b5e178
+    # device and device_type will be used only in case when the device doesn't have fstab record
b5e178
+    ensure_mount_option_in_fstab "$mount_point" "$MOUNT_OPTION" "$device" "$device_type"
b5e178
+    ensure_partition_is_mounted "$mount_point"
b5e178
+done
b5e178
b5e178
From 36958b72896a69cb580f00a986673c8ae99cb011 Mon Sep 17 00:00:00 2001
b5e178
From: Milan Lysonek <mlysonek@redhat.com>
b5e178
Date: Tue, 9 Feb 2021 12:45:54 +0100
b5e178
Subject: [PATCH 3/5] Add mount_option_nodev_nonroot_local_partitions test
b5e178
 scenarios
b5e178
b5e178
---
b5e178
 .../tests/correct.pass.sh                     | 23 +++++++++++++++++
b5e178
 .../local_mounted_during_runtime.fail.sh      | 19 ++++++++++++++
b5e178
 .../tests/missing_multiple_nodev.fail.sh      | 23 +++++++++++++++++
b5e178
 .../tests/missing_one_nodev.fail.sh           | 23 +++++++++++++++++
b5e178
 .../tests/remote_without_nodev.pass.sh        | 25 +++++++++++++++++++
b5e178
 5 files changed, 113 insertions(+)
b5e178
 create mode 100644 linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/tests/correct.pass.sh
b5e178
 create mode 100644 linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/tests/local_mounted_during_runtime.fail.sh
b5e178
 create mode 100644 linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/tests/missing_multiple_nodev.fail.sh
b5e178
 create mode 100644 linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/tests/missing_one_nodev.fail.sh
b5e178
 create mode 100644 linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/tests/remote_without_nodev.pass.sh
b5e178
b5e178
diff --git a/linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/tests/correct.pass.sh b/linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/tests/correct.pass.sh
b5e178
new file mode 100644
b5e178
index 0000000000..8bfac4b80f
b5e178
--- /dev/null
b5e178
+++ b/linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/tests/correct.pass.sh
b5e178
@@ -0,0 +1,23 @@
b5e178
+#!/bin/bash
b5e178
+
b5e178
+. $SHARED/partition.sh
b5e178
+
b5e178
+# Add nodev option to all records in fstab to ensure that test will
b5e178
+# run on environment where everything is set correctly for rule check.
b5e178
+cp /etc/fstab /etc/fstab.backup
b5e178
+sed -e 's/\bnodev\b/,/g' -e 's/,,//g' -e 's/\s,\s/defaults/g' /etc/fstab.backup
b5e178
+awk '{$4 = $4",nodev"; print}' /etc/fstab.backup > /etc/fstab
b5e178
+# Remount all partitions. (--all option can't be used because it doesn't
b5e178
+# mount e.g. /boot partition
b5e178
+declare -a partitions=( $(awk '{print $2}' /etc/fstab | grep "^/\w") )
b5e178
+for partition in ${partitions[@]}; do
b5e178
+    mount -o remount "$partition"
b5e178
+done
b5e178
+
b5e178
+PARTITION="/dev/new_partition1"; create_partition
b5e178
+make_fstab_given_partition_line "/tmp/partition1" ext2 nodev
b5e178
+mount_partition "/tmp/partition1"
b5e178
+
b5e178
+PARTITION="/dev/new_partition2"; create_partition
b5e178
+make_fstab_given_partition_line "/tmp/partition2" ext2 nodev
b5e178
+mount_partition "/tmp/partition2"
b5e178
diff --git a/linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/tests/local_mounted_during_runtime.fail.sh b/linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/tests/local_mounted_during_runtime.fail.sh
b5e178
new file mode 100644
b5e178
index 0000000000..84cadd6f73
b5e178
--- /dev/null
b5e178
+++ b/linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/tests/local_mounted_during_runtime.fail.sh
b5e178
@@ -0,0 +1,19 @@
b5e178
+#!/bin/bash
b5e178
+
b5e178
+. $SHARED/partition.sh
b5e178
+
b5e178
+# Add nodev option to all records in fstab to ensure that test will
b5e178
+# run on environment where everything is set correctly for rule check.
b5e178
+cp /etc/fstab /etc/fstab.backup
b5e178
+sed -e 's/\bnodev\b/,/g' -e 's/,,//g' -e 's/\s,\s/defaults/g' /etc/fstab.backup
b5e178
+awk '{$4 = $4",nodev"; print}' /etc/fstab.backup > /etc/fstab
b5e178
+# Remount all partitions. (--all option can't be used because it doesn't
b5e178
+# mount e.g. /boot partition
b5e178
+declare -a partitions=( $(awk '{print $2}' /etc/fstab | grep "^/\w") )
b5e178
+for partition in ${partitions[@]}; do
b5e178
+    mount -o remount "$partition"
b5e178
+done
b5e178
+
b5e178
+PARTITION="/dev/new_partition1"; create_partition
b5e178
+mkdir /tmp/test_dir
b5e178
+mount $PARTITION /tmp/test_dir
b5e178
diff --git a/linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/tests/missing_multiple_nodev.fail.sh b/linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/tests/missing_multiple_nodev.fail.sh
b5e178
new file mode 100644
b5e178
index 0000000000..7a09093f46
b5e178
--- /dev/null
b5e178
+++ b/linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/tests/missing_multiple_nodev.fail.sh
b5e178
@@ -0,0 +1,23 @@
b5e178
+#!/bin/bash
b5e178
+
b5e178
+. $SHARED/partition.sh
b5e178
+
b5e178
+# Add nodev option to all records in fstab to ensure that test will
b5e178
+# run on environment where everything is set correctly for rule check.
b5e178
+cp /etc/fstab /etc/fstab.backup
b5e178
+sed -e 's/\bnodev\b/,/g' -e 's/,,//g' -e 's/\s,\s/defaults/g' /etc/fstab.backup
b5e178
+awk '{$4 = $4",nodev"; print}' /etc/fstab.backup > /etc/fstab
b5e178
+# Remount all partitions. (--all option can't be used because it doesn't
b5e178
+# mount e.g. /boot partition
b5e178
+declare -a partitions=( $(awk '{print $2}' /etc/fstab | grep "^/\w") )
b5e178
+for partition in ${partitions[@]}; do
b5e178
+    mount -o remount "$partition"
b5e178
+done
b5e178
+
b5e178
+PARTITION="/dev/new_partition1"; create_partition
b5e178
+make_fstab_given_partition_line "/tmp/partition1" ext2
b5e178
+mount_partition "/tmp/partition1"
b5e178
+
b5e178
+PARTITION="/dev/new_partition2"; create_partition
b5e178
+make_fstab_given_partition_line "/tmp/partition2" ext2
b5e178
+mount_partition "/tmp/partition2"
b5e178
diff --git a/linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/tests/missing_one_nodev.fail.sh b/linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/tests/missing_one_nodev.fail.sh
b5e178
new file mode 100644
b5e178
index 0000000000..c20a98bdcc
b5e178
--- /dev/null
b5e178
+++ b/linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/tests/missing_one_nodev.fail.sh
b5e178
@@ -0,0 +1,23 @@
b5e178
+#!/bin/bash
b5e178
+
b5e178
+. $SHARED/partition.sh
b5e178
+
b5e178
+# Add nodev option to all records in fstab to ensure that test will
b5e178
+# run on environment where everything is set correctly for rule check.
b5e178
+cp /etc/fstab /etc/fstab.backup
b5e178
+sed -e 's/\bnodev\b/,/g' -e 's/,,//g' -e 's/\s,\s/defaults/g' /etc/fstab.backup
b5e178
+awk '{$4 = $4",nodev"; print}' /etc/fstab.backup > /etc/fstab
b5e178
+# Remount all partitions. (--all option can't be used because it doesn't
b5e178
+# mount e.g. /boot partition
b5e178
+declare -a partitions=( $(awk '{print $2}' /etc/fstab | grep "^/\w") )
b5e178
+for partition in ${partitions[@]}; do
b5e178
+    mount -o remount "$partition"
b5e178
+done
b5e178
+
b5e178
+PARTITION="/dev/new_partition1"; create_partition
b5e178
+make_fstab_given_partition_line "/tmp/partition1" ext2 nodev
b5e178
+mount_partition "/tmp/partition1"
b5e178
+
b5e178
+PARTITION="/dev/new_partition2"; create_partition
b5e178
+make_fstab_given_partition_line "/tmp/partition2" ext2
b5e178
+mount_partition "/tmp/partition2"
b5e178
diff --git a/linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/tests/remote_without_nodev.pass.sh b/linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/tests/remote_without_nodev.pass.sh
b5e178
new file mode 100644
b5e178
index 0000000000..a95410526f
b5e178
--- /dev/null
b5e178
+++ b/linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/tests/remote_without_nodev.pass.sh
b5e178
@@ -0,0 +1,25 @@
b5e178
+#!/bin/bash
b5e178
+# packages = nfs-utils
b5e178
+
b5e178
+. $SHARED/partition.sh
b5e178
+
b5e178
+# Add nodev option to all records in fstab to ensure that test will
b5e178
+# run on environment where everything is set correctly for rule check.
b5e178
+cp /etc/fstab /etc/fstab.backup
b5e178
+sed -e 's/\bnodev\b/,/g' -e 's/,,//g' -e 's/\s,\s/defaults/g' /etc/fstab.backup
b5e178
+awk '{$4 = $4",nodev"; print}' /etc/fstab.backup > /etc/fstab
b5e178
+# Remount all partitions. (--all option can't be used because it doesn't
b5e178
+# mount e.g. /boot partition
b5e178
+declare -a partitions=( $(awk '{print $2}' /etc/fstab | grep "^/\w") )
b5e178
+for partition in ${partitions[@]}; do
b5e178
+    mount -o remount "$partition"
b5e178
+done
b5e178
+
b5e178
+mkdir /tmp/testdir
b5e178
+mkdir /tmp/testmount
b5e178
+chown 2 /tmp/testdir
b5e178
+chmod 777 /tmp/testdir
b5e178
+
b5e178
+echo '/tmp/testdir localhost(rw)' > /etc/exports
b5e178
+systemctl restart nfs-server
b5e178
+mount.nfs localhost:/tmp/testdir /tmp/testmount
b5e178
b5e178
From b7bec83d7a3ad186413777f70fe2b5d20e01e56b Mon Sep 17 00:00:00 2001
b5e178
From: Watson Sato <wsato@redhat.com>
b5e178
Date: Wed, 10 Feb 2021 18:32:26 +0100
b5e178
Subject: [PATCH 4/5] Add Ansible for
b5e178
 mount_option_nodev_nonroot_local_partitions
b5e178
b5e178
The remediation metadata were inspired by the template mount_options
b5e178
---
b5e178
 .../ansible/shared.yml                         | 18 ++++++++++++++++++
b5e178
 1 file changed, 18 insertions(+)
b5e178
 create mode 100644 linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/ansible/shared.yml
b5e178
b5e178
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
b5e178
new file mode 100644
b5e178
index 0000000000..8530604308
b5e178
--- /dev/null
b5e178
+++ b/linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/ansible/shared.yml
b5e178
@@ -0,0 +1,18 @@
b5e178
+# platform = multi_platform_all
b5e178
+# reboot = false
b5e178
+# strategy = configure
b5e178
+# complexity = low
b5e178
+# disruption = high
b5e178
+
b5e178
+- name: Ensure non-root local partitions are mounted with nodev option
b5e178
+  mount:
b5e178
+    path: "{{ item.mount }}"
b5e178
+    src: "{{ item.device}}"
b5e178
+    opts: "{{ item.options }},nodev"
b5e178
+    state: "mounted"
b5e178
+    fstype: "{{ item.fstype }}"
b5e178
+  when:
b5e178
+    - "item.mount is match('/\\w')"
b5e178
+    - "item.options is not search('nodev')"
b5e178
+  with_items:
b5e178
+    - "{{ ansible_facts.mounts }}"
b5e178
b5e178
From dab22894ca0798dde27c77704a7fd34d62d77f8f Mon Sep 17 00:00:00 2001
b5e178
From: Watson Sato <wsato@redhat.com>
b5e178
Date: Wed, 10 Feb 2021 20:29:32 +0100
b5e178
Subject: [PATCH 5/5] Add space before and after variable
b5e178
b5e178
---
b5e178
 .../ansible/shared.yml                                          | 2 +-
b5e178
 1 file changed, 1 insertion(+), 1 deletion(-)
b5e178
b5e178
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
b5e178
index 8530604308..2aa9a53e4d 100644
b5e178
--- a/linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/ansible/shared.yml
b5e178
+++ b/linux_os/guide/system/permissions/partitions/mount_option_nodev_nonroot_local_partitions/ansible/shared.yml
b5e178
@@ -7,7 +7,7 @@
b5e178
 - name: Ensure non-root local partitions are mounted with nodev option
b5e178
   mount:
b5e178
     path: "{{ item.mount }}"
b5e178
-    src: "{{ item.device}}"
b5e178
+    src: "{{ item.device }}"
b5e178
     opts: "{{ item.options }},nodev"
b5e178
     state: "mounted"
b5e178
     fstype: "{{ item.fstype }}"