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

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
5fd106
index 08ffd76aed6..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
5fd106
@@ -4,6 +4,26 @@
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') }}}
5fd106
+{{%- macro delete_line_in_sudoers_d(line) %}}
5fd106
+- name: "Find out if /etc/sudoers.d/* files contain {{{ line }}} to be deduplicated"
5fd106
+  find:
5fd106
+    path: "/etc/sudoers.d"
5fd106
+    patterns: "*"
5fd106
+    contains: '^{{{ line }}}$'
5fd106
+  register: sudoers_d_defaults
5fd106
+
5fd106
+- name: "Remove found occurrences of {{{ line }}} from /etc/sudoers.d/* files"
5fd106
+  lineinfile:
5fd106
+    path: "{{ item.path }}"
5fd106
+    regexp: "^{{{ line }}}$"
5fd106
+    state: absent
5fd106
+  with_items: "{{ sudoers_d_defaults.files }}"
5fd106
+{{%- endmacro %}}
5fd106
+
5fd106
+{{{- delete_line_in_sudoers_d("Defaults !targetpw") }}}
5fd106
+{{{- delete_line_in_sudoers_d("Defaults !rootpw") }}}
5fd106
+{{{- delete_line_in_sudoers_d("Defaults !runaspw") }}}
5fd106
+
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') }}}
5fd106
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
5fd106
index ea0ac67fa1c..3b327f3fc88 100644
5fd106
--- a/linux_os/guide/system/software/sudo/sudoers_validate_passwd/bash/shared.sh
5fd106
+++ b/linux_os/guide/system/software/sudo/sudoers_validate_passwd/bash/shared.sh
5fd106
@@ -1,5 +1,17 @@
5fd106
 # platform = multi_platform_all
5fd106
 
5fd106
+{{%- macro delete_line_in_sudoers_d(line) %}}
5fd106
+if grep -x '^{{{line}}}$' /etc/sudoers.d/*; then
5fd106
+    find /etc/sudoers.d/ -type f -exec sed -i "/{{{line}}}/d" {} \;
5fd106
+fi
5fd106
+{{%- endmacro %}}
5fd106
+
5fd106
+{{{- delete_line_in_sudoers_d("Defaults !targetpw") }}}
5fd106
+{{{- delete_line_in_sudoers_d("Defaults !rootpw") }}}
5fd106
+{{{- delete_line_in_sudoers_d("Defaults !runaspw") }}}
5fd106
+
5fd106
 {{{ set_config_file(path="/etc/sudoers", parameter="Defaults !targetpw", value="", create=true, insensitive=false, separator="", separator_regex="", prefix_regex="") }}}
5fd106
 {{{ set_config_file(path="/etc/sudoers", parameter="Defaults !rootpw", value="", create=true, insensitive=false, separator="", separator_regex="", prefix_regex="") }}}
5fd106
 {{{ set_config_file(path="/etc/sudoers", parameter="Defaults !runaspw", value="", create=true, insensitive=false, separator="", separator_regex="", prefix_regex="") }}}
5fd106
+
5fd106
+
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.
5fd106
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
5fd106
index 00000000000..a258d108a00
ff1465
--- /dev/null
5fd106
+++ b/linux_os/guide/system/software/sudo/sudoers_validate_passwd/tests/sudoers_d_duplicate.fail.sh
5fd106
@@ -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
5fd106
+echo 'Defaults !targetpw' >> /etc/sudoers.d/00-complianceascode.conf
5fd106
+echo 'Defaults !rootpw' >> /etc/sudoers.d/00-complianceascode.conf
5fd106
+echo 'Defaults !runaspw' >> /etc/sudoers.d/00-complianceascode.conf
5fd106
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
5fd106
index 00000000000..6247b5230e4
ff1465
--- /dev/null
5fd106
+++ b/linux_os/guide/system/software/sudo/sudoers_validate_passwd/tests/sudoers_validate_passwd_duplicates.fail.sh
5fd106
@@ -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
5fd106
+echo 'Defaults !runaspw' >> /etc/sudoers