Blame SOURCES/scap-security-guide-0.1.51-add_ansible_system_shutdown_PR_5761.patch

c99e83
From 2f6ceca58e64ab6c362afef629ac6ac235b0abe9 Mon Sep 17 00:00:00 2001
c99e83
From: Watson Sato <wsato@redhat.com>
c99e83
Date: Fri, 15 May 2020 11:52:35 +0200
c99e83
Subject: [PATCH 1/4] audit_rules_system_shutdown: Don't remove unrelated line
c99e83
c99e83
Very likey a copy-pasta error from bash remediation for
c99e83
audit_rules_immutable
c99e83
---
c99e83
 .../audit_rules_system_shutdown/bash/shared.sh                  | 2 +-
c99e83
 1 file changed, 1 insertion(+), 1 deletion(-)
c99e83
c99e83
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_system_shutdown/bash/shared.sh b/linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_system_shutdown/bash/shared.sh
c99e83
index 1c9748ce9b..b56513cdcd 100644
c99e83
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_system_shutdown/bash/shared.sh
c99e83
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_system_shutdown/bash/shared.sh
c99e83
@@ -8,7 +8,7 @@
c99e83
 # files to check if '-f .*' setting is present in that '*.rules' file already.
c99e83
 # If found, delete such occurrence since auditctl(8) manual page instructs the
c99e83
 # '-f 2' rule should be placed as the last rule in the configuration
c99e83
-find /etc/audit /etc/audit/rules.d -maxdepth 1 -type f -name '*.rules' -exec sed -i '/-e[[:space:]]\+.*/d' {} ';'
c99e83
+find /etc/audit /etc/audit/rules.d -maxdepth 1 -type f -name '*.rules' -exec sed -i '/-f[[:space:]]\+.*/d' {} ';'
c99e83
 
c99e83
 # Append '-f 2' requirement at the end of both:
c99e83
 # * /etc/audit/audit.rules file 		(for auditctl case)
c99e83
c99e83
From 189aed2c79620940438fc025a3cb9919cd8ee80a Mon Sep 17 00:00:00 2001
c99e83
From: Watson Sato <wsato@redhat.com>
c99e83
Date: Fri, 15 May 2020 12:12:21 +0200
c99e83
Subject: [PATCH 2/4] Add Ansible for audit_rules_system_shutdown
c99e83
c99e83
Along with very basic test scenarios
c99e83
---
c99e83
 .../ansible/shared.yml                        | 28 +++++++++++++++++++
c99e83
 .../tests/augen_correct.pass.sh               |  4 +++
c99e83
 .../tests/augen_e_2_immutable.fail.sh         |  3 ++
c99e83
 3 files changed, 35 insertions(+)
c99e83
 create mode 100644 linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_system_shutdown/ansible/shared.yml
c99e83
 create mode 100644 linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_system_shutdown/tests/augen_correct.pass.sh
c99e83
 create mode 100644 linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_system_shutdown/tests/augen_e_2_immutable.fail.sh
