Blame SOURCES/scap-security-guide-0.1.61-add_RHEL_08_0103789_include_sudoers-PR_8196.patch

0c1482
From 19bd5adfd804590b15e42cc75287b792706286d5 Mon Sep 17 00:00:00 2001
0c1482
From: Watson Sato <wsato@redhat.com>
0c1482
Date: Thu, 10 Feb 2022 15:25:06 +0100
0c1482
Subject: [PATCH 1/9] Add rule to check for default sudoers includedir
0c1482
0c1482
This rule supports RHEL-08-010379.
0c1482
---
0c1482
 .../ansible/shared.yml                        |  7 ++++
0c1482
 .../sudoers_default_includedir/bash/shared.sh | 11 ++++++
0c1482
 .../oval/shared.xml                           | 23 +++++++++++
0c1482
 .../sudo/sudoers_default_includedir/rule.yml  | 38 +++++++++++++++++++
0c1482
 .../tests/default_includedir.pass.sh          |  7 ++++
0c1482
 .../tests/duplicate_includedir.fail.sh        |  7 ++++
0c1482
 .../tests/no_includedir.fail.sh               |  4 ++
0c1482
 .../tests/two_includedir.fail.sh              |  8 ++++
0c1482
 9 files changed, 105 insertions(+), 3 deletions(-)
0c1482
 create mode 100644 linux_os/guide/system/software/sudo/sudoers_default_includedir/ansible/shared.yml
0c1482
 create mode 100644 linux_os/guide/system/software/sudo/sudoers_default_includedir/bash/shared.sh
0c1482
 create mode 100644 linux_os/guide/system/software/sudo/sudoers_default_includedir/oval/shared.xml
0c1482
 create mode 100644 linux_os/guide/system/software/sudo/sudoers_default_includedir/rule.yml
0c1482
 create mode 100644 linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/default_includedir.pass.sh
0c1482
 create mode 100644 linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/duplicate_includedir.fail.sh
0c1482
 create mode 100644 linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/no_includedir.fail.sh
0c1482
 create mode 100644 linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/two_includedir.fail.sh
