Blame SOURCES/scap-security-guide-0.1.61-file_owner-PR_7789.patch

12e95e
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/file_ownership_audit_configuration/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/file_ownership_audit_configuration/rule.yml
12e95e
new file mode 100644
12e95e
index 00000000000..968ef336148
12e95e
--- /dev/null
12e95e
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/file_ownership_audit_configuration/rule.yml
12e95e
@@ -0,0 +1,39 @@
12e95e
+documentation_complete: true
12e95e
+
12e95e
+title: 'Audit Configuration Files Must Be Owned By Root'
12e95e
+
12e95e
+description: |-
12e95e
+    All audit configuration files must be owned by root user.
12e95e
+    {{{ describe_file_owner(file="/etc/audit/", owner="root") }}}
12e95e
+    {{{ describe_file_owner(file="/etc/audit/rules.d/", owner="root") }}}
12e95e
+
12e95e
+rationale: |-
12e95e
+    Without the capability to restrict which roles and individuals can
12e95e
+    select which events are audited, unauthorized personnel may be able
12e95e
+    to prevent the auditing of critical events.
12e95e
+    Misconfigured audits may degrade the system's performance by
12e95e
+    overwhelming the audit log. Misconfigured audits may also make it more
12e95e
+    difficult to establish, correlate, and investigate the events relating
12e95e
+    to an incident or identify those responsible for one.
12e95e
+
12e95e
+severity: medium
12e95e
+
12e95e
+references:
12e95e
+    disa: CCI-000171
12e95e
+    srg: SRG-OS-000063-GPOS-00032
12e95e
+    stigid@ubuntu2004: UBTU-20-010134
12e95e
+
12e95e
+ocil: |-
12e95e
+    {{{ describe_file_owner(file="/etc/audit/", owner="root") }}}
12e95e
+    {{{ describe_file_owner(file="/etc/audit/rules.d/", owner="root") }}}
12e95e
+
12e95e
+template:
12e95e
+    name: file_owner
12e95e
+    vars:
12e95e
+        filepath:
12e95e
+            - /etc/audit/
12e95e
+            - /etc/audit/rules.d/
12e95e
+        file_regex:
12e95e
+            - ^audit(\.rules|d\.conf)$
12e95e
+            - ^.*\.rules$
12e95e
+        fileuid: '0'
12e95e
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/file_ownership_audit_configuration/tests/correct_owner.pass.sh b/linux_os/guide/system/auditing/auditd_configure_rules/file_ownership_audit_configuration/tests/correct_owner.pass.sh
12e95e
new file mode 100644
12e95e
index 00000000000..4d67307a1ef
12e95e
--- /dev/null
12e95e
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/file_ownership_audit_configuration/tests/correct_owner.pass.sh
12e95e
@@ -0,0 +1,6 @@
12e95e
+#!/bin/bash
12e95e
+# packages = audit
12e95e
+
12e95e
+chown 0 /etc/audit/audit.rules
12e95e
+chown 0 /etc/audit/auditd.conf
12e95e
+chown 0 -R /etc/audit/rules.d/
12e95e
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/file_ownership_audit_configuration/tests/incorrect_owner.fail.sh b/linux_os/guide/system/auditing/auditd_configure_rules/file_ownership_audit_configuration/tests/incorrect_owner.fail.sh
12e95e
new file mode 100644
12e95e
index 00000000000..337074fab92
12e95e
--- /dev/null
12e95e
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/file_ownership_audit_configuration/tests/incorrect_owner.fail.sh
12e95e
@@ -0,0 +1,7 @@
12e95e
+#!/bin/bash
12e95e
+# packages = audit
12e95e
+
12e95e
+useradd testuser_123
12e95e
+chown testuser_123 /etc/audit/audit.rules
12e95e
+chown testuser_123 /etc/audit/auditd.conf
12e95e
+chown testuser_123 -R /etc/audit/rules.d/
12e95e
diff --git a/linux_os/guide/system/permissions/files/permissions_var_log_dir/file_owner_var_log_syslog/rule.yml b/linux_os/guide/system/permissions/files/permissions_var_log_dir/file_owner_var_log_syslog/rule.yml
12e95e
new file mode 100644
12e95e
index 00000000000..f1bf515455d
12e95e
--- /dev/null
12e95e
+++ b/linux_os/guide/system/permissions/files/permissions_var_log_dir/file_owner_var_log_syslog/rule.yml
12e95e
@@ -0,0 +1,27 @@
12e95e
+documentation_complete: true
12e95e
+
12e95e
+title: 'Verify User Who Owns /var/log/syslog File'
12e95e
+
12e95e
+description: '{{{ describe_file_owner(file="/var/log/syslog", owner="syslog") }}}'
12e95e
+
12e95e
+rationale: |-
12e95e
+    The <tt>/var/log/syslog</tt> file contains logs of error messages in
12e95e
+    the system and should only be accessed by authorized personnel.
12e95e
+
12e95e
+severity: medium
12e95e
+
12e95e
+references:
12e95e
+    disa: CCI-001314
12e95e
+    srg: SRG-OS-000206-GPOS-00084
12e95e
+    stigid@ubuntu2004: UBTU-20-010421
12e95e
+
12e95e
+ocil_clause: '{{{ ocil_clause_file_owner(file="/var/log/syslog", owner="syslog") }}}'
12e95e
+
12e95e
+ocil: |-
12e95e
+    {{{ ocil_file_owner(file="/var/log/syslog", owner="syslog") }}}
12e95e
+
12e95e
+template:
12e95e
+    name: file_owner
12e95e
+    vars:
12e95e
+        filepath: /var/log/syslog
12e95e
+        fileuid: '104'
12e95e
diff --git a/linux_os/guide/system/permissions/files/permissions_within_important_dirs/dir_ownership_binary_dirs/rule.yml b/linux_os/guide/system/permissions/files/permissions_within_important_dirs/dir_ownership_binary_dirs/rule.yml
12e95e
new file mode 100644
12e95e
index 00000000000..e2362388678
12e95e
--- /dev/null
12e95e
+++ b/linux_os/guide/system/permissions/files/permissions_within_important_dirs/dir_ownership_binary_dirs/rule.yml
12e95e
@@ -0,0 +1,55 @@
12e95e
+documentation_complete: true
12e95e
+
12e95e
+title: 'Verify that System Executable Have Root Ownership'
12e95e
+
12e95e
+description: |-
12e95e
+    
/bin
12e95e
+    /sbin
12e95e
+    /usr/bin
12e95e
+    /usr/sbin
12e95e
+    /usr/local/bin
12e95e
+    /usr/local/sbin
12e95e
+    All these directories should be owned by the <tt>root</tt> user.
12e95e
+    If any directory DIR in these directories is found
12e95e
+    to be owned by a user other than root, correct its ownership with the
12e95e
+    following command:
12e95e
+    
$ sudo chown root DIR
12e95e
+
12e95e
+rationale: |-
12e95e
+    System binaries are executed by privileged users as well as system services,
12e95e
+    and restrictive permissions are necessary to ensure that their
12e95e
+    execution of these programs cannot be co-opted.
12e95e
+
12e95e
+severity: medium
12e95e
+
12e95e
+references:
12e95e
+    disa: CCI-001495
12e95e
+    srg: SRG-OS-000258-GPOS-00099
12e95e
+    stigid@ubuntu2004: UBTU-20-010424
12e95e
+
12e95e
+ocil_clause: 'any system exectables directories are found to not be owned by root'
12e95e
+
12e95e
+ocil: |-
12e95e
+    System executables are stored in the following directories by default:
12e95e
+    
/bin
12e95e
+    /sbin
12e95e
+    /usr/bin
12e95e
+    /usr/local/bin
12e95e
+    /usr/local/sbin
12e95e
+    /usr/sbin
12e95e
+    For each of these directories, run the following command to find files
12e95e
+    not owned by root:
12e95e
+    
$ sudo find -L DIR/ ! -user root -type d -exec chown root {} \;
12e95e
+
12e95e
+template:
12e95e
+    name: file_owner
12e95e
+    vars:
12e95e
+        filepath:
12e95e
+            - /bin/
12e95e
+            - /sbin/
12e95e
+            - /usr/bin/
12e95e
+            - /usr/sbin/
12e95e
+            - /usr/local/bin/
12e95e
+            - /usr/local/sbin/
12e95e
+        recursive: 'true'
12e95e
+        fileuid: '0'
12e95e
diff --git a/linux_os/guide/system/permissions/files/permissions_within_important_dirs/file_ownership_audit_binaries/rule.yml b/linux_os/guide/system/permissions/files/permissions_within_important_dirs/file_ownership_audit_binaries/rule.yml
12e95e
new file mode 100644
12e95e
index 00000000000..0c7d9b313d5
12e95e
--- /dev/null
12e95e
+++ b/linux_os/guide/system/permissions/files/permissions_within_important_dirs/file_ownership_audit_binaries/rule.yml
12e95e
@@ -0,0 +1,77 @@
12e95e
+documentation_complete: true
12e95e
+
12e95e
+prodtype: ubuntu2004
12e95e
+
12e95e
+title: 'Verify that audit tools are owned by root'
12e95e
+
12e95e
+description: |-
12e95e
+    The {{{ full_name }}} operating system audit tools must have the proper
12e95e
+    ownership configured to protected against unauthorized access.
12e95e
+
12e95e
+    Verify it by running the following command:
12e95e
+    
$ stat -c "%n %U" /sbin/auditctl /sbin/aureport /sbin/ausearch /sbin/autrace /sbin/auditd /sbin/audispd /sbin/augenrules
12e95e
+
12e95e
+    /sbin/auditctl root
12e95e
+    /sbin/aureport root
12e95e
+    /sbin/ausearch root
12e95e
+    /sbin/autrace root
12e95e
+    /sbin/auditd root
12e95e
+    /sbin/audispd root
12e95e
+    /sbin/augenrules root
12e95e
+    
12e95e
+
12e95e
+    Audit tools needed to successfully view and manipulate audit information
12e95e
+    system activity and records. Audit tools include custom queries and report
12e95e
+    generators
12e95e
+
12e95e
+rationale: |-
12e95e
+    Protecting audit information also includes identifying and protecting the
12e95e
+    tools used to view and manipulate log data. Therefore, protecting audit
12e95e
+    tools is necessary to prevent unauthorized operation on audit information.
12e95e
+ 
12e95e
+    Operating systems providing tools to interface with audit information
12e95e
+    will leverage user permissions and roles identifying the user accessing the
12e95e
+    tools and the corresponding rights the user enjoys to make access decisions
12e95e
+    regarding the access to audit tools.
12e95e
+
12e95e
+severity: medium
12e95e
+
12e95e
+references:
12e95e
+    disa: CCI-001493,CCI-001494
12e95e
+    srg: SRG-OS-000256-GPiOS-00097,SRG-OS-000257-GPOS-00098
12e95e
+    stigid@ubuntu2004: UBTU-20-010200
12e95e
+
12e95e
+ocil: |-
12e95e
+    Verify it by running the following command:
12e95e
+    
$ stat -c "%n %U" /sbin/auditctl /sbin/aureport /sbin/ausearch /sbin/autrace /sbin/auditd /sbin/audispd /sbin/augenrules
12e95e
+
12e95e
+    /sbin/auditctl root
12e95e
+    /sbin/aureport root
12e95e
+    /sbin/ausearch root
12e95e
+    /sbin/autrace root
12e95e
+    /sbin/auditd root
12e95e
+    /sbin/audispd root
12e95e
+    /sbin/augenrules root
12e95e
+    
12e95e
+
12e95e
+    If the command does not return all the above lines, the missing ones
12e95e
+    need to be added.
12e95e
+
12e95e
+    Run the following command to correct the permissions of the missing
12e95e
+    entries:
12e95e
+    
$ sudo chown root [audit_tool] 
12e95e
+
12e95e
+    Replace "[audit_tool]" with each audit tool not owned by root.
12e95e
+
12e95e
+template:
12e95e
+    name: file_owner
12e95e
+    vars:
12e95e
+        filepath:
12e95e
+            - /sbin/auditctl
12e95e
+            - /sbin/aureport
12e95e
+            - /sbin/ausearch
12e95e
+            - /sbin/autrace
12e95e
+            - /sbin/auditd
12e95e
+            - /sbin/audispd
12e95e
+            - /sbin/augenrules
12e95e
+        fileuid: '0'
12e95e
diff --git a/shared/templates/file_owner/ansible.template b/shared/templates/file_owner/ansible.template
12e95e
index 80eaae8d50b..590c9fc6055 100644
12e95e
--- a/shared/templates/file_owner/ansible.template
12e95e
+++ b/shared/templates/file_owner/ansible.template
12e95e
@@ -25,7 +25,7 @@
12e95e
 
