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

ff1465
commit 804ab7d7e48d3d6a93aab8c99a1b71410553983b
ff1465
Author: Watson Sato <wsato@redhat.com>
ff1465
Date:   Mon Feb 28 11:44:13 2022 +0100
ff1465
ff1465
    Manual edited patch scap-security-guide-0.1.61-add_RHEL_08_0103789_include_sudoers-PR_8196.patch.
ff1465
ff1465
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
ff1465
new file mode 100644
ff1465
index 0000000..0d8c9e7
ff1465
--- /dev/null
ff1465
+++ b/linux_os/guide/system/software/sudo/sudoers_default_includedir/ansible/shared.yml
ff1465
@@ -0,0 +1,21 @@
ff1465
+# platform = multi_platform_all
ff1465
+# reboot = false
ff1465
+# strategy = configure
ff1465
+# complexity = low
ff1465
+# disruption = low
ff1465
+
ff1465
+{{{ ansible_only_lineinfile(msg='Ensure sudo only has the default includedir', line_regex='^#includedir.*$', path='/etc/sudoers', new_line='#includedir /etc/sudoers.d') }}}
ff1465
+{{{ ansible_lineinfile(msg='Ensure sudoers doesn\'t include other non-default file', regex='^#include[\s]+.*$', path='/etc/sudoers', state='absent') }}}
ff1465
+- name: "Find out if /etc/sudoers.d/* files contain file or directory includes"
ff1465
+  find:
ff1465
+    path: "/etc/sudoers.d"
ff1465
+    patterns: "*"
ff1465
+    contains: '^#include(dir)?\s.*$'
ff1465
+  register: sudoers_d_includes
ff1465
+
ff1465
+- name: "Remove found occurrences of file and directory inclues from /etc/sudoers.d/* files"
ff1465
+  lineinfile:
ff1465
+    path: "{{ item.path }}"
ff1465
+    regexp: '^#include(dir)?\s.*$'
ff1465
+    state: absent
ff1465
+  with_items: "{{ sudoers_d_includes.files }}"
ff1465
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
ff1465
new file mode 100644
ff1465
index 0000000..fbff5eb
ff1465
--- /dev/null
ff1465
+++ b/linux_os/guide/system/software/sudo/sudoers_default_includedir/bash/shared.sh
ff1465
@@ -0,0 +1,21 @@
ff1465
+# platform = multi_platform_all
ff1465
+
ff1465
+sudoers_config_file="/etc/sudoers"
ff1465
+sudoers_config_dir="/etc/sudoers.d"
ff1465
+sudoers_includedir_count=$(grep -c "#includedir" "$sudoers_config_file")
ff1465
+if [ "$sudoers_includedir_count" -gt 1 ]; then
ff1465
+    sed -i "/#includedir.*/d" "$sudoers_config_file"
ff1465
+    echo "#includedir /etc/sudoers.d" >> "$sudoers_config_file"
ff1465
+elif [ "$sudoers_includedir_count" -eq 0 ]; then
ff1465
+    echo "#includedir /etc/sudoers.d" >> "$sudoers_config_file"
ff1465
+else
ff1465
+    if ! grep -q "^#includedir /etc/sudoers.d" "$sudoers_config_file"; then
ff1465
+        sed -i "s|^#includedir.*|#includedir /etc/sudoers.d|g" "$sudoers_config_file"
ff1465
+    fi
ff1465
+fi
ff1465
+
ff1465
+sed -i "/^#include\s\+.*/d" "$sudoers_config_file"
ff1465
+
ff1465
+if grep -Pr "^#include(dir)? .*" "$sudoers_config_dir" ; then
ff1465
+    sed -i "/^#include\(dir\)\?\s\+.*/d" "$sudoers_config_dir"/*
ff1465
+fi
ff1465
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
ff1465
new file mode 100644
ff1465
index 0000000..59cab0b
ff1465
--- /dev/null
ff1465
+++ b/linux_os/guide/system/software/sudo/sudoers_default_includedir/oval/shared.xml
ff1465
@@ -0,0 +1,46 @@
ff1465
+<def-group>
ff1465
+  <definition class="compliance" id="{{{ rule_id }}}" version="1">
ff1465
+    {{{ oval_metadata("Check if sudo includes only the default includedir") }}}
ff1465
+    <criteria operator="AND">
ff1465
+      <criterion comment="Check /etc/sudoers for #includedir" test_ref="test_sudoers_default_includedir" />
ff1465
+      <criterion comment="Check /etc/sudoers for #include" test_ref="test_sudoers_without_include" />
ff1465
+      <criterion comment="Check /etc/sudoers.d for includes" test_ref="test_sudoersd_without_includes" />
ff1465
+    </criteria>
ff1465
+  </definition>
ff1465
+
ff1465
+  
ff1465
+      comment="audit augenrules rmmod" id="test_sudoers_default_includedir" version="1">
ff1465
+    <ind:object object_ref="object_sudoers_default_includedir" />
ff1465
+    <ind:state state_ref="state_sudoers_default_includedir" />
ff1465
+  </ind:textfilecontent54_test>
ff1465
+  <ind:textfilecontent54_object id="object_sudoers_default_includedir" version="1">
ff1465
+    <ind:filepath>/etc/sudoers</ind:filepath>
ff1465
+    <ind:pattern operation="pattern match">^#includedir[\s]+(.*)$</ind:pattern>
ff1465
+    <ind:instance operation="greater than or equal" datatype="int">1</ind:instance>
ff1465
+  </ind:textfilecontent54_object>
ff1465
+  <ind:textfilecontent54_state id="state_sudoers_default_includedir" version="1">
ff1465
+    <ind:subexpression operation="equals">/etc/sudoers.d</ind:subexpression>
ff1465
+  </ind:textfilecontent54_state>
ff1465
+
ff1465
+  
ff1465
+      comment="audit augenrules rmmod" id="test_sudoers_without_include" version="1">
ff1465
+    <ind:object object_ref="object_sudoers_without_include" />
ff1465
+  </ind:textfilecontent54_test>
ff1465
+  <ind:textfilecontent54_object id="object_sudoers_without_include" version="1">
ff1465
+    <ind:filepath>/etc/sudoers</ind:filepath>
ff1465
+    <ind:pattern operation="pattern match">^#include[\s]+.*$</ind:pattern>
ff1465
+    <ind:instance operation="greater than or equal" datatype="int">1</ind:instance>
ff1465
+  </ind:textfilecontent54_object>
ff1465
+
ff1465
+  
ff1465
+      comment="audit augenrules rmmod" id="test_sudoersd_without_includes" version="1">
ff1465
+    <ind:object object_ref="object_sudoersd_without_includes" />
ff1465
+  </ind:textfilecontent54_test>
ff1465
+  <ind:textfilecontent54_object id="object_sudoersd_without_includes" version="1">
ff1465
+    <ind:path>/etc/sudoers.d/</ind:path>
ff1465
+    <ind:filename operation="pattern match">.*</ind:filename>
ff1465
+    <ind:pattern operation="pattern match">^#include(dir)?[\s]+.*$</ind:pattern>
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_default_includedir/rule.yml b/linux_os/guide/system/software/sudo/sudoers_default_includedir/rule.yml
ff1465
new file mode 100644
ff1465
index 0000000..a97bd3e
ff1465
--- /dev/null
ff1465
+++ b/linux_os/guide/system/software/sudo/sudoers_default_includedir/rule.yml
ff1465
@@ -0,0 +1,40 @@
ff1465
+documentation_complete: true
ff1465
+
ff1465
+prodtype: fedora,rhel7,rhel8,rhel9
ff1465
+
ff1465
+title: 'Ensure sudo only includes the default configuration directory'
ff1465
+
ff1465
+description: |-
ff1465
+    Administrators can configure authorized <tt>sudo</tt> users via drop-in files, and it is possible to include
ff1465
+    other directories and configuration files from the file currently being parsed.
ff1465
+  
ff1465
+    Make sure that <tt>/etc/sudoers</tt> only includes drop-in configuration files from <tt>/etc/sudoers.d</tt>.
ff1465
+    The <tt>/etc/sudoers</tt> should contain only one <tt>#includedir</tt> directive pointing to
ff1465
+    <tt>/etc/sudoers.d</tt>, and no file in <tt>/etc/sudoers.d/</tt> should include other files or directories.
ff1465
+    Note that the '#' character doesn't denote a comment in the configuration file.
ff1465
+
ff1465
+rationale: |-
ff1465
+   Some <tt>sudo</tt> configurtion options allow users to run programs without re-authenticating.
ff1465
+   Use of these configuration options makes it easier for one compromised accound to be used to
ff1465
+   compromise other accounts.
ff1465
+
ff1465
+severity: medium
ff1465
+
ff1465
+identifiers:
ff1465
+    cce@rhel7: CCE-86277-1
ff1465
+    cce@rhel8: CCE-86377-9
ff1465
+    cce@rhel9: CCE-86477-7
ff1465
+
ff1465
+references:
ff1465
+    disa: CCI-000366
ff1465
+    srg: SRG-OS-000480-GPOS-00227
ff1465
+    stigid@rhel8: RHEL-08-010379
ff1465
+
ff1465
+ocil_clause: "the /etc/sudoers doesn't include /etc/sudores.d or includes other directories?"
ff1465
+
ff1465
+ocil: |-
ff1465
+    To determine whether <tt>sudo</tt> command includes configuration files from the appropriate directory,
ff1465
+    run the following command:
ff1465
+    
$ sudo grep -rP '^#include(dir)?' /etc/sudoers /etc/sudoers.d
ff1465
+    If only the line <tt>/etc/sudoers:#includedir /etc/sudoers.d</tt> is returned, then the drop-in include configuration is set correctly.
ff1465
+    Any other line returned is a finding.
ff1465
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
ff1465
new file mode 100644
ff1465
index 0000000..ac0c808
ff1465
--- /dev/null
ff1465
+++ b/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/default_includedir.pass.sh
ff1465
@@ -0,0 +1,7 @@
ff1465
+#!/bin/bash
ff1465
+# platform = multi_platform_all
ff1465
+
ff1465
+# Ensure default config is there
ff1465
+if ! grep -q "#includedir /etc/sudoers.d" /etc/sudoers; then
ff1465
+    echo "#includedir /etc/sudoers.d" >> /etc/sudoers
ff1465
+fi
ff1465
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
ff1465
new file mode 100644
ff1465
index 0000000..5bad822
ff1465
--- /dev/null
ff1465
+++ b/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/duplicate_includedir.fail.sh
ff1465
@@ -0,0 +1,7 @@
ff1465
+#!/bin/bash
ff1465
+# platform = multi_platform_all
ff1465
+
ff1465
+# duplicate default entry
ff1465
+if grep -q "#includedir /etc/sudoers.d" /etc/sudoers; then
ff1465
+    echo "#includedir /etc/sudoers.d" >> /etc/sudoers
ff1465
+fi
ff1465
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
ff1465
new file mode 100644
ff1465
index 0000000..1e0ab8a
ff1465
--- /dev/null
ff1465
+++ b/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/no_includedir.fail.sh
ff1465
@@ -0,0 +1,4 @@
ff1465
+#!/bin/bash
ff1465
+# platform = multi_platform_all
ff1465
+
ff1465
+sed -i "/#includedir.*/d" /etc/sudoers
ff1465
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
ff1465
new file mode 100644
ff1465
index 0000000..3f14ecc
ff1465
--- /dev/null
ff1465
+++ b/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/sudoers.d_with_include.fail.sh
ff1465
@@ -0,0 +1,10 @@
ff1465
+#!/bin/bash
ff1465
+# platform = multi_platform_all
ff1465
+
ff1465
+mkdir -p /etc/sudoers.d
ff1465
+# Ensure default config is there
ff1465
+if ! grep -q "#includedir /etc/sudoers.d" /etc/sudoers; then
ff1465
+    echo "#includedir /etc/sudoers.d" >> /etc/sudoers
ff1465
+fi
ff1465
+
ff1465
+echo "#include /etc/my-sudoers" > /etc/sudoers.d/my-sudoers
ff1465
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
ff1465
new file mode 100644
ff1465
index 0000000..8951507
ff1465
--- /dev/null
ff1465
+++ b/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/sudoers.d_with_includedir.fail.sh
ff1465
@@ -0,0 +1,10 @@
ff1465
+#!/bin/bash
ff1465
+# platform = multi_platform_all
ff1465
+
ff1465
+mkdir -p /etc/sudoers.d
ff1465
+# Ensure default config is there
ff1465
+if ! grep -q "#includedir /etc/sudoers.d" /etc/sudoers; then
ff1465
+    echo "#includedir /etc/sudoers.d" >> /etc/sudoers
ff1465
+fi
ff1465
+
ff1465
+echo "#includedir /etc/my-sudoers.d" > /etc/sudoers.d/my-sudoers
ff1465
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
ff1465
new file mode 100644
ff1465
index 0000000..ad04880
ff1465
--- /dev/null
ff1465
+++ b/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/sudoers_with_include.fail.sh
ff1465
@@ -0,0 +1,11 @@
ff1465
+#!/bin/bash
ff1465
+# platform = multi_platform_all
ff1465
+
ff1465
+# Ensure default config is there
ff1465
+if ! grep -q "#includedir /etc/sudoers.d" /etc/sudoers; then
ff1465
+    echo "#includedir /etc/sudoers.d" >> /etc/sudoers
ff1465
+fi
ff1465
+
ff1465
+if ! grep -q "#include " /etc/sudoers; then
ff1465
+    echo "#include /etc/my-sudoers" >> /etc/sudoers
ff1465
+fi
ff1465
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
ff1465
new file mode 100644
ff1465
index 0000000..09d14ea
ff1465
--- /dev/null
ff1465
+++ b/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/two_includedir.fail.sh
ff1465
@@ -0,0 +1,8 @@
ff1465
+#!/bin/bash
ff1465
+# platform = multi_platform_all
ff1465
+
ff1465
+# Ensure that there are two different indludedirs
ff1465
+if ! grep -q "#includedir /etc/sudoers.d" /etc/sudoers; then
ff1465
+    echo "#includedir /etc/sudoers.d" >> /etc/sudoers
ff1465
+fi
ff1465
+echo "#includedir /opt/extra_config.d" >> /etc/sudoers
ff1465
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
ff1465
new file mode 100644
ff1465
index 0000000..55a072a
ff1465
--- /dev/null
ff1465
+++ b/linux_os/guide/system/software/sudo/sudoers_default_includedir/tests/wrong_includedir.fail.sh
ff1465
@@ -0,0 +1,5 @@
ff1465
+#!/bin/bash
ff1465
+# platform = multi_platform_all
ff1465
+
ff1465
+sed -i "/#includedir.*/d" /etc/sudoers
ff1465
+echo "#includedir /opt/extra_config.d" >> /etc/sudoers
ff1465
diff --git a/products/rhel8/profiles/stig.profile b/products/rhel8/profiles/stig.profile
ff1465
index bfb3753..f5fed4a 100644
ff1465
--- a/products/rhel8/profiles/stig.profile
ff1465
+++ b/products/rhel8/profiles/stig.profile
ff1465
@@ -271,6 +271,9 @@ selections:
ff1465
     # RHEL-08-010376