0c1482
0c1482
diff --git a/linux_os/guide/system/software/sudo/sudoers_default_includedir/ansible/shared.yml b/linux_os/guide/system/software/sudo/sudoers_default_includedir/ansible/shared.yml
0c1482
new file mode 100644
0c1482
index 00000000000..d9d5933285f
0c1482
--- /dev/null
0c1482
+++ b/linux_os/guide/system/software/sudo/sudoers_default_includedir/ansible/shared.yml
0c1482
@@ -0,0 +1,7 @@
0c1482
+# platform = multi_platform_all
0c1482
+# # reboot = false
0c1482
+# # strategy = configure
0c1482
+# # complexity = low
0c1482
+# # disruption = low
0c1482
+
0c1482
+{{{ ansible_only_lineinfile(msg='Ensure sudo only has the default includedir', line_regex='^#includedir.*$', path='/etc/sudoers', new_line='#includedir /etc/sudoers.d') }}}
0c1482
diff --git a/linux_os/guide/system/software/sudo/sudoers_default_includedir/bash/shared.sh b/linux_os/guide/system/software/sudo/sudoers_default_includedir/bash/shared.sh
0c1482
new file mode 100644
0c1482
index 00000000000..3a9e2da985b
0c1482
--- /dev/null
0c1482
+++ b/linux_os/guide/system/software/sudo/sudoers_default_includedir/bash/shared.sh
0c1482
@@ -0,0 +1,11 @@
0c1482
+# platform = multi_platform_all
0c1482
+
0c1482
+sudoers_config_file="/etc/sudoers"
0c1482
+sudoers_includedir_count=$(grep -c "#includedir" "$sudoers_config_file")
0c1482
+if [ "$sudoers_includedir_count" -gt 1 ]; then
0c1482
+    sed -i "/#includedir.*/d" "$sudoers_config_file"
0c1482
+    echo "#includedir /etc/sudoers.d" >> "$sudoers_config_file"
0c1482
+fi
0c1482
+if [ "$sudoers_includedir_count" -eq 0 ]; then
0c1482
+    echo "#includedir /etc/sudoers.d" >> "$sudoers_config_file"
0c1482
+fi
0c1482
diff --git a/linux_os/guide/system/software/sudo/sudoers_default_includedir/oval/shared.xml b/linux_os/guide/system/software/sudo/sudoers_default_includedir/oval/shared.xml
0c1482
new file mode 100644
0c1482
index 00000000000..5618c64291c
0c1482
--- /dev/null
0c1482
+++ b/linux_os/guide/system/software/sudo/sudoers_default_includedir/oval/shared.xml
0c1482
@@ -0,0 +1,23 @@
0c1482
+<def-group>
0c1482
+  <definition class="compliance" id="{{{ rule_id }}}" version="1">
0c1482
+    {{{ oval_metadata("Check if sudo includes only the default includedir") }}}
0c1482
+    <criteria operator="AND">
0c1482
+      <criterion comment="Check /etc/sudoers for #includedir" test_ref="test_sudoers_default_includedir" />
0c1482
+    </criteria>
0c1482
+  </definition>
0c1482
+
0c1482
+  
0c1482
+      comment="audit augenrules rmmod" id="test_sudoers_default_includedir" version="1">
0c1482
+    <ind:object object_ref="object_sudoers_default_includedir" />
0c1482
+    <ind:state state_ref="state_sudoers_default_includedir" />
0c1482
+  </ind:textfilecontent54_test>
0c1482
+  <ind:textfilecontent54_object id="object_sudoers_default_includedir" version="1">
0c1482
+    <ind:filepath>/etc/sudoers</ind:filepath>
0c1482
+    <ind:pattern operation="pattern match">^#includedir[\s]+(.*)$</ind:pattern>
0c1482
+    <ind:instance operation="greater than or equal" datatype="int">1</ind:instance>
0c1482
+  </ind:textfilecontent54_object>
0c1482
+  <ind:textfilecontent54_state id="state_sudoers_default_includedir" version="1">
0c1482
+    <ind:subexpression operation="equals">/etc/sudoers.d</ind:subexpression>
0c1482
+  </ind:textfilecontent54_state>
0c1482
+
0c1482
+</def-group>
0c1482
diff --git a/linux_os/guide/system/software/sudo/sudoers_default_includedir/rule.yml b/linux_os/guide/system/software/sudo/sudoers_default_includedir/rule.yml
0c1482
new file mode 100644
0c1482
index 00000000000..5c33121f911
0c1482
--- /dev/null
0c1482
+++ b/linux_os/guide/system/software/sudo/sudoers_default_includedir/rule.yml
0c1482
@@ -0,0 +1,38 @@
0c1482
+documentation_complete: true
0c1482
+
0c1482
+prodtype: fedora,rhel7,rhel8,rhel9
0c1482
+
0c1482
+title: 'Ensure sudo only includes the default configuration directory'
0c1482
+
0c1482
+description: |-
0c1482
+    Administrators can configure authorized <tt>sudo</tt> users via drop-in files, and it is possible to include
0c1482
+    other directories and configuration files from the file currently being parsed.
0c1482
+  
0c1482
+    Make sure that <tt>/etc/sudoers</tt> only includes drop-in configuration files from <tt>/etc/sudoers.d</tt>.
0c1482
+    The <tt>/etc/sudoers</tt> should contain only one <tt>#includedir</tt> directive pointing to
0c1482
+    <tt>/etc/sudoers.d</tt>
0c1482
+    Note that the '#' character doesn't denote a comment in the configuration file.
0c1482
+
0c1482
+rationale: |-
0c1482
+   Some <tt>sudo</tt> configurtion options allow users to run programs without re-authenticating.
0c1482
+   Use of these configuration options makes it easier for one compromised accound to be used to
0c1482
+   compromise other accounts.
0c1482
+
0c1482
+severity: medium
0c1482
+
0c1482
+identifiers:
0c1482
+    cce@rhel7: CCE-86277-1
0c1482
+    cce@rhel8: CCE-86377-9
0c1482
+    cce@rhel9: CCE-86477-7
0c1482
+
0c1482
+references:
0c1482
+    disa: CCI-000366
0c1482
+    stigid@rhel8: RHEL-08-010379
0c1482
+
0c1482
+ocil_clause: "the /etc/sudoers doesn't include /etc/sudores.d or includes other directories?"
0c1482
+
0c1482
+ocil: |-
0c1482
+    To determine whether <tt>sudo</tt> command includes configuration files from the appropriate directory,
0c1482
+    run the following command:
0c1482
+    
$ sudo grep 'include' /etc/sudoers
0c1482
+    If only the line <tt>#includedir /etc/sudoers> is returned, then the drop-in file configuration is set correctly.
0c1482
diff --git a/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/default_includedir.pass.sh b/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/default_includedir.pass.sh
0c1482
new file mode 100644
0c1482
index 00000000000..ac0c808ccd6
0c1482
--- /dev/null
0c1482
+++ b/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/default_includedir.pass.sh
0c1482
@@ -0,0 +1,7 @@
0c1482
+#!/bin/bash
0c1482
+# platform = multi_platform_all
0c1482
+
0c1482
+# Ensure default config is there
0c1482
+if ! grep -q "#includedir /etc/sudoers.d" /etc/sudoers; then
0c1482
+    echo "#includedir /etc/sudoers.d" >> /etc/sudoers
0c1482
+fi
0c1482
diff --git a/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/duplicate_includedir.fail.sh b/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/duplicate_includedir.fail.sh
0c1482
new file mode 100644
0c1482
index 00000000000..5bad8225625
0c1482
--- /dev/null
0c1482
+++ b/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/duplicate_includedir.fail.sh
0c1482
@@ -0,0 +1,7 @@
0c1482
+#!/bin/bash
0c1482
+# platform = multi_platform_all
0c1482
+
0c1482
+# duplicate default entry
0c1482
+if grep -q "#includedir /etc/sudoers.d" /etc/sudoers; then
0c1482
+    echo "#includedir /etc/sudoers.d" >> /etc/sudoers
0c1482
+fi
0c1482
diff --git a/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/no_includedir.fail.sh b/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/no_includedir.fail.sh
0c1482
new file mode 100644
0c1482
index 00000000000..1e0ab8aea92
0c1482
--- /dev/null
0c1482
+++ b/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/no_includedir.fail.sh
0c1482
@@ -0,0 +1,4 @@
0c1482
+#!/bin/bash
0c1482
+# platform = multi_platform_all
0c1482
+
0c1482
+sed -i "/#includedir.*/d" /etc/sudoers
0c1482
diff --git a/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/two_includedir.fail.sh b/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/two_includedir.fail.sh
0c1482
new file mode 100644
0c1482
index 00000000000..09d14eab630
0c1482
--- /dev/null
0c1482
+++ b/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/two_includedir.fail.sh
0c1482
@@ -0,0 +1,8 @@
0c1482
+#!/bin/bash
0c1482
+# platform = multi_platform_all
0c1482
+
0c1482
+# Ensure that there are two different indludedirs
0c1482
+if ! grep -q "#includedir /etc/sudoers.d" /etc/sudoers; then
0c1482
+    echo "#includedir /etc/sudoers.d" >> /etc/sudoers
0c1482
+fi
0c1482
+echo "#includedir /opt/extra_config.d" >> /etc/sudoers
0c1482
0c1482
From 99fe46922243e8dff5822e2ed6eb49addd000baa Mon Sep 17 00:00:00 2001
0c1482
From: Watson Sato <wsato@redhat.com>
0c1482
Date: Thu, 10 Feb 2022 16:21:46 +0100
0c1482
Subject: [PATCH 2/9] Select rule in RHEL8 STIG
0c1482
0c1482
Select sudoers_default_indludedir aligning to RHEL8 STIG V1R5
0c1482
---
0c1482
 products/rhel8/profiles/stig.profile | 3 +++