12e95e
 - name: Ensure owner on {{{ path }}} recursively
12e95e
   file:
12e95e
-    paths "{{{ path }}}"
12e95e
+    path: "{{{ path }}}"
12e95e
     state: directory
12e95e
     recurse: yes
12e95e
     owner: "{{{ FILEUID }}}"
12e95e
diff --git a/shared/templates/file_owner/tests/missing_file_test.pass.sh b/shared/templates/file_owner/tests/missing_file_test.pass.sh
12e95e
index 938e6b30819..4e3683f9dcf 100644
12e95e
--- a/shared/templates/file_owner/tests/missing_file_test.pass.sh
12e95e
+++ b/shared/templates/file_owner/tests/missing_file_test.pass.sh
12e95e
@@ -1,8 +1,18 @@
12e95e
 #!/bin/bash
12e95e
 #
12e95e
 
12e95e
-{{% if MISSING_FILE_PASS %}}
12e95e
-    rm -f {{{ FILEPATH }}}
12e95e
-{{% else %}}
12e95e
-    true
12e95e
-{{% endif %}}
12e95e
+{{% for path in FILEPATH %}}
12e95e
+    {{% if MISSING_FILE_PASS %}}
12e95e
+        rm -f {{{ path }}}
12e95e
+    {{% else %}}
12e95e
+        {{% if IS_DIRECTORY and RECURSIVE %}}
12e95e
+        find -L {{{ path }}} -type d -exec chown {{{ FILEUID }}} {} \;
12e95e
+        {{% else %}}
12e95e
+        if [ ! -f {{{ path }}} ]; then
12e95e
+            mkdir -p "$(dirname '{{{ path }}}')"
12e95e
+            touch {{{ path }}}
12e95e
+        fi
12e95e
+        chown {{{ FILEUID }}} {{{ path }}}
12e95e
+        {{% endif %}}
12e95e
+    {{% endif %}}
12e95e
+{{% endfor %}}