ff1465
     - sysctl_kernel_perf_event_paranoid
ff1465
 
ff1465
+    # RHEL-08-010379
ff1465
+    - sudoers_default_includedir
ff1465
+
ff1465
     # RHEL-08-010380
ff1465
     - sudo_remove_nopasswd
ff1465
 
ff1465
diff --git a/shared/references/cce-redhat-avail.txt b/shared/references/cce-redhat-avail.txt
ff1465
index ec92589..99bccc7 100644
ff1465
--- a/shared/references/cce-redhat-avail.txt
ff1465
+++ b/shared/references/cce-redhat-avail.txt
ff1465
@@ -478,7 +478,6 @@ CCE-86373-8
ff1465
 CCE-86374-6
ff1465
 CCE-86375-3
ff1465
 CCE-86376-1
ff1465
-CCE-86377-9
ff1465
 CCE-86378-7
ff1465
 CCE-86379-5
ff1465
 CCE-86380-3
ff1465
@@ -576,7 +575,6 @@ CCE-86473-6
ff1465
 CCE-86474-4
ff1465
 CCE-86475-1
ff1465
 CCE-86476-9
ff1465
-CCE-86477-7
ff1465
 CCE-86478-5
ff1465
 CCE-86479-3
ff1465
 CCE-86480-1