0c1482
 1 file changed, 3 insertions(+)
0c1482
0c1482
diff --git a/products/rhel8/profiles/stig.profile b/products/rhel8/profiles/stig.profile
0c1482
index d92bc72971c..e13bda7a787 100644
0c1482
--- a/products/rhel8/profiles/stig.profile
0c1482
+++ b/products/rhel8/profiles/stig.profile
0c1482
@@ -271,6 +271,9 @@ selections:
0c1482
     # RHEL-08-010376
0c1482
     - sysctl_kernel_perf_event_paranoid
0c1482
 
0c1482
+    # RHEL-08-010379
0c1482
+    - sudoers_default_includedir
0c1482
+
0c1482
     # RHEL-08-010380
0c1482
     - sudo_remove_nopasswd
0c1482
 
0c1482
0c1482
From 3686fe72a6e27049f1c46d0a4efa07e1b42b6a20 Mon Sep 17 00:00:00 2001
0c1482
From: Watson Sato <wsato@redhat.com>
0c1482
Date: Thu, 10 Feb 2022 17:26:59 +0100
0c1482
Subject: [PATCH 3/9] Add test and fix for case when the single includedir is
0c1482
 wrong
0c1482
0c1482
---
0c1482
 .../sudo/sudoers_default_includedir/bash/shared.sh         | 7 +++++--
0c1482
 .../tests/wrong_includedir.fail.sh                         | 5 +++++
0c1482
 2 files changed, 10 insertions(+), 2 deletions(-)
0c1482
 create mode 100644 linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/wrong_includedir.fail.sh
0c1482
0c1482
diff --git a/linux_os/guide/system/software/sudo/sudoers_default_includedir/bash/shared.sh b/linux_os/guide/system/software/sudo/sudoers_default_includedir/bash/shared.sh
0c1482
index 3a9e2da985b..258af02c121 100644
0c1482
--- a/linux_os/guide/system/software/sudo/sudoers_default_includedir/bash/shared.sh
0c1482
+++ b/linux_os/guide/system/software/sudo/sudoers_default_includedir/bash/shared.sh
0c1482
@@ -5,7 +5,10 @@ sudoers_includedir_count=$(grep -c "#includedir" "$sudoers_config_file")
0c1482
 if [ "$sudoers_includedir_count" -gt 1 ]; then
0c1482
     sed -i "/#includedir.*/d" "$sudoers_config_file"
