Blame SOURCES/scap-security-guide-0.1.61-update_RHEL_08_010383-PR_8138.patch

ff1465
From 133d331a04e1ba27324291006c65c2bfa467e49d Mon Sep 17 00:00:00 2001
ff1465
From: Gabriel Becker <ggasparb@redhat.com>
ff1465
Date: Tue, 1 Feb 2022 16:54:16 +0100
ff1465
Subject: [PATCH 1/2] Update RHEL-08-010383 to require only one occurrence of a
ff1465
 config.
ff1465
ff1465
The V1R5 release of RHEL8 STIG requires that the configuration should be
ff1465
present only in one configuration file to prevent any ordering problem
ff1465
when the modules loads the configuration using drop-in files that use
ff1465
the lexicographically order of file names.
ff1465
---
ff1465
 .../sudo/sudoers_validate_passwd/ansible/shared.yml  |  6 +++---
ff1465
 .../sudo/sudoers_validate_passwd/oval/shared.xml     | 12 ++++++------
ff1465
 .../software/sudo/sudoers_validate_passwd/rule.yml   |  3 ++-
ff1465
 .../tests/sudoers_validate_passwd_duplicates.fail.sh |  7 +++++++
ff1465
 4 files changed, 18 insertions(+), 10 deletions(-)
ff1465
 create mode 100644 linux_os/guide/system/software/sudo/sudoers_validate_passwd/tests/sudoers_validate_passwd_duplicates.fail.sh
ff1465
ff1465
diff --git a/linux_os/guide/system/software/sudo/sudoers_validate_passwd/ansible/shared.yml b/linux_os/guide/system/software/sudo/sudoers_validate_passwd/ansible/shared.yml
ff1465
index 08ffd76aed6..19673634fb3 100644
ff1465
--- a/linux_os/guide/system/software/sudo/sudoers_validate_passwd/ansible/shared.yml
ff1465
+++ b/linux_os/guide/system/software/sudo/sudoers_validate_passwd/ansible/shared.yml
ff1465
@@ -4,6 +4,6 @@
ff1465
 # complexity = low
ff1465
 # disruption = low
ff1465
 
ff1465
-{{{ ansible_lineinfile(msg='Ensure that Defaults !targetpw is defined in sudoers', path='/etc/sudoers', new_line='Defaults !targetpw', create='yes', state='present') }}}
ff1465
-{{{ ansible_lineinfile(msg='Ensure that Defaults !rootpw is defined in sudoers', path='/etc/sudoers', new_line='Defaults !rootpw', create='yes', state='present') }}}
ff1465
-{{{ ansible_lineinfile(msg='Ensure that Defaults !runaspw is defined in sudoers', path='/etc/sudoers', new_line='Defaults !runaspw', create='yes', state='present') }}}
ff1465
+{{{ ansible_only_lineinfile(msg='Ensure that Defaults !targetpw is defined in sudoers', line_regex='^Defaults !targetpw$', path='/etc/sudoers', new_line='Defaults !targetpw') }}}
ff1465
+{{{ ansible_only_lineinfile(msg='Ensure that Defaults !rootpw is defined in sudoers', line_regex='^Defaults !rootpw$', path='/etc/sudoers', new_line='Defaults !rootpw') }}}
ff1465
+{{{ ansible_only_lineinfile(msg='Ensure that Defaults !runaspw is defined in sudoers', line_regex='^Defaults !runaspw$', path='/etc/sudoers', new_line='Defaults !runaspw') }}}
ff1465
diff --git a/linux_os/guide/system/software/sudo/sudoers_validate_passwd/oval/shared.xml b/linux_os/guide/system/software/sudo/sudoers_validate_passwd/oval/shared.xml
ff1465
index 646e6bfb7c0..b3fadd53bee 100644
ff1465
--- a/linux_os/guide/system/software/sudo/sudoers_validate_passwd/oval/shared.xml
ff1465
+++ b/linux_os/guide/system/software/sudo/sudoers_validate_passwd/oval/shared.xml
ff1465
@@ -8,17 +8,17 @@
ff1465
       </criteria>