ff1465
diff --git a/tests/data/profile_stability/rhel8/stig.profile b/tests/data/profile_stability/rhel8/stig.profile
ff1465
index 2411f02..2dbc2e4 100644
ff1465
--- a/tests/data/profile_stability/rhel8/stig.profile
ff1465
+++ b/tests/data/profile_stability/rhel8/stig.profile
ff1465
@@ -360,6 +360,7 @@ selections:
ff1465
 - sudo_remove_nopasswd
ff1465
 - sudo_require_reauthentication
ff1465
 - sudo_restrict_privilege_elevation_to_authorized
ff1465
+- sudoers_default_includedir
ff1465
 - sudoers_validate_passwd
ff1465
 - sysctl_crypto_fips_enabled
ff1465
 - sysctl_fs_protected_hardlinks
ff1465
diff --git a/tests/data/profile_stability/rhel8/stig_gui.profile b/tests/data/profile_stability/rhel8/stig_gui.profile
ff1465
index f0a9601..cd76884 100644
ff1465
--- a/tests/data/profile_stability/rhel8/stig_gui.profile
ff1465
+++ b/tests/data/profile_stability/rhel8/stig_gui.profile
ff1465
@@ -371,6 +371,7 @@ selections:
ff1465
 - sudo_remove_nopasswd
ff1465
 - sudo_require_reauthentication
ff1465
 - sudo_restrict_privilege_elevation_to_authorized
ff1465
+- sudoers_default_includedir
ff1465
 - sudoers_validate_passwd
ff1465
 - sysctl_crypto_fips_enabled
ff1465
 - sysctl_fs_protected_hardlinks