0c1482
     echo "#includedir /etc/sudoers.d" >> "$sudoers_config_file"
0c1482
-fi
0c1482
-if [ "$sudoers_includedir_count" -eq 0 ]; then
0c1482
+elif [ "$sudoers_includedir_count" -eq 0 ]; then
0c1482
     echo "#includedir /etc/sudoers.d" >> "$sudoers_config_file"
0c1482
+else
0c1482
+    if ! grep -q "^#includedir /etc/sudoers.d" /etc/sudoers; then
0c1482
+        sed -i "s|^#includedir.*|#includedir /etc/sudoers.d|g" /etc/sudoers
0c1482
+    fi
0c1482
 fi
0c1482
diff --git a/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/wrong_includedir.fail.sh b/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/wrong_includedir.fail.sh
0c1482
new file mode 100644
0c1482
index 00000000000..55a072adf3c
0c1482
--- /dev/null
0c1482
+++ b/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/wrong_includedir.fail.sh
0c1482
@@ -0,0 +1,5 @@
0c1482
+#!/bin/bash
0c1482
+# platform = multi_platform_all
0c1482
+
0c1482
+sed -i "/#includedir.*/d" /etc/sudoers
0c1482
+echo "#includedir /opt/extra_config.d" >> /etc/sudoers
0c1482
0c1482
From 0b20b495ed82cead1a033170b900c13da5260603 Mon Sep 17 00:00:00 2001
0c1482
From: Watson Sato <wsato@redhat.com>
0c1482
Date: Mon, 14 Feb 2022 14:50:11 +0100
0c1482
Subject: [PATCH 4/9] Add tests for sudo file and dir includes in
0c1482
 /etc/sudoers.d
0c1482
0c1482
---
0c1482
 .../tests/sudoers.d_with_include.fail.sh              |  9 +++++++++
0c1482
 .../tests/sudoers.d_with_includedir.fail.sh           |  9 +++++++++
0c1482
 .../tests/sudoers_with_include.fail.sh                | 11 +++++++++++
0c1482
 3 files changed, 29 insertions(+)
0c1482
 create mode 100644 linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/sudoers.d_with_include.fail.sh
0c1482
 create mode 100644 linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/sudoers.d_with_includedir.fail.sh
0c1482
 create mode 100644 linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/sudoers_with_include.fail.sh
0c1482
0c1482
diff --git a/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/sudoers.d_with_include.fail.sh b/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/sudoers.d_with_include.fail.sh
0c1482
new file mode 100644
0c1482
index 00000000000..554ef2e060d
0c1482
--- /dev/null
0c1482
+++ b/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/sudoers.d_with_include.fail.sh
0c1482
@@ -0,0 +1,9 @@
0c1482
+#!/bin/bash
0c1482
+# platform = multi_platform_all
0c1482
+
0c1482
+# Ensure default config is there
0c1482
+if ! grep -q "#includedir /etc/sudoers.d" /etc/sudoers; then
0c1482
+    echo "#includedir /etc/sudoers.d" >> /etc/sudoers
0c1482
+fi
0c1482
+
0c1482
+echo "#include /etc/my-sudoers" > /etc/sudoers.d/my-sudoers
0c1482
diff --git a/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/sudoers.d_with_includedir.fail.sh b/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/sudoers.d_with_includedir.fail.sh
0c1482
new file mode 100644
0c1482
index 00000000000..516b68b5a3e
0c1482
--- /dev/null
0c1482
+++ b/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/sudoers.d_with_includedir.fail.sh
0c1482
@@ -0,0 +1,9 @@
0c1482
+#!/bin/bash
0c1482
+# platform = multi_platform_all
0c1482
+
0c1482
+# Ensure default config is there
0c1482
+if ! grep -q "#includedir /etc/sudoers.d" /etc/sudoers; then
0c1482
+    echo "#includedir /etc/sudoers.d" >> /etc/sudoers
0c1482
+fi
0c1482
+
0c1482
+echo "#includedir /etc/my-sudoers.d" > /etc/sudoers.d/my-sudoers
0c1482
diff --git a/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/sudoers_with_include.fail.sh b/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/sudoers_with_include.fail.sh
0c1482
new file mode 100644
0c1482
index 00000000000..ad04880e334
0c1482
--- /dev/null
0c1482
+++ b/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/sudoers_with_include.fail.sh
0c1482
@@ -0,0 +1,11 @@
0c1482
+#!/bin/bash
0c1482
+# platform = multi_platform_all
0c1482
+
0c1482
+# Ensure default config is there
0c1482
+if ! grep -q "#includedir /etc/sudoers.d" /etc/sudoers; then
0c1482
+    echo "#includedir /etc/sudoers.d" >> /etc/sudoers
0c1482
+fi
0c1482
+
0c1482
+if ! grep -q "#include " /etc/sudoers; then
0c1482
+    echo "#include /etc/my-sudoers" >> /etc/sudoers
0c1482
+fi
0c1482
0c1482
From d91e3eefe6c265c27634cb15b0f276a298f81645 Mon Sep 17 00:00:00 2001
0c1482
From: Watson Sato <wsato@redhat.com>
0c1482
Date: Mon, 14 Feb 2022 14:59:18 +0100
0c1482
Subject: [PATCH 5/9] Update rule catch and remove other sudo includes
0c1482
0c1482
Any other #include or #includedir besides:
0c1482
"/etc/sudoers: #includedir /etc/sudoers.d" should be removed.
0c1482
---
0c1482
 .../ansible/shared.yml                        | 14 +++++++++++