c99e83
c99e83
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_system_shutdown/ansible/shared.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_system_shutdown/ansible/shared.yml
c99e83
new file mode 100644
c99e83
index 0000000000..b9e8fa87fa
c99e83
--- /dev/null
c99e83
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_system_shutdown/ansible/shared.yml
c99e83
@@ -0,0 +1,28 @@
c99e83
+# platform = multi_platform_all
c99e83
+# reboot = true
c99e83
+# strategy = restrict
c99e83
+# complexity = low
c99e83
+# disruption = low
c99e83
+
c99e83
+- name: Collect all files from /etc/audit/rules.d with .rules extension
c99e83
+  find:
c99e83
+    paths: "/etc/audit/rules.d/"
c99e83
+    patterns: "*.rules"
c99e83
+  register: find_rules_d
c99e83
+
c99e83
+- name: Remove the -f option from all Audit config files
c99e83
+  lineinfile:
c99e83
+    path: "{{ item }}"
c99e83
+    regexp: '^\s*(?:-f)\s+.*$'
c99e83
+    state: absent
c99e83
+  loop: "{{ find_rules_d.files | map(attribute='path') | list + ['/etc/audit/audit.rules'] }}"
c99e83
+
c99e83
+- name: Add Audit -f option into /etc/audit/rules.d/immutable.rules and /etc/audit/audit.rules
c99e83
+  lineinfile:
c99e83
+    path: "{{ item }}"
c99e83
+    create: True
c99e83
+    line: "-f 2"
c99e83
+  loop:
c99e83
+    - "/etc/audit/audit.rules"
c99e83
+    - "/etc/audit/rules.d/immutable.rules"
c99e83
+
c99e83
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_system_shutdown/tests/augen_correct.pass.sh b/linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_system_shutdown/tests/augen_correct.pass.sh
c99e83
new file mode 100644
c99e83
index 0000000000..0587b937e0
c99e83
--- /dev/null
c99e83
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_system_shutdown/tests/augen_correct.pass.sh
c99e83
@@ -0,0 +1,4 @@
c99e83
+#!/bin/bash
c99e83
+
c99e83
+echo "-e 2" > /etc/audit/rules.d/immutable.rules
c99e83
+echo "-f 2" >> /etc/audit/rules.d/immutable.rules
c99e83
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_system_shutdown/tests/augen_e_2_immutable.fail.sh b/linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_system_shutdown/tests/augen_e_2_immutable.fail.sh
c99e83
new file mode 100644
c99e83
index 0000000000..fa5b7231df
c99e83
--- /dev/null
c99e83
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_system_shutdown/tests/augen_e_2_immutable.fail.sh
c99e83
@@ -0,0 +1,3 @@
c99e83
+#!/bin/bash
c99e83
+
c99e83
+echo "-e 2" > /etc/audit/rules.d/immutable.rules
c99e83
c99e83
From d693af1e00521d85b5745001aa13860bdac16632 Mon Sep 17 00:00:00 2001
c99e83
From: Watson Sato <wsato@redhat.com>
c99e83
Date: Fri, 15 May 2020 14:06:08 +0200
c99e83
Subject: [PATCH 3/4] Clarify audit_rules_immutable Ansible task name
c99e83
c99e83
---
c99e83
 .../audit_rules_immutable/ansible/shared.yml                    | 2 +-
c99e83
 1 file changed, 1 insertion(+), 1 deletion(-)
c99e83
c99e83
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_immutable/ansible/shared.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_immutable/ansible/shared.yml
c99e83
index 5ac7b3dabb..1cafb744cc 100644
c99e83
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_immutable/ansible/shared.yml
c99e83
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_immutable/ansible/shared.yml
c99e83
@@ -17,7 +17,7 @@
c99e83
     state: absent
c99e83
   loop: "{{ find_rules_d.files | map(attribute='path') | list + ['/etc/audit/audit.rules'] }}"
c99e83
 
c99e83
-- name: Insert configuration into /etc/audit/rules.d/immutable.rules and /etc/audit/audit.rules
c99e83
+- name: Add Audit -e option into /etc/audit/rules.d/immutable.rules and /etc/audit/audit.rules
c99e83
   lineinfile:
c99e83
     path: "{{ item }}"
c99e83
     create: True
c99e83
c99e83
From 92d38c1968059e53e3ab20f46f5ce0885a989aee Mon Sep 17 00:00:00 2001
c99e83
From: Watson Sato <wsato@redhat.com>
c99e83
Date: Tue, 19 May 2020 11:02:56 +0200
c99e83
Subject: [PATCH 4/4] Remove misleading comments in system shutdown fix
c99e83
c99e83
---
c99e83
 .../audit_rules_system_shutdown/bash/shared.sh            | 8 --------
c99e83
 1 file changed, 8 deletions(-)
c99e83
c99e83
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_system_shutdown/bash/shared.sh b/linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_system_shutdown/bash/shared.sh
c99e83
index b56513cdcd..a349bb1ca1 100644
c99e83
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_system_shutdown/bash/shared.sh
c99e83
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_system_shutdown/bash/shared.sh
c99e83
@@ -4,16 +4,8 @@
c99e83
 #
c99e83
 # /etc/audit/audit.rules,			(for auditctl case)
c99e83
 # /etc/audit/rules.d/*.rules			(for augenrules case)
c99e83
-#
c99e83
-# files to check if '-f .*' setting is present in that '*.rules' file already.
c99e83
-# If found, delete such occurrence since auditctl(8) manual page instructs the
c99e83
-# '-f 2' rule should be placed as the last rule in the configuration
c99e83
 find /etc/audit /etc/audit/rules.d -maxdepth 1 -type f -name '*.rules' -exec sed -i '/-f[[:space:]]\+.*/d' {} ';'
c99e83
 
c99e83
-# Append '-f 2' requirement at the end of both:
c99e83
-# * /etc/audit/audit.rules file 		(for auditctl case)
c99e83
-# * /etc/audit/rules.d/immutable.rules		(for augenrules case)
c99e83
-
c99e83
 for AUDIT_FILE in "/etc/audit/audit.rules" "/etc/audit/rules.d/immutable.rules"
c99e83
 do
c99e83
 	echo '' >> $AUDIT_FILE