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

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