0c1482
 .../sudoers_default_includedir/bash/shared.sh |  7 ++++--
0c1482
 .../oval/shared.xml                           | 23 +++++++++++++++++++
0c1482
 .../sudo/sudoers_default_includedir/rule.yml  |  7 +++---
0c1482
 4 files changed, 46 insertions(+), 5 deletions(-)
0c1482
0c1482
diff --git a/linux_os/guide/system/software/sudo/sudoers_default_includedir/ansible/shared.yml b/linux_os/guide/system/software/sudo/sudoers_default_includedir/ansible/shared.yml
0c1482
index d9d5933285f..175a447e0d9 100644
0c1482
--- a/linux_os/guide/system/software/sudo/sudoers_default_includedir/ansible/shared.yml
0c1482
+++ b/linux_os/guide/system/software/sudo/sudoers_default_includedir/ansible/shared.yml
0c1482
@@ -5,3 +5,17 @@
0c1482
 # # disruption = low
0c1482
 
0c1482
 {{{ ansible_only_lineinfile(msg='Ensure sudo only has the default includedir', line_regex='^#includedir.*$', path='/etc/sudoers', new_line='#includedir /etc/sudoers.d') }}}
0c1482
+{{{ ansible_lineinfile(msg='Ensure sudoers doesn\'t include other non-default file', regex='^#include[\s]+.*$', path='/etc/sudoers', state='absent') }}}
0c1482
+- name: "Find out if /etc/sudoers.d/* files contain file or directory includes"
0c1482
+  find:
0c1482
+    path: "/etc/sudoers.d"
0c1482
+    patterns: "*"
0c1482
+    contains: '^#include(dir)?\s.*$'
0c1482
+  register: sudoers_d_includes
0c1482
+
0c1482
+- name: "Remove found occurrences of file and directory inclues from /etc/sudoers.d/* files"
0c1482
+  lineinfile:
0c1482
+    path: "{{ item.path }}"
0c1482
+    regexp: '^#include(dir)?\s.*$'
0c1482
+    state: absent
0c1482
+  with_items: "{{ sudoers_d_includes.files }}"
0c1482
diff --git a/linux_os/guide/system/software/sudo/sudoers_default_includedir/bash/shared.sh b/linux_os/guide/system/software/sudo/sudoers_default_includedir/bash/shared.sh
0c1482
index 258af02c121..2d00b471677 100644
0c1482
--- a/linux_os/guide/system/software/sudo/sudoers_default_includedir/bash/shared.sh
0c1482
+++ b/linux_os/guide/system/software/sudo/sudoers_default_includedir/bash/shared.sh
0c1482
@@ -1,6 +1,7 @@
0c1482
 # platform = multi_platform_all
0c1482
 
0c1482
 sudoers_config_file="/etc/sudoers"
0c1482
+sudoers_config_dir="/etc/sudoers.d"
0c1482
 sudoers_includedir_count=$(grep -c "#includedir" "$sudoers_config_file")
0c1482
 if [ "$sudoers_includedir_count" -gt 1 ]; then
0c1482
     sed -i "/#includedir.*/d" "$sudoers_config_file"
0c1482
@@ -8,7 +9,9 @@ if [ "$sudoers_includedir_count" -gt 1 ]; then
0c1482
 elif [ "$sudoers_includedir_count" -eq 0 ]; then
0c1482
     echo "#includedir /etc/sudoers.d" >> "$sudoers_config_file"
0c1482
 else
0c1482
-    if ! grep -q "^#includedir /etc/sudoers.d" /etc/sudoers; then
0c1482
-        sed -i "s|^#includedir.*|#includedir /etc/sudoers.d|g" /etc/sudoers
0c1482
+    if ! grep -q "^#includedir /etc/sudoers.d" "$sudoers_config_file"; then
0c1482
+        sed -i "s|^#includedir.*|#includedir /etc/sudoers.d|g" "$sudoers_config_file"
0c1482
     fi
0c1482
 fi