ff1465
   </definition>
ff1465
 
ff1465
-  
ff1465
+  
ff1465
   id="test_sudoers_targetpw_config" version="1">
ff1465
     <ind:object object_ref="object_test_sudoers_targetpw_config" />
ff1465
   </ind:textfilecontent54_test>
ff1465
 
ff1465
-  
ff1465
+  
ff1465
   id="test_sudoers_rootpw_config" version="1">
ff1465
     <ind:object object_ref="object_test_sudoers_rootpw_config" />
ff1465
   </ind:textfilecontent54_test>
ff1465
 
ff1465
-  
ff1465
+  
ff1465
   id="test_sudoers_runaspw_config" version="1">
ff1465
     <ind:object object_ref="object_test_sudoers_runaspw_config" />
ff1465
   </ind:textfilecontent54_test>
ff1465
@@ -26,19 +26,19 @@
ff1465
   <ind:textfilecontent54_object id="object_test_sudoers_targetpw_config" version="1">
ff1465
     <ind:filepath operation="pattern match">^/etc/sudoers(\.d/.*)?$</ind:filepath>
ff1465
     <ind:pattern operation="pattern match">^Defaults !targetpw$\r?\n</ind:pattern>
ff1465
-    <ind:instance datatype="int">1</ind:instance>
ff1465
+    <ind:instance operation="greater than or equal" datatype="int">1</ind:instance>
ff1465
   </ind:textfilecontent54_object>
ff1465
 
ff1465
   <ind:textfilecontent54_object id="object_test_sudoers_rootpw_config" version="1">
ff1465
     <ind:filepath operation="pattern match">^/etc/sudoers(\.d/.*)?$</ind:filepath>
ff1465
     <ind:pattern operation="pattern match">^Defaults !rootpw$\r?\n</ind:pattern>
ff1465
-    <ind:instance datatype="int">1</ind:instance>
ff1465
+    <ind:instance operation="greater than or equal" datatype="int">1</ind:instance>
ff1465
   </ind:textfilecontent54_object>
ff1465
 
ff1465
   <ind:textfilecontent54_object id="object_test_sudoers_runaspw_config" version="1">
ff1465
     <ind:filepath operation="pattern match">^/etc/sudoers(\.d/.*)?$</ind:filepath>
ff1465
     <ind:pattern operation="pattern match">^Defaults !runaspw$\r?\n</ind:pattern>
ff1465
-    <ind:instance datatype="int">1</ind:instance>
ff1465
+    <ind:instance operation="greater than or equal" datatype="int">1</ind:instance>
ff1465
   </ind:textfilecontent54_object>
ff1465
 
ff1465
 </def-group>
ff1465
diff --git a/linux_os/guide/system/software/sudo/sudoers_validate_passwd/rule.yml b/linux_os/guide/system/software/sudo/sudoers_validate_passwd/rule.yml
ff1465
index ccc29b77d15..698021d8fd0 100644
ff1465
--- a/linux_os/guide/system/software/sudo/sudoers_validate_passwd/rule.yml
ff1465
+++ b/linux_os/guide/system/software/sudo/sudoers_validate_passwd/rule.yml
ff1465
@@ -42,7 +42,8 @@ ocil_clause: 'invoke user passwd when using sudo'
ff1465
 ocil: |-
ff1465
     Run the following command to Verify that the sudoers security policy is configured to use the invoking user's password for privilege escalation:
ff1465
     
 sudo egrep -i '(!rootpw|!targetpw|!runaspw)' /etc/sudoers /etc/sudoers.d/* | grep -v '#'
ff1465
-    If no results are returned, this is a finding
ff1465
+    If no results are returned, this is a finding.
ff1465
+    If results are returned from more than one file location, this is a finding.
ff1465
     If "Defaults !targetpw" is not defined, this is a finding.
ff1465
     If "Defaults !rootpw" is not defined, this is a finding.
ff1465
     If "Defaults !runaspw" is not defined, this is a finding.
ff1465
diff --git a/linux_os/guide/system/software/sudo/sudoers_validate_passwd/tests/sudoers_validate_passwd_duplicates.fail.sh b/linux_os/guide/system/software/sudo/sudoers_validate_passwd/tests/sudoers_validate_passwd_duplicates.fail.sh
ff1465
new file mode 100644
ff1465
index 00000000000..6247b5230e4
ff1465
--- /dev/null
ff1465
+++ b/linux_os/guide/system/software/sudo/sudoers_validate_passwd/tests/sudoers_validate_passwd_duplicates.fail.sh
ff1465
@@ -0,0 +1,7 @@
ff1465
+# platform = multi_platform_fedora,multi_platform_ol,multi_platform_rhel,SUSE Linux Enterprise 15
ff1465
+# packages = sudo
ff1465
+
ff1465
+echo 'Defaults !targetpw' >> /etc/sudoers
ff1465
+echo 'Defaults !rootpw' >> /etc/sudoers
ff1465
+echo 'Defaults !runaspw' >> /etc/sudoers
ff1465
+echo 'Defaults !runaspw' >> /etc/sudoers
ff1465
ff1465
From 315b248c77252fc3145cdf34fede98b1a32a7c04 Mon Sep 17 00:00:00 2001
ff1465
From: Gabriel Becker <ggasparb@redhat.com>
ff1465
Date: Wed, 9 Feb 2022 15:24:23 +0100
ff1465
Subject: [PATCH 2/2] Update remediations of sudoers_validate_passwd to remove
ff1465
 duplicates.
ff1465
ff1465
---
ff1465
 .../ansible/shared.yml                        | 20 +++++++++++++++++++
ff1465
 .../sudoers_validate_passwd/bash/shared.sh    | 12 +++++++++++
ff1465
 .../tests/sudoers_d_duplicate.fail.sh         |  9 +++++++++
ff1465
 3 files changed, 41 insertions(+)
ff1465
 create mode 100644 linux_os/guide/system/software/sudo/sudoers_validate_passwd/tests/sudoers_d_duplicate.fail.sh
ff1465
ff1465
diff --git a/linux_os/guide/system/software/sudo/sudoers_validate_passwd/ansible/shared.yml b/linux_os/guide/system/software/sudo/sudoers_validate_passwd/ansible/shared.yml
ff1465
index 19673634fb3..399ca1ea3ce 100644
ff1465
--- a/linux_os/guide/system/software/sudo/sudoers_validate_passwd/ansible/shared.yml
ff1465
+++ b/linux_os/guide/system/software/sudo/sudoers_validate_passwd/ansible/shared.yml
ff1465
@@ -4,6 +4,26 @@
ff1465
 # complexity = low
ff1465
 # disruption = low
ff1465
 
ff1465
+{{%- macro delete_line_in_sudoers_d(line) %}}
ff1465
+- name: "Find out if /etc/sudoers.d/* files contain {{{ line }}} to be deduplicated"
ff1465
+  find:
ff1465
+    path: "/etc/sudoers.d"
ff1465
+    patterns: "*"
ff1465
+    contains: '^{{{ line }}}$'
ff1465
+  register: sudoers_d_defaults
ff1465
+
ff1465
+- name: "Remove found occurrences of {{{ line }}} from /etc/sudoers.d/* files"
ff1465
+  lineinfile:
ff1465
+    path: "{{ item.path }}"
ff1465
+    regexp: "^{{{ line }}}$"
ff1465
+    state: absent
ff1465
+  with_items: "{{ sudoers_d_defaults.files }}"
ff1465
+{{%- endmacro %}}
ff1465
+
ff1465
+{{{- delete_line_in_sudoers_d("Defaults !targetpw") }}}
ff1465
+{{{- delete_line_in_sudoers_d("Defaults !rootpw") }}}
ff1465
+{{{- delete_line_in_sudoers_d("Defaults !runaspw") }}}
ff1465
+
ff1465
 {{{ ansible_only_lineinfile(msg='Ensure that Defaults !targetpw is defined in sudoers', line_regex='^Defaults !targetpw$', path='/etc/sudoers', new_line='Defaults !targetpw') }}}
ff1465
 {{{ ansible_only_lineinfile(msg='Ensure that Defaults !rootpw is defined in sudoers', line_regex='^Defaults !rootpw$', path='/etc/sudoers', new_line='Defaults !rootpw') }}}
ff1465
 {{{ ansible_only_lineinfile(msg='Ensure that Defaults !runaspw is defined in sudoers', line_regex='^Defaults !runaspw$', path='/etc/sudoers', new_line='Defaults !runaspw') }}}
ff1465
diff --git a/linux_os/guide/system/software/sudo/sudoers_validate_passwd/bash/shared.sh b/linux_os/guide/system/software/sudo/sudoers_validate_passwd/bash/shared.sh
ff1465
index ea0ac67fa1c..3b327f3fc88 100644
ff1465
--- a/linux_os/guide/system/software/sudo/sudoers_validate_passwd/bash/shared.sh
ff1465
+++ b/linux_os/guide/system/software/sudo/sudoers_validate_passwd/bash/shared.sh
ff1465
@@ -1,5 +1,17 @@
ff1465
 # platform = multi_platform_all
ff1465
 
ff1465
+{{%- macro delete_line_in_sudoers_d(line) %}}
ff1465
+if grep -x '^{{{line}}}$' /etc/sudoers.d/*; then
ff1465
+    find /etc/sudoers.d/ -type f -exec sed -i "/{{{line}}}/d" {} \;
ff1465
+fi
ff1465
+{{%- endmacro %}}
ff1465
+
ff1465
+{{{- delete_line_in_sudoers_d("Defaults !targetpw") }}}
ff1465
+{{{- delete_line_in_sudoers_d("Defaults !rootpw") }}}
ff1465
+{{{- delete_line_in_sudoers_d("Defaults !runaspw") }}}
ff1465
+
ff1465
 {{{ set_config_file(path="/etc/sudoers", parameter="Defaults !targetpw", value="", create=true, insensitive=false, separator="", separator_regex="", prefix_regex="") }}}
ff1465
 {{{ set_config_file(path="/etc/sudoers", parameter="Defaults !rootpw", value="", create=true, insensitive=false, separator="", separator_regex="", prefix_regex="") }}}
ff1465
 {{{ set_config_file(path="/etc/sudoers", parameter="Defaults !runaspw", value="", create=true, insensitive=false, separator="", separator_regex="", prefix_regex="") }}}
ff1465
+
ff1465
+
ff1465
diff --git a/linux_os/guide/system/software/sudo/sudoers_validate_passwd/tests/sudoers_d_duplicate.fail.sh b/linux_os/guide/system/software/sudo/sudoers_validate_passwd/tests/sudoers_d_duplicate.fail.sh
ff1465
new file mode 100644
ff1465
index 00000000000..a258d108a00
ff1465
--- /dev/null
ff1465
+++ b/linux_os/guide/system/software/sudo/sudoers_validate_passwd/tests/sudoers_d_duplicate.fail.sh
ff1465
@@ -0,0 +1,9 @@
ff1465
+# platform = multi_platform_fedora,multi_platform_ol,multi_platform_rhel,SUSE Linux Enterprise 15
ff1465
+# packages = sudo
ff1465
+
ff1465
+echo 'Defaults !targetpw' >> /etc/sudoers
ff1465
+echo 'Defaults !rootpw' >> /etc/sudoers
ff1465
+echo 'Defaults !runaspw' >> /etc/sudoers
ff1465
+echo 'Defaults !targetpw' >> /etc/sudoers.d/00-complianceascode.conf
ff1465
+echo 'Defaults !rootpw' >> /etc/sudoers.d/00-complianceascode.conf
ff1465
+echo 'Defaults !runaspw' >> /etc/sudoers.d/00-complianceascode.conf