Blame SOURCES/scap-security-guide-0.1.55-add_sudoers_explicit_command_args-PR_6525.diff

618a7c
diff --git a/controls/anssi.yml b/controls/anssi.yml
618a7c
index 851993512..515a4a172 100644
618a7c
--- a/controls/anssi.yml
618a7c
+++ b/controls/anssi.yml
618a7c
@@ -850,7 +850,8 @@ controls:
618a7c
   - id: R63
618a7c
     level: intermediary
618a7c
     title: Explicit arguments in sudo specifications
618a7c
-    # rules: TBD
618a7c
+    rules:
618a7c
+    - sudoers_explicit_command_args
618a7c
 
618a7c
   - id: R64
618a7c
     level: intermediary
618a7c
diff --git a/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/oval/shared.xml b/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/oval/shared.xml
618a7c
new file mode 100644
618a7c
index 000000000..94a0cb421
618a7c
--- /dev/null
618a7c
+++ b/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/oval/shared.xml
618a7c
@@ -0,0 +1,25 @@
618a7c
+<def-group>
618a7c
+     <definition class="compliance" id="{{{ rule_id }}}" version="1">
618a7c
+     {{{ oval_metadata("Check that sudoers doesn't contain commands without arguments specified") }}}
618a7c
+     <criteria operator="AND">
618a7c
+	     <criterion comment="Make sure that no commands are without arguments" test_ref="test_{{{ rule_id }}}" />
618a7c
+     </criteria>
618a7c
+  </definition>
618a7c
+
618a7c
+  
618a7c
+  comment="Make sure that no command in user spec is without any argument"
618a7c
+	  id="test_{{{ rule_id }}}" version="1">
618a7c
+  <ind:object object_ref="object_{{{ rule_id }}}" />
618a7c
+  </ind:textfilecontent54_test>
618a7c
+
618a7c
+  <ind:textfilecontent54_object id="object_{{{ rule_id }}}" version="1">
618a7c
+    <ind:filepath operation="pattern match">^/etc/sudoers(\.d/.*)?$</ind:filepath>
618a7c
+    
618a7c
+         where a command is <runas spec>?<anything except ,>+,
618a7c
+           - ',' is a command delimiter, while
618a7c
+         The last capturing group holds the offending command without args.
618a7c
+    -->
618a7c
+    <ind:pattern operation="pattern match">^(?:\s*[^#=]+)=(?:\s*(?:\([^\)]+\))?\s*(?!\s*\()[^,\s]+(?:[ \t]+[^,\s]+)+[ \t]*,)*(\s*(?:\([^\)]+\))?\s*(?!\s*\()[^,\s]+[ \t]*(?:,|$))</ind:pattern>
618a7c
+    <ind:instance datatype="int">1</ind:instance>
618a7c
+  </ind:textfilecontent54_object>
618a7c
+</def-group>
618a7c
diff --git a/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/rule.yml b/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/rule.yml
618a7c
new file mode 100644
618a7c
index 000000000..a0590c8b0
618a7c
--- /dev/null
618a7c
+++ b/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/rule.yml
618a7c
@@ -0,0 +1,46 @@
618a7c
+documentation_complete: true
618a7c
+
618a7c
+title: "Explicit arguments in sudo specifications"
618a7c
+
618a7c
+description: |-
618a7c
+    All commands in the sudoers file must strictly specify the arguments allowed to be used for a given user.
618a7c
+    If the command is supposed to be executed only without arguments, pass "" as an argument in the corresponding user specification.
618a7c
+
618a7c
+rationale: |-
618a7c
+    Any argument can modify quite significantly the behavior of a program, whether regarding the
618a7c
+    realized operation (read, write, delete, etc.) or accessed resources (path in a file system tree). To
618a7c
+    avoid any possibility of misuse of a command by a user, the ambiguities must be removed at the
618a7c
+    level of its specification.
618a7c
+
618a7c
+    For example, on some systems, the kernel messages are only accessible by root.
618a7c
+    If a user nevertheless must have the privileges to read them, the argument of the dmesg command has to be restricted
618a7c
+    in order to prevent the user from flushing the buffer through the -c option:
618a7c
+    
618a7c
+    user ALL = dmesg ""
618a7c
+    
618a7c
+
618a7c
+severity: medium
618a7c
+
618a7c
+identifiers:
618a7c
+  cce@rhel7: CCE-83631-2
618a7c
+  cce@rhel8: CCE-83632-0
618a7c
+
618a7c
+references:
618a7c
+    anssi: BP28(R63)
618a7c
+
618a7c
+ocil_clause: '/etc/sudoers file contains user specifications that allow execution of commands with any arguments'
618a7c
+
618a7c
+ocil: |-
618a7c
+    To determine if arguments that commands can be executed with are restricted, run the following command:
618a7c
+    
$ sudo grep -PR '^(?:\s*[^#=]+)=(?:\s*(?:\([^\)]+\))?\s*(?!\s*\()[^,\s]+(?:[ \t]+[^,\s]+)+[ \t]*,)*(\s*(?:\([^\)]+\))?\s*(?!\s*\()[^,\s]+[ \t]*(?:,|$))' /etc/sudoers /etc/sudoers.d/
618a7c
+    The command should return no output.
618a7c
+
618a7c
+platform: sudo
618a7c
+
618a7c
+warnings:
618a7c
+  - general:
618a7c
+      This rule doesn't come with a remediation, as absence of arguments in the user spec doesn't mean that the command is intended to be executed with no arguments.
618a7c
+
618a7c
+  - general:
618a7c
+      The rule can produce false findings when an argument contains a comma - sudoers syntax allows comma escaping using backslash, but the check doesn't support that.
618a7c
+      For example, root ALL=(ALL) echo 1\,2 allows root to execute echo 1,2, but the check would interpret it as two commands echo 1\ and 2.
618a7c
diff --git a/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/commented.pass.sh b/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/commented.pass.sh
618a7c
new file mode 100644
618a7c
index 000000000..b0d05b2a5
618a7c
--- /dev/null
618a7c
+++ b/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/commented.pass.sh
618a7c
@@ -0,0 +1,5 @@
618a7c
+# platform = multi_platform_all
618a7c
+# packages = sudo
618a7c
+
618a7c
+echo '#jen,!fred		ALL, !SERVERS = !/bin/sh' > /etc/sudoers
618a7c
+echo '# somebody ALL=/bin/ls, (!bob,alice) !/bin/cat, /bin/dog' > /etc/sudoers.d/foo
618a7c
diff --git a/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/complex-1.fail.sh b/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/complex-1.fail.sh
618a7c
new file mode 100644
618a7c
index 000000000..c6f885f9f
618a7c
--- /dev/null
618a7c
+++ b/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/complex-1.fail.sh
618a7c
@@ -0,0 +1,5 @@
618a7c
+# platform = multi_platform_all
618a7c
+# packages = sudo
618a7c
+# remediation = none
618a7c
+
618a7c
+echo 'somebody ALL=/bin/ls, (!bob,alice) /bin/cat arg, /bin/dog' > /etc/sudoers
618a7c
diff --git a/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/complex-2.fail.sh b/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/complex-2.fail.sh
618a7c
new file mode 100644
618a7c
index 000000000..fce851f55
618a7c
--- /dev/null
618a7c
+++ b/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/complex-2.fail.sh
618a7c
@@ -0,0 +1,5 @@
618a7c
+# platform = multi_platform_all
618a7c
+# packages = sudo
618a7c
+# remediation = none
618a7c
+
618a7c
+echo 'nobody ALL=/bin/ls, (!bob,alice) /bin/dog, /bin/cat arg' > /etc/sudoers
618a7c
diff --git a/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/false_positive.fail.sh b/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/false_positive.fail.sh
618a7c
new file mode 100644
618a7c
index 000000000..baf66468d
618a7c
--- /dev/null
618a7c
+++ b/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/false_positive.fail.sh
618a7c
@@ -0,0 +1,9 @@
618a7c
+# platform = multi_platform_all
618a7c
+# remediation = none
618a7c
+# packages = sudo
618a7c
+
618a7c
+# The val1\,val2 is the first argument of the /bin/dog command that contains a comma.
618a7c
+# Our check tends to interpret the comma as commad delimiter, so the dog arg is val1\
618a7c
+# and val2 is another command in the user spec.
618a7c
+echo 'nobody ALL=/bin/ls "", (!bob,alice) /bin/dog val1\,val2, /bin/cat ""' > /etc/sudoers
618a7c
+
618a7c
diff --git a/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/simple.fail.sh b/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/simple.fail.sh
618a7c
new file mode 100644
618a7c
index 000000000..9a04a205a
618a7c
--- /dev/null
618a7c
+++ b/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/simple.fail.sh
618a7c
@@ -0,0 +1,5 @@
618a7c
+# platform = multi_platform_all
618a7c
+# packages = sudo
618a7c
+# remediation = none
618a7c
+
618a7c
+echo 'jen,!fred		ALL,SERVERS = /bin/sh ' > /etc/sudoers
618a7c
diff --git a/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/simple.pass.sh b/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/simple.pass.sh
618a7c
new file mode 100644
618a7c
index 000000000..4a3a7c94b
618a7c
--- /dev/null
618a7c
+++ b/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/simple.pass.sh
618a7c
@@ -0,0 +1,6 @@
618a7c
+# platform = multi_platform_all
618a7c
+# packages = sudo
618a7c
+
618a7c
+echo 'nobody ALL=/bin/ls "", (!bob,alice) /bin/dog arg, /bin/cat ""' > /etc/sudoers
618a7c
+echo 'jen,!fred		ALL,!SERVERS = /bin/sh arg' >> /etc/sudoers
618a7c
+echo 'nobody ALL=/bin/ls arg arg, (bob,!alice) /bin/dog arg, /bin/cat arg' > /etc/sudoers.d/foo
618a7c
diff --git a/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/sudoers_d.fail.sh b/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/sudoers_d.fail.sh
618a7c
new file mode 100644
618a7c
index 000000000..9643a3337
618a7c
--- /dev/null
618a7c
+++ b/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/sudoers_d.fail.sh
618a7c
@@ -0,0 +1,9 @@
618a7c
+# platform = multi_platform_all
618a7c
+# packages = sudo
618a7c
+# remediation = none
618a7c
+
618a7c
+echo 'nobody ALL=/bin/ls, (!bob,alice) /bin/dog arg, /bin/cat ""' > /etc/sudoers
618a7c
+echo 'jen,!fred		ALL,!SERVERS = /bin/sh arg' >> /etc/sudoers
618a7c
+echo 'nobody ALL=/bin/ls, (bob,!alice) /bin/dog arg, /bin/cat arg' > /etc/sudoers.d/foo
618a7c
+
618a7c
+echo 'user ALL = ALL' > /etc/sudoers.d/bar
618a7c
diff --git a/shared/references/cce-redhat-avail.txt b/shared/references/cce-redhat-avail.txt
618a7c
index 4dbec8255..94a116b59 100644
618a7c
--- a/shared/references/cce-redhat-avail.txt
618a7c
+++ b/shared/references/cce-redhat-avail.txt
618a7c
@@ -140,8 +140,6 @@ CCE-83626-2
618a7c
 CCE-83627-0
618a7c
 CCE-83628-8
618a7c
 CCE-83629-6
618a7c
-CCE-83631-2
618a7c
-CCE-83632-0
618a7c
 CCE-83633-8
618a7c
 CCE-83634-6
618a7c
 CCE-83635-3