0c1482
+sed -i "/^#include\s\+.*/d" "$sudoers_config_file" "${sudoers_config_dir}"/*
0c1482
+sed -i "/^#includedir\s\+.*/d" "${sudoers_config_dir}"/*
0c1482
diff --git a/linux_os/guide/system/software/sudo/sudoers_default_includedir/oval/shared.xml b/linux_os/guide/system/software/sudo/sudoers_default_includedir/oval/shared.xml
0c1482
index 5618c64291c..59cab0b89de 100644
0c1482
--- a/linux_os/guide/system/software/sudo/sudoers_default_includedir/oval/shared.xml
0c1482
+++ b/linux_os/guide/system/software/sudo/sudoers_default_includedir/oval/shared.xml
0c1482
@@ -3,6 +3,8 @@
0c1482
     {{{ oval_metadata("Check if sudo includes only the default includedir") }}}
0c1482
     <criteria operator="AND">
0c1482
       <criterion comment="Check /etc/sudoers for #includedir" test_ref="test_sudoers_default_includedir" />
0c1482
+      <criterion comment="Check /etc/sudoers for #include" test_ref="test_sudoers_without_include" />
0c1482
+      <criterion comment="Check /etc/sudoers.d for includes" test_ref="test_sudoersd_without_includes" />
0c1482
     </criteria>
0c1482
   </definition>
0c1482
 
0c1482
@@ -20,4 +22,25 @@
0c1482
     <ind:subexpression operation="equals">/etc/sudoers.d</ind:subexpression>
0c1482
   </ind:textfilecontent54_state>
0c1482
 
0c1482
+  
0c1482
+      comment="audit augenrules rmmod" id="test_sudoers_without_include" version="1">
0c1482
+    <ind:object object_ref="object_sudoers_without_include" />
0c1482
+  </ind:textfilecontent54_test>
0c1482
+  <ind:textfilecontent54_object id="object_sudoers_without_include" version="1">
0c1482
+    <ind:filepath>/etc/sudoers</ind:filepath>
0c1482
+    <ind:pattern operation="pattern match">^#include[\s]+.*$</ind:pattern>
0c1482
+    <ind:instance operation="greater than or equal" datatype="int">1</ind:instance>
0c1482
+  </ind:textfilecontent54_object>
0c1482
+
0c1482
+  
0c1482
+      comment="audit augenrules rmmod" id="test_sudoersd_without_includes" version="1">
0c1482
+    <ind:object object_ref="object_sudoersd_without_includes" />
0c1482
+  </ind:textfilecontent54_test>
0c1482
+  <ind:textfilecontent54_object id="object_sudoersd_without_includes" version="1">
0c1482
+    <ind:path>/etc/sudoers.d/</ind:path>
0c1482
+    <ind:filename operation="pattern match">.*</ind:filename>
0c1482
+    <ind:pattern operation="pattern match">^#include(dir)?[\s]+.*$</ind:pattern>
0c1482
+    <ind:instance operation="greater than or equal" datatype="int">1</ind:instance>
0c1482
+  </ind:textfilecontent54_object>
0c1482
+
0c1482
 </def-group>
0c1482
diff --git a/linux_os/guide/system/software/sudo/sudoers_default_includedir/rule.yml b/linux_os/guide/system/software/sudo/sudoers_default_includedir/rule.yml
0c1482
index 5c33121f911..3a8c22ac8af 100644
0c1482
--- a/linux_os/guide/system/software/sudo/sudoers_default_includedir/rule.yml
0c1482
+++ b/linux_os/guide/system/software/sudo/sudoers_default_includedir/rule.yml
0c1482
@@ -10,7 +10,7 @@ description: |-
0c1482
   
0c1482
     Make sure that <tt>/etc/sudoers</tt> only includes drop-in configuration files from <tt>/etc/sudoers.d</tt>.
0c1482
     The <tt>/etc/sudoers</tt> should contain only one <tt>#includedir</tt> directive pointing to
0c1482
-    <tt>/etc/sudoers.d</tt>
0c1482
+    <tt>/etc/sudoers.d</tt>, and no file in <tt>/etc/sudoers.d/</tt> should include other files or directories.
0c1482
     Note that the '#' character doesn't denote a comment in the configuration file.
0c1482
 
0c1482
 rationale: |-
0c1482
@@ -34,5 +34,6 @@ ocil_clause: "the /etc/sudoers doesn't include /etc/sudores.d or includes other
0c1482
 ocil: |-
0c1482
     To determine whether <tt>sudo</tt> command includes configuration files from the appropriate directory,
0c1482
     run the following command:
0c1482
-    
$ sudo grep 'include' /etc/sudoers
0c1482
-    If only the line <tt>#includedir /etc/sudoers> is returned, then the drop-in file configuration is set correctly.
0c1482
+    
$ sudo grep -rP '^#include(dir)?' /etc/sudoers /etc/sudoers.d
0c1482
+    If only the line <tt>/etc/sudoers:#includedir /etc/sudoers.d</tt> is returned, then the drop-in include configuration is set correctly.
0c1482
+    Any other line returned is a finding.
0c1482
0c1482
From ead72b744f1fc03893184079c079df27780044c2 Mon Sep 17 00:00:00 2001
0c1482
From: Watson Sato <wsato@redhat.com>
0c1482
Date: Mon, 14 Feb 2022 15:00:46 +0100
0c1482
Subject: [PATCH 6/9] Add SRG to sudoers_default_includedir
0c1482
0c1482
---
0c1482
 .../system/software/sudo/sudoers_default_includedir/rule.yml     | 1 +
0c1482
 1 file changed, 1 insertion(+)
0c1482
0c1482
diff --git a/linux_os/guide/system/software/sudo/sudoers_default_includedir/rule.yml b/linux_os/guide/system/software/sudo/sudoers_default_includedir/rule.yml
0c1482
index 3a8c22ac8af..a97bd3efb2c 100644
0c1482
--- a/linux_os/guide/system/software/sudo/sudoers_default_includedir/rule.yml
0c1482
+++ b/linux_os/guide/system/software/sudo/sudoers_default_includedir/rule.yml
0c1482
@@ -27,6 +27,7 @@ identifiers:
0c1482
 
0c1482
 references:
0c1482
     disa: CCI-000366
0c1482
+    srg: SRG-OS-000480-GPOS-00227
0c1482
     stigid@rhel8: RHEL-08-010379
0c1482
 
0c1482
 ocil_clause: "the /etc/sudoers doesn't include /etc/sudores.d or includes other directories?"
0c1482
0c1482
From c1a08fe6b8e6388b89b190ca74e57af06e7c999c Mon Sep 17 00:00:00 2001
0c1482
From: Watson Sato <wsato@redhat.com>
0c1482
Date: Mon, 14 Feb 2022 16:12:32 +0100
0c1482
Subject: [PATCH 7/9] Update RHEL8 STIG profile stability data
0c1482
0c1482
---
0c1482
 tests/data/profile_stability/rhel8/stig.profile     | 1 +
0c1482
 tests/data/profile_stability/rhel8/stig_gui.profile | 1 +
0c1482
 2 files changed, 2 insertions(+)
0c1482
0c1482
diff --git a/tests/data/profile_stability/rhel8/stig.profile b/tests/data/profile_stability/rhel8/stig.profile
0c1482
index e4fee44f9f9..974b28757e9 100644
0c1482
--- a/tests/data/profile_stability/rhel8/stig.profile
0c1482
+++ b/tests/data/profile_stability/rhel8/stig.profile
0c1482
@@ -365,6 +365,7 @@ selections:
0c1482
 - sudo_remove_nopasswd
0c1482
 - sudo_require_reauthentication
0c1482
 - sudo_restrict_privilege_elevation_to_authorized
0c1482
+- sudoers_default_includedir
0c1482
 - sudoers_validate_passwd
0c1482
 - sysctl_crypto_fips_enabled
0c1482
 - sysctl_fs_protected_hardlinks
0c1482
diff --git a/tests/data/profile_stability/rhel8/stig_gui.profile b/tests/data/profile_stability/rhel8/stig_gui.profile
0c1482
index 83d04775e3a..99e0af4f5a6 100644
0c1482
--- a/tests/data/profile_stability/rhel8/stig_gui.profile
0c1482
+++ b/tests/data/profile_stability/rhel8/stig_gui.profile
0c1482
@@ -376,6 +376,7 @@ selections:
0c1482
 - sudo_remove_nopasswd
0c1482
 - sudo_require_reauthentication
0c1482
 - sudo_restrict_privilege_elevation_to_authorized
0c1482
+- sudoers_default_includedir
0c1482
 - sudoers_validate_passwd
0c1482
 - sysctl_crypto_fips_enabled
0c1482
 - sysctl_fs_protected_hardlinks
0c1482
0c1482
From adae3ecbda4362e23cd1f30e053db37d6a1d403b Mon Sep 17 00:00:00 2001
0c1482
From: Watson Sato <wsato@redhat.com>
0c1482
Date: Mon, 14 Feb 2022 16:59:22 +0100
0c1482
Subject: [PATCH 8/9] Fix Ansible remediation metadata
0c1482
0c1482
---
0c1482
 .../sudo/sudoers_default_includedir/ansible/shared.yml    | 8 ++++----
0c1482
 1 file changed, 4 insertions(+), 4 deletions(-)
0c1482
0c1482
diff --git a/linux_os/guide/system/software/sudo/sudoers_default_includedir/ansible/shared.yml b/linux_os/guide/system/software/sudo/sudoers_default_includedir/ansible/shared.yml
0c1482
index 175a447e0d9..0d8c9e75184 100644
0c1482
--- a/linux_os/guide/system/software/sudo/sudoers_default_includedir/ansible/shared.yml
0c1482
+++ b/linux_os/guide/system/software/sudo/sudoers_default_includedir/ansible/shared.yml
0c1482
@@ -1,8 +1,8 @@
0c1482
 # platform = multi_platform_all
0c1482
-# # reboot = false
0c1482
-# # strategy = configure
0c1482
-# # complexity = low
0c1482
-# # disruption = low
0c1482
+# reboot = false
0c1482
+# strategy = configure
0c1482
+# complexity = low
0c1482
+# disruption = low
0c1482
 
0c1482
 {{{ ansible_only_lineinfile(msg='Ensure sudo only has the default includedir', line_regex='^#includedir.*$', path='/etc/sudoers', new_line='#includedir /etc/sudoers.d') }}}
0c1482
 {{{ ansible_lineinfile(msg='Ensure sudoers doesn\'t include other non-default file', regex='^#include[\s]+.*$', path='/etc/sudoers', state='absent') }}}
0c1482
0c1482
From d3f048456908b316c0dcc0bff2328cf87fe6e7de Mon Sep 17 00:00:00 2001
0c1482
From: Watson Sato <wsato@redhat.com>
0c1482
Date: Mon, 14 Feb 2022 17:39:39 +0100
0c1482
Subject: [PATCH 9/9] Handle case when /etc/sudoers.d doesn't exist
0c1482
0c1482
The remediation skips the directory, and the test scenarios create the
0c1482
dir to ensure the test scenario works.
0c1482
---
0c1482
 .../sudo/sudoers_default_includedir/bash/shared.sh        | 8 ++++++--
0c1482
 .../tests/sudoers.d_with_include.fail.sh                  | 1 +
0c1482
 .../tests/sudoers.d_with_includedir.fail.sh               | 1 +
0c1482
 3 files changed, 8 insertions(+), 2 deletions(-)
0c1482
0c1482
diff --git a/linux_os/guide/system/software/sudo/sudoers_default_includedir/bash/shared.sh b/linux_os/guide/system/software/sudo/sudoers_default_includedir/bash/shared.sh
0c1482
index 2d00b471677..fbff5eb6f30 100644
0c1482
--- a/linux_os/guide/system/software/sudo/sudoers_default_includedir/bash/shared.sh
0c1482
+++ b/linux_os/guide/system/software/sudo/sudoers_default_includedir/bash/shared.sh
0c1482
@@ -13,5 +13,9 @@ else
0c1482
         sed -i "s|^#includedir.*|#includedir /etc/sudoers.d|g" "$sudoers_config_file"
0c1482
     fi
0c1482
 fi
0c1482
-sed -i "/^#include\s\+.*/d" "$sudoers_config_file" "${sudoers_config_dir}"/*
0c1482
-sed -i "/^#includedir\s\+.*/d" "${sudoers_config_dir}"/*
0c1482
+
0c1482
+sed -i "/^#include\s\+.*/d" "$sudoers_config_file"
0c1482
+
0c1482
+if grep -Pr "^#include(dir)? .*" "$sudoers_config_dir" ; then
0c1482
+    sed -i "/^#include\(dir\)\?\s\+.*/d" "$sudoers_config_dir"/*
0c1482
+fi
0c1482
diff --git a/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/sudoers.d_with_include.fail.sh b/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/sudoers.d_with_include.fail.sh
0c1482
index 554ef2e060d..3f14ecc1627 100644
0c1482
--- a/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/sudoers.d_with_include.fail.sh
0c1482
+++ b/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/sudoers.d_with_include.fail.sh
0c1482
@@ -1,6 +1,7 @@
0c1482
 #!/bin/bash
0c1482
 # platform = multi_platform_all
0c1482
 
0c1482
+mkdir -p /etc/sudoers.d
0c1482
 # Ensure default config is there
0c1482
 if ! grep -q "#includedir /etc/sudoers.d" /etc/sudoers; then
0c1482
     echo "#includedir /etc/sudoers.d" >> /etc/sudoers
0c1482
diff --git a/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/sudoers.d_with_includedir.fail.sh b/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/sudoers.d_with_includedir.fail.sh
0c1482
index 516b68b5a3e..89515076ff1 100644
0c1482
--- a/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/sudoers.d_with_includedir.fail.sh
0c1482
+++ b/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/sudoers.d_with_includedir.fail.sh
0c1482
@@ -1,6 +1,7 @@
0c1482
 #!/bin/bash
0c1482
 # platform = multi_platform_all
0c1482
 
0c1482
+mkdir -p /etc/sudoers.d
0c1482
 # Ensure default config is there
0c1482
 if ! grep -q "#includedir /etc/sudoers.d" /etc/sudoers; then
0c1482
     echo "#includedir /etc/sudoers.d" >> /etc/sudoers