Blame SOURCES/scap-security-guide-0.1.58-group_audit_syscalls-PR_7329.patch

9be3b2
From 54a0e7e0c0d00eacf21f68492517db8968d4e0b2 Mon Sep 17 00:00:00 2001
9be3b2
From: Watson Sato <wsato@redhat.com>
9be3b2
Date: Wed, 4 Aug 2021 15:01:45 +0200
9be3b2
Subject: [PATCH 01/31] Change fix_audit_syscall_rule to group syscalls
9be3b2
9be3b2
The function actually separated the syscalls into individual lines.
9be3b2
* Improve and extend rule skeleton matching with more explicit rule
9be3b2
  options for action, arch, auid and other filters.
9be3b2
* Make explicit the syscalls that can be grouped through the
9be3b2
  'syscall_groupings' parameter.
9be3b2
* Make they key to use more explicit, instead of implicit through
9be3b2
  'group'.
9be3b2
---
9be3b2
 .../fix_audit_syscall_rule.sh                 | 218 ++++++++----------
9be3b2
 .../bash.template                             |  26 ++-
9be3b2
 .../audit_rules_dac_modification/template.py  |   4 +
9be3b2
 .../bash.template                             |  13 +-
9be3b2
 .../template.py                               |  14 ++
9be3b2
 .../audit_rules_path_syscall/bash.template    |  13 +-
9be3b2
 .../audit_rules_path_syscall/template.py      |   4 +
9be3b2
 .../bash.template                             |  17 +-
9be3b2
 .../template.py                               |   4 +
9be3b2
 .../bash.template                             |  25 +-
9be3b2
 .../template.py                               |  14 ++
9be3b2
 11 files changed, 195 insertions(+), 157 deletions(-)
9be3b2
 create mode 100644 shared/templates/audit_rules_file_deletion_events/template.py
9be3b2
 create mode 100644 shared/templates/audit_rules_unsuccessful_file_modification/template.py
9be3b2
9be3b2
diff --git a/shared/bash_remediation_functions/fix_audit_syscall_rule.sh b/shared/bash_remediation_functions/fix_audit_syscall_rule.sh
9be3b2
index 4e16af2fb71..6bf5ac15436 100644
9be3b2
--- a/shared/bash_remediation_functions/fix_audit_syscall_rule.sh
9be3b2
+++ b/shared/bash_remediation_functions/fix_audit_syscall_rule.sh
9be3b2
@@ -10,40 +10,48 @@
9be3b2
 #
9be3b2
 # for further details.
9be3b2
 #
9be3b2
-# Expects five arguments (each of them is required) in the form of:
9be3b2
+# Expects seven arguments (each of them is required) in the form of:
9be3b2
 # * audit tool				tool used to load audit rules,
9be3b2
 # 					either 'auditctl', or 'augenrules
9be3b2
-# * audit rules' pattern		audit rule skeleton for same syscall
9be3b2
-# * syscall group			greatest common string this rule shares
9be3b2
-# 					with other rules from the same group
9be3b2
-# * architecture			architecture this rule is intended for
9be3b2
-# * full form of new rule to add	expected full form of audit rule as to be
9be3b2
-# 					added into audit.rules file
9be3b2
+# * action_arch_filters		The action and arch filters of the rule
9be3b2
+#					For example, "-a always,exit -F arch=b64"
9be3b2
+# * other_filters			Other filters that may characterize the rule:
9be3b2
+#					For example, "-F a2&03 -F path=/etc/passwd"
9be3b2
+# * auid_filters			The auid filters of the rule
9be3b2
+#					For example, "-F auid>=1000 -F auid!=unset"
9be3b2
+# * syscall					The syscall to ensure presense among audit rules
9be3b2
+#					For example, "chown"
9be3b2
+# * syscall_groupings		Other syscalls that can be grouped with 'syscall'
9be3b2
+#					as a space separated list.
9be3b2
+#					For example, "fchown lchown fchownat"
9be3b2
+# * key						The key to use when appending a new rule
9be3b2
 #
9be3b2
-# Note: The 2-th up to 4-th arguments are used to determine how many existing
9be3b2
+# Notes:
9be3b2
+# - The 2-nd up to 4-th arguments are used to determine how many existing
9be3b2
 # audit rules will be inspected for resemblance with the new audit rule
9be3b2
-# (5-th argument) the function is going to add. The rule's similarity check
9be3b2
-# is performed to optimize audit.rules definition (merge syscalls of the same
9be3b2
-# group into one rule) to avoid the "single-syscall-per-audit-rule" performance
9be3b2
-# penalty.
9be3b2
-#
9be3b2
-# Example call:
9be3b2
-#
9be3b2
-#	See e.g. 'audit_rules_file_deletion_events.sh' remediation script
9be3b2
-#
9be3b2
+# the function is going to add.
9be3b2
+# - The function's similarity check uses the 5-th argument to optimize audit
9be3b2
+# rules definitions (merge syscalls of the same group into one rule) to avoid
9be3b2
+# the "single-syscall-per-audit-rule" performance penalty.
9be3b2
+# - The key argument (7-th argument) is not used when the syscall is grouped to an
9be3b2
+# existing audit rule. The audit rule will retain the key it already had.
9be3b2
+
9be3b2
 function fix_audit_syscall_rule {
9be3b2
 
9be3b2
 # Load function arguments into local variables
9be3b2
 local tool="$1"
9be3b2
-local pattern="$2"
9be3b2
-local group="$3"
9be3b2
-local arch="$4"
9be3b2
-local full_rule="$5"
9be3b2
+local action_arch_filters="$2"
9be3b2
+local other_filters="$3"
9be3b2
+local auid_filters="$4"
9be3b2
+local syscall="$5"
9be3b2
+local syscall_grouping
9be3b2
+read -a syscall_grouping <<< "$6"
9be3b2
+local key="$7"
9be3b2
 
9be3b2
 # Check sanity of the input
9be3b2
-if [ $# -ne "5" ]
9be3b2
+if [ $# -ne "7" ]
9be3b2
 then
9be3b2
-	echo "Usage: fix_audit_syscall_rule 'tool' 'pattern' 'group' 'arch' 'full rule'"
9be3b2
+	echo "Usage: fix_audit_syscall_rule 'tool' 'action_arch_filters' 'other_filters' 'auid_filters' 'syscall' 'syscall_grouping' 'key'"
9be3b2
 	echo "Aborting."
9be3b2
 	exit 1
9be3b2
 fi
9be3b2
@@ -74,16 +82,17 @@ then
9be3b2
 # file to the list of files to be inspected
9be3b2
 elif [ "$tool" == 'auditctl' ]
9be3b2
 then
9be3b2
+	default_file="/etc/audit/audit.rules"
9be3b2
 	files_to_inspect+=('/etc/audit/audit.rules' )
9be3b2
 # If audit tool is 'augenrules', then check if the audit rule is defined
9be3b2
 # If rule is defined, add '/etc/audit/rules.d/*.rules' to the list for inspection
9be3b2
 # If rule isn't defined yet, add '/etc/audit/rules.d/$key.rules' to the list for inspection
9be3b2
 elif [ "$tool" == 'augenrules' ]
9be3b2
 then
9be3b2
-	# Extract audit $key from audit rule so we can use it later
9be3b2
 	matches=()
9be3b2
-	key=$(expr "$full_rule" : '.*-k[[:space:]]\([^[:space:]]\+\)' '|' "$full_rule" : '.*-F[[:space:]]key=\([^[:space:]]\+\)')
9be3b2
-	readarray -t matches < <(sed -s -n -e "\;${pattern};!d" -e "/${arch}/!d" -e "/${group}/!d;F" /etc/audit/rules.d/*.rules)
9be3b2
+	default_file="/etc/audit/rules.d/${key}.rules"
9be3b2
+	# As other_filters may include paths, lets use a different delimiter for it
9be3b2
+	readarray -t matches < <(sed -s -n -e "/${action_arch_filters}/!d" -e "\#${other_filters}#!d" -e "/${auid_filters}/!d" /etc/audit/rules.d/*.rules)
9be3b2
 	if [ $? -ne 0 ]
9be3b2
 	then
9be3b2
 		retval=1
9be3b2
@@ -106,115 +115,88 @@ then
9be3b2
 fi
9be3b2
 
9be3b2
 #
9be3b2
-# Indicator that we want to append $full_rule into $audit_file by default
9be3b2
+# Indicator that we want to append $full_rule into $audit_file or edit a rule in it
9be3b2
 local append_expected_rule=0
9be3b2
 
9be3b2
 for audit_file in "${files_to_inspect[@]}"
9be3b2
 do
9be3b2
-	# Filter existing $audit_file rules' definitions to select those that:
9be3b2
-	# * follow the rule pattern, and
9be3b2
-	# * meet the hardware architecture requirement, and
9be3b2
-	# * are current syscall group specific
9be3b2
-	readarray -t existing_rules < <(sed -e "\;${pattern};!d" -e "/${arch}/!d" -e "/${group}/!d"  "$audit_file")
9be3b2
+	# Filter existing $audit_file rules' definitions to select those that satisfy the rule pattern,
9be3b2
+	# i.e, collect rules that match:
9be3b2
+	# * the action, list and arch, (2-nd argument)
9be3b2
+	# * the other filters, (3-rd argument)
9be3b2
+	# * the auid filters, (4-rd argument)
9be3b2
+	readarray -t similar_rules < <(sed -e "/${action_arch_filters}/!d"  -e "\#${other_filters}#!d" -e "/${auid_filters}/!d" "$audit_file")
9be3b2
 	if [ $? -ne 0 ]
9be3b2
 	then
9be3b2
 		retval=1
9be3b2
 	fi
9be3b2
 
9be3b2
-	# Process rules found case-by-case
9be3b2
-	for rule in "${existing_rules[@]}"
9be3b2
+	local candidate_rules=()
9be3b2
+	# Filter out rules that have more fields then required. This will remove rules more specific than the required scope
9be3b2
+	for s_rule in "${similar_rules[@]}"
9be3b2
+	do
9be3b2
+		# Strip all the options and fields we know of,
9be3b2
+		# than check if there was any field left over
9be3b2
+		extra_fields=$(sed -E -e "s/${action_arch_filters}//"  -e "s#${other_filters}##" -e "s/${auid_filters}//" -e "s/((:?-S [[:alnum:],]+)+)//g" -e "s/-F key=\w+|-k \w+//"<<< "$s_rule")
9be3b2
+		grep -q -- "-F" <<< "$extra_fields"
9be3b2
+		if [ $? -ne 0 ]
9be3b2
+		then
9be3b2
+			candidate_rules+=("$s_rule")
9be3b2
+		fi
9be3b2
+	done
9be3b2
+
9be3b2
+	# Check if the syscall we want is present in any of the similar existing rules
9be3b2
+	for rule in "${candidate_rules[@]}"
9be3b2
 	do
9be3b2
-		# Found rule is for same arch & key, but differs (e.g. in count of -S arguments)
9be3b2
-		if [ "${rule}" != "${full_rule}" ]
9be3b2
+		rule_syscalls=$(echo "$rule" | grep -o -P '(-S [\w,]+)+' | xargs)
9be3b2
+		grep -q -- "\b${syscall}\b" <<< "$rule_syscalls"
9be3b2
+		if [ $? -eq 0 ]
9be3b2
 		then
9be3b2
-			# If so, isolate just '(-S \w)+' substring of that rule
9be3b2
-			rule_syscalls=$(echo "$rule" | grep -o -P '(-S \w+ )+')
9be3b2
-			# Check if list of '-S syscall' arguments of that rule is subset
9be3b2
-			# of '-S syscall' list of expected $full_rule
9be3b2
-			if grep -q -- "$rule_syscalls" <<< "$full_rule"
9be3b2
+			# We found a rule with the syscall we want
9be3b2
+			return $retval
9be3b2
+		fi
9be3b2
+
9be3b2
+		# Check if this rule can be grouped with our target syscall and keep track of it
9be3b2
+		for syscall_g in "${syscall_grouping[@]}"
9be3b2
+		do
9be3b2
+			if grep -q -- "\b${syscall_g}\b" <<< "$rule_syscalls"
9be3b2
 			then
9be3b2
-				# Rule is covered (i.e. the list of -S syscalls for this rule is
9be3b2
-				# subset of -S syscalls of $full_rule => existing rule can be deleted
9be3b2
-				# Thus delete the rule from audit.rules & our array
9be3b2
-				sed -i -e "\;${rule};d" "$audit_file"
9be3b2
-				if [ $? -ne 0 ]
9be3b2
-				then
9be3b2
-					retval=1
9be3b2
-				fi
9be3b2
-				existing_rules=("${existing_rules[@]//$rule/}")
9be3b2
-			else
9be3b2
-				# Rule isn't covered by $full_rule - it besides -S syscall arguments
9be3b2
-				# for this group contains also -S syscall arguments for other syscall
9be3b2
-				# group. Example: '-S lchown -S fchmod -S fchownat' => group='chown'
9be3b2
-				# since 'lchown' & 'fchownat' share 'chown' substring
9be3b2
-				# Therefore:
9be3b2
-				# * 1) delete the original rule from audit.rules
9be3b2
-				# (original '-S lchown -S fchmod -S fchownat' rule would be deleted)
9be3b2
-				# * 2) delete the -S syscall arguments for this syscall group, but
9be3b2
-				# keep those not belonging to this syscall group
9be3b2
-				# (original '-S lchown -S fchmod -S fchownat' would become '-S fchmod'
9be3b2
-				# * 3) append the modified (filtered) rule again into audit.rules
9be3b2
-				# if the same rule not already present
9be3b2
-				#
9be3b2
-				# 1) Delete the original rule
9be3b2
-				sed -i -e "\;${rule};d" "$audit_file"
9be3b2
-				if [ $? -ne 0 ]
9be3b2
-				then
9be3b2
-					retval=1
9be3b2
-				fi
9be3b2
-
9be3b2
-				# 2) Delete syscalls for this group, but keep those from other groups
9be3b2
-				# Convert current rule syscall's string into array splitting by '-S' delimiter
9be3b2
-				IFS_BKP="$IFS"
9be3b2
-				IFS=$'-S'
9be3b2
-				read -a rule_syscalls_as_array <<< "$rule_syscalls"
9be3b2
-				# Reset IFS back to default
9be3b2
-				IFS="$IFS_BKP"
9be3b2
-				# Splitting by "-S" can't be replaced by the readarray functionality easily
9be3b2
-
9be3b2
-				# Declare new empty string to hold '-S syscall' arguments from other groups
9be3b2
-				new_syscalls_for_rule=''
9be3b2
-				# Walk through existing '-S syscall' arguments
9be3b2
-				for syscall_arg in "${rule_syscalls_as_array[@]}"
9be3b2
-				do
9be3b2
-					# Skip empty $syscall_arg values
9be3b2
-					if [ "$syscall_arg" == '' ]
9be3b2
-					then
9be3b2
-						continue
9be3b2
-					fi
9be3b2
-					# If the '-S syscall' doesn't belong to current group add it to the new list
9be3b2
-					# (together with adding '-S' delimiter back for each of such item found)
9be3b2
-					if grep -q -v -- "$group" <<< "$syscall_arg"
9be3b2
-					then
9be3b2
-						new_syscalls_for_rule="$new_syscalls_for_rule -S $syscall_arg"
9be3b2
-					fi
9be3b2
-				done
9be3b2
-				# Replace original '-S syscall' list with the new one for this rule
9be3b2
-				updated_rule=${rule//$rule_syscalls/$new_syscalls_for_rule}
9be3b2
-				# Squeeze repeated whitespace characters in rule definition (if any) into one
9be3b2
-				updated_rule=$(echo "$updated_rule" | tr -s '[:space:]')
9be3b2
-				# 3) Append the modified / filtered rule again into audit.rules
9be3b2
-				#    (but only in case it's not present yet to prevent duplicate definitions)
9be3b2
-				if ! grep -q -- "$updated_rule" "$audit_file"
9be3b2
-				then
9be3b2
-					echo "$updated_rule" >> "$audit_file"
9be3b2
-				fi
9be3b2
+				local file_to_edit=${audit_file}
9be3b2
+				local rule_to_edit=${rule}
9be3b2
+				local rule_syscalls_to_edit=${rule_syscalls}
9be3b2
 			fi
9be3b2
-		else
9be3b2
-			# $audit_file already contains the expected rule form for this
9be3b2
-			# architecture & key => don't insert it second time
9be3b2
-			append_expected_rule=1
9be3b2
-		fi
9be3b2
+		done
9be3b2
 	done
9be3b2
+done
9be3b2
+
9be3b2
+
9be3b2
+# We checked all rules that matched the expected resemblance patter (action, arch & auid)
9be3b2
+# At this point we know if we need to either append the $full_rule or group
9be3b2
+# the syscall together with an exsiting rule
9be3b2
 
9be3b2
-	# We deleted all rules that were subset of the expected one for this arch & key.
9be3b2
-	# Also isolated rules containing system calls not from this system calls group.
9be3b2
-	# Now append the expected rule if it's not present in $audit_file yet
9be3b2
-	if [[ ${append_expected_rule} -eq "0" ]]
9be3b2
+# Append the full_rule if it cannot be grouped to any other rule
9be3b2
+if [ -z ${rule_to_edit+x} ]
9be3b2
+then
9be3b2
+	# Build full_rule while avoid adding double spaces when other_filters is empty
9be3b2
+	local full_rule="$action_arch_filters -S $syscall $([[ $other_filters ]] && echo "$other_filters ")$auid_filters -F key=$key"
9be3b2
+	echo "$full_rule" >> "$default_file"
9be3b2
+else
9be3b2
+	# Check if the syscalls are declared as a comma separated list or
9be3b2
+	# as multiple -S parameters
9be3b2
+	if grep -q -- "," <<< "${rule_syscalls_to_edit}"
9be3b2
 	then
9be3b2
-		echo "$full_rule" >> "$audit_file"
9be3b2
+		new_grouped_syscalls="${rule_syscalls_to_edit},${syscall}"
9be3b2
+	else
9be3b2
+		new_grouped_syscalls="${rule_syscalls_to_edit} -S ${syscall}"
9be3b2
 	fi
9be3b2
-done
9be3b2
+
9be3b2
+	# Group the syscall in the rule
9be3b2
+	sed -i -e "\#${rule_to_edit}#s#${rule_syscalls_to_edit}#${new_grouped_syscalls}#" "$file_to_edit"
9be3b2
+	if [ $? -ne 0 ]
9be3b2
+	then
9be3b2
+		retval=1
9be3b2
+	fi
9be3b2
+fi
9be3b2
 
9be3b2
 return $retval
9be3b2
 
9be3b2
diff --git a/shared/templates/audit_rules_dac_modification/bash.template b/shared/templates/audit_rules_dac_modification/bash.template
9be3b2
index d64d264635c..b2de8d355e1 100644
9be3b2
--- a/shared/templates/audit_rules_dac_modification/bash.template
9be3b2
+++ b/shared/templates/audit_rules_dac_modification/bash.template
9be3b2
@@ -9,25 +9,31 @@
9be3b2
 
9be3b2
 for ARCH in "${RULE_ARCHS[@]}"
9be3b2
 do
9be3b2
-	PATTERN="-a always,exit -F arch=$ARCH -S {{{ ATTR }}} -F auid>=.*"
9be3b2
-	GROUP="perm_mod"
9be3b2
-	FULL_RULE="-a always,exit -F arch=$ARCH -S {{{ ATTR }}} -F auid>={{{ auid }}} -F auid!=unset -F key=perm_mod"
9be3b2
+	ACTION_ARCH_FILTERS="-a always,exit -F arch=$ARCH"
9be3b2
+	OTHER_FILTERS=""
9be3b2
+	AUID_FILTERS="-F auid>={{{ auid }}} -F auid!=unset"
9be3b2
+	SYSCALL="{{{ ATTR }}}"
9be3b2
+	KEY="perm_mod"
9be3b2
+	SYSCALL_GROUPING="{{{ SYSCALL_GROUPING }}}"
9be3b2
 
9be3b2
 	# Perform the remediation for both possible tools: 'auditctl' and 'augenrules'
9be3b2
-	fix_audit_syscall_rule "augenrules" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
-	fix_audit_syscall_rule "auditctl" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
+	fix_audit_syscall_rule "augenrules" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
+	fix_audit_syscall_rule "auditctl" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
 done
9be3b2
 
9be3b2
 
9be3b2
 {{% if CHECK_ROOT_USER %}}
9be3b2
 for ARCH in "${RULE_ARCHS[@]}"
9be3b2
 do
9be3b2
-	PATTERN="-a always,exit -F arch=$ARCH -S {{{ ATTR }}} -F auid=0.*"
9be3b2
-	GROUP="perm_mod"
9be3b2
-	FULL_RULE="-a always,exit -F arch=$ARCH -S {{{ ATTR }}} -F auid=0 -F key=perm_mod"
9be3b2
+	ACTION_ARCH_FILTERS="-a always,exit -F arch=$ARCH"
9be3b2
+	OTHER_FILTERS=""
9be3b2
+	AUID_FILTERS="-F auid=0"
9be3b2
+	SYSCALL="{{{ ATTR }}}"
9be3b2
+	KEY="perm_mod"
9be3b2
+	SYSCALL_GROUPING="{{{ SYSCALL_GROUPING }}}"
9be3b2
 
9be3b2
 	# Perform the remediation for both possible tools: 'auditctl' and 'augenrules'
9be3b2
-	fix_audit_syscall_rule "augenrules" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
-	fix_audit_syscall_rule "auditctl" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
+	fix_audit_syscall_rule "augenrules" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
+	fix_audit_syscall_rule "auditctl" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
 done
9be3b2
 {{% endif %}}
9be3b2
diff --git a/shared/templates/audit_rules_dac_modification/template.py b/shared/templates/audit_rules_dac_modification/template.py
9be3b2
index e12e9c27e56..7dc53e81f7d 100644
9be3b2
--- a/shared/templates/audit_rules_dac_modification/template.py
9be3b2
+++ b/shared/templates/audit_rules_dac_modification/template.py
9be3b2
@@ -3,5 +3,9 @@
9be3b2
 
9be3b2
 def preprocess(data, lang):
9be3b2
     data["check_root_user"] = parse_template_boolean_value(data, parameter="check_root_user", default_value=False)
9be3b2
+    if lang == "bash":
9be3b2
+        if "syscall_grouping" in data:
9be3b2
+            # Make it easier to tranform the syscall_grouping into a Bash array
9be3b2
+            data["syscall_grouping"] = " ".join(data["syscall_grouping"])
9be3b2
 
9be3b2
     return data
9be3b2
diff --git a/shared/templates/audit_rules_file_deletion_events/bash.template b/shared/templates/audit_rules_file_deletion_events/bash.template
9be3b2
index 851b0fd43e3..b5b4c46a7cd 100644
9be3b2
--- a/shared/templates/audit_rules_file_deletion_events/bash.template
9be3b2
+++ b/shared/templates/audit_rules_file_deletion_events/bash.template
9be3b2
@@ -9,10 +9,13 @@
9be3b2
 
9be3b2
 for ARCH in "${RULE_ARCHS[@]}"
9be3b2
 do
9be3b2
-	PATTERN="-a always,exit -F arch=$ARCH -S {{{ NAME }}}.*"
9be3b2
-	GROUP="delete"
9be3b2
-	FULL_RULE="-a always,exit -F arch=$ARCH -S {{{ NAME }}} -F auid>={{{ auid }}} -F auid!=unset -F key=delete"
9be3b2
+	ACTION_ARCH_FILTERS="-a always,exit -F arch=$ARCH"
9be3b2
+	OTHER_FILTERS=""
9be3b2
+	AUID_FILTERS="-F auid>={{{ auid }}} -F auid!=unset"
9be3b2
+	SYSCALL="{{{ NAME }}}"
9be3b2
+	KEY="delete"
9be3b2
+	SYSCALL_GROUPING="{{{ SYSCALL_GROUPING }}}"
9be3b2
 	# Perform the remediation for both possible tools: 'auditctl' and 'augenrules'
9be3b2
-	fix_audit_syscall_rule "auditctl" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
-	fix_audit_syscall_rule "augenrules" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
+	fix_audit_syscall_rule "augenrules" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
+	fix_audit_syscall_rule "auditctl" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
 done
9be3b2
diff --git a/shared/templates/audit_rules_file_deletion_events/template.py b/shared/templates/audit_rules_file_deletion_events/template.py
9be3b2
new file mode 100644
9be3b2
index 00000000000..7be137c1eb9
9be3b2
--- /dev/null
9be3b2
+++ b/shared/templates/audit_rules_file_deletion_events/template.py
9be3b2
@@ -0,0 +1,14 @@
9be3b2
+import ssg.utils
9be3b2
+
9be3b2
+
9be3b2
+def _audit_rules_file_deletion_events(data, lang):
9be3b2
+    if lang == "bash":
9be3b2
+        if "syscall_grouping" in data:
9be3b2
+            # Make it easier to tranform the syscall_grouping into a Bash array
9be3b2
+            data["syscall_grouping"] = " ".join(data["syscall_grouping"])
9be3b2
+    return data
9be3b2
+
9be3b2
+
9be3b2
+def preprocess(data, lang):
9be3b2
+    return _audit_rules_file_deletion_events(data, lang)
9be3b2
+
9be3b2
diff --git a/shared/templates/audit_rules_path_syscall/bash.template b/shared/templates/audit_rules_path_syscall/bash.template
9be3b2
index 656d168ddd2..676f6c37deb 100644
9be3b2
--- a/shared/templates/audit_rules_path_syscall/bash.template
9be3b2
+++ b/shared/templates/audit_rules_path_syscall/bash.template
9be3b2
@@ -9,10 +9,13 @@
9be3b2
 
9be3b2
 for ARCH in "${RULE_ARCHS[@]}"
9be3b2
 do
9be3b2
-	PATTERN="-a always,exit -F arch=$ARCH -S {{{ SYSCALL }}} -F {{{ POS }}}&03 -F path={{{ PATH }}}.*"
9be3b2
-	GROUP="modify"
9be3b2
-	FULL_RULE="-a always,exit -F arch=$ARCH -S {{{ SYSCALL }}} -F {{{ POS }}}&03 -F path={{{ PATH }}} -F auid>={{{ auid }}} -F auid!=unset -F key=modify"
9be3b2
+	ACTION_ARCH_FILTERS="-a always,exit -F arch=$ARCH"
9be3b2
+	OTHER_FILTERS="-F {{{ POS }}}&03 -F path={{{ PATH }}}"
9be3b2
+	AUID_FILTERS="-F auid>={{{ auid }}} -F auid!=unset"
9be3b2
+	SYSCALL="{{{ SYSCALL }}}"
9be3b2
+	KEY="user-modify"
9be3b2
+	SYSCALL_GROUPING="{{{ SYSCALL_GROUPING }}}"
9be3b2
 	# Perform the remediation for both possible tools: 'auditctl' and 'augenrules'
9be3b2
-	fix_audit_syscall_rule "auditctl" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
-	fix_audit_syscall_rule "augenrules" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
+	fix_audit_syscall_rule "augenrules" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
+	fix_audit_syscall_rule "auditctl" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
 done
9be3b2
diff --git a/shared/templates/audit_rules_path_syscall/template.py b/shared/templates/audit_rules_path_syscall/template.py
9be3b2
index beb25a6e69d..7e0877a02b9 100644
9be3b2
--- a/shared/templates/audit_rules_path_syscall/template.py
9be3b2
+++ b/shared/templates/audit_rules_path_syscall/template.py
9be3b2
@@ -7,4 +7,8 @@ def preprocess(data, lang):
9be3b2
         # remove root slash made into '_'
9be3b2
         pathid = pathid[1:]
9be3b2
         data["pathid"] = pathid
9be3b2
+    elif lang == "bash":
9be3b2
+        if "syscall_grouping" in data:
9be3b2
+            # Make it easier to tranform the syscall_grouping into a Bash array
9be3b2
+            data["syscall_grouping"] = " ".join(data["syscall_grouping"])
9be3b2
     return data
9be3b2
diff --git a/shared/templates/audit_rules_privileged_commands/bash.template b/shared/templates/audit_rules_privileged_commands/bash.template
9be3b2
index d03a92061cb..bd9d4d12484 100644
9be3b2
--- a/shared/templates/audit_rules_privileged_commands/bash.template
9be3b2
+++ b/shared/templates/audit_rules_privileged_commands/bash.template
9be3b2
@@ -1,16 +1,17 @@
9be3b2
 {{%- if product in ["rhel8", "rhel9", "sle12", "sle15"] %}}
9be3b2
-  {{%- set perm_x="-F perm=x " %}}
9be3b2
+  {{%- set perm_x=" -F perm=x " %}}
9be3b2
 {{%- endif %}}
9be3b2
 # platform = multi_platform_rhel,multi_platform_fedora,multi_platform_ol,multi_platform_rhv
9be3b2
 
9be3b2
 # Include source function library.
9be3b2
 . /usr/share/scap-security-guide/remediation_functions
9be3b2
 
9be3b2
-PATTERN="-a always,exit -F path={{{ PATH }}}\\s\\+.*"
9be3b2
-GROUP="privileged"
9be3b2
-# Although the fix doesn't use ARCH, we reset it because it could have been set by some other remediation
9be3b2
-ARCH=""
9be3b2
-FULL_RULE="-a always,exit -F path={{{ PATH }}} {{{ perm_x }}}-F auid>={{{ auid }}} -F auid!=unset -F key=privileged"
9be3b2
+ACTION_ARCH_FILTERS="-a always,exit"
9be3b2
+OTHER_FILTERS="-F path={{{ PATH }}}{{{ perm_x }}}"
9be3b2
+AUID_FILTERS="-F auid>={{{ auid }}} -F auid!=unset"
9be3b2
+SYSCALL="{{{ ATTR }}}"
9be3b2
+KEY="privileged"
9be3b2
+SYSCALL_GROUPING="{{{ SYSCALL_GROUPING }}}"
9be3b2
 # Perform the remediation for both possible tools: 'auditctl' and 'augenrules'
9be3b2
-fix_audit_syscall_rule "auditctl" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
-fix_audit_syscall_rule "augenrules" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
+fix_audit_syscall_rule "augenrules" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
+fix_audit_syscall_rule "auditctl" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
diff --git a/shared/templates/audit_rules_privileged_commands/template.py b/shared/templates/audit_rules_privileged_commands/template.py
9be3b2
index 444b2aab083..43302a6690a 100644
9be3b2
--- a/shared/templates/audit_rules_privileged_commands/template.py
9be3b2
+++ b/shared/templates/audit_rules_privileged_commands/template.py
9be3b2
@@ -15,4 +15,8 @@ def preprocess(data, lang):
9be3b2
         if npath[0] == '_':
9be3b2
             npath = npath[1:]
9be3b2
         data["normalized_path"] = npath
9be3b2
+    elif lang == "bash":
9be3b2
+        if "syscall_grouping" in data:
9be3b2
+            # Make it easier to tranform the syscall_grouping into a Bash array
9be3b2
+            data["syscall_grouping"] = " ".join(data["syscall_grouping"])
9be3b2
     return data
9be3b2
diff --git a/shared/templates/audit_rules_unsuccessful_file_modification/bash.template b/shared/templates/audit_rules_unsuccessful_file_modification/bash.template
9be3b2
index daf146f7eb5..4adaa86fd58 100644
9be3b2
--- a/shared/templates/audit_rules_unsuccessful_file_modification/bash.template
9be3b2
+++ b/shared/templates/audit_rules_unsuccessful_file_modification/bash.template
9be3b2
@@ -7,22 +7,25 @@
9be3b2
 # Retrieve hardware architecture of the underlying system
9be3b2
 [ "$(getconf LONG_BIT)" = "32" ] && RULE_ARCHS=("b32") || RULE_ARCHS=("b32" "b64")
9be3b2
 
9be3b2
+AUID_FILTERS="-F auid>={{{ auid }}} -F auid!=unset"
9be3b2
+SYSCALL="{{{ NAME }}}"
9be3b2
+KEY="access"
9be3b2
+SYSCALL_GROUPING="{{{ SYSCALL_GROUPING }}}"
9be3b2
+
9be3b2
 for ARCH in "${RULE_ARCHS[@]}"
9be3b2
 do
9be3b2
-	PATTERN="-a always,exit -F arch=$ARCH -S {{{ NAME }}} -F exit=-EACCES.*"
9be3b2
-	GROUP="access"
9be3b2
-	FULL_RULE="-a always,exit -F arch=$ARCH -S {{{ NAME }}} -F exit=-EACCES -F auid>={{{ auid }}} -F auid!=unset -F key=access"
9be3b2
+	ACTION_ARCH_FILTERS="-a always,exit -F arch=$ARCH"
9be3b2
+	OTHER_FILTERS="-F exit=-EACCES"
9be3b2
 	# Perform the remediation for both possible tools: 'auditctl' and 'augenrules'
9be3b2
-	fix_audit_syscall_rule "auditctl" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
-	fix_audit_syscall_rule "augenrules" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
+	fix_audit_syscall_rule "augenrules" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
+	fix_audit_syscall_rule "auditctl" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
 done
9be3b2
 
9be3b2
 for ARCH in "${RULE_ARCHS[@]}"
9be3b2
 do
9be3b2
-        PATTERN="-a always,exit -F arch=$ARCH -S {{{ NAME }}} -F exit=-EPERM.*"
9be3b2
-        GROUP="access"
9be3b2
-        FULL_RULE="-a always,exit -F arch=$ARCH -S {{{ NAME }}} -F exit=-EPERM -F auid>={{{ auid }}} -F auid!=unset -F key=access"
9be3b2
-        # Perform the remediation for both possible tools: 'auditctl' and 'augenrules'
9be3b2
-        fix_audit_syscall_rule "auditctl" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
-        fix_audit_syscall_rule "augenrules" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
+	ACTION_ARCH_FILTERS="-a always,exit -F arch=$ARCH"
9be3b2
+	OTHER_FILTERS="-F exit=-EPERM"
9be3b2
+	# Perform the remediation for both possible tools: 'auditctl' and 'augenrules'
9be3b2
+	fix_audit_syscall_rule "augenrules" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
+	fix_audit_syscall_rule "auditctl" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
 done
9be3b2
diff --git a/shared/templates/audit_rules_unsuccessful_file_modification/template.py b/shared/templates/audit_rules_unsuccessful_file_modification/template.py
9be3b2
new file mode 100644
9be3b2
index 00000000000..a4e58609f66
9be3b2
--- /dev/null
9be3b2
+++ b/shared/templates/audit_rules_unsuccessful_file_modification/template.py
9be3b2
@@ -0,0 +1,14 @@
9be3b2
+import ssg.utils
9be3b2
+
9be3b2
+
9be3b2
+def _audit_rules_unsuccessful_file_modification(data, lang):
9be3b2
+    if lang == "bash":
9be3b2
+        if "syscall_grouping" in data:
9be3b2
+            # Make it easier to tranform the syscall_grouping into a Bash array
9be3b2
+            data["syscall_grouping"] = " ".join(data["syscall_grouping"])
9be3b2
+    return data
9be3b2
+
9be3b2
+
9be3b2
+def preprocess(data, lang):
9be3b2
+    return _audit_rules_unsuccessful_file_modification(data, lang)
9be3b2
+
9be3b2
9be3b2
From 4c682eadba5ec03ed1204ba9d1b190634bd855d8 Mon Sep 17 00:00:00 2001
9be3b2
From: Watson Sato <wsato@redhat.com>
9be3b2
Date: Wed, 4 Aug 2021 15:32:18 +0200
9be3b2
Subject: [PATCH 02/31] Set syscall grouping for chmod rules
9be3b2
9be3b2
---
9be3b2
 .../audit_rules_dac_modification_chmod/rule.yml               | 4 ++++
9be3b2
 .../audit_rules_dac_modification_fchmod/rule.yml              | 4 ++++
9be3b2
 .../audit_rules_dac_modification_fchmodat/rule.yml            | 4 ++++
9be3b2
 3 files changed, 12 insertions(+)
9be3b2
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_chmod/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_chmod/rule.yml
9be3b2
index bc3e47523f5..07d37b18aa3 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_chmod/rule.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_chmod/rule.yml
9be3b2
@@ -76,3 +76,7 @@ template:
9be3b2
     name: audit_rules_dac_modification
9be3b2
     vars:
9be3b2
         attr: chmod
9be3b2
+        syscall_grouping:
9be3b2
+          - chmod
9be3b2
+          - fchmod
9be3b2
+          - fchmodat
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_fchmod/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_fchmod/rule.yml
9be3b2
index ed4d88cb0c6..6c3cc5592ac 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_fchmod/rule.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_fchmod/rule.yml
9be3b2
@@ -74,3 +74,7 @@ template:
9be3b2
     name: audit_rules_dac_modification
9be3b2
     vars:
9be3b2
         attr: fchmod
9be3b2
+        syscall_grouping:
9be3b2
+          - chmod
9be3b2
+          - fchmod
9be3b2
+          - fchmodat
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_fchmodat/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_fchmodat/rule.yml
9be3b2
index 2db3878939a..3e51d482a9c 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_fchmodat/rule.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_fchmodat/rule.yml
9be3b2
@@ -74,3 +74,7 @@ template:
9be3b2
     name: audit_rules_dac_modification
9be3b2
     vars:
9be3b2
         attr: fchmodat
9be3b2
+        syscall_grouping:
9be3b2
+          - chmod
9be3b2
+          - fchmod
9be3b2
+          - fchmodat
9be3b2
9be3b2
From eaaaa86b8a07082cdc92d967af09e0908ef22905 Mon Sep 17 00:00:00 2001
9be3b2
From: Watson Sato <wsato@redhat.com>
9be3b2
Date: Wed, 4 Aug 2021 15:32:52 +0200
9be3b2
Subject: [PATCH 03/31] Set syscall grouping for chown rules
9be3b2
9be3b2
---
9be3b2
 .../audit_rules_dac_modification_chown/rule.yml              | 5 +++++
9be3b2
 .../audit_rules_dac_modification_fchown/rule.yml             | 5 +++++
9be3b2
 .../audit_rules_dac_modification_fchownat/rule.yml           | 5 +++++
9be3b2
 .../audit_rules_dac_modification_lchown/rule.yml             | 5 +++++
9be3b2
 4 files changed, 20 insertions(+)
9be3b2
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_chown/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_chown/rule.yml
9be3b2
index 6b3236cf953..e2d9944a3bb 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_chown/rule.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_chown/rule.yml
9be3b2
@@ -74,3 +74,8 @@ template:
9be3b2
     name: audit_rules_dac_modification
9be3b2
     vars:
9be3b2
         attr: chown
9be3b2
+        syscall_grouping:
9be3b2
+          - chown
9be3b2
+          - fchown
9be3b2
+          - fchownat
9be3b2
+          - lchown
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_fchown/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_fchown/rule.yml
9be3b2
index 37dfb89ef29..d89875fcaab 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_fchown/rule.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_fchown/rule.yml
9be3b2
@@ -77,3 +77,8 @@ template:
9be3b2
     name: audit_rules_dac_modification
9be3b2
     vars:
9be3b2
         attr: fchown
9be3b2
+        syscall_grouping:
9be3b2
+          - chown
9be3b2
+          - fchown
9be3b2
+          - fchownat
9be3b2
+          - lchown
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_fchownat/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_fchownat/rule.yml
9be3b2
index f75ac769d8d..e6caaeb5c9f 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_fchownat/rule.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_fchownat/rule.yml
9be3b2
@@ -74,3 +74,8 @@ template:
9be3b2
     name: audit_rules_dac_modification
9be3b2
     vars:
9be3b2
         attr: fchownat
9be3b2
+        syscall_grouping:
9be3b2
+          - chown
9be3b2
+          - fchown
9be3b2
+          - fchownat
9be3b2
+          - lchown
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_lchown/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_lchown/rule.yml
9be3b2
index edc053bfb30..190509c0c8d 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_lchown/rule.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_lchown/rule.yml
9be3b2
@@ -74,3 +74,8 @@ template:
9be3b2
     name: audit_rules_dac_modification
9be3b2
     vars:
9be3b2
         attr: lchown
9be3b2
+        syscall_grouping:
9be3b2
+          - chown
9be3b2
+          - fchown
9be3b2
+          - fchownat
9be3b2
+          - lchown
9be3b2
9be3b2
From b1d747cb65e6e869be2b3c99d295cb6f75c98b61 Mon Sep 17 00:00:00 2001
9be3b2
From: Watson Sato <wsato@redhat.com>
9be3b2
Date: Wed, 4 Aug 2021 15:33:21 +0200
9be3b2
Subject: [PATCH 04/31] Set syscall groupings for set/remove xattr rules
9be3b2
9be3b2
---
9be3b2
 .../audit_rules_dac_modification_fremovexattr/rule.yml     | 7 +++++++
9be3b2
 .../audit_rules_dac_modification_fsetxattr/rule.yml        | 7 +++++++
9be3b2
 .../audit_rules_dac_modification_lremovexattr/rule.yml     | 7 +++++++
9be3b2
 .../audit_rules_dac_modification_lsetxattr/rule.yml        | 7 +++++++
9be3b2
 .../audit_rules_dac_modification_removexattr/rule.yml      | 7 +++++++
9be3b2
 .../audit_rules_dac_modification_setxattr/rule.yml         | 7 +++++++
9be3b2
 6 files changed, 42 insertions(+)
9be3b2
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_fremovexattr/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_fremovexattr/rule.yml
9be3b2
index 5bd1b25eafb..b9ad3c7942e 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_fremovexattr/rule.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_fremovexattr/rule.yml
9be3b2
@@ -93,3 +93,10 @@ template:
9be3b2
         attr: fremovexattr
9be3b2
         check_root_user@rhel8: "true"
9be3b2
         check_root_user@rhel9: "true"
9be3b2
+        syscall_grouping:
9be3b2
+          - fremovexattr
9be3b2
+          - lremovexattr
9be3b2
+          - removexattr
9be3b2
+          - fsetxattr
9be3b2
+          - lsetxattr
9be3b2
+          - setxattr
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_fsetxattr/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_fsetxattr/rule.yml
9be3b2
index 410dd8a5efa..cedf05f9765 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_fsetxattr/rule.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_fsetxattr/rule.yml
9be3b2
@@ -88,3 +88,10 @@ template:
9be3b2
         attr: fsetxattr
9be3b2
         check_root_user@rhel8: "true"
9be3b2
         check_root_user@rhel9: "true"
9be3b2
+        syscall_grouping:
9be3b2
+          - fremovexattr
9be3b2
+          - lremovexattr
9be3b2
+          - removexattr
9be3b2
+          - fsetxattr
9be3b2
+          - lsetxattr
9be3b2
+          - setxattr
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_lremovexattr/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_lremovexattr/rule.yml
9be3b2
index 947c768efd8..ffdacdf09e7 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_lremovexattr/rule.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_lremovexattr/rule.yml
9be3b2
@@ -93,3 +93,10 @@ template:
9be3b2
         attr: lremovexattr
9be3b2
         check_root_user@rhel8: "true"
9be3b2
         check_root_user@rhel9: "true"
9be3b2
+        syscall_grouping:
9be3b2
+          - fremovexattr
9be3b2
+          - lremovexattr
9be3b2
+          - removexattr
9be3b2
+          - fsetxattr
9be3b2
+          - lsetxattr
9be3b2
+          - setxattr
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_lsetxattr/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_lsetxattr/rule.yml
9be3b2
index ed1fd3715d2..3662262f674 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_lsetxattr/rule.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_lsetxattr/rule.yml
9be3b2
@@ -86,3 +86,10 @@ template:
9be3b2
         attr: lsetxattr
9be3b2
         check_root_user@rhel8: "true"
9be3b2
         check_root_user@rhel9: "true"
9be3b2
+        syscall_grouping:
9be3b2
+          - fremovexattr
9be3b2
+          - lremovexattr
9be3b2
+          - removexattr
9be3b2
+          - fsetxattr
9be3b2
+          - lsetxattr
9be3b2
+          - setxattr
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_removexattr/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_removexattr/rule.yml
9be3b2
index 61e69432d1a..ac9d3492aad 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_removexattr/rule.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_removexattr/rule.yml
9be3b2
@@ -92,3 +92,10 @@ template:
9be3b2
         attr: removexattr
9be3b2
         check_root_user@rhel8: "true"
9be3b2
         check_root_user@rhel9: "true"
9be3b2
+        syscall_grouping:
9be3b2
+          - fremovexattr
9be3b2
+          - lremovexattr
9be3b2
+          - removexattr
9be3b2
+          - fsetxattr
9be3b2
+          - lsetxattr
9be3b2
+          - setxattr
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_setxattr/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_setxattr/rule.yml
9be3b2
index 12489a74a01..b661a1f99ae 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_setxattr/rule.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_dac_actions/audit_rules_dac_modification_setxattr/rule.yml
9be3b2
@@ -88,3 +88,10 @@ template:
9be3b2
         attr: setxattr
9be3b2
         check_root_user@rhel8: "true"
9be3b2
         check_root_user@rhel9: "true"
9be3b2
+        syscall_grouping:
9be3b2
+          - fremovexattr
9be3b2
+          - lremovexattr
9be3b2
+          - removexattr
9be3b2
+          - fsetxattr
9be3b2
+          - lsetxattr
9be3b2
+          - setxattr
9be3b2
9be3b2
From 46a087995ffe3d49644d8e8adcbc9b1747947339 Mon Sep 17 00:00:00 2001
9be3b2
From: Watson Sato <wsato@redhat.com>
9be3b2
Date: Wed, 4 Aug 2021 15:34:08 +0200
9be3b2
Subject: [PATCH 05/31] Set syscall groupings for remove and delete rules
9be3b2
9be3b2
---
9be3b2
 .../audit_rules_file_deletion_events_rename/rule.yml        | 6 ++++++
9be3b2
 .../audit_rules_file_deletion_events_renameat/rule.yml      | 6 ++++++
9be3b2
 .../audit_rules_file_deletion_events_rmdir/rule.yml         | 6 ++++++
9be3b2
 .../audit_rules_file_deletion_events_unlink/rule.yml        | 6 ++++++
9be3b2
 .../audit_rules_file_deletion_events_unlinkat/rule.yml      | 6 ++++++
9be3b2
 5 files changed, 30 insertions(+)
9be3b2
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_deletion_events/audit_rules_file_deletion_events_rename/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_deletion_events/audit_rules_file_deletion_events_rename/rule.yml
9be3b2
index 9dd83f6dbae..d6dcb8694ad 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_deletion_events/audit_rules_file_deletion_events_rename/rule.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_deletion_events/audit_rules_file_deletion_events_rename/rule.yml
9be3b2
@@ -59,3 +59,9 @@ template:
9be3b2
     name: audit_rules_file_deletion_events
9be3b2
     vars:
9be3b2
         name: rename
9be3b2
+        syscall_grouping:
9be3b2
+          - unlink
9be3b2
+          - unlinkat
9be3b2
+          - rename
9be3b2
+          - renameat
9be3b2
+          - rmdir
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_deletion_events/audit_rules_file_deletion_events_renameat/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_deletion_events/audit_rules_file_deletion_events_renameat/rule.yml
9be3b2
index cd9aa9f5e61..5f583992c48 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_deletion_events/audit_rules_file_deletion_events_renameat/rule.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_deletion_events/audit_rules_file_deletion_events_renameat/rule.yml
9be3b2
@@ -59,3 +59,9 @@ template:
9be3b2
     name: audit_rules_file_deletion_events
9be3b2
     vars:
9be3b2
         name: renameat
9be3b2
+        syscall_grouping:
9be3b2
+          - unlink
9be3b2
+          - unlinkat
9be3b2
+          - rename
9be3b2
+          - renameat
9be3b2
+          - rmdir
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_deletion_events/audit_rules_file_deletion_events_rmdir/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_deletion_events/audit_rules_file_deletion_events_rmdir/rule.yml
9be3b2
index 6e0bb755b0d..5368c9dad58 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_deletion_events/audit_rules_file_deletion_events_rmdir/rule.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_deletion_events/audit_rules_file_deletion_events_rmdir/rule.yml
9be3b2
@@ -57,3 +57,9 @@ template:
9be3b2
     name: audit_rules_file_deletion_events
9be3b2
     vars:
9be3b2
         name: rmdir
9be3b2
+        syscall_grouping:
9be3b2
+          - unlink
9be3b2
+          - unlinkat
9be3b2
+          - rename
9be3b2
+          - renameat
9be3b2
+          - rmdir
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_deletion_events/audit_rules_file_deletion_events_unlink/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_deletion_events/audit_rules_file_deletion_events_unlink/rule.yml
9be3b2
index be4e328b7c8..ecdca27b14d 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_deletion_events/audit_rules_file_deletion_events_unlink/rule.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_deletion_events/audit_rules_file_deletion_events_unlink/rule.yml
9be3b2
@@ -59,3 +59,9 @@ template:
9be3b2
     name: audit_rules_file_deletion_events
9be3b2
     vars:
9be3b2
         name: unlink
9be3b2
+        syscall_grouping:
9be3b2
+          - unlink
9be3b2
+          - unlinkat
9be3b2
+          - rename
9be3b2
+          - renameat
9be3b2
+          - rmdir
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_deletion_events/audit_rules_file_deletion_events_unlinkat/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_deletion_events/audit_rules_file_deletion_events_unlinkat/rule.yml
9be3b2
index eaf8f1e08bd..158d24dc708 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_deletion_events/audit_rules_file_deletion_events_unlinkat/rule.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_deletion_events/audit_rules_file_deletion_events_unlinkat/rule.yml
9be3b2
@@ -59,3 +59,9 @@ template:
9be3b2
     name: audit_rules_file_deletion_events
9be3b2
     vars:
9be3b2
         name: unlinkat
9be3b2
+        syscall_grouping:
9be3b2
+          - unlink
9be3b2
+          - unlinkat
9be3b2
+          - rename
9be3b2
+          - renameat
9be3b2
+          - rmdir
9be3b2
9be3b2
From 121afe11a8c050b7c07c8a2595da898dc8f7a1b6 Mon Sep 17 00:00:00 2001
9be3b2
From: Watson Sato <wsato@redhat.com>
9be3b2
Date: Wed, 4 Aug 2021 15:34:44 +0200
9be3b2
Subject: [PATCH 06/31] Set syscall grouping for create, open and truncate
9be3b2
 rules
9be3b2
9be3b2
---
9be3b2
 .../rule.yml                                               | 7 +++++++
9be3b2
 .../rule.yml                                               | 7 +++++++
9be3b2
 .../rule.yml                                               | 7 +++++++
9be3b2
 .../rule.yml                                               | 7 +++++++
9be3b2
 .../rule.yml                                               | 7 +++++++
9be3b2
 .../rule.yml                                               | 7 +++++++
9be3b2
 6 files changed, 42 insertions(+)
9be3b2
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_creat/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_creat/rule.yml
9be3b2
index 08cc99133a4..5c751cb230e 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_creat/rule.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_creat/rule.yml
9be3b2
@@ -79,3 +79,10 @@ template:
9be3b2
     name: audit_rules_unsuccessful_file_modification
9be3b2
     vars:
9be3b2
         name: creat
9be3b2
+        syscall_grouping:
9be3b2
+          - creat
9be3b2
+          - ftruncate
9be3b2
+          - truncate
9be3b2
+          - open
9be3b2
+          - openat
9be3b2
+          - open_by_handle_at
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_ftruncate/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_ftruncate/rule.yml
9be3b2
index e9b688b9b4e..76bcea154bf 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_ftruncate/rule.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_ftruncate/rule.yml
9be3b2
@@ -82,3 +82,10 @@ template:
9be3b2
     name: audit_rules_unsuccessful_file_modification
9be3b2
     vars:
9be3b2
         name: ftruncate
9be3b2
+        syscall_grouping:
9be3b2
+          - creat
9be3b2
+          - ftruncate
9be3b2
+          - truncate
9be3b2
+          - open
9be3b2
+          - openat
9be3b2
+          - open_by_handle_at
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_open/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_open/rule.yml
9be3b2
index 6e242270074..7c6764d2a01 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_open/rule.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_open/rule.yml
9be3b2
@@ -82,3 +82,10 @@ template:
9be3b2
     name: audit_rules_unsuccessful_file_modification
9be3b2
     vars:
9be3b2
         name: open
9be3b2
+        syscall_grouping:
9be3b2
+          - creat
9be3b2
+          - ftruncate
9be3b2
+          - truncate
9be3b2
+          - open
9be3b2
+          - openat
9be3b2
+          - open_by_handle_at
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_open_by_handle_at/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_open_by_handle_at/rule.yml
9be3b2
index 2b6008fce1f..9bb5ffe3fcb 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_open_by_handle_at/rule.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_open_by_handle_at/rule.yml
9be3b2
@@ -78,3 +78,10 @@ template:
9be3b2
     name: audit_rules_unsuccessful_file_modification
9be3b2
     vars:
9be3b2
         name: open_by_handle_at
9be3b2
+        syscall_grouping:
9be3b2
+          - creat
9be3b2
+          - ftruncate
9be3b2
+          - truncate
9be3b2
+          - open
9be3b2
+          - openat
9be3b2
+          - open_by_handle_at
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_openat/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_openat/rule.yml
9be3b2
index 308e3da789a..c99656cc744 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_openat/rule.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_openat/rule.yml
9be3b2
@@ -82,3 +82,10 @@ template:
9be3b2
     name: audit_rules_unsuccessful_file_modification
9be3b2
     vars:
9be3b2
         name: openat
9be3b2
+        syscall_grouping:
9be3b2
+          - creat
9be3b2
+          - ftruncate
9be3b2
+          - truncate
9be3b2
+          - open
9be3b2
+          - openat
9be3b2
+          - open_by_handle_at
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_truncate/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_truncate/rule.yml
9be3b2
index 6ab8d289176..12771beb7e0 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_truncate/rule.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_truncate/rule.yml
9be3b2
@@ -81,3 +81,10 @@ template:
9be3b2
     name: audit_rules_unsuccessful_file_modification
9be3b2
     vars:
9be3b2
         name: truncate
9be3b2
+        syscall_grouping:
9be3b2
+          - creat
9be3b2
+          - ftruncate
9be3b2
+          - truncate
9be3b2
+          - open
9be3b2
+          - openat
9be3b2
+          - open_by_handle_at
9be3b2
9be3b2
From 9dd2d39f3b5b6e0ac9f961718d8e3d7e1a02e101 Mon Sep 17 00:00:00 2001
9be3b2
From: Watson Sato <wsato@redhat.com>
9be3b2
Date: Wed, 4 Aug 2021 17:15:16 +0200
9be3b2
Subject: [PATCH 07/31] Print filenames in sed command
9be3b2
9be3b2
The ";F" was not a typo!
9be3b2
Hopefully this makes it more explicit the function of '-e "F"'.
9be3b2
---
9be3b2
 .../bash_remediation_functions/fix_audit_syscall_rule.sh | 9 ++-------
9be3b2
 1 file changed, 2 insertions(+), 7 deletions(-)
9be3b2
9be3b2
diff --git a/shared/bash_remediation_functions/fix_audit_syscall_rule.sh b/shared/bash_remediation_functions/fix_audit_syscall_rule.sh
9be3b2
index 6bf5ac15436..791e64d05c1 100644
9be3b2
--- a/shared/bash_remediation_functions/fix_audit_syscall_rule.sh
9be3b2
+++ b/shared/bash_remediation_functions/fix_audit_syscall_rule.sh
9be3b2
@@ -1,4 +1,3 @@
9be3b2
-# Function to fix syscall audit rule for given system call. It is
9be3b2
 # based on example audit syscall rule definitions as outlined in
9be3b2
 # /usr/share/doc/audit-2.3.7/stig.rules file provided with the audit
9be3b2
 # package. It will combine multiple system calls belonging to the same
9be3b2
@@ -89,18 +88,14 @@ then
9be3b2
 # If rule isn't defined yet, add '/etc/audit/rules.d/$key.rules' to the list for inspection
9be3b2
 elif [ "$tool" == 'augenrules' ]
9be3b2
 then
9be3b2
-	matches=()
9be3b2
 	default_file="/etc/audit/rules.d/${key}.rules"
9be3b2
 	# As other_filters may include paths, lets use a different delimiter for it
9be3b2
-	readarray -t matches < <(sed -s -n -e "/${action_arch_filters}/!d" -e "\#${other_filters}#!d" -e "/${auid_filters}/!d" /etc/audit/rules.d/*.rules)
9be3b2
+	# The "F" script expression tells sed to print the filenames where the expressions matched
9be3b2
+	readarray -t files_to_inspect < <(sed -s -n -e "/${action_arch_filters}/!d" -e "\#${other_filters}#!d" -e "/${auid_filters}/!d" -e "F" /etc/audit/rules.d/*.rules)
9be3b2
 	if [ $? -ne 0 ]
9be3b2
 	then
9be3b2
 		retval=1
9be3b2
 	fi
9be3b2
-	for match in "${matches[@]}"
9be3b2
-	do
9be3b2
-		files_to_inspect+=("${match}")
9be3b2
-	done
9be3b2
 	# Case when particular rule isn't defined in /etc/audit/rules.d/*.rules yet
9be3b2
 	if [ ${#files_to_inspect[@]} -eq "0" ]
9be3b2
 	then
9be3b2
9be3b2
From 56194cadf92fdfa020f650bf0152cf65270e4631 Mon Sep 17 00:00:00 2001
9be3b2
From: Watson Sato <wsato@redhat.com>
9be3b2
Date: Thu, 5 Aug 2021 00:35:47 +0200
9be3b2
Subject: [PATCH 08/31] Handle cases where the rule has no syscall
9be3b2
9be3b2
When syscall is not set, just don't add the -S parameter.
9be3b2
The audit privileged commands use the fix_audit_syscall_rule despite
9be3b2
not adding a -S syscall.
9be3b2
Same situation happens for directory_access_var_log_audit.
9be3b2
---
9be3b2
 .../bash/shared.sh                            | 13 +++--
9be3b2
 .../fix_audit_syscall_rule.sh                 | 51 ++++++++++++-------
9be3b2
 .../bash.template                             |  2 +-
9be3b2
 3 files changed, 41 insertions(+), 25 deletions(-)
9be3b2
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/directory_access_var_log_audit/bash/shared.sh b/linux_os/guide/system/auditing/auditd_configure_rules/directory_access_var_log_audit/bash/shared.sh
9be3b2
index 53f2923d687..0c4e8ffdbd3 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/directory_access_var_log_audit/bash/shared.sh
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/directory_access_var_log_audit/bash/shared.sh
9be3b2
@@ -3,9 +3,12 @@
9be3b2
 # Include source function library.
9be3b2
 . /usr/share/scap-security-guide/remediation_functions
9be3b2
 
9be3b2
-PATTERN="-a always,exit -F path=/var/log/audit/\\s\\+.*"
9be3b2
-GROUP="access-audit-trail"
9be3b2
-FULL_RULE="-a always,exit -F dir=/var/log/audit/ -F perm=r -F auid>={{{ auid }}} -F auid!=unset -F key=access-audit-trail"
9be3b2
+ACTION_ARCH_FILTERS="-a always,exit -F arch=$ARCH"
9be3b2
+OTHER_FILTERS="-F dir=/var/log/audit/ -F perm=r"
9be3b2
+AUID_FILTERS="-F auid>={{{ auid }}} -F auid!=unset"
9be3b2
+SYSCALL=""
9be3b2
+KEY="access-audit-trail"
9be3b2
+SYSCALL_GROUPING=""
9be3b2
 # Perform the remediation for both possible tools: 'auditctl' and 'augenrules'
9be3b2
-fix_audit_syscall_rule "auditctl" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
-fix_audit_syscall_rule "augenrules" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
+fix_audit_syscall_rule "augenrules" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
+fix_audit_syscall_rule "auditctl" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
diff --git a/shared/bash_remediation_functions/fix_audit_syscall_rule.sh b/shared/bash_remediation_functions/fix_audit_syscall_rule.sh
9be3b2
index 791e64d05c1..69430416da3 100644
9be3b2
--- a/shared/bash_remediation_functions/fix_audit_syscall_rule.sh
9be3b2
+++ b/shared/bash_remediation_functions/fix_audit_syscall_rule.sh
9be3b2
@@ -140,28 +140,37 @@ do
9be3b2
 		fi
9be3b2
 	done
9be3b2
 
9be3b2
-	# Check if the syscall we want is present in any of the similar existing rules
9be3b2
-	for rule in "${candidate_rules[@]}"
9be3b2
-	do
9be3b2
-		rule_syscalls=$(echo "$rule" | grep -o -P '(-S [\w,]+)+' | xargs)
9be3b2
-		grep -q -- "\b${syscall}\b" <<< "$rule_syscalls"
9be3b2
-		if [ $? -eq 0 ]
9be3b2
-		then
9be3b2
-			# We found a rule with the syscall we want
9be3b2
-			return $retval
9be3b2
-		fi
9be3b2
-
9be3b2
-		# Check if this rule can be grouped with our target syscall and keep track of it
9be3b2
-		for syscall_g in "${syscall_grouping[@]}"
9be3b2
+	if [[ $syscall ]]
9be3b2
+	then
9be3b2
+		# Check if the syscall we want is present in any of the similar existing rules
9be3b2
+		for rule in "${candidate_rules[@]}"
9be3b2
 		do
9be3b2
-			if grep -q -- "\b${syscall_g}\b" <<< "$rule_syscalls"
9be3b2
+			rule_syscalls=$(echo "$rule" | grep -o -P '(-S [\w,]+)+' | xargs)
9be3b2
+			grep -q -- "\b${syscall}\b" <<< "$rule_syscalls"
9be3b2
+			if [ $? -eq 0 ]
9be3b2
 			then
9be3b2
-				local file_to_edit=${audit_file}
9be3b2
-				local rule_to_edit=${rule}
9be3b2
-				local rule_syscalls_to_edit=${rule_syscalls}
9be3b2
+				# We found a rule with the syscall we want
9be3b2
+				return $retval
9be3b2
 			fi
9be3b2
+
9be3b2
+			# Check if this rule can be grouped with our target syscall and keep track of it
9be3b2
+			for syscall_g in "${syscall_grouping[@]}"
9be3b2
+			do
9be3b2
+				if grep -q -- "\b${syscall_g}\b" <<< "$rule_syscalls"
9be3b2
+				then
9be3b2
+					local file_to_edit=${audit_file}
9be3b2
+					local rule_to_edit=${rule}
9be3b2
+					local rule_syscalls_to_edit=${rule_syscalls}
9be3b2
+				fi
9be3b2
+			done
9be3b2
 		done
9be3b2
-	done
9be3b2
+	else
9be3b2
+		# If there is any candidate rule, it is compliant.
9be3b2
+		if [[ $candidate_rules ]]
9be3b2
+		then
9be3b2
+			return $retval
9be3b2
+		fi
9be3b2
+	fi
9be3b2
 done
9be3b2
 
9be3b2
 
9be3b2
@@ -173,7 +182,11 @@ done
9be3b2
 if [ -z ${rule_to_edit+x} ]
9be3b2
 then
9be3b2
 	# Build full_rule while avoid adding double spaces when other_filters is empty
9be3b2
-	local full_rule="$action_arch_filters -S $syscall $([[ $other_filters ]] && echo "$other_filters ")$auid_filters -F key=$key"
9be3b2
+	if [[ $syscall ]]
9be3b2
+	then
9be3b2
+		local syscall_filters="-S $syscall"
9be3b2
+	fi
9be3b2
+	local full_rule="$action_arch_filters $([[ $syscall_filters ]] && echo "$syscall_filters ")$([[ $other_filters ]] && echo "$other_filters ")$auid_filters -F key=$key"
9be3b2
 	echo "$full_rule" >> "$default_file"
9be3b2
 else
9be3b2
 	# Check if the syscalls are declared as a comma separated list or
9be3b2
diff --git a/shared/templates/audit_rules_privileged_commands/bash.template b/shared/templates/audit_rules_privileged_commands/bash.template
9be3b2
index bd9d4d12484..b5879085a45 100644
9be3b2
--- a/shared/templates/audit_rules_privileged_commands/bash.template
9be3b2
+++ b/shared/templates/audit_rules_privileged_commands/bash.template
9be3b2
@@ -9,7 +9,7 @@
9be3b2
 ACTION_ARCH_FILTERS="-a always,exit"
9be3b2
 OTHER_FILTERS="-F path={{{ PATH }}}{{{ perm_x }}}"
9be3b2
 AUID_FILTERS="-F auid>={{{ auid }}} -F auid!=unset"
9be3b2
-SYSCALL="{{{ ATTR }}}"
9be3b2
+SYSCALL=""
9be3b2
 KEY="privileged"
9be3b2
 SYSCALL_GROUPING="{{{ SYSCALL_GROUPING }}}"
9be3b2
 # Perform the remediation for both possible tools: 'auditctl' and 'augenrules'
9be3b2
9be3b2
From aa3b0ea2f194487c3f270e2f4d32768318c06ffa Mon Sep 17 00:00:00 2001
9be3b2
From: Watson Sato <wsato@redhat.com>
9be3b2
Date: Thu, 5 Aug 2021 15:30:46 +0200
9be3b2
Subject: [PATCH 09/31] Enhance fix_audit_syscall_rule to handle multiple
9be3b2
 syscalls
9be3b2
9be3b2
Some rules deal with single handedly with multiple profiles.
9be3b2
These rules expect to use the fix_audit_syscall_rule to add a rule with
9be3b2
muliple syscalls at a time.
9be3b2
---
9be3b2
 .../bash/shared.sh                            | 14 +++---
9be3b2
 .../bash/shared.sh                            | 26 ++++++-----
9be3b2
 .../fix_audit_syscall_rule.sh                 | 44 ++++++++++++++-----
9be3b2
 3 files changed, 58 insertions(+), 26 deletions(-)
9be3b2
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_deletion_events/audit_rules_file_deletion_events/bash/shared.sh b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_deletion_events/audit_rules_file_deletion_events/bash/shared.sh
9be3b2
index 02020a84773..2b5e6649680 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_deletion_events/audit_rules_file_deletion_events/bash/shared.sh
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_deletion_events/audit_rules_file_deletion_events/bash/shared.sh
9be3b2
@@ -9,11 +9,13 @@
9be3b2
 
9be3b2
 for ARCH in "${RULE_ARCHS[@]}"
9be3b2
 do
9be3b2
-	PATTERN="-a always,exit -F arch=$ARCH -S .* -F auid>={{{ auid }}} -F auid!=unset -k *"
9be3b2
-	# Use escaped BRE regex to specify rule group
9be3b2
-	GROUP="\(rmdir\|unlink\|rename\)"
9be3b2
-	FULL_RULE="-a always,exit -F arch=$ARCH -S rmdir -S unlink -S unlinkat -S rename -S renameat -F auid>={{{ auid }}} -F auid!=unset -k delete"
9be3b2
+	ACTION_ARCH_FILTERS="-a always,exit -F arch=$ARCH"
9be3b2
+	OTHER_FILTERS=""
9be3b2
+	AUID_FILTERS="-F auid>={{{ auid }}} -F auid!=unset"
9be3b2
+	SYSCALL="rmdir unlink unlinkat rename renameat"
9be3b2
+	KEY="delete"
9be3b2
+	SYSCALL_GROUPING="rmdir unlink unlinkat rename renameat"
9be3b2
 	# Perform the remediation for both possible tools: 'auditctl' and 'augenrules'
9be3b2
-	fix_audit_syscall_rule "auditctl" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
-	fix_audit_syscall_rule "augenrules" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
+	fix_audit_syscall_rule "augenrules" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
+	fix_audit_syscall_rule "auditctl" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
 done
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification/bash/shared.sh b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification/bash/shared.sh
9be3b2
index cdde2eabe04..bf931e46430 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification/bash/shared.sh
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification/bash/shared.sh
9be3b2
@@ -11,20 +11,26 @@ for ARCH in "${RULE_ARCHS[@]}"
9be3b2
 do
9be3b2
 
9be3b2
 	# First fix the -EACCES requirement
9be3b2
-	PATTERN="-a always,exit -F arch=$ARCH -S .* -F exit=-EACCES -F auid>={{{ auid }}} -F auid!=unset -k *"
9be3b2
-	# Use escaped BRE regex to specify rule group
9be3b2
-	GROUP="\(creat\|open\|truncate\)"
9be3b2
-	FULL_RULE="-a always,exit -F arch=$ARCH -S creat -S open -S openat -S open_by_handle_at -S truncate -S ftruncate -F exit=-EACCES -F auid>={{{ auid }}} -F auid!=unset -k access"
9be3b2
+	ACTION_ARCH_FILTERS="-a always,exit -F arch=$ARCH"
9be3b2
+	OTHER_FILTERS="-F exit=EACCES"
9be3b2
+	AUID_FILTERS="-F auid>={{{ auid }}} -F auid!=unset"
9be3b2
+	SYSCALL="creat open openat open_by_handle_at truncate ftruncate"
9be3b2
+	KEY="access"
9be3b2
+	SYSCALL_GROUPING="creat open openat open_by_handle_at truncate ftruncate"
9be3b2
 	# Perform the remediation for both possible tools: 'auditctl' and 'augenrules'
9be3b2
-	fix_audit_syscall_rule "auditctl" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
-	fix_audit_syscall_rule "augenrules" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
+	fix_audit_syscall_rule "augenrules" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
+	fix_audit_syscall_rule "auditctl" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
 
9be3b2
 	# Then fix the -EPERM requirement
9be3b2
-	PATTERN="-a always,exit -F arch=$ARCH -S .* -F exit=-EPERM -F auid>={{{ auid }}} -F auid!=unset -k *"
9be3b2
 	# No need to change content of $GROUP variable - it's the same as for -EACCES case above
9be3b2
-	FULL_RULE="-a always,exit -F arch=$ARCH -S creat -S open -S openat -S open_by_handle_at -S truncate -S ftruncate -F exit=-EPERM -F auid>={{{ auid }}} -F auid!=unset -k access"
9be3b2
+	ACTION_ARCH_FILTERS="-a always,exit -F arch=$ARCH"
9be3b2
+	OTHER_FILTERS="-F exit=EPERM"
9be3b2
+	AUID_FILTERS="-F auid>={{{ auid }}} -F auid!=unset"
9be3b2
+	SYSCALL="creat open openat open_by_handle_at truncate ftruncate"
9be3b2
+	KEY="access"
9be3b2
+	SYSCALL_GROUPING="creat open openat open_by_handle_at truncate ftruncate"
9be3b2
 	# Perform the remediation for both possible tools: 'auditctl' and 'augenrules'
9be3b2
-	fix_audit_syscall_rule "auditctl" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
-	fix_audit_syscall_rule "augenrules" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
+	fix_audit_syscall_rule "augenrules" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
+	fix_audit_syscall_rule "auditctl" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
 
9be3b2
 done
9be3b2
diff --git a/shared/bash_remediation_functions/fix_audit_syscall_rule.sh b/shared/bash_remediation_functions/fix_audit_syscall_rule.sh
9be3b2
index 69430416da3..c8492149ad9 100644
9be3b2
--- a/shared/bash_remediation_functions/fix_audit_syscall_rule.sh
9be3b2
+++ b/shared/bash_remediation_functions/fix_audit_syscall_rule.sh
9be3b2
@@ -42,7 +42,8 @@ local tool="$1"
9be3b2
 local action_arch_filters="$2"
9be3b2
 local other_filters="$3"
9be3b2
 local auid_filters="$4"
9be3b2
-local syscall="$5"
9be3b2
+local syscall_a
9be3b2
+read -a syscall_a <<< "$5"
9be3b2
 local syscall_grouping
9be3b2
 read -a syscall_grouping <<< "$6"
9be3b2
 local key="$7"
9be3b2
@@ -140,16 +141,25 @@ do
9be3b2
 		fi
9be3b2
 	done
9be3b2
 
9be3b2
-	if [[ $syscall ]]
9be3b2
+	if [[ ${#syscall_a[@]} -ge 1 ]]
9be3b2
 	then
9be3b2
 		# Check if the syscall we want is present in any of the similar existing rules
9be3b2
 		for rule in "${candidate_rules[@]}"
9be3b2
 		do
9be3b2
 			rule_syscalls=$(echo "$rule" | grep -o -P '(-S [\w,]+)+' | xargs)
9be3b2
-			grep -q -- "\b${syscall}\b" <<< "$rule_syscalls"
9be3b2
-			if [ $? -eq 0 ]
9be3b2
+			local all_syscalls_found=0
9be3b2
+			for syscall in "${syscall_a[@]}"
9be3b2
+			do
9be3b2
+				grep -q -- "\b${syscall}\b" <<< "$rule_syscalls"
9be3b2
+				if [ $? -eq 1 ]
9be3b2
+				then
9be3b2
+					# A syscall was not found in the candidate rule
9be3b2
+					all_syscalls_found=1
9be3b2
+				fi
9be3b2
+			done
9be3b2
+			if [[ $all_syscalls_found -eq 0 ]]
9be3b2
 			then
9be3b2
-				# We found a rule with the syscall we want
9be3b2
+				# We found a rule with all the syscall(s) we want
9be3b2
 				return $retval
9be3b2
 			fi
9be3b2
 
9be3b2
@@ -182,21 +192,35 @@ done
9be3b2
 if [ -z ${rule_to_edit+x} ]
9be3b2
 then
9be3b2
 	# Build full_rule while avoid adding double spaces when other_filters is empty
9be3b2
-	if [[ $syscall ]]
9be3b2
+	if [[ ${syscall_a} ]]
9be3b2
 	then
9be3b2
-		local syscall_filters="-S $syscall"
9be3b2
+		local syscall_filters=""
9be3b2
+		for syscall in "${syscall_a[@]}"
9be3b2
+		do
9be3b2
+			syscall_filters+="-S $syscall "
9be3b2
+		done
9be3b2
 	fi
9be3b2
-	local full_rule="$action_arch_filters $([[ $syscall_filters ]] && echo "$syscall_filters ")$([[ $other_filters ]] && echo "$other_filters ")$auid_filters -F key=$key"
9be3b2
+	local full_rule="$action_arch_filters $([[ $syscall_filters ]] && echo "$syscall_filters")$([[ $other_filters ]] && echo "$other_filters ")$auid_filters -F key=$key"
9be3b2
 	echo "$full_rule" >> "$default_file"
9be3b2
 else
9be3b2
 	# Check if the syscalls are declared as a comma separated list or
9be3b2
 	# as multiple -S parameters
9be3b2
 	if grep -q -- "," <<< "${rule_syscalls_to_edit}"
9be3b2
 	then
9be3b2
-		new_grouped_syscalls="${rule_syscalls_to_edit},${syscall}"
9be3b2
+		delimiter=","
9be3b2
 	else
9be3b2
-		new_grouped_syscalls="${rule_syscalls_to_edit} -S ${syscall}"
9be3b2
+		delimiter=" -S "
9be3b2
 	fi
9be3b2
+	new_grouped_syscalls="${rule_syscalls_to_edit}"
9be3b2
+	for syscall in "${syscall_a[@]}"
9be3b2
+	do
9be3b2
+		grep -q -- "\b${syscall}\b" <<< "${rule_syscalls_to_edit}"
9be3b2
+		if [ $? -eq 1 ]
9be3b2
+		then
9be3b2
+			# A syscall was not found in the candidate rule
9be3b2
+			new_grouped_syscalls+="${delimiter}${syscall}"
9be3b2
+		fi
9be3b2
+	done
9be3b2
 
9be3b2
 	# Group the syscall in the rule
9be3b2
 	sed -i -e "\#${rule_to_edit}#s#${rule_syscalls_to_edit}#${new_grouped_syscalls}#" "$file_to_edit"
9be3b2
9be3b2
From 0b18f68fa86a16f659995736567ed3649bb58ef2 Mon Sep 17 00:00:00 2001
9be3b2
From: Watson Sato <wsato@redhat.com>
9be3b2
Date: Thu, 5 Aug 2021 18:56:13 +0200
9be3b2
Subject: [PATCH 10/31] Enhance fix_audit_syscall_rule to handle rules without
9be3b2
 auid
9be3b2
9be3b2
Enhance the bash function to nicely handle calls without auid filters
9be3b2
defined.
9be3b2
And updated the remediations of rules calling fix_audit_syscall_rule to
9be3b2
the new parameters.
9be3b2
---
9be3b2
 .../bash/shared.sh                                 | 13 ++++++++-----
9be3b2
 .../bash/shared.sh                                 | 13 ++++++++-----
9be3b2
 .../bash/shared.sh                                 | 13 ++++++++-----
9be3b2
 .../bash/shared.sh                                 | 13 ++++++++-----
9be3b2
 .../bash/shared.sh                                 | 14 ++++++++------
9be3b2
 .../fix_audit_syscall_rule.sh                      |  8 +++++---
9be3b2
 6 files changed, 45 insertions(+), 29 deletions(-)
9be3b2
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading/bash/shared.sh b/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading/bash/shared.sh
9be3b2
index a89cb10e13d..cee43a0a104 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading/bash/shared.sh
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading/bash/shared.sh
9be3b2
@@ -13,10 +13,13 @@
9be3b2
 
9be3b2
 for ARCH in "${RULE_ARCHS[@]}"
9be3b2
 do
9be3b2
-        GROUP="modules"
9be3b2
-        PATTERN="-a always,exit -F arch=$ARCH -S init_module -S delete_module -S finit_module \(-F key=\|-k \).*"
9be3b2
-        FULL_RULE="-a always,exit -F arch=$ARCH -S init_module -S delete_module -S finit_module -k modules"
9be3b2
+        ACTION_ARCH_FILTERS="-a always,exit -F arch=$ARCH"
9be3b2
+        OTHER_FILTERS=""
9be3b2
+        AUID_FILTERS=""
9be3b2
+        SYSCALL="init_module finit_module delete_module"
9be3b2
+        KEY="modules"
9be3b2
+        SYSCALL_GROUPING="init_module finit_module delete_module"
9be3b2
         # Perform the remediation for both possible tools: 'auditctl' and 'augenrules'
9be3b2
-        fix_audit_syscall_rule "auditctl" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
-        fix_audit_syscall_rule "augenrules" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
+        fix_audit_syscall_rule "augenrules" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
+        fix_audit_syscall_rule "auditctl" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
 done
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading_delete/bash/shared.sh b/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading_delete/bash/shared.sh
9be3b2
index 7dabc28d807..7e0e101f754 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading_delete/bash/shared.sh
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading_delete/bash/shared.sh
9be3b2
@@ -13,10 +13,13 @@
9be3b2
 
9be3b2
 for ARCH in "${RULE_ARCHS[@]}"
9be3b2
 do
9be3b2
-	PATTERN="-a always,exit -F arch=$ARCH -S delete_module \(-F key=\|-k \).*"
9be3b2
-	GROUP="modules"
9be3b2
-	FULL_RULE="-a always,exit -F arch=$ARCH -S delete_module -k modules"
9be3b2
+	ACTION_ARCH_FILTERS="-a always,exit -F arch=$ARCH"
9be3b2
+	OTHER_FILTERS=""
9be3b2
+	AUID_FILTERS=""
9be3b2
+	SYSCALL="delete_module"
9be3b2
+	KEY="modules"
9be3b2
+	SYSCALL_GROUPING="delete_module"
9be3b2
 	# Perform the remediation for both possible tools: 'auditctl' and 'augenrules'
9be3b2
-	fix_audit_syscall_rule "auditctl" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
-	fix_audit_syscall_rule "augenrules" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
+	fix_audit_syscall_rule "augenrules" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
+	fix_audit_syscall_rule "auditctl" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
 done
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading_finit/bash/shared.sh b/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading_finit/bash/shared.sh
9be3b2
index 6e8df8c5095..1b2854d9c61 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading_finit/bash/shared.sh
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading_finit/bash/shared.sh
9be3b2
@@ -13,10 +13,13 @@
9be3b2
 
9be3b2
 for ARCH in "${RULE_ARCHS[@]}"
9be3b2
 do
9be3b2
-	PATTERN="-a always,exit -F arch=$ARCH -S finit_module \(-F key=\|-k \).*"
9be3b2
-	GROUP="modules"
9be3b2
-	FULL_RULE="-a always,exit -F arch=$ARCH -S finit_module -k modules"
9be3b2
+	ACTION_ARCH_FILTERS="-a always,exit -F arch=$ARCH"
9be3b2
+	OTHER_FILTERS=""
9be3b2
+	AUID_FILTERS=""
9be3b2
+	SYSCALL="finit_module"
9be3b2
+	KEY="modules"
9be3b2
+	SYSCALL_GROUPING="init_module finit_module"
9be3b2
 	# Perform the remediation for both possible tools: 'auditctl' and 'augenrules'
9be3b2
-	fix_audit_syscall_rule "auditctl" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
-	fix_audit_syscall_rule "augenrules" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
+	fix_audit_syscall_rule "augenrules" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
+	fix_audit_syscall_rule "auditctl" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
 done
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading_init/bash/shared.sh b/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading_init/bash/shared.sh
9be3b2
index 437127f4553..3bb7f89d37c 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading_init/bash/shared.sh
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading_init/bash/shared.sh
9be3b2
@@ -13,10 +13,13 @@
9be3b2
 
9be3b2
 for ARCH in "${RULE_ARCHS[@]}"
9be3b2
 do
9be3b2
-	PATTERN="-a always,exit -F arch=$ARCH -S init_module \(-F key=\|-k \).*"
9be3b2
-	GROUP="modules"
9be3b2
-	FULL_RULE="-a always,exit -F arch=$ARCH -S init_module -k modules"
9be3b2
+	ACTION_ARCH_FILTERS="-a always,exit -F arch=$ARCH"
9be3b2
+	OTHER_FILTERS=""
9be3b2
+	AUID_FILTERS=""
9be3b2
+	SYSCALL="init_module"
9be3b2
+	KEY="modules"
9be3b2
+	SYSCALL_GROUPING="init_module finit_module"
9be3b2
 	# Perform the remediation for both possible tools: 'auditctl' and 'augenrules'
9be3b2
-	fix_audit_syscall_rule "auditctl" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
-	fix_audit_syscall_rule "augenrules" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
+	fix_audit_syscall_rule "augenrules" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
+	fix_audit_syscall_rule "auditctl" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
 done
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_networkconfig_modification/bash/shared.sh b/linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_networkconfig_modification/bash/shared.sh
9be3b2
index 4e4869a83a7..3c5e593dc5e 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_networkconfig_modification/bash/shared.sh
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_networkconfig_modification/bash/shared.sh
9be3b2
@@ -9,13 +9,15 @@
9be3b2
 
9be3b2
 for ARCH in "${RULE_ARCHS[@]}"
9be3b2
 do
9be3b2
-	PATTERN="-a always,exit -F arch=$ARCH -S .* -k *"
9be3b2
-	# Use escaped BRE regex to specify rule group
9be3b2
-	GROUP="set\(host\|domain\)name"
9be3b2
-	FULL_RULE="-a always,exit -F arch=$ARCH -S sethostname -S setdomainname -k audit_rules_networkconfig_modification"
9be3b2
+	ACTION_ARCH_FILTERS="-a always,exit -F arch=$ARCH"
9be3b2
+	OTHER_FILTERS=""
9be3b2
+	AUID_FILTERS=""
9be3b2
+	SYSCALL="sethostname setdomainname"
9be3b2
+	KEY="audit_rules_networkconfig_modification"
9be3b2
+	SYSCALL_GROUPING="sethostname setdomainname"
9be3b2
 	# Perform the remediation for both possible tools: 'auditctl' and 'augenrules'
9be3b2
-	fix_audit_syscall_rule "auditctl" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
-	fix_audit_syscall_rule "augenrules" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
+	fix_audit_syscall_rule "augenrules" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
+	fix_audit_syscall_rule "auditctl" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
 done
9be3b2
 
9be3b2
 # Then perform the remediations for the watch rules
9be3b2
diff --git a/shared/bash_remediation_functions/fix_audit_syscall_rule.sh b/shared/bash_remediation_functions/fix_audit_syscall_rule.sh
9be3b2
index c8492149ad9..5cc130a0236 100644
9be3b2
--- a/shared/bash_remediation_functions/fix_audit_syscall_rule.sh
9be3b2
+++ b/shared/bash_remediation_functions/fix_audit_syscall_rule.sh
9be3b2
@@ -194,13 +194,15 @@ then
9be3b2
 	# Build full_rule while avoid adding double spaces when other_filters is empty
9be3b2
 	if [[ ${syscall_a} ]]
9be3b2
 	then
9be3b2
-		local syscall_filters=""
9be3b2
+		local syscall_string=""
9be3b2
 		for syscall in "${syscall_a[@]}"
9be3b2
 		do
9be3b2
-			syscall_filters+="-S $syscall "
9be3b2
+			syscall_string+=" -S $syscall"
9be3b2
 		done
9be3b2
 	fi
9be3b2
-	local full_rule="$action_arch_filters $([[ $syscall_filters ]] && echo "$syscall_filters")$([[ $other_filters ]] && echo "$other_filters ")$auid_filters -F key=$key"
9be3b2
+	local other_string=$([[ $other_filters ]] && echo " $other_filters")
9be3b2
+	local auid_string=$([[ $auid_filters ]] && echo " $auid_filters")
9be3b2
+	local full_rule="${action_arch_filters}${syscall_string}${other_string}${auid_string} -F key=${key}"
9be3b2
 	echo "$full_rule" >> "$default_file"
9be3b2
 else
9be3b2
 	# Check if the syscalls are declared as a comma separated list or
9be3b2
9be3b2
From 8c4984428445376dd1ddb03947deda2d73321972 Mon Sep 17 00:00:00 2001
9be3b2
From: Watson Sato <wsato@redhat.com>
9be3b2
Date: Thu, 5 Aug 2021 18:59:47 +0200
9be3b2
Subject: [PATCH 11/31] Move suid_privileged_function to new
9be3b2
 fix_audit_sycall_rule
9be3b2
9be3b2
The OVAL check was also updated to accept the key as a Field parameter.
9be3b2
---
9be3b2
 .../bash/shared.sh                            | 26 ++++++++++++-------
9be3b2
 .../oval/shared.xml                           | 16 ++++++------
9be3b2
 2 files changed, 24 insertions(+), 18 deletions(-)
9be3b2
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_suid_privilege_function/bash/shared.sh b/linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_suid_privilege_function/bash/shared.sh
9be3b2
index 561c8f74a8f..3976979360c 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_suid_privilege_function/bash/shared.sh
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_suid_privilege_function/bash/shared.sh
9be3b2
@@ -9,20 +9,26 @@
9be3b2
 
9be3b2
 for ARCH in "${RULE_ARCHS[@]}"
9be3b2
 do
9be3b2
-	PATTERN="-a always,exit -F arch=$ARCH -S execve -C uid!=euid -F euid=0"
9be3b2
-	GROUP="privileged"
9be3b2
-	FULL_RULE="-a always,exit -F arch=$ARCH -S execve -C uid!=euid -F euid=0 -k setuid"
9be3b2
+	ACTION_ARCH_FILTERS="-a always,exit -F arch=$ARCH"
9be3b2
+	OTHER_FILTERS="-C uid!=euid -F euid=0"
9be3b2
+	AUID_FILTERS=""
9be3b2
+	SYSCALL="execve"
9be3b2
+	KEY="setuid"
9be3b2
+	SYSCALL_GROUPING=""
9be3b2
 	# Perform the remediation for both possible tools: 'auditctl' and 'augenrules'
9be3b2
-	fix_audit_syscall_rule "auditctl" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
-	fix_audit_syscall_rule "augenrules" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
+	fix_audit_syscall_rule "augenrules" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
+	fix_audit_syscall_rule "auditctl" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
 done
9be3b2
 
9be3b2
 for ARCH in "${RULE_ARCHS[@]}"
9be3b2
 do
9be3b2
-	PATTERN="-a always,exit -F arch=$ARCH -S execve -C gid!=egid -F egid=0"
9be3b2
-	GROUP="privileged"
9be3b2
-	FULL_RULE="-a always,exit -F arch=$ARCH -S execve -C gid!=egid -F egid=0 -k setgid"
9be3b2
+	ACTION_ARCH_FILTERS="-a always,exit -F arch=$ARCH"
9be3b2
+	OTHER_FILTERS="-C gid!=egid -F egid=0"
9be3b2
+	AUID_FILTERS=""
9be3b2
+	SYSCALL="execve"
9be3b2
+	KEY="setgid"
9be3b2
+	SYSCALL_GROUPING=""
9be3b2
 	# Perform the remediation for both possible tools: 'auditctl' and 'augenrules'
9be3b2
-	fix_audit_syscall_rule "auditctl" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
-	fix_audit_syscall_rule "augenrules" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
+	fix_audit_syscall_rule "augenrules" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
+	fix_audit_syscall_rule "auditctl" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
 done
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_suid_privilege_function/oval/shared.xml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_suid_privilege_function/oval/shared.xml
9be3b2
index 9247d81b89c..5115eb6c8c4 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_suid_privilege_function/oval/shared.xml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_suid_privilege_function/oval/shared.xml
9be3b2
@@ -30,7 +30,7 @@
9be3b2
   </ind:textfilecontent54_test>
9be3b2
   <ind:textfilecontent54_object id="object_32bit_uid_privileged_function_augenrules" version="1">
9be3b2
     <ind:filepath operation="pattern match">^/etc/audit/rules\.d/.*\.rules$</ind:filepath>
9be3b2
-    <ind:pattern operation="pattern match">^[\s]*-a[\s]+always,exit[\s]+-F[\s]+arch=b32[\s]+-S[\s]+execve[\s]+-C[\s]uid!=euid[\s]+-F[\s]euid=0[\s]+-k[\s]setuid[\s]*$</ind:pattern>
9be3b2
+    <ind:pattern operation="pattern match">^[\s]*-a[\s]+always,exit[\s]+-F[\s]+arch=b32[\s]+-S[\s]+execve[\s]+-C[\s]uid!=euid[\s]+-F[\s]euid=0[\s]+(-k[\s]+|-F[\s]+key=)setuid[\s]*$</ind:pattern>
9be3b2
     <ind:instance datatype="int">1</ind:instance>
9be3b2
   </ind:textfilecontent54_object>
9be3b2
 
9be3b2
@@ -39,7 +39,7 @@
9be3b2
   </ind:textfilecontent54_test>
9be3b2
   <ind:textfilecontent54_object id="object_64bit_uid_privileged_function_augenrules" version="1">
9be3b2
     <ind:filepath operation="pattern match">^/etc/audit/rules\.d/.*\.rules$</ind:filepath>
9be3b2
-    <ind:pattern operation="pattern match">^[\s]*-a[\s]+always,exit[\s]+-F[\s]+arch=b64[\s]+-S[\s]+execve[\s]+-C[\s]uid!=euid[\s]+-F[\s]euid=0[\s]+-k[\s]setuid[\s]*$</ind:pattern>
9be3b2
+    <ind:pattern operation="pattern match">^[\s]*-a[\s]+always,exit[\s]+-F[\s]+arch=b64[\s]+-S[\s]+execve[\s]+-C[\s]uid!=euid[\s]+-F[\s]euid=0[\s]+(-k[\s]+|-F[\s]+key=)setuid[\s]*$</ind:pattern>
9be3b2
     <ind:instance datatype="int">1</ind:instance>
9be3b2
   </ind:textfilecontent54_object>
9be3b2
 
9be3b2
@@ -48,7 +48,7 @@
9be3b2
   </ind:textfilecontent54_test>
9be3b2
   <ind:textfilecontent54_object id="object_32bit_uid_privileged_function_auditctl" version="1">
9be3b2
     <ind:filepath>/etc/audit/audit.rules</ind:filepath>
9be3b2
-    <ind:pattern operation="pattern match">^[\s]*-a[\s]+always,exit[\s]+-F[\s]+arch=b32[\s]+-S[\s]+execve[\s]+-C[\s]uid!=euid[\s]+-F[\s]euid=0[\s]+-k[\s]setuid[\s]*$</ind:pattern>
9be3b2
+    <ind:pattern operation="pattern match">^[\s]*-a[\s]+always,exit[\s]+-F[\s]+arch=b32[\s]+-S[\s]+execve[\s]+-C[\s]uid!=euid[\s]+-F[\s]euid=0[\s]+(-k[\s]+|-F[\s]+key=)setuid[\s]*$</ind:pattern>
9be3b2
     <ind:instance datatype="int">1</ind:instance>
9be3b2
   </ind:textfilecontent54_object>
9be3b2
 
9be3b2
@@ -57,7 +57,7 @@
9be3b2
   </ind:textfilecontent54_test>
9be3b2
   <ind:textfilecontent54_object id="object_64bit_uid_privileged_function_auditctl" version="1">
9be3b2
     <ind:filepath>/etc/audit/audit.rules</ind:filepath>
9be3b2
-    <ind:pattern operation="pattern match">^[\s]*-a[\s]+always,exit[\s]+-F[\s]+arch=b64[\s]+-S[\s]+execve[\s]+-C[\s]uid!=euid[\s]+-F[\s]euid=0[\s]+-k[\s]setuid[\s]*$</ind:pattern>
9be3b2
+    <ind:pattern operation="pattern match">^[\s]*-a[\s]+always,exit[\s]+-F[\s]+arch=b64[\s]+-S[\s]+execve[\s]+-C[\s]uid!=euid[\s]+-F[\s]euid=0[\s]+(-k[\s]+|-F[\s]+key=)setuid[\s]*$</ind:pattern>
9be3b2
     <ind:instance datatype="int">1</ind:instance>
9be3b2
   </ind:textfilecontent54_object>
9be3b2
 
9be3b2
@@ -66,7 +66,7 @@
9be3b2
   </ind:textfilecontent54_test>
9be3b2
   <ind:textfilecontent54_object id="object_32bit_gid_privileged_function_augenrules" version="1">
9be3b2
     <ind:filepath operation="pattern match">^/etc/audit/rules\.d/.*\.rules$</ind:filepath>
9be3b2
-    <ind:pattern operation="pattern match">^[\s]*-a[\s]+always,exit[\s]+-F[\s]+arch=b32[\s]+-S[\s]+execve[\s]+-C[\s]gid!=egid[\s]+-F[\s]egid=0[\s]+-k[\s]setgid[\s]*$</ind:pattern>
9be3b2
+    <ind:pattern operation="pattern match">^[\s]*-a[\s]+always,exit[\s]+-F[\s]+arch=b32[\s]+-S[\s]+execve[\s]+-C[\s]gid!=egid[\s]+-F[\s]egid=0[\s]+(-k[\s]+|-F[\s]+key=)setgid[\s]*$</ind:pattern>
9be3b2
     <ind:instance datatype="int">1</ind:instance>
9be3b2
   </ind:textfilecontent54_object>
9be3b2
 
9be3b2
@@ -75,7 +75,7 @@
9be3b2
   </ind:textfilecontent54_test>
9be3b2
   <ind:textfilecontent54_object id="object_64bit_gid_privileged_function_augenrules" version="1">
9be3b2
     <ind:filepath operation="pattern match">^/etc/audit/rules\.d/.*\.rules$</ind:filepath>
9be3b2
-    <ind:pattern operation="pattern match">^[\s]*-a[\s]+always,exit[\s]+-F[\s]+arch=b64[\s]+-S[\s]+execve[\s]+-C[\s]gid!=egid[\s]+-F[\s]egid=0[\s]+-k[\s]setgid[\s]*$</ind:pattern>
9be3b2
+    <ind:pattern operation="pattern match">^[\s]*-a[\s]+always,exit[\s]+-F[\s]+arch=b64[\s]+-S[\s]+execve[\s]+-C[\s]gid!=egid[\s]+-F[\s]egid=0[\s]+(-k[\s]+|-F[\s]+key=)setgid[\s]*$</ind:pattern>
9be3b2
     <ind:instance datatype="int">1</ind:instance>
9be3b2
   </ind:textfilecontent54_object>
9be3b2
 
9be3b2
@@ -84,7 +84,7 @@
9be3b2
   </ind:textfilecontent54_test>
9be3b2
   <ind:textfilecontent54_object id="object_32bit_gid_privileged_function_auditctl" version="1">
9be3b2
     <ind:filepath>/etc/audit/audit.rules</ind:filepath>
9be3b2
-    <ind:pattern operation="pattern match">^[\s]*-a[\s]+always,exit[\s]+-F[\s]+arch=b32[\s]+-S[\s]+execve[\s]+-C[\s]gid!=egid[\s]+-F[\s]egid=0[\s]+-k[\s]setgid[\s]*$</ind:pattern>
9be3b2
+    <ind:pattern operation="pattern match">^[\s]*-a[\s]+always,exit[\s]+-F[\s]+arch=b32[\s]+-S[\s]+execve[\s]+-C[\s]gid!=egid[\s]+-F[\s]egid=0[\s]+(-k[\s]+|-F[\s]+key=)setgid[\s]*$</ind:pattern>
9be3b2
     <ind:instance datatype="int">1</ind:instance>
9be3b2
   </ind:textfilecontent54_object>
9be3b2
 
9be3b2
@@ -93,7 +93,7 @@
9be3b2
   </ind:textfilecontent54_test>
9be3b2
   <ind:textfilecontent54_object id="object_64bit_gid_privileged_function_auditctl" version="1">
9be3b2
     <ind:filepath>/etc/audit/audit.rules</ind:filepath>
9be3b2
-    <ind:pattern operation="pattern match">^[\s]*-a[\s]+always,exit[\s]+-F[\s]+arch=b64[\s]+-S[\s]+execve[\s]+-C[\s]gid!=egid[\s]+-F[\s]egid=0[\s]+-k[\s]setgid[\s]*$</ind:pattern>
9be3b2
+    <ind:pattern operation="pattern match">^[\s]*-a[\s]+always,exit[\s]+-F[\s]+arch=b64[\s]+-S[\s]+execve[\s]+-C[\s]gid!=egid[\s]+-F[\s]egid=0[\s]+(-k[\s]+|-F[\s]+key=)setgid[\s]*$</ind:pattern>
9be3b2
     <ind:instance datatype="int">1</ind:instance>
9be3b2
   </ind:textfilecontent54_object>
9be3b2
 
9be3b2
9be3b2
From ed948b76b8ce20179a00622b9e04a4d4cd32850f Mon Sep 17 00:00:00 2001
9be3b2
From: Watson Sato <wsato@redhat.com>
9be3b2
Date: Fri, 6 Aug 2021 09:45:42 +0200
9be3b2
Subject: [PATCH 12/31] Update remediarions for time syscalls rules
9be3b2
9be3b2
Update rules audit_rules_time_clock_settime and bash shared
9be3b2
remediation perform_audit_adjtimex_settimeofday_stime_remediation
9be3b2
to group their syscalls.
9be3b2
---
9be3b2
 .../bash/shared.sh                             | 13 ++++++++-----
9be3b2
 ..._adjtimex_settimeofday_stime_remediation.sh | 18 +++++++++++-------
9be3b2
 2 files changed, 19 insertions(+), 12 deletions(-)
9be3b2
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_time_rules/audit_rules_time_clock_settime/bash/shared.sh b/linux_os/guide/system/auditing/auditd_configure_rules/audit_time_rules/audit_rules_time_clock_settime/bash/shared.sh
9be3b2
index ffddb94df69..0d51b6b9400 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_time_rules/audit_rules_time_clock_settime/bash/shared.sh
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_time_rules/audit_rules_time_clock_settime/bash/shared.sh
9be3b2
@@ -9,10 +9,13 @@
9be3b2
 
9be3b2
 for ARCH in "${RULE_ARCHS[@]}"
9be3b2
 do
9be3b2
-	PATTERN="-a always,exit -F arch=$ARCH -S clock_settime -F a0=.* \(-F key=\|-k \).*"
9be3b2
-	GROUP="clock_settime"
9be3b2
-	FULL_RULE="-a always,exit -F arch=$ARCH -S clock_settime -F a0=0x0 -k time-change"
9be3b2
+	ACTION_ARCH_FILTERS="-a always,exit -F arch=$ARCH"
9be3b2
+	OTHER_FILTERS="-F a0=0x0"
9be3b2
+	AUID_FILTERS=""
9be3b2
+	SYSCALL="clock_settime"
9be3b2
+	KEY="time-change"
9be3b2
+	SYSCALL_GROUPING=""
9be3b2
 	# Perform the remediation for both possible tools: 'auditctl' and 'augenrules'
9be3b2
-	fix_audit_syscall_rule "auditctl" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
-	fix_audit_syscall_rule "augenrules" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
+	fix_audit_syscall_rule "augenrules" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
+	fix_audit_syscall_rule "auditctl" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
 done
9be3b2
diff --git a/shared/bash_remediation_functions/perform_audit_adjtimex_settimeofday_stime_remediation.sh b/shared/bash_remediation_functions/perform_audit_adjtimex_settimeofday_stime_remediation.sh
9be3b2
index be1425b454c..ca3ccc37513 100644
9be3b2
--- a/shared/bash_remediation_functions/perform_audit_adjtimex_settimeofday_stime_remediation.sh
9be3b2
+++ b/shared/bash_remediation_functions/perform_audit_adjtimex_settimeofday_stime_remediation.sh
9be3b2
@@ -19,24 +19,28 @@ function perform_audit_adjtimex_settimeofday_stime_remediation {
9be3b2
 for ARCH in "${RULE_ARCHS[@]}"
9be3b2
 do
9be3b2
 
9be3b2
-	PATTERN="-a always,exit -F arch=${ARCH} -S .* -k *"
9be3b2
 	# Create expected audit group and audit rule form for particular system call & architecture
9be3b2
 	if [ ${ARCH} = "b32" ]
9be3b2
 	then
9be3b2
+		ACTION_ARCH_FILTERS="-a always,exit -F arch=$ARCH"
9be3b2
 		# stime system call is known at 32-bit arch (see e.g "$ ausyscall i386 stime" 's output)
9be3b2
 		# so append it to the list of time group system calls to be audited
9be3b2
-		GROUP="\(adjtimex\|settimeofday\|stime\)"
9be3b2
-		FULL_RULE="-a always,exit -F arch=${ARCH} -S adjtimex -S settimeofday -S stime -k audit_time_rules"
9be3b2
+		SYSCALL="adjtimex settimeofday stime"
9be3b2
+		SYSCALL_GROUPING="adjtimex settimeofday stime"
9be3b2
 	elif [ ${ARCH} = "b64" ]
9be3b2
 	then
9be3b2
+		ACTION_ARCH_FILTERS="-a always,exit -F arch=$ARCH"
9be3b2
 		# stime system call isn't known at 64-bit arch (see "$ ausyscall x86_64 stime" 's output)
9be3b2
 		# therefore don't add it to the list of time group system calls to be audited
9be3b2
-		GROUP="\(adjtimex\|settimeofday\)"
9be3b2
-		FULL_RULE="-a always,exit -F arch=${ARCH} -S adjtimex -S settimeofday -k audit_time_rules"
9be3b2
+		SYSCALL="adjtimex settimeofday"
9be3b2
+		SYSCALL_GROUPING="adjtimex settimeofday"
9be3b2
 	fi
9be3b2
+	OTHER_FILTERS=""
9be3b2
+	AUID_FILTERS=""
9be3b2
+	KEY="audit_time_rules"
9be3b2
 	# Perform the remediation for both possible tools: 'auditctl' and 'augenrules'
9be3b2
-	fix_audit_syscall_rule "auditctl" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
-	fix_audit_syscall_rule "augenrules" "$PATTERN" "$GROUP" "$ARCH" "$FULL_RULE"
9be3b2
+	fix_audit_syscall_rule "augenrules" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
+	fix_audit_syscall_rule "auditctl" "$ACTION_ARCH_FILTERS" "$OTHER_FILTERS" "$AUID_FILTERS" "$SYSCALL" "$SYSCALL_GROUPING" "$KEY"
9be3b2
 done
9be3b2
 
9be3b2
 }
9be3b2
9be3b2
From 8af4ced71baa5794bfa9be2cfcf9a9519066e597 Mon Sep 17 00:00:00 2001
9be3b2
From: Watson Sato <wsato@redhat.com>
9be3b2
Date: Tue, 17 Aug 2021 11:50:46 +0200
9be3b2
Subject: [PATCH 13/31] Improve audit syscall rule macro to group syscalls
9be3b2
9be3b2
The macros now group the syscall rule according to the grouping argument
9be3b2
The Ansible macros follow same argument pattern as the Bash remediations
9be3b2
(soon to become macros).
9be3b2
---
9be3b2
 .../ansible/shared.yml                        |  36 ++-
9be3b2
 .../ansible/shared.yml                        |  36 ++-
9be3b2
 .../ansible/shared.yml                        |  36 ++-
9be3b2
 .../ansible/shared.yml                        |  36 ++-
9be3b2
 .../ansible/shared.yml                        |  36 ++-
9be3b2
 .../audit_rules_time_stime/ansible/shared.yml |  18 +-
9be3b2
 shared/macros-ansible.jinja                   | 220 +++++++++---------
9be3b2
 7 files changed, 292 insertions(+), 126 deletions(-)
9be3b2
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading/ansible/shared.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading/ansible/shared.yml
9be3b2
index 8421076fbb3..905c14feb82 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading/ansible/shared.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading/ansible/shared.yml
9be3b2
@@ -15,11 +15,39 @@
9be3b2
 
9be3b2
 - name: Perform remediation of Audit rules for kernel module loading for x86 platform
9be3b2
   block:
9be3b2
-    {{{ ansible_audit_augenrules_add_syscall_rule(arch="b32", syscalls=audit_syscalls, key="modules")|indent(4) }}}
9be3b2
-    {{{ ansible_audit_auditctl_add_syscall_rule(arch="b32", syscalls=audit_syscalls, key="modules")|indent(4) }}}
9be3b2
+    {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b32",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="",
9be3b2
+      syscalls=audit_syscalls,
9be3b2
+      key="modules",
9be3b2
+      syscall_grouping=audit_syscalls,
9be3b2
+      )|indent(4) }}}
9be3b2
+    {{{ ansible_audit_auditctl_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b32",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="",
9be3b2
+      syscalls=audit_syscalls,
9be3b2
+      key="modules",
9be3b2
+      syscall_grouping=audit_syscalls,
9be3b2
+      )|indent(4) }}}
9be3b2
 
9be3b2
 - name: Perform remediation of Audit rules for kernel module loading for x86_64 platform
9be3b2
   block:
9be3b2
-    {{{ ansible_audit_augenrules_add_syscall_rule(arch="b64", syscalls=audit_syscalls, key="modules")|indent(4) }}}
9be3b2
-    {{{ ansible_audit_auditctl_add_syscall_rule(arch="b64", syscalls=audit_syscalls, key="modules")|indent(4) }}}
9be3b2
+    {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b64",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="",
9be3b2
+      syscalls=audit_syscalls,
9be3b2
+      key="modules",
9be3b2
+      syscall_grouping=audit_syscalls,
9be3b2
+      )|indent(4) }}}
9be3b2
+    {{{ ansible_audit_auditctl_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b64",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="",
9be3b2
+      syscalls=audit_syscalls,
9be3b2
+      key="modules",
9be3b2
+      syscall_grouping=audit_syscalls,
9be3b2
+      )|indent(4) }}}
9be3b2
   when: audit_arch == "b64"
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_networkconfig_modification/ansible/shared.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_networkconfig_modification/ansible/shared.yml
9be3b2
index fa07d5bf944..b5262d795c6 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_networkconfig_modification/ansible/shared.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_rules_networkconfig_modification/ansible/shared.yml
9be3b2
@@ -13,13 +13,41 @@
9be3b2
 
9be3b2
 - name: Remediate audit rules for network configuration for x86
9be3b2
   block:
9be3b2
-    {{{ ansible_audit_augenrules_add_syscall_rule(arch="b32", syscalls=["sethostname", "setdomainname"], key="audit_rules_networkconfig_modification")|indent(4) }}}
9be3b2
-    {{{ ansible_audit_auditctl_add_syscall_rule(arch="b32", syscalls=["sethostname", "setdomainname"], key="audit_rules_networkconfig_modification")|indent(4) }}}
9be3b2
+    {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b32",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="",
9be3b2
+      syscalls=["sethostname", "setdomainname"],
9be3b2
+      key="audit_rules_networkconfig_modification",
9be3b2
+      syscall_grouping=["sethostname", "setdomainname"],
9be3b2
+      )|indent(4) }}}
9be3b2
+    {{{ ansible_audit_auditctl_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b32",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="",
9be3b2
+      syscalls=["sethostname", "setdomainname"],
9be3b2
+      key="audit_rules_networkconfig_modification",
9be3b2
+      syscall_grouping=["sethostname", "setdomainname"],
9be3b2
+      )|indent(4) }}}
9be3b2
 
9be3b2
 - name: Remediate audit rules for network configuration for x86_64
9be3b2
   block:
9be3b2
-    {{{ ansible_audit_augenrules_add_syscall_rule(arch="b64", syscalls=["sethostname", "setdomainname"], key="audit_rules_networkconfig_modification")|indent(4) }}}
9be3b2
-    {{{ ansible_audit_auditctl_add_syscall_rule(arch="b64", syscalls=["sethostname", "setdomainname"], key="audit_rules_networkconfig_modification")|indent(4) }}}
9be3b2
+    {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b64",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="",
9be3b2
+      syscalls=["sethostname", "setdomainname"],
9be3b2
+      key="audit_rules_networkconfig_modification",
9be3b2
+      syscall_grouping=["sethostname", "setdomainname"],
9be3b2
+      )|indent(4) }}}
9be3b2
+    {{{ ansible_audit_auditctl_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b64",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="",
9be3b2
+      syscalls=["sethostname", "setdomainname"],
9be3b2
+      key="audit_rules_networkconfig_modification",
9be3b2
+      syscall_grouping=["sethostname", "setdomainname"],
9be3b2
+      )|indent(4) }}}
9be3b2
   when: audit_arch == "b64"
9be3b2
 
9be3b2
 # remediate watches
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_time_rules/audit_rules_time_adjtimex/ansible/shared.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_time_rules/audit_rules_time_adjtimex/ansible/shared.yml
9be3b2
index 921b8e34cb2..a5d7cc5e0aa 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_time_rules/audit_rules_time_adjtimex/ansible/shared.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_time_rules/audit_rules_time_adjtimex/ansible/shared.yml
9be3b2
@@ -10,11 +10,39 @@
9be3b2
 
9be3b2
 - name: Perform remediation of Audit rules for adjtimex for x86 platform
9be3b2
   block:
9be3b2
-    {{{ ansible_audit_augenrules_add_syscall_rule(arch="b32", syscalls=["adjtimex"], key="audit_time_rules")|indent(4) }}}
9be3b2
-    {{{ ansible_audit_auditctl_add_syscall_rule(arch="b32", syscalls=["adjtimex"], key="audit_time_rules")|indent(4) }}}
9be3b2
+    {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b32",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="",
9be3b2
+      syscalls=["adjtimex"],
9be3b2
+      key="audit_time_rules",
9be3b2
+      syscall_grouping=["adjtimex", "settimeofday", "stime"],
9be3b2
+      )|indent(4) }}}
9be3b2
+    {{{ ansible_audit_auditctl_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b32",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="",
9be3b2
+      syscalls=["adjtimex"],
9be3b2
+      key="audit_time_rules",
9be3b2
+      syscall_grouping=["adjtimex", "settimeofday", "stime"],
9be3b2
+      )|indent(4) }}}
9be3b2
 
9be3b2
 - name: Perform remediation of Audit rules for adjtimex for x86_64 platform
9be3b2
   block:
9be3b2
-    {{{ ansible_audit_augenrules_add_syscall_rule(arch="b64", syscalls=["adjtimex"], key="audit_time_rules")|indent(4) }}}
9be3b2
-    {{{ ansible_audit_auditctl_add_syscall_rule(arch="b64", syscalls=["adjtimex"], key="audit_time_rules")|indent(4) }}}
9be3b2
+    {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b64",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="",
9be3b2
+      syscalls=["adjtimex"],
9be3b2
+      key="audit_time_rules",
9be3b2
+      syscall_grouping=["adjtimex", "settimeofday"],
9be3b2
+      )|indent(4) }}}
9be3b2
+    {{{ ansible_audit_auditctl_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b64",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="",
9be3b2
+      syscalls=["adjtimex"],
9be3b2
+      key="audit_time_rules",
9be3b2
+      syscall_grouping=["adjtimex", "settimeofday", "stime"],
9be3b2
+      )|indent(4) }}}
9be3b2
   when: audit_arch == "b64"
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_time_rules/audit_rules_time_clock_settime/ansible/shared.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_time_rules/audit_rules_time_clock_settime/ansible/shared.yml
9be3b2
index e77850fa251..c07ee41fe03 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_time_rules/audit_rules_time_clock_settime/ansible/shared.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_time_rules/audit_rules_time_clock_settime/ansible/shared.yml
9be3b2
@@ -12,11 +12,39 @@
9be3b2
 
9be3b2
 - name: Perform remediation of Audit rules for clock_settime for x86 platform
9be3b2
   block:
9be3b2
-    {{{ ansible_audit_augenrules_add_syscall_rule(arch="b32", syscalls=["clock_settime"], key="time-change", fields=["a0=0x0"])|indent(4) }}}
9be3b2
-    {{{ ansible_audit_auditctl_add_syscall_rule(arch="b32", syscalls=["clock_settime"], key="time-change", fields=["a0=0x0"])|indent(4) }}}
9be3b2
+    {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b32",
9be3b2
+      other_filters="-F a0=0x0",
9be3b2
+      auid_filters="",
9be3b2
+      syscalls=["clock_settime"],
9be3b2
+      key="time-change",
9be3b2
+      syscall_grouping=[],
9be3b2
+      )|indent(4) }}}
9be3b2
+    {{{ ansible_audit_auditctl_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b32",
9be3b2
+      other_filters="-F a0=0x0",
9be3b2
+      auid_filters="",
9be3b2
+      syscalls=["clock_settime"],
9be3b2
+      key="time-change",
9be3b2
+      syscall_grouping=[],
9be3b2
+      )|indent(4) }}}
9be3b2
 
9be3b2
 - name: Perform remediation of Audit rules for clock_settime for x86_64 platform
9be3b2
   block:
9be3b2
-    {{{ ansible_audit_augenrules_add_syscall_rule(arch="b64", syscalls=["clock_settime"], key="time-change", fields=["a0=0x0"])|indent(4) }}}
9be3b2
-    {{{ ansible_audit_auditctl_add_syscall_rule(arch="b64", syscalls=["clock_settime"], key="time-change", fields=["a0=0x0"])|indent(4) }}}
9be3b2
+    {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b64",
9be3b2
+      other_filters="-F a0=0x0",
9be3b2
+      auid_filters="",
9be3b2
+      syscalls=["clock_settime"],
9be3b2
+      key="time-change",
9be3b2
+      syscall_grouping=[],
9be3b2
+      )|indent(4) }}}
9be3b2
+    {{{ ansible_audit_auditctl_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b64",
9be3b2
+      other_filters="-F a0=0x0",
9be3b2
+      auid_filters="",
9be3b2
+      syscalls=["clock_settime"],
9be3b2
+      key="time-change",
9be3b2
+      syscall_grouping=[],
9be3b2
+      )|indent(4) }}}
9be3b2
   when: audit_arch == "b64"
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_time_rules/audit_rules_time_settimeofday/ansible/shared.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_time_rules/audit_rules_time_settimeofday/ansible/shared.yml
9be3b2
index b1a25c2776d..e4be5e2406f 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_time_rules/audit_rules_time_settimeofday/ansible/shared.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_time_rules/audit_rules_time_settimeofday/ansible/shared.yml
9be3b2
@@ -10,11 +10,39 @@
9be3b2
 
9be3b2
 - name: Perform remediation of Audit rules for settimeofday for x86 platform
9be3b2
   block:
9be3b2
-    {{{ ansible_audit_augenrules_add_syscall_rule(arch="b32", syscalls=["settimeofday"], key="audit_time_rules")|indent(4) }}}
9be3b2
-    {{{ ansible_audit_auditctl_add_syscall_rule(arch="b32", syscalls=["settimeofday"], key="audit_time_rules")|indent(4) }}}
9be3b2
+    {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b32",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="",
9be3b2
+      syscalls=["settimeofday"],
9be3b2
+      key="audit_time_rules",
9be3b2
+      syscall_grouping=["adjtimex", "settimeofday", "stime"],
9be3b2
+      )|indent(4) }}}
9be3b2
+    {{{ ansible_audit_auditctl_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b32",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="",
9be3b2
+      syscalls=["settimeofday"],
9be3b2
+      key="audit_time_rules",
9be3b2
+      syscall_grouping=["adjtimex", "settimeofday", "stime"],
9be3b2
+      )|indent(4) }}}
9be3b2
 
9be3b2
 - name: Perform remediation of Audit rules for settimeofday for x86_64 platform
9be3b2
   block:
9be3b2
-    {{{ ansible_audit_augenrules_add_syscall_rule(arch="b64", syscalls=["settimeofday"], key="audit_time_rules")|indent(4) }}}
9be3b2
-    {{{ ansible_audit_auditctl_add_syscall_rule(arch="b64", syscalls=["settimeofday"], key="audit_time_rules")|indent(4) }}}
9be3b2
+    {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b64",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="",
9be3b2
+      syscalls=["settimeofday"],
9be3b2
+      key="audit_time_rules",
9be3b2
+      syscall_grouping=["adjtimex", "settimeofday", "stime"],
9be3b2
+      )|indent(4) }}}
9be3b2
+    {{{ ansible_audit_auditctl_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b64",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="",
9be3b2
+      syscalls=["settimeofday"],
9be3b2
+      key="audit_time_rules",
9be3b2
+      syscall_grouping=["adjtimex", "settimeofday", "stime"],
9be3b2
+      )|indent(4) }}}
9be3b2
   when: audit_arch == "b64"
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_time_rules/audit_rules_time_stime/ansible/shared.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_time_rules/audit_rules_time_stime/ansible/shared.yml
9be3b2
index b57c71ce21f..96fc5c15655 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_time_rules/audit_rules_time_stime/ansible/shared.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_time_rules/audit_rules_time_stime/ansible/shared.yml
9be3b2
@@ -6,5 +6,19 @@
9be3b2
 
9be3b2
 - name: Perform remediation of Audit rules for stime syscall for x86 platform
9be3b2
   block:
9be3b2
-    {{{ ansible_audit_augenrules_add_syscall_rule(arch="b32", syscalls=["stime"], key="audit_time_rules")|indent(4) }}}
9be3b2
-    {{{ ansible_audit_auditctl_add_syscall_rule(arch="b32", syscalls=["stime"], key="audit_time_rules")|indent(4) }}}
9be3b2
+    {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b32",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="",
9be3b2
+      syscalls=["stime"],
9be3b2
+      key="audit_time_rules",
9be3b2
+      syscall_grouping=["adjtimex", "settimeofday", "stime"],
9be3b2
+      )|indent(4) }}}
9be3b2
+    {{{ ansible_audit_auditctl_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b32",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="",
9be3b2
+      syscalls=["stime"],
9be3b2
+      key="audit_time_rules",
9be3b2
+      syscall_grouping=["adjtimex", "settimeofday", "stime"],
9be3b2
+      )|indent(4) }}}
9be3b2
diff --git a/shared/macros-ansible.jinja b/shared/macros-ansible.jinja
9be3b2
index 116077b9a52..5e120deee58 100644
9be3b2
--- a/shared/macros-ansible.jinja
9be3b2
+++ b/shared/macros-ansible.jinja
9be3b2
@@ -385,135 +385,147 @@ The macro requires following parameters:
9be3b2
 {{#
9be3b2
 The following macro remediates Audit syscall rule in /etc/audit/rules.d directory.
9be3b2
 The macro requires following parameters:
9be3b2
-- arch: an architecture to be used in the Audit rule (b32, b64)
9be3b2
-- syscalls: list of syscalls supplied as a list ["syscall1", "syscall2"] etc.
9be3b2
-- key: a key to use as rule identifier.
9be3b2
-- fields (optional): list of syscall fields to add (e.g.: auid=unset, exit=-EPERM, a0&0100);
9be3b2
-  Add them in the order you expect them to be in the audit rule.
9be3b2
-Note that if there  already exists a rule wit the same key in the /etc/audit/rules.d directory, the rule will be placed in the same file.
9be3b2
+- action_arch_filters:  The action and arch filters of the rule
9be3b2
+                        For example, "-a always,exit -F arch=b64"
9be3b2
+- other_filters:        Other filters that may characterize the rule:
9be3b2
+                        For example, "-F a2&03 -F path=/etc/passwd"
9be3b2
+- auid_filters:         The auid filters of the rule
9be3b2
+                        For example, "-F auid>=1000 -F auid!=unset"
9be3b2
+- syscalls:             List of syscalls to ensure presense among audit rules
9be3b2
+                        For example, "['fchown', 'lchown', 'fchownat']"
9be3b2
+- syscall_groupings:    List of other syscalls that can be grouped with 'syscalls'
9be3b2
+                        For example, "['fchown', 'lchown', 'fchownat']"
9be3b2
+- key:                  The key to use when appending a new rule
9be3b2
 #}}
9be3b2
-{{% macro ansible_audit_augenrules_add_syscall_rule(arch="", syscalls=[], key="", fields=[]) -%}}
9be3b2
-- name: Declare list of syscals
9be3b2
+{{% macro ansible_audit_augenrules_add_syscall_rule(action_arch_filters="", other_filters="", auid_filters="", syscalls=[], key="", syscall_grouping=[]) -%}}
9be3b2
+{{% if other_filters != "" %}}
9be3b2
+    {{% set other_filters = " " ~ other_filters %}}
9be3b2
+{{% endif %}}
9be3b2
+{{% if auid_filters != "" %}}
9be3b2
+    {{% set auid_filters = " " ~ auid_filters %}}
9be3b2
+{{% endif %}}
9be3b2
+- name: Declare list of syscalls
9be3b2
   set_fact:
9be3b2
     syscalls: {{{ syscalls }}}
9be3b2
+    syscall_grouping: {{{ syscall_grouping }}}
9be3b2
 
9be3b2
-- name: Declare number of syscalls
9be3b2
-  set_fact: audit_syscalls_number_of_syscalls="{{ syscalls|length|int }}"
9be3b2
+- name: Check existence of syscalls for in /etc/audit/rules.d/
9be3b2
+  find:
9be3b2
+    paths: /etc/audit/rules.d
9be3b2
+    contains: '{{{ action_arch_filters }}}(( -S |,)\w+)*(( -S |,){{ item }})+(( -S |,)\w+)*{{{ other_filters }}}{{{ auid_filters }}} (-k\s+|-F\s+key=)\S+\s*$'
9be3b2
+    patterns: '*.rules'
9be3b2
+  register: find_command
9be3b2
+  loop: '{{ syscall_grouping }}'
9be3b2
 
9be3b2
-{{#
9be3b2
-This dictionary is a Jinja2 trick to allow loops to change variables defined out of its scope.
9be3b2
-See official documentation: https://jinja.palletsprojects.com/en/2.11.x/templates/#assignments
9be3b2
-#}}
9be3b2
-{{% set fields_data = { 'regex' : "", 'plain_text': "" } %}}
9be3b2
-{{% for field in fields %}}
9be3b2
-    {{% set not_used = fields_data.update({'regex': fields_data.regex + '(?:-F[\s]+' + field + '[\s]+)'}) %}}
9be3b2
-    {{% set not_used = fields_data.update({'plain_text': fields_data.plain_text + ' -F ' + field }) %}}
9be3b2
-{{% endfor %}}
9be3b2
+- name: Declare syscalls found per file
9be3b2
+  set_fact: syscalls_per_file="{{ syscalls_per_file | default({}) | combine( {item.files[0].path :[item.item]+(syscalls_per_file | default({})).get(item.files[0].path, []) } ) }}"
9be3b2
+  loop: "{{ find_command.results | selectattr('matched') | list}}"
9be3b2
 
9be3b2
-- name: Check existence of syscalls for architecture {{{ arch }}} in /etc/audit/rules.d/
9be3b2
-  find:
9be3b2
-    paths: "/etc/audit/rules.d"
9be3b2
-    contains: '^[\s]*-a[\s]+always,exit[\s]+(?:.*-F[\s]+arch={{{ arch }}}[\s]+)(?:.*(-S[\s]+{{ item }}[\s]+|([\s]+|[,]){{ item }}([\s]+|[,]))).*{{{ fields_data.regex }}}(-k[\s]+|-F[\s]+key=)[\S]+[\s]*$'
9be3b2
-    patterns: "*.rules"
9be3b2
-  register: audit_syscalls_found_{{{ arch }}}_rules_d
9be3b2
-  loop: "{{ syscalls }}"
9be3b2
+- name: Declare files where syscalls where found
9be3b2
+  set_fact: found_paths="{{ find_command.results | map(attribute='files') | flatten | map(attribute='path') | list }}"
9be3b2
 
9be3b2
-- name: Get number of matched syscalls for architecture {{{ arch }}} in /etc/audit/rules.d/
9be3b2
-  set_fact: audit_syscalls_matched_{{{ arch }}}_rules_d="{{ audit_syscalls_found_{{{ arch }}}_rules_d.results|sum(attribute='matched')|int }}"
9be3b2
+- name: Count occurrences of syscalls in paths
9be3b2
+  set_fact: found_paths_dict="{{ found_paths_dict | default({}) | combine({ item:1+(found_paths_dict | default({})).get(item, 0) }) }}"
9be3b2
+  loop: "{{ find_command.results | map(attribute='files') | flatten | map(attribute='path') | list }}"
9be3b2
 
9be3b2
-- name: Search /etc/audit/rules.d for other rules with the key {{{ key }}}
9be3b2
-  find:
9be3b2
-    paths: "/etc/audit/rules.d"
9be3b2
-    contains: '^.*(?:-F key=|-k\s+){{{ key }}}$'
9be3b2
-    patterns: "*.rules"
9be3b2
-  register: find_syscalls_files
9be3b2
+- name: Get path with most syscalls
9be3b2
+  set_fact: audit_file="{{ (found_paths_dict | dict2items() | sort(attribute='value') | last).key }}"
9be3b2
+  when: found_paths | length >= 1
9be3b2
 
9be3b2
-- name: Use /etc/audit/rules.d/{{{ key }}}.rules as the recipient for the rule
9be3b2
-  set_fact:
9be3b2
-    all_files:
9be3b2
-      - /etc/audit/rules.d/{{{ key }}}.rules
9be3b2
-  when: find_syscalls_files.matched is defined and find_syscalls_files.matched == 0
9be3b2
+- name: No file with syscall found, set path to /etc/audit/rules.d/{{{ key }}}.rules
9be3b2
+  set_fact: audit_file="/etc/audit/rules.d/{{{ key }}}.rules"
9be3b2
+  when: found_paths | length == 0
9be3b2
 
9be3b2
-- name: Use matched file as the recipient for the rule
9be3b2
+- name: Declare found syscalls
9be3b2
+  set_fact: syscalls_found="{{ find_command.results | selectattr('matched') | map(attribute='item') | list }}"
9be3b2
+
9be3b2
+- name: Declare missing syscalls
9be3b2
   set_fact:
9be3b2
-    all_files:
9be3b2
-      - "{{ find_syscalls_files.files | map(attribute='path') | list | first }}"
9be3b2
-  when: find_syscalls_files.matched is defined and find_syscalls_files.matched > 0
9be3b2
+    missing_syscalls="{{ syscalls | difference(syscalls_found) }}"
9be3b2
 
9be3b2
-- name: "Insert the syscall rule in {{ all_files[0] }}"
9be3b2
-  block:
9be3b2
-    - name: "Construct rule: add rule list, action and arch"
9be3b2
-      set_fact: tmpline="-a always,exit -F arch={{{ arch }}}"
9be3b2
-    - name: "Construct rule: add syscalls"
9be3b2
-      set_fact: tmpline="{{ tmpline + ' -S ' + item.item }}"
9be3b2
-      loop: "{{ audit_syscalls_found_{{{ arch }}}_rules_d.results }}"
9be3b2
-      when: item.matched is defined and item.matched == 0
9be3b2
-    - name: "Construct rule: add fields and key"
9be3b2
-      set_fact: tmpline="{{ tmpline + '{{{ fields_data.plain_text }}} -k {{{ key }}}' }}"
9be3b2
-    - name: "Insert the line in {{ all_files[0] }}"
9be3b2
-      lineinfile:
9be3b2
-        path: "{{ all_files[0] }}"
9be3b2
-        line: "{{ tmpline }}"
9be3b2
-        create: true
9be3b2
-        state: present
9be3b2
-  when: audit_syscalls_matched_{{{ arch }}}_rules_d < audit_syscalls_number_of_syscalls
9be3b2
+- name: Replace the audit rule in {{ audit_file }}
9be3b2
+  lineinfile:
9be3b2
+    path: '{{ audit_file }}'
9be3b2
+    regexp: '({{{ action_arch_filters }}})(?=.*(?:(?:-S |,)(?:{{ syscalls_per_file[audit_file] | join("|") }}))\b)((?:( -S |,)\w+)+)({{{ other_filters }}}{{{ auid_filters }}} (?:-k |-F key=)\w+)'
9be3b2
+    line: '\1\2\3{{ missing_syscalls | join("\3") }}\4'
9be3b2
+    backrefs: yes
9be3b2
+    state: present
9be3b2
+  when: syscalls_found | length > 0 and missing_syscalls | length > 0
9be3b2
+
9be3b2
+- name: Add the audit rule to {{ audit_file }}
9be3b2
+  lineinfile:
9be3b2
+    path: '{{ audit_file }}'
9be3b2
+    line: "{{{ action_arch_filters }}} -S {{ syscalls | join(',') }}{{{ other_filters }}}{{{ auid_filters}}} -F key={{{ key }}}"
9be3b2
+    create: true
9be3b2
+    state: present
9be3b2
+  when: syscalls_found | length == 0
9be3b2
 {{%- endmacro %}}
9be3b2
 
9be3b2
 {{#
9be3b2
 The following macro remediates Audit syscall rule in /etc/audit/audit.rules file.
9be3b2
 The macro requires following parameters:
9be3b2
-- arch: an architecture to be used in the Audit rule (b32, b64)
9be3b2
-- syscalls: list of syscalls supplied as a list ["syscall1", "syscall2"] etc.
9be3b2
-- key: a key to use as rule identifier.
9be3b2
-- fields (optional): list of syscall fields to add (e.g.: auid=unset, exit=-EPERM, a0&0100);
9be3b2
-  Add them in the order you expect them to be in the audit rule.
9be3b2
+- action_arch_filters:  The action and arch filters of the rule
9be3b2
+                        For example, "-a always,exit -F arch=b64"
9be3b2
+- other_filters:        Other filters that may characterize the rule:
9be3b2
+                        For example, "-F a2&03 -F path=/etc/passwd"
9be3b2
+- auid_filters:         The auid filters of the rule
9be3b2
+                        For example, "-F auid>=1000 -F auid!=unset"
9be3b2
+- syscalls:             List of syscalls to ensure presense among audit rules
9be3b2
+                        For example, "['fchown', 'lchown', 'fchownat']"
9be3b2
+- syscall_groupings:    List of other syscalls that can be grouped with 'syscalls'
9be3b2
+                        For example, "['fchown', 'lchown', 'fchownat']"
9be3b2
+- key:                  The key to use when appending a new rule
9be3b2
 #}}
9be3b2
-{{% macro ansible_audit_auditctl_add_syscall_rule(arch="", syscalls=[], key="", fields=[]) -%}}
9be3b2
-- name: Declare list of syscals
9be3b2
+{{% macro ansible_audit_auditctl_add_syscall_rule(action_arch_filters="", other_filters="", auid_filters="", syscalls=[], key="", syscall_grouping=[]) -%}}
9be3b2
+{{% if other_filters!= "" %}}
9be3b2
+    {{% set other_filters = " " ~ other_filters %}}
9be3b2
+{{% endif %}}
9be3b2
+{{% if auid_filters!= "" %}}
9be3b2
+    {{% set auid_filters = " " ~ auid_filters %}}
9be3b2
+{{% endif %}}
9be3b2
+- name: Declare list of syscalls
9be3b2
   set_fact:
9be3b2
     syscalls: {{{ syscalls }}}
9be3b2
+    syscall_grouping: {{{ syscall_grouping }}}
9be3b2
+
9be3b2
+- name: Check existence of syscalls for in /etc/audit/rules.d/
9be3b2
+  find:
9be3b2
+    paths: /etc/audit
9be3b2
+    contains: '{{{ action_arch_filters }}}(( -S |,)\w+)*(( -S |,){{ item }})+(( -S |,)\w+)*{{{ other_filters }}}{{{ auid_filters }}} (-k\s+|-F\s+key=)\S+\s*$'
9be3b2
+    patterns: 'audit.rules'
9be3b2
+  register: find_command
9be3b2
+  loop: '{{ syscall_grouping }}'
9be3b2
 
9be3b2
-- name: Declare number of syscalls
9be3b2
-  set_fact: audit_syscalls_number_of_syscalls="{{ syscalls|length|int }}"
9be3b2
+- name: Set path to /etc/audit/rules.d/{{{ key }}}.rules
9be3b2
+  set_fact: audit_file="/etc/audit/audit.rules"
9be3b2
 
9be3b2
-{{#
9be3b2
-This dictionary is a Jinja2 trick to allow loops to change variables defined out of its scope.
9be3b2
-See official documentation: https://jinja.palletsprojects.com/en/2.11.x/templates/#assignments
9be3b2
-#}}
9be3b2
-{{% set fields_data = { 'regex' : "", 'plain_text': "" } %}}
9be3b2
-{{% for field in fields %}}
9be3b2
-    {{% set not_used = fields_data.update({'regex': fields_data.regex + '(?:-F[\s]+' + field + '[\s]+)'}) %}}
9be3b2
-    {{% set not_used = fields_data.update({'plain_text': fields_data.plain_text + ' -F ' + field }) %}}
9be3b2
-{{% endfor %}}
9be3b2
+- name: Declare found syscalls
9be3b2
+  set_fact: syscalls_found="{{ find_command.results | selectattr('matched') | map(attribute='item') | list }}"
9be3b2
 
9be3b2
-- name: Check existence of syscalls for architecture {{{ arch }}} in /etc/audit/audit.rules
9be3b2
-  find:
9be3b2
-    paths: "/etc/audit"
9be3b2
-    contains: '^[\s]*-a[\s]+always,exit[\s]+(?:.*-F[\s]+arch={{{ arch }}}[\s]+)(?:.*(-S[\s]+{{ item }}[\s]+|([\s]+|[,]){{ item }}([\s]+|[,]))).*{{{ fields_data.regex }}}(-k[\s]+|-F[\s]+key=)[\S]+[\s]*$'
9be3b2
-    patterns: "audit.rules"
9be3b2
-  register: audit_syscalls_found_{{{ arch }}}_audit_rules
9be3b2
-  loop: "{{ syscalls }}"
9be3b2
+- name: Declare missing syscalls
9be3b2
+  set_fact:
9be3b2
+    missing_syscalls="{{ syscalls | difference(syscalls_found) }}"
9be3b2
 
9be3b2
-- name: Get number of matched syscalls for architecture {{{ arch }}} in /etc/audit/audit.rules
9be3b2
-  set_fact: audit_syscalls_matched_{{{ arch }}}_audit_rules="{{ audit_syscalls_found_{{{ arch }}}_audit_rules.results|sum(attribute='matched')|int }}"
9be3b2
+- name: Replace the audit rule in {{ audit_file }}
9be3b2
+  lineinfile:
9be3b2
+    path: '{{ audit_file }}'
9be3b2
+    regexp: '({{{ action_arch_filters }}})(?=.*(?:(?:-S |,)(?:{{ syscalls_found | join("|") }}))\b)((?:( -S |,)\w+)+)({{{ other_filters }}}{{{ auid_filters }}} (?:-k |-F key=)\w+)'
9be3b2
+    line: '\1\2\3{{ missing_syscalls | join("\3") }}\4'
9be3b2
+    backrefs: yes
9be3b2
+    state: present
9be3b2
+  when: syscalls_found | length > 0 and missing_syscalls | length > 0
9be3b2
+
9be3b2
+- name: Add the audit rule to {{ audit_file }}
9be3b2
+  lineinfile:
9be3b2
+    path: '{{ audit_file }}'
9be3b2
+    line: "{{{ action_arch_filters }}} -S {{ syscalls | join(',') }}{{{ other_filters }}}{{{ auid_filters}}} -F key={{{ key }}}"
9be3b2
+    create: true
9be3b2
+    state: present
9be3b2
+  when: syscalls_found | length == 0
9be3b2
+- name: Declare list of syscals
9be3b2
+  set_fact:
9be3b2
+    syscalls: {{{ syscalls }}}
9be3b2
 
9be3b2
-- name: Insert the syscall rule in /etc/audit/audit.rules
9be3b2
-  block:
9be3b2
-    - name: "Construct rule: add rule list, action and arch"
9be3b2
-      set_fact: tmpline="-a always,exit -F arch={{{ arch }}}"
9be3b2
-    - name: "Construct rule: add syscalls"
9be3b2
-      set_fact: tmpline="{{ tmpline + ' -S ' + item.item }}"
9be3b2
-      loop: "{{ audit_syscalls_found_{{{ arch }}}_audit_rules.results }}"
9be3b2
-      when: item.matched is defined and item.matched == 0
9be3b2
-    - name: "Construct rule: add fields and key"
9be3b2
-      set_fact: tmpline="{{ tmpline + '{{{ fields_data.plain_text }}} -k {{{ key }}}' }}"
9be3b2
-    - name: Insert the line in /etc/audit/audit.rules
9be3b2
-      lineinfile:
9be3b2
-        path: "/etc/audit/audit.rules"
9be3b2
-        line: "{{ tmpline }}"
9be3b2
-        create: true
9be3b2
-        state: present
9be3b2
-  when: audit_syscalls_matched_{{{ arch }}}_audit_rules < audit_syscalls_number_of_syscalls
9be3b2
 {{%- endmacro %}}
9be3b2
 
9be3b2
 {{% macro ansible_sssd_ldap_config(parameter, value) -%}}
9be3b2
9be3b2
From a355d5b5578477a4464023dccccdb474ff571768 Mon Sep 17 00:00:00 2001
9be3b2
From: Watson Sato <wsato@redhat.com>
9be3b2
Date: Tue, 17 Aug 2021 14:35:17 +0200
9be3b2
Subject: [PATCH 14/31] Move template audit_rules_path_syscall to Ansible macro
9be3b2
9be3b2
---
9be3b2
 .../audit_rules_path_syscall/ansible.template | 100 +++++++-----------
9be3b2
 .../audit_rules_path_syscall/template.py      |   7 ++
9be3b2
 2 files changed, 44 insertions(+), 63 deletions(-)
9be3b2
9be3b2
diff --git a/shared/templates/audit_rules_path_syscall/ansible.template b/shared/templates/audit_rules_path_syscall/ansible.template
9be3b2
index d519609fa02..20440a36237 100644
9be3b2
--- a/shared/templates/audit_rules_path_syscall/ansible.template
9be3b2
+++ b/shared/templates/audit_rules_path_syscall/ansible.template
9be3b2
@@ -11,67 +11,41 @@
9be3b2
   set_fact:
9be3b2
     audit_arch: "b{{ ansible_architecture | regex_replace('.*(\\d\\d$)','\\1') }}"
9be3b2
 
9be3b2
-#
9be3b2
-# Inserts/replaces the rule in /etc/audit/rules.d
9be3b2
-#
9be3b2
-- name: Search /etc/audit/rules.d for other DAC audit rules
9be3b2
-  find:
9be3b2
-    paths: "/etc/audit/rules.d"
9be3b2
-    recurse: no
9be3b2
-    contains: ".*{{{ SYSCALL }}}(,[\\S]+)?[\\s]+-F[\\s]+{{{ POS }}}&03[\\s]+-F[\\s]+path={{{ PATH }}}.*"
9be3b2
-    patterns: "*.rules"
9be3b2
-  register: find_{{{ SYSCALL }}}
9be3b2
-
9be3b2
-- name: If existing DAC ruleset not found, use /etc/audit/rules.d/modify.rules as the recipient for the rule
9be3b2
-  set_fact:
9be3b2
-    all_files:
9be3b2
-      - /etc/audit/rules.d/modify.rules
9be3b2
-  when: find_{{{ SYSCALL }}}.matched is defined and find_{{{ SYSCALL }}}.matched == 0
9be3b2
-
9be3b2
-- name: Use matched file as the recipient for the rule
9be3b2
-  set_fact:
9be3b2
-    all_files:
9be3b2
-      - "{{ find_{{{ SYSCALL }}}.files | map(attribute='path') | list | first }}"
9be3b2
-  when: find_{{{ SYSCALL }}}.matched is defined and find_{{{ SYSCALL }}}.matched > 0
9be3b2
-
9be3b2
-- name: Inserts/replaces the {{{ SYSCALL }}} rule in rules.d when on x86
9be3b2
-  lineinfile:
9be3b2
-    path: "{{ all_files[0] }}"
9be3b2
-    line: "{{ item }}"
9be3b2
-    create: yes
9be3b2
-    regexp: "-a always,exit -F arch=b32 -S {{{ SYSCALL }}} -F {{{ POS }}}&03 -F path={{{ PATH }}} -F auid>={{{ auid }}} -F auid!=unset -F key=[\\S]+"
9be3b2
-  with_items:
9be3b2
-    - "-a always,exit -F arch=b32 -S {{{ SYSCALL }}} -F {{{ POS }}}&03 -F path={{{ PATH }}} -F auid>={{{ auid }}} -F auid!=unset -F key=modify"
9be3b2
-
9be3b2
-- name: Inserts/replaces the {{{ SYSCALL }}} rule in rules.d when on x86_64
9be3b2
-  lineinfile:
9be3b2
-    path: "{{ all_files[0] }}"
9be3b2
-    line: "{{ item }}"
9be3b2
-    create: yes
9be3b2
-    regexp: "-a always,exit -F arch=b64 -S {{{ SYSCALL }}} -F {{{ POS }}}&03 -F path={{{ PATH }}} -F auid>={{{ auid }}} -F auid!=unset -F key=[\\S]+"
9be3b2
-  with_items:
9be3b2
-    - "-a always,exit -F arch=b64 -S {{{ SYSCALL }}} -F {{{ POS }}}&03 -F path={{{ PATH }}} -F auid>={{{ auid }}} -F auid!=unset -F key=modify"
9be3b2
-  when: audit_arch is defined and audit_arch == 'b64'
9be3b2
-#   
9be3b2
-# Inserts/replaces the rule in /etc/audit/audit.rules
9be3b2
-#
9be3b2
-- name: Inserts/replaces the {{{ SYSCALL }}} rule in /etc/audit/audit.rules when on x86
9be3b2
-  lineinfile:
9be3b2
-    line: "{{ item }}"
9be3b2
-    state: present
9be3b2
-    dest: /etc/audit/audit.rules
9be3b2
-    create: yes
9be3b2
-    regexp: "-a always,exit -F arch=b32 -S {{{ SYSCALL }}} -F {{{ POS }}}&03 -F path={{{ PATH }}} -F auid>={{{ auid }}} -F auid!=unset -F key=[\\S]+"
9be3b2
-  with_items:
9be3b2
-    - "-a always,exit -F arch=b32 -S {{{ SYSCALL }}} -F {{{ POS }}}&03 -F path={{{ PATH }}} -F auid>={{{ auid }}} -F auid!=unset -F key=modify"
9be3b2
+- name: Perform remediattion of Audit rules for {{{ SYSCALL }}} for x86 platform
9be3b2
+  block:
9be3b2
+    {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b32",
9be3b2
+      other_filters="-F "~POS~"&03 -F path="~PATH,
9be3b2
+      auid_filters="-F auid>="~auid~" -F auid!=unset",
9be3b2
+      syscalls=SYSCALL,
9be3b2
+      key="modify",
9be3b2
+      syscall_grouping=SYSCALL_GROUPING,
9be3b2
+      )|indent(4) }}}
9be3b2
+    {{{ ansible_audit_auditctl_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b32",
9be3b2
+      other_filters="-F "~POS~"&03 -F path="~PATH,
9be3b2
+      auid_filters="-F auid>="~auid~" -F auid!=unset",
9be3b2
+      syscalls=SYSCALL,
9be3b2
+      key="modify",
9be3b2
+      syscall_grouping=SYSCALL_GROUPING,
9be3b2
+      )|indent(4) }}}
9be3b2
 
9be3b2
-- name: Inserts/replaces the {{{ SYSCALL }}} rule in audit.rules when on x86_64
9be3b2
-  lineinfile:
9be3b2
-    line: "{{ item }}"
9be3b2
-    state: present
9be3b2
-    dest: /etc/audit/audit.rules
9be3b2
-    create: yes
9be3b2
-    regexp: "-a always,exit -F arch=b64 -S {{{ SYSCALL }}} -F {{{ POS }}}&03 -F path={{{ PATH }}} -F auid>={{{ auid }}} -F auid!=unset -F key=[\\S]+"
9be3b2
-  with_items:
9be3b2
-    - "-a always,exit -F arch=b64 -S {{{ SYSCALL }}} -F {{{ POS }}}&03 -F path={{{ PATH }}} -F auid>={{{ auid }}} -F auid!=unset -F key=modify"
9be3b2
-  when: audit_arch is defined and audit_arch == 'b64'
9be3b2
+- name: Perform remediattion of Audit rules for {{{ SYSCALL }}} for x86_64 platform
9be3b2
+  block:
9be3b2
+    {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b64",
9be3b2
+      other_filters="-F "~POS~"&03 -F path="~PATH,
9be3b2
+      auid_filters="-F auid>="~auid~" -F auid!=unset",
9be3b2
+      syscalls=SYSCALL,
9be3b2
+      key="modify",
9be3b2
+      syscall_grouping=SYSCALL_GROUPING,
9be3b2
+      )|indent(4) }}}
9be3b2
+    {{{ ansible_audit_auditctl_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b64",
9be3b2
+      other_filters="-F "~POS~"&03 -F path="~PATH,
9be3b2
+      auid_filters="-F auid>="~auid~" -F auid!=unset",
9be3b2
+      syscalls=SYSCALL,
9be3b2
+      key="modify",
9be3b2
+      syscall_grouping=SYSCALL_GROUPING,
9be3b2
+      )|indent(4) }}}
9be3b2
+  when: audit_arch == "b64"
9be3b2
diff --git a/shared/templates/audit_rules_path_syscall/template.py b/shared/templates/audit_rules_path_syscall/template.py
9be3b2
index 7e0877a02b9..c13f34b94e0 100644
9be3b2
--- a/shared/templates/audit_rules_path_syscall/template.py
9be3b2
+++ b/shared/templates/audit_rules_path_syscall/template.py
9be3b2
@@ -11,4 +11,11 @@ def preprocess(data, lang):
9be3b2
         if "syscall_grouping" in data:
9be3b2
             # Make it easier to tranform the syscall_grouping into a Bash array
9be3b2
             data["syscall_grouping"] = " ".join(data["syscall_grouping"])
9be3b2
+    elif lang == "ansible":
9be3b2
+        if "syscall" in data:
9be3b2
+            # Tranform the syscall into a Ansible list
9be3b2
+            data["syscall"] = [ data["syscall"] ]
9be3b2
+        if "syscall_grouping" not in data:
9be3b2
+            # Ensure that syscall_grouping is a list
9be3b2
+            data["syscall_grouping"] = []
9be3b2
     return data
9be3b2
9be3b2
From 27d64329d2d9d3cdac03f0a46866f99c299b430d Mon Sep 17 00:00:00 2001
9be3b2
From: Watson Sato <wsato@redhat.com>
9be3b2
Date: Tue, 17 Aug 2021 16:37:12 +0200
9be3b2
Subject: [PATCH 15/31] Move template audit_rules_dac_modification to Ansible
9be3b2
 macro
9be3b2
9be3b2
Use Ansible macro ansible_audit_augenrules_add_syscall_rule and
9be3b2
ansible_audit_auditctl_add_syscall_rule that group the syscalls
9be3b2
according to defined grouping.
9be3b2
---
9be3b2
 .../ansible.template                          | 152 ++++++++----------
9be3b2
 .../audit_rules_dac_modification/template.py  |   7 +
9be3b2
 2 files changed, 76 insertions(+), 83 deletions(-)
9be3b2
9be3b2
diff --git a/shared/templates/audit_rules_dac_modification/ansible.template b/shared/templates/audit_rules_dac_modification/ansible.template
9be3b2
index d048978456d..d2ce6c50052 100644
9be3b2
--- a/shared/templates/audit_rules_dac_modification/ansible.template
9be3b2
+++ b/shared/templates/audit_rules_dac_modification/ansible.template
9be3b2
@@ -11,91 +11,77 @@
9be3b2
   set_fact:
9be3b2
     audit_arch: "b{{ ansible_architecture | regex_replace('.*(\\d\\d$)','\\1') }}"
9be3b2
 
9be3b2
-#
9be3b2
-# Inserts/replaces the rule in /etc/audit/rules.d
9be3b2
-#
9be3b2
-- name: Search /etc/audit/rules.d for other DAC audit rules
9be3b2
-  find:
9be3b2
-    paths: "/etc/audit/rules.d"
9be3b2
-    recurse: no
9be3b2
-    contains: "-F key=perm_mod$"
9be3b2
-    patterns: "*.rules"
9be3b2
-  register: find_{{{ ATTR }}}
9be3b2
-
9be3b2
-- name: If existing DAC ruleset not found, use /etc/audit/rules.d/privileged.rules as the recipient for the rule
9be3b2
-  set_fact:
9be3b2
-    all_files:
9be3b2
-      - /etc/audit/rules.d/privileged.rules
9be3b2
-  when: find_{{{ ATTR }}}.matched is defined and find_{{{ ATTR }}}.matched == 0
9be3b2
-
9be3b2
-- name: Use matched file as the recipient for the rule
9be3b2
-  set_fact:
9be3b2
-    all_files:
9be3b2
-      - "{{ find_{{{ ATTR }}}.files | map(attribute='path') | list | first }}"
9be3b2
-  when: find_{{{ ATTR }}}.matched is defined and find_{{{ ATTR }}}.matched > 0
9be3b2
-
9be3b2
-- name: Inserts/replaces the {{{ ATTR }}} rule in rules.d when on x86
9be3b2
-  lineinfile:
9be3b2
-    path: "{{ all_files[0] }}"
9be3b2
-    line: "-a always,exit -F arch=b32 -S {{{ ATTR }}} -F auid>={{{ auid }}} -F auid!=unset -F key=perm_mod"
9be3b2
-    create: yes
9be3b2
-
9be3b2
+- name: Perform remediattion of Audit rules for {{{ ATTR }}} for x86 platform
9be3b2
+  block:
9be3b2
+    {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b32",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="-F auid>="~auid~" -F auid!=unset",
9be3b2
+      syscalls=ATTR,
9be3b2
+      key="perm_mod",
9be3b2
+      syscall_grouping=SYSCALL_GROUPING,
9be3b2
+      )|indent(4) }}}
9be3b2
+    {{{ ansible_audit_auditctl_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b32",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="-F auid>="~auid~" -F auid!=unset",
9be3b2
+      syscalls=ATTR,
9be3b2
+      key="perm_mod",
9be3b2
+      syscall_grouping=SYSCALL_GROUPING,
9be3b2
+      )|indent(4) }}}
9be3b2
 {{%- if CHECK_ROOT_USER %}}
9be3b2
-- name: Inserts/replaces the {{{ ATTR }}} rule with auid=0 in rules.d when on x86
9be3b2
-  lineinfile:
9be3b2
-    path: "{{ all_files[0] }}"
9be3b2
-    line: "-a always,exit -F arch=b32 -S {{{ ATTR }}} -F auid=0 -F key=perm_mod"
9be3b2
-    create: yes
9be3b2
+    {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b32",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="-F auid=0",
9be3b2
+      syscalls=ATTR,
9be3b2
+      key="perm_mod",
9be3b2
+      syscall_grouping=SYSCALL_GROUPING,
9be3b2
+      )|indent(4) }}}
9be3b2
+    {{{ ansible_audit_auditctl_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b32",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="-F auid=0",
9be3b2
+      syscalls=ATTR,
9be3b2
+      key="perm_mod",
9be3b2
+      syscall_grouping=SYSCALL_GROUPING,
9be3b2
+      )|indent(4) }}}
9be3b2
 {{%- endif %}}
9be3b2
 
9be3b2
-- name: Inserts/replaces the {{{ ATTR }}} rule in rules.d when on x86_64
9be3b2
-  lineinfile:
9be3b2
-    path: "{{ all_files[0] }}"
9be3b2
-    line: "-a always,exit -F arch=b64 -S {{{ ATTR }}} -F auid>={{{ auid }}} -F auid!=unset -F key=perm_mod"
9be3b2
-    create: yes
9be3b2
-  when: audit_arch is defined and audit_arch == 'b64'
9be3b2
-
9be3b2
-{{%- if CHECK_ROOT_USER %}}
9be3b2
-- name: Inserts/replaces the {{{ ATTR }}} rule with auid=0 in rules.d when on x86_64
9be3b2
-  lineinfile:
9be3b2
-    path: "{{ all_files[0] }}"
9be3b2
-    line: "-a always,exit -F arch=b64 -S {{{ ATTR }}} -F auid=0 -F key=perm_mod"
9be3b2
-    create: yes
9be3b2
-  when: audit_arch is defined and audit_arch == 'b64'
9be3b2
-{{%- endif %}}
9be3b2
-#   
9be3b2
-# Inserts/replaces the rule in /etc/audit/audit.rules
9be3b2
-#
9be3b2
-- name: Inserts/replaces the {{{ ATTR }}} rule in /etc/audit/audit.rules when on x86
9be3b2
-  lineinfile:
9be3b2
-    line: "-a always,exit -F arch=b32 -S {{{ ATTR }}} -F auid>={{{ auid }}} -F auid!=unset -F key=perm_mod"
9be3b2
-    state: present
9be3b2
-    dest: /etc/audit/audit.rules
9be3b2
-    create: yes
9be3b2
-
9be3b2
-{{%- if CHECK_ROOT_USER %}}
9be3b2
-- name: Inserts/replaces the {{{ ATTR }}} rule with auid=0 in /etc/audit/audit.rules when on x86
9be3b2
-  lineinfile:
9be3b2
-    line: "-a always,exit -F arch=b32 -S {{{ ATTR }}} -F auid=0 -F key=perm_mod"
9be3b2
-    state: present
9be3b2
-    dest: /etc/audit/audit.rules
9be3b2
-    create: yes
9be3b2
-{{%- endif %}}
9be3b2
-
9be3b2
-- name: Inserts/replaces the {{{ ATTR }}} rule in audit.rules when on x86_64
9be3b2
-  lineinfile:
9be3b2
-    line: "-a always,exit -F arch=b64 -S {{{ ATTR }}} -F auid>={{{ auid }}} -F auid!=unset -F key=perm_mod"
9be3b2
-    state: present
9be3b2
-    dest: /etc/audit/audit.rules
9be3b2
-    create: yes
9be3b2
-  when: audit_arch is defined and audit_arch == 'b64'
9be3b2
-
9be3b2
+- name: Perform remediattion of Audit rules for {{{ ATTR }}} for x86_64 platform
9be3b2
+  block:
9be3b2
+    {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b64",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="-F auid>="~auid~" -F auid!=unset",
9be3b2
+      syscalls=ATTR,
9be3b2
+      key="perm_mod",
9be3b2
+      syscall_grouping=SYSCALL_GROUPING,
9be3b2
+      )|indent(4) }}}
9be3b2
+    {{{ ansible_audit_auditctl_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b64",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="-F auid>="~auid~" -F auid!=unset",
9be3b2
+      syscalls=ATTR,
9be3b2
+      key="perm_mod",
9be3b2
+      syscall_grouping=SYSCALL_GROUPING,
9be3b2
+      )|indent(4) }}}
9be3b2
 {{%- if CHECK_ROOT_USER %}}
9be3b2
-- name: Inserts/replaces the {{{ ATTR }}} rule with auid=0 in audit.rules when on x86_64
9be3b2
-  lineinfile:
9be3b2
-    line: "-a always,exit -F arch=b64 -S {{{ ATTR }}} -F auid=0 -F auid!=unset -F key=perm_mod"
9be3b2
-    state: present
9be3b2
-    dest: /etc/audit/audit.rules
9be3b2
-    create: yes
9be3b2
-  when: audit_arch is defined and audit_arch == 'b64'
9be3b2
+    {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b64",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="-F auid=0",
9be3b2
+      syscalls=ATTR,
9be3b2
+      key="perm_mod",
9be3b2
+      syscall_grouping=SYSCALL_GROUPING,
9be3b2
+      )|indent(4) }}}
9be3b2
+    {{{ ansible_audit_auditctl_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b64",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="-F auid=0",
9be3b2
+      syscalls=ATTR,
9be3b2
+      key="perm_mod",
9be3b2
+      syscall_grouping=SYSCALL_GROUPING,
9be3b2
+      )|indent(4) }}}
9be3b2
 {{%- endif %}}
9be3b2
+  when: audit_arch == "b64"
9be3b2
diff --git a/shared/templates/audit_rules_dac_modification/template.py b/shared/templates/audit_rules_dac_modification/template.py
9be3b2
index 7dc53e81f7d..eebd0b6f4ee 100644
9be3b2
--- a/shared/templates/audit_rules_dac_modification/template.py
9be3b2
+++ b/shared/templates/audit_rules_dac_modification/template.py
9be3b2
@@ -7,5 +7,12 @@ def preprocess(data, lang):
9be3b2
         if "syscall_grouping" in data:
9be3b2
             # Make it easier to tranform the syscall_grouping into a Bash array
9be3b2
             data["syscall_grouping"] = " ".join(data["syscall_grouping"])
9be3b2
+    elif lang == "ansible":
9be3b2
+        if "attr" in data:
9be3b2
+            # Tranform the syscall into a Ansible list
9be3b2
+            data["attr"] = [ data["attr"] ]
9be3b2
+        if "syscall_grouping" not in data:
9be3b2
+            # Ensure that syscall_grouping is a list
9be3b2
+            data["syscall_grouping"] = []
9be3b2
 
9be3b2
     return data
9be3b2
9be3b2
From cd507f507d3fb756c49e4ca19d47f17d951e1a9f Mon Sep 17 00:00:00 2001
9be3b2
From: Watson Sato <wsato@redhat.com>
9be3b2
Date: Tue, 17 Aug 2021 16:59:48 +0200
9be3b2
Subject: [PATCH 16/31] Move template
9be3b2
 audit_rules_unsuccessfull_file_modification to Ansible macro
9be3b2
9be3b2
Use Ansible macro ansible_audit_augenrules_add_syscall_rule and
9be3b2
ansible_audit_auditctl_add_syscall_rule that group the syscalls
9be3b2
according to defined grouping.
9be3b2
---
9be3b2
 .../ansible.template                          | 102 +++++++-----------
9be3b2
 .../template.py                               |   8 ++
9be3b2
 2 files changed, 47 insertions(+), 63 deletions(-)
9be3b2
9be3b2
diff --git a/shared/templates/audit_rules_unsuccessful_file_modification/ansible.template b/shared/templates/audit_rules_unsuccessful_file_modification/ansible.template
9be3b2
index 8e8e003a5b0..cb5decc6a6e 100644
9be3b2
--- a/shared/templates/audit_rules_unsuccessful_file_modification/ansible.template
9be3b2
+++ b/shared/templates/audit_rules_unsuccessful_file_modification/ansible.template
9be3b2
@@ -11,67 +11,43 @@
9be3b2
   set_fact:
9be3b2
     audit_arch: "b{{ ansible_architecture | regex_replace('.*(\\d\\d$)','\\1') }}"
9be3b2
 
9be3b2
-#
9be3b2
-# Inserts/replaces the rule in /etc/audit/rules.d
9be3b2
-#
9be3b2
-- name: Search /etc/audit/rules.d for other DAC audit rules
9be3b2
-  find:
9be3b2
-    paths: "/etc/audit/rules.d"
9be3b2
-    recurse: no
9be3b2
-    contains: "-F key=perm_mod$"
9be3b2
-    patterns: "*.rules"
9be3b2
-  register: find_{{{ NAME }}}
9be3b2
-
9be3b2
-- name: If existing DAC ruleset not found, use /etc/audit/rules.d/access.rules as the recipient for the rule
9be3b2
-  set_fact:
9be3b2
-    all_files:
9be3b2
-      - /etc/audit/rules.d/access.rules
9be3b2
-  when: find_{{{ NAME }}}.matched is defined and find_{{{ NAME }}}.matched == 0
9be3b2
-
9be3b2
-- name: Use matched file as the recipient for the rule
9be3b2
-  set_fact:
9be3b2
-    all_files:
9be3b2
-      - "{{ find_{{{ NAME }}}.files | map(attribute='path') | list | first }}"
9be3b2
-  when: find_{{{ NAME }}}.matched is defined and find_{{{ NAME }}}.matched > 0
9be3b2
-
9be3b2
-- name: Inserts/replaces the {{{ NAME }}} rule in rules.d when on x86
9be3b2
-  lineinfile:
9be3b2
-    path: "{{ all_files[0] }}"
9be3b2
-    line: "{{ item }}"
9be3b2
-    create: yes
9be3b2
-  with_items:
9be3b2
-    - "-a always,exit -F arch=b32 -S {{{ NAME }}} -F exit=-EACCES -F auid>={{{ auid }}} -F auid!=unset -F key=access"
9be3b2
-    - "-a always,exit -F arch=b32 -S {{{ NAME }}} -F exit=-EPERM -F auid>={{{ auid }}} -F auid!=unset -F key=access"
9be3b2
-
9be3b2
-- name: Inserts/replaces the {{{ NAME }}} rule in rules.d when on x86_64
9be3b2
-  lineinfile:
9be3b2
-    path: "{{ all_files[0] }}"
9be3b2
-    line: "{{ item }}"
9be3b2
-    create: yes
9be3b2
-  with_items:
9be3b2
-    - "-a always,exit -F arch=b64 -S {{{ NAME }}} -F exit=-EACCES -F auid>={{{ auid }}} -F auid!=unset -F key=access"
9be3b2
-    - "-a always,exit -F arch=b64 -S {{{ NAME }}} -F exit=-EPERM -F auid>={{{ auid }}} -F auid!=unset -F key=access"
9be3b2
-  when: audit_arch is defined and audit_arch == 'b64'
9be3b2
-#   
9be3b2
-# Inserts/replaces the rule in /etc/audit/audit.rules
9be3b2
-#
9be3b2
-- name: Inserts/replaces the {{{ NAME }}} rule in /etc/audit/audit.rules when on x86
9be3b2
-  lineinfile:
9be3b2
-    line: "{{ item }}"
9be3b2
-    state: present
9be3b2
-    dest: /etc/audit/audit.rules
9be3b2
-    create: yes
9be3b2
-  with_items:
9be3b2
-    - "-a always,exit -F arch=b32 -S {{{ NAME }}} -F exit=-EACCES -F auid>={{{ auid }}} -F auid!=unset -F key=access"
9be3b2
-    - "-a always,exit -F arch=b32 -S {{{ NAME }}} -F exit=-EPERM -F auid>={{{ auid }}} -F auid!=unset -F key=access"
9be3b2
+{{% for EXIT_CODE in ["EACCES","EPERM"] %}}
9be3b2
+- name: Perform remediation of Audit rules for {{{ NAME }}} {{{ EXIT_CODE}}} for x86 platform
9be3b2
+  block:
9be3b2
+    {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b32",
9be3b2
+      other_filters="-F exit=-"~EXIT_CODE,
9be3b2
+      auid_filters="-F auid>="~auid~" -F auid!=unset",
9be3b2
+      syscalls=NAME,
9be3b2
+      key="access",
9be3b2
+      syscall_grouping=SYSCALL_GROUPING,
9be3b2
+      )|indent(4) }}}
9be3b2
+    {{{ ansible_audit_auditctl_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b32",
9be3b2
+      other_filters="-F exit=-"~EXIT_CODE,
9be3b2
+      auid_filters="-F auid>="~auid~" -F auid!=unset",
9be3b2
+      syscalls=NAME,
9be3b2
+      key="access",
9be3b2
+      syscall_grouping=SYSCALL_GROUPING,
9be3b2
+      )|indent(4) }}}
9be3b2
 
9be3b2
-- name: Inserts/replaces the {{{ NAME }}} rule in audit.rules when on x86_64
9be3b2
-  lineinfile:
9be3b2
-    line: "{{ item }}"
9be3b2
-    state: present
9be3b2
-    dest: /etc/audit/audit.rules
9be3b2
-    create: yes
9be3b2
-  with_items:
9be3b2
-    - "-a always,exit -F arch=b64 -S {{{ NAME }}} -F exit=-EACCES -F auid>={{{ auid }}} -F auid!=unset -F key=access"
9be3b2
-    - "-a always,exit -F arch=b64 -S {{{ NAME }}} -F exit=-EPERM -F auid>={{{ auid }}} -F auid!=unset -F key=access"
9be3b2
-  when: audit_arch is defined and audit_arch == 'b64'
9be3b2
+- name: Perform remediattion of Audit rules for {{{ NAME }}} {{{ EXIT_CODE }}} for x86_64 platform
9be3b2
+  block:
9be3b2
+    {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b64",
9be3b2
+      other_filters="-F exit=-"~EXIT_CODE,
9be3b2
+      auid_filters="-F auid>="~auid~" -F auid!=unset",
9be3b2
+      syscalls=NAME,
9be3b2
+      key="access",
9be3b2
+      syscall_grouping=SYSCALL_GROUPING,
9be3b2
+      )|indent(4) }}}
9be3b2
+    {{{ ansible_audit_auditctl_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b64",
9be3b2
+      other_filters="-F exit=-"~EXIT_CODE,
9be3b2
+      auid_filters="-F auid>="~auid~" -F auid!=unset",
9be3b2
+      syscalls=NAME,
9be3b2
+      key="access",
9be3b2
+      syscall_grouping=SYSCALL_GROUPING,
9be3b2
+      )|indent(4) }}}
9be3b2
+  when: audit_arch == "b64"
9be3b2
+{{% endfor %}}
9be3b2
diff --git a/shared/templates/audit_rules_unsuccessful_file_modification/template.py b/shared/templates/audit_rules_unsuccessful_file_modification/template.py
9be3b2
index a4e58609f66..62abfad9a2c 100644
9be3b2
--- a/shared/templates/audit_rules_unsuccessful_file_modification/template.py
9be3b2
+++ b/shared/templates/audit_rules_unsuccessful_file_modification/template.py
9be3b2
@@ -6,6 +6,14 @@ def _audit_rules_unsuccessful_file_modification(data, lang):
9be3b2
         if "syscall_grouping" in data:
9be3b2
             # Make it easier to tranform the syscall_grouping into a Bash array
9be3b2
             data["syscall_grouping"] = " ".join(data["syscall_grouping"])
9be3b2
+    elif lang == "ansible":
9be3b2
+        if "name" in data:
9be3b2
+            # Tranform the syscall into a Ansible list
9be3b2
+            # The syscall is under 'name'
9be3b2
+            data["name"] = [ data["name"] ]
9be3b2
+        if "syscall_grouping" not in data:
9be3b2
+            # Ensure that syscall_grouping is a list
9be3b2
+            data["syscall_grouping"] = []
9be3b2
     return data
9be3b2
 
9be3b2
 
9be3b2
9be3b2
From 52dcdb4be6c1b450bfb074684b4657a40963e752 Mon Sep 17 00:00:00 2001
9be3b2
From: Watson Sato <wsato@redhat.com>
9be3b2
Date: Tue, 17 Aug 2021 17:34:26 +0200
9be3b2
Subject: [PATCH 17/31] Add syscall_groups to unsuccessful_file_mofication
9be3b2
 rules
9be3b2
9be3b2
The groupings were based on the rule description.
9be3b2
---
9be3b2
 .../rule.yml                                               | 7 +++++++
9be3b2
 .../rule.yml                                               | 5 +++++
9be3b2
 .../rule.yml                                               | 7 +++++++
9be3b2
 .../rule.yml                                               | 7 +++++++
9be3b2
 .../rule.yml                                               | 5 +++++
9be3b2
 .../rule.yml                                               | 5 +++++
9be3b2
 .../rule.yml                                               | 7 +++++++
9be3b2
 .../rule.yml                                               | 5 +++++
9be3b2
 .../rule.yml                                               | 7 +++++++
9be3b2
 .../rule.yml                                               | 5 +++++
9be3b2
 .../rule.yml                                               | 5 +++++
9be3b2
 .../rule.yml                                               | 6 ++++++
9be3b2
 .../rule.yml                                               | 7 +++++++
9be3b2
 .../rule.yml                                               | 5 +++++
9be3b2
 .../rule.yml                                               | 5 +++++
9be3b2
 15 files changed, 88 insertions(+)
9be3b2
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_chmod/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_chmod/rule.yml
9be3b2
index 7cf5855bcae..ddfe1e9d6c3 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_chmod/rule.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_chmod/rule.yml
9be3b2
@@ -51,3 +51,10 @@ template:
9be3b2
     name: audit_rules_unsuccessful_file_modification
9be3b2
     vars:
9be3b2
         name: chmod
9be3b2
+        syscall_grouping:
9be3b2
+          - chmod
9be3b2
+          - fchmod
9be3b2
+          - fchmodat
9be3b2
+          - fsetxattr
9be3b2
+          - lsetxattr
9be3b2
+          - setxattr
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_chown/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_chown/rule.yml
9be3b2
index 090463bd402..6ca6e27b24d 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_chown/rule.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_chown/rule.yml
9be3b2
@@ -51,3 +51,8 @@ template:
9be3b2
     name: audit_rules_unsuccessful_file_modification
9be3b2
     vars:
9be3b2
         name: chown
9be3b2
+        syscall_grouping:
9be3b2
+          - chown
9be3b2
+          - fchown
9be3b2
+          - fchownat
9be3b2
+          - lchown
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_fchmod/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_fchmod/rule.yml
9be3b2
index fc2b945ef9b..1a93b4537e0 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_fchmod/rule.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_fchmod/rule.yml
9be3b2
@@ -51,3 +51,10 @@ template:
9be3b2
     name: audit_rules_unsuccessful_file_modification
9be3b2
     vars:
9be3b2
         name: fchmod
9be3b2
+        syscall_grouping:
9be3b2
+          - chmod
9be3b2
+          - fchmod
9be3b2
+          - fchmodat
9be3b2
+          - fsetxattr
9be3b2
+          - lsetxattr
9be3b2
+          - setxattr
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_fchmodat/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_fchmodat/rule.yml
9be3b2
index e4da28ec070..dd77cd60639 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_fchmodat/rule.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_fchmodat/rule.yml
9be3b2
@@ -51,3 +51,10 @@ template:
9be3b2
     name: audit_rules_unsuccessful_file_modification
9be3b2
     vars:
9be3b2
         name: fchmodat
9be3b2
+        syscall_grouping:
9be3b2
+          - chmod
9be3b2
+          - fchmod
9be3b2
+          - fchmodat
9be3b2
+          - fsetxattr
9be3b2
+          - lsetxattr
9be3b2
+          - setxattr
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_fchown/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_fchown/rule.yml
9be3b2
index 69a9ddf72b1..3e5da890340 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_fchown/rule.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_fchown/rule.yml
9be3b2
@@ -51,3 +51,8 @@ template:
9be3b2
     name: audit_rules_unsuccessful_file_modification
9be3b2
     vars:
9be3b2
         name: fchown
9be3b2
+        syscall_grouping:
9be3b2
+          - chown
9be3b2
+          - fchown
9be3b2
+          - fchownat
9be3b2
+          - lchown
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_fchownat/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_fchownat/rule.yml
9be3b2
index 7da6b8a4d73..76f0e177b67 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_fchownat/rule.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_fchownat/rule.yml
9be3b2
@@ -51,3 +51,8 @@ template:
9be3b2
     name: audit_rules_unsuccessful_file_modification
9be3b2
     vars:
9be3b2
         name: fchownat
9be3b2
+        syscall_grouping:
9be3b2
+          - chown
9be3b2
+          - fchown
9be3b2
+          - fchownat
9be3b2
+          - lchown
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_fsetxattr/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_fsetxattr/rule.yml
9be3b2
index eaa9f32081f..bf1ff86737c 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_fsetxattr/rule.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_fsetxattr/rule.yml
9be3b2
@@ -51,3 +51,10 @@ template:
9be3b2
     name: audit_rules_unsuccessful_file_modification
9be3b2
     vars:
9be3b2
         name: fsetxattr
9be3b2
+        syscall_grouping:
9be3b2
+          - chmod
9be3b2
+          - fchmod
9be3b2
+          - fchmodat
9be3b2
+          - fsetxattr
9be3b2
+          - lsetxattr
9be3b2
+          - setxattr
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_lchown/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_lchown/rule.yml
9be3b2
index 84c71963545..3d42cea2ac1 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_lchown/rule.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_lchown/rule.yml
9be3b2
@@ -55,3 +55,8 @@ template:
9be3b2
     name: audit_rules_unsuccessful_file_modification
9be3b2
     vars:
9be3b2
         name: lchown
9be3b2
+        syscall_grouping:
9be3b2
+          - chown
9be3b2
+          - fchown
9be3b2
+          - fchownat
9be3b2
+          - lchown
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_lsetxattr/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_lsetxattr/rule.yml
9be3b2
index 1de114c65d5..e388ec2d69e 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_lsetxattr/rule.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_lsetxattr/rule.yml
9be3b2
@@ -51,3 +51,10 @@ template:
9be3b2
     name: audit_rules_unsuccessful_file_modification
9be3b2
     vars:
9be3b2
         name: lsetxattr
9be3b2
+        syscall_grouping:
9be3b2
+          - chmod
9be3b2
+          - fchmod
9be3b2
+          - fchmodat
9be3b2
+          - fsetxattr
9be3b2
+          - lsetxattr
9be3b2
+          - setxattr
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_rename/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_rename/rule.yml
9be3b2
index 0aac53c1d2f..ae390fc9904 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_rename/rule.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_rename/rule.yml
9be3b2
@@ -64,3 +64,8 @@ template:
9be3b2
     name: audit_rules_unsuccessful_file_modification
9be3b2
     vars:
9be3b2
         name: rename
9be3b2
+        syscall_grouping:
9be3b2
+          - rename
9be3b2
+          - renameat
9be3b2
+          - unlink
9be3b2
+          - unlinkat
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_renameat/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_renameat/rule.yml
9be3b2
index 81bb79b5589..ab5d3b8d7b3 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_renameat/rule.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_renameat/rule.yml
9be3b2
@@ -64,3 +64,8 @@ template:
9be3b2
     name: audit_rules_unsuccessful_file_modification
9be3b2
     vars:
9be3b2
         name: renameat
9be3b2
+        syscall_grouping:
9be3b2
+          - rename
9be3b2
+          - renameat
9be3b2
+          - unlink
9be3b2
+          - unlinkat
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_renameat2/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_renameat2/rule.yml
9be3b2
index 57dc243760d..f0c7e1a9ca9 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_renameat2/rule.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_renameat2/rule.yml
9be3b2
@@ -49,3 +49,9 @@ template:
9be3b2
     name: audit_rules_unsuccessful_file_modification
9be3b2
     vars:
9be3b2
         name: renameat2
9be3b2
+        syscall_grouping:
9be3b2
+          - rename
9be3b2
+          - renameat
9be3b2
+          - renameat2
9be3b2
+          - unlink
9be3b2
+          - unlinkat
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_setxattr/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_setxattr/rule.yml
9be3b2
index a406dba0e8d..a45d0cdac86 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_setxattr/rule.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_setxattr/rule.yml
9be3b2
@@ -51,3 +51,10 @@ template:
9be3b2
     name: audit_rules_unsuccessful_file_modification
9be3b2
     vars:
9be3b2
         name: setxattr
9be3b2
+        syscall_grouping:
9be3b2
+          - chmod
9be3b2
+          - fchmod
9be3b2
+          - fchmodat
9be3b2
+          - fsetxattr
9be3b2
+          - lsetxattr
9be3b2
+          - setxattr
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_unlink/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_unlink/rule.yml
9be3b2
index 55f4582ba74..c78957bab21 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_unlink/rule.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_unlink/rule.yml
9be3b2
@@ -66,3 +66,8 @@ template:
9be3b2
     name: audit_rules_unsuccessful_file_modification
9be3b2
     vars:
9be3b2
         name: unlink
9be3b2
+        syscall_grouping:
9be3b2
+          - rename
9be3b2
+          - renameat
9be3b2
+          - unlink
9be3b2
+          - unlinkat
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_unlinkat/rule.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_unlinkat/rule.yml
9be3b2
index 0a672366fe8..8fa62518cb5 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_unlinkat/rule.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification_unlinkat/rule.yml
9be3b2
@@ -66,3 +66,8 @@ template:
9be3b2
     name: audit_rules_unsuccessful_file_modification
9be3b2
     vars:
9be3b2
         name: unlinkat
9be3b2
+        syscall_grouping:
9be3b2
+          - rename
9be3b2
+          - renameat
9be3b2
+          - unlink
9be3b2
+          - unlinkat
9be3b2
9be3b2
From bc7152399c205b25c9a471deffc0497d26896cd7 Mon Sep 17 00:00:00 2001
9be3b2
From: Watson Sato <wsato@redhat.com>
9be3b2
Date: Tue, 17 Aug 2021 17:45:45 +0200
9be3b2
Subject: [PATCH 18/31] Move template audit_rules_privileged_commands to
9be3b2
 Ansible macro
9be3b2
9be3b2
Update the macros to handle better empty syscalls parameter.
9be3b2
9be3b2
Use Ansible macro ansible_audit_augenrules_add_syscall_rule and
9be3b2
ansible_audit_auditctl_add_syscall_rule that group the syscalls
9be3b2
according to defined grouping.
9be3b2
---
9be3b2
 shared/macros-ansible.jinja                   | 14 ++++-
9be3b2
 .../ansible.template                          | 56 +++++++------------
9be3b2
 .../template.py                               |  4 ++
9be3b2
 3 files changed, 35 insertions(+), 39 deletions(-)
9be3b2
9be3b2
diff --git a/shared/macros-ansible.jinja b/shared/macros-ansible.jinja
9be3b2
index 5e120deee58..a067742b1f4 100644
9be3b2
--- a/shared/macros-ansible.jinja
9be3b2
+++ b/shared/macros-ansible.jinja
9be3b2
@@ -404,6 +404,11 @@ The macro requires following parameters:
9be3b2
 {{% if auid_filters != "" %}}
9be3b2
     {{% set auid_filters = " " ~ auid_filters %}}
9be3b2
 {{% endif %}}
9be3b2
+{{% if syscalls == [] %}}
9be3b2
+    {{% set syscall_flag = "" %}}
9be3b2
+{{% else %}}
9be3b2
+    {{% set syscall_flag = " -S " %}}
9be3b2
+{{% endif %}}
9be3b2
 - name: Declare list of syscalls
9be3b2
   set_fact:
9be3b2
     syscalls: {{{ syscalls }}}
9be3b2
@@ -455,7 +460,7 @@ The macro requires following parameters:
9be3b2
 - name: Add the audit rule to {{ audit_file }}
9be3b2
   lineinfile:
9be3b2
     path: '{{ audit_file }}'
9be3b2
-    line: "{{{ action_arch_filters }}} -S {{ syscalls | join(',') }}{{{ other_filters }}}{{{ auid_filters}}} -F key={{{ key }}}"
9be3b2
+    line: "{{{ action_arch_filters }}}{{{ syscall_flag }}}{{ syscalls | join(',') }}{{{ other_filters }}}{{{ auid_filters}}} -F key={{{ key }}}"
9be3b2
     create: true
9be3b2
     state: present
9be3b2
   when: syscalls_found | length == 0
9be3b2
@@ -483,6 +488,11 @@ The macro requires following parameters:
9be3b2
 {{% if auid_filters!= "" %}}
9be3b2
     {{% set auid_filters = " " ~ auid_filters %}}
9be3b2
 {{% endif %}}
9be3b2
+{{% if syscalls == [] %}}
9be3b2
+    {{% set syscall_flag = "" %}}
9be3b2
+{{% else %}}
9be3b2
+    {{% set syscall_flag = " -S " %}}
9be3b2
+{{% endif %}}
9be3b2
 - name: Declare list of syscalls
9be3b2
   set_fact:
9be3b2
     syscalls: {{{ syscalls }}}
9be3b2
@@ -518,7 +528,7 @@ The macro requires following parameters:
9be3b2
 - name: Add the audit rule to {{ audit_file }}
9be3b2
   lineinfile:
9be3b2
     path: '{{ audit_file }}'
9be3b2
-    line: "{{{ action_arch_filters }}} -S {{ syscalls | join(',') }}{{{ other_filters }}}{{{ auid_filters}}} -F key={{{ key }}}"
9be3b2
+    line: "{{{ action_arch_filters }}}{{{ syscall_flag }}}{{ syscalls | join(',') }}{{{ other_filters }}}{{{ auid_filters}}} -F key={{{ key }}}"
9be3b2
     create: true
9be3b2
     state: present
9be3b2
   when: syscalls_found | length == 0
9be3b2
diff --git a/shared/templates/audit_rules_privileged_commands/ansible.template b/shared/templates/audit_rules_privileged_commands/ansible.template
9be3b2
index 06154e10ceb..b1788b59b8a 100644
9be3b2
--- a/shared/templates/audit_rules_privileged_commands/ansible.template
9be3b2
+++ b/shared/templates/audit_rules_privileged_commands/ansible.template
9be3b2
@@ -1,5 +1,5 @@
9be3b2
 {{%- if product in ["rhel8", "rhel9", "sle12", "sle15"] %}}
9be3b2
-  {{%- set perm_x="-F perm=x " %}}
9be3b2
+  {{%- set perm_x=" -F perm=x" %}}
9be3b2
 {{%- endif %}}
9be3b2
 # platform = multi_platform_rhel,multi_platform_fedora,multi_platform_ol,multi_platform_rhv,multi_platform_sle
9be3b2
 # reboot = false
9be3b2
@@ -7,39 +7,21 @@
9be3b2
 # complexity = low
9be3b2
 # disruption = low
9be3b2
 
9be3b2
-# Inserts/replaces the rule in /etc/audit/rules.d
9be3b2
-
9be3b2
-- name: Search /etc/audit/rules.d for audit rule entries
9be3b2
-  find:
9be3b2
-    paths: "/etc/audit/rules.d"
9be3b2
-    recurse: no
9be3b2
-    contains: "^.*path={{{ PATH }}}.*$"
9be3b2
-    patterns: "*.rules"
9be3b2
-  register: find_{{{ NAME }}}
9be3b2
-
9be3b2
-- name: Use /etc/audit/rules.d/privileged.rules as the recipient for the rule
9be3b2
-  set_fact:
9be3b2
-    all_files:
9be3b2
-      - /etc/audit/rules.d/privileged.rules
9be3b2
-  when: find_{{{ NAME }}}.matched is defined and find_{{{ NAME }}}.matched == 0
9be3b2
-
9be3b2
-- name: Use matched file as the recipient for the rule
9be3b2
-  set_fact:
9be3b2
-    all_files:
9be3b2
-      - "{{ find_{{{ NAME }}}.files | map(attribute='path') | list | first }}"
9be3b2
-  when: find_{{{ NAME }}}.matched is defined and find_{{{ NAME }}}.matched > 0
9be3b2
-
9be3b2
-
9be3b2
-- name: Inserts/replaces the {{{ NAME }}} rule in rules.d
9be3b2
-  lineinfile:
9be3b2
-    path: "{{ all_files[0] }}"
9be3b2
-    line: '-a always,exit -F path={{{ PATH }}} {{{ perm_x }}}-F auid>={{{ auid }}} -F auid!=unset -F key=privileged'
9be3b2
-    create: yes
9be3b2
-
9be3b2
-# Inserts/replaces the {{{ NAME }}} rule in /etc/audit/audit.rules
9be3b2
-
9be3b2
-- name: Inserts/replaces the {{{ NAME }}} rule in audit.rules
9be3b2
-  lineinfile:
9be3b2
-    path: /etc/audit/audit.rules
9be3b2
-    line: '-a always,exit -F path={{{ PATH }}} {{{ perm_x }}}-F auid>={{{ auid }}} -F auid!=unset -F key=privileged'
9be3b2
-    create: yes
9be3b2
+- name: Perform remediattion of Audit rules for {{{ PATH }}}
9be3b2
+  block:
9be3b2
+    {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit",
9be3b2
+      other_filters="-F path="~PATH~perm_x,
9be3b2
+      auid_filters="-F auid>="~auid~" -F auid!=unset",
9be3b2
+      syscalls=SYSCALL,
9be3b2
+      key="privileged",
9be3b2
+      syscall_grouping=SYSCALL_GROUPING,
9be3b2
+      )|indent(4) }}}
9be3b2
+    {{{ ansible_audit_auditctl_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit",
9be3b2
+      other_filters="-F path="~PATH~perm_x,
9be3b2
+      auid_filters="-F auid>="~auid~" -F auid!=unset",
9be3b2
+      syscalls=SYSCALL,
9be3b2
+      key="privileged",
9be3b2
+      syscall_grouping=SYSCALL_GROUPING,
9be3b2
+      )|indent(4) }}}
9be3b2
diff --git a/shared/templates/audit_rules_privileged_commands/template.py b/shared/templates/audit_rules_privileged_commands/template.py
9be3b2
index 43302a6690a..0cf6cba79cc 100644
9be3b2
--- a/shared/templates/audit_rules_privileged_commands/template.py
9be3b2
+++ b/shared/templates/audit_rules_privileged_commands/template.py
9be3b2
@@ -19,4 +19,8 @@ def preprocess(data, lang):
9be3b2
         if "syscall_grouping" in data:
9be3b2
             # Make it easier to tranform the syscall_grouping into a Bash array
9be3b2
             data["syscall_grouping"] = " ".join(data["syscall_grouping"])
9be3b2
+    elif lang == "ansible":
9be3b2
+        # This template does not use the 'syscall' parameters
9be3b2
+        data["syscall"] = []
9be3b2
+        data["syscall_grouping"] = []
9be3b2
     return data
9be3b2
9be3b2
From 93e082296abbaa4f62e1352e4240c72ade510740 Mon Sep 17 00:00:00 2001
9be3b2
From: Watson Sato <wsato@redhat.com>
9be3b2
Date: Tue, 17 Aug 2021 18:15:50 +0200
9be3b2
Subject: [PATCH 19/31] Move template audit_rules_file_deletion_events to
9be3b2
 Ansible macro
9be3b2
9be3b2
Use Ansible macro ansible_audit_augenrules_add_syscall_rule and
9be3b2
ansible_audit_auditctl_add_syscall_rule that group the syscalls
9be3b2
according to defined grouping.
9be3b2
---
9be3b2
 .../ansible.template                          | 88 ++++++++-----------
9be3b2
 .../template.py                               |  8 ++
9be3b2
 2 files changed, 45 insertions(+), 51 deletions(-)
9be3b2
9be3b2
diff --git a/shared/templates/audit_rules_file_deletion_events/ansible.template b/shared/templates/audit_rules_file_deletion_events/ansible.template
9be3b2
index 12d6088ecea..ec732133838 100644
9be3b2
--- a/shared/templates/audit_rules_file_deletion_events/ansible.template
9be3b2
+++ b/shared/templates/audit_rules_file_deletion_events/ansible.template
9be3b2
@@ -11,55 +11,41 @@
9be3b2
   set_fact:
9be3b2
     audit_arch: "b{{ ansible_architecture | regex_replace('.*(\\d\\d$)','\\1') }}"
9be3b2
 
9be3b2
-#
9be3b2
-# Inserts/replaces the rule in /etc/audit/rules.d
9be3b2
-#
9be3b2
-- name: Search /etc/audit/rules.d for other DAC audit rules
9be3b2
-  find:
9be3b2
-    paths: "/etc/audit/rules.d"
9be3b2
-    recurse: no
9be3b2
-    contains: "-F key=delete$"
9be3b2
-    patterns: "*.rules"
9be3b2
-  register: find_{{{ NAME }}}
9be3b2
-
9be3b2
-- name: If existing DAC ruleset not found, use /etc/audit/rules.d/delete.rules as the recipient for the rule
9be3b2
-  set_fact:
9be3b2
-    all_files:
9be3b2
-      - /etc/audit/rules.d/delete.rules
9be3b2
-  when: find_{{{ NAME }}}.matched is defined and find_{{{ NAME }}}.matched == 0
9be3b2
-
9be3b2
-- name: Use matched file as the recipient for the rule
9be3b2
-  set_fact:
9be3b2
-    all_files:
9be3b2
-      - "{{ find_{{{ NAME }}}.files | map(attribute='path') | list | first }}"
9be3b2
-  when: find_{{{ NAME }}}.matched is defined and find_{{{ NAME }}}.matched > 0
9be3b2
-
9be3b2
-- name: Inserts/replaces the {{{ NAME }}} rule in rules.d when on x86
9be3b2
-  lineinfile:
9be3b2
-    path: "{{ all_files[0] }}"
9be3b2
-    line: "-a always,exit -F arch=b32 -S {{{ NAME }}} -F auid>={{{ auid }}} -F auid!=unset -F key=delete"
9be3b2
-    create: yes
9be3b2
-
9be3b2
-- name: Inserts/replaces the {{{ NAME }}} rule in rules.d when on x86_64
9be3b2
-  lineinfile:
9be3b2
-    path: "{{ all_files[0] }}"
9be3b2
-    line: "-a always,exit -F arch=b64 -S {{{ NAME }}} -F auid>={{{ auid }}} -F auid!=unset -F key=delete"
9be3b2
-    create: yes
9be3b2
-  when: audit_arch is defined and audit_arch == 'b64'
9be3b2
-#   
9be3b2
-# Inserts/replaces the rule in /etc/audit/audit.rules
9be3b2
-#
9be3b2
-- name: Inserts/replaces the {{{ NAME }}} rule in /etc/audit/audit.rules when on x86
9be3b2
-  lineinfile:
9be3b2
-    line: "-a always,exit -F arch=b32 -S {{{ NAME }}} -F auid>={{{ auid }}} -F auid!=unset -F key=delete"
9be3b2
-    state: present
9be3b2
-    dest: /etc/audit/audit.rules
9be3b2
-    create: yes
9be3b2
+- name: Perform remediattion of Audit rules for {{{ NAME }}} for x86 platform
9be3b2
+  block:
9be3b2
+    {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b32",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="-F auid>="~auid~" -F auid!=unset",
9be3b2
+      syscalls=NAME,
9be3b2
+      key="delete",
9be3b2
+      syscall_grouping=SYSCALL_GROUPING,
9be3b2
+      )|indent(4) }}}
9be3b2
+    {{{ ansible_audit_auditctl_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b32",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="-F auid>="~auid~" -F auid!=unset",
9be3b2
+      syscalls=NAME,
9be3b2
+      key="delete",
9be3b2
+      syscall_grouping=SYSCALL_GROUPING,
9be3b2
+      )|indent(4) }}}
9be3b2
 
9be3b2
-- name: Inserts/replaces the {{{ NAME }}} rule in audit.rules when on x86_64
9be3b2
-  lineinfile:
9be3b2
-    line: "-a always,exit -F arch=b64 -S {{{ NAME }}} -F auid>={{{ auid }}} -F auid!=unset -F key=delete"
9be3b2
-    state: present
9be3b2
-    dest: /etc/audit/audit.rules
9be3b2
-    create: yes
9be3b2
-  when: audit_arch is defined and audit_arch == 'b64'
9be3b2
+- name: Perform remediattion of Audit rules for {{{ NAME }}} for x86_64 platform
9be3b2
+  block:
9be3b2
+    {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b64",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="-F auid>="~auid~" -F auid!=unset",
9be3b2
+      syscalls=NAME,
9be3b2
+      key="delete",
9be3b2
+      syscall_grouping=SYSCALL_GROUPING,
9be3b2
+      )|indent(4) }}}
9be3b2
+    {{{ ansible_audit_auditctl_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b64",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="-F auid>="~auid~" -F auid!=unset",
9be3b2
+      syscalls=NAME,
9be3b2
+      key="delete",
9be3b2
+      syscall_grouping=SYSCALL_GROUPING,
9be3b2
+      )|indent(4) }}}
9be3b2
+  when: audit_arch == "b64"
9be3b2
diff --git a/shared/templates/audit_rules_file_deletion_events/template.py b/shared/templates/audit_rules_file_deletion_events/template.py
9be3b2
index 7be137c1eb9..1141a99826b 100644
9be3b2
--- a/shared/templates/audit_rules_file_deletion_events/template.py
9be3b2
+++ b/shared/templates/audit_rules_file_deletion_events/template.py
9be3b2
@@ -6,6 +6,14 @@ def _audit_rules_file_deletion_events(data, lang):
9be3b2
         if "syscall_grouping" in data:
9be3b2
             # Make it easier to tranform the syscall_grouping into a Bash array
9be3b2
             data["syscall_grouping"] = " ".join(data["syscall_grouping"])
9be3b2
+    elif lang == "ansible":
9be3b2
+        if "name" in data:
9be3b2
+            # Tranform the syscall into a Ansible list
9be3b2
+            # The syscall is under 'name'
9be3b2
+            data["name"] = [ data["name"] ]
9be3b2
+        if "syscall_grouping" not in data:
9be3b2
+            # Ensure that syscall_grouping is a list
9be3b2
+            data["syscall_grouping"] = []
9be3b2
     return data
9be3b2
 
9be3b2
 
9be3b2
9be3b2
From 5db4692a9efd86713e79c6fb72f87bf4898338e9 Mon Sep 17 00:00:00 2001
9be3b2
From: Watson Sato <wsato@redhat.com>
9be3b2
Date: Tue, 17 Aug 2021 19:16:54 +0200
9be3b2
Subject: [PATCH 20/31] Update Ansible audit_rules_kernel_module_loading_* to
9be3b2
 use macros
9be3b2
9be3b2
Update remediation of following rules to use Ansible macro syscall rule
9be3b2
- audit_rules_kernel_module_loading_delete
9be3b2
- audit_rules_kernel_module_loading_finit
9be3b2
- audit_rules_kernel_module_loading_init
9be3b2
---
9be3b2
 .../ansible/shared.yml                        | 89 ++++++++-----------
9be3b2
 .../ansible/shared.yml                        | 89 ++++++++-----------
9be3b2
 .../ansible/shared.yml                        | 88 ++++++++----------
9be3b2
 3 files changed, 114 insertions(+), 152 deletions(-)
9be3b2
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading_delete/ansible/shared.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading_delete/ansible/shared.yml
9be3b2
index 60f477ac355..863ba6f0134 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading_delete/ansible/shared.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading_delete/ansible/shared.yml
9be3b2
@@ -10,54 +10,41 @@
9be3b2
   set_fact:
9be3b2
     audit_arch: "b{{ ansible_architecture | regex_replace('.*(\\d\\d$)','\\1') }}"
9be3b2
 
9be3b2
-# Inserts/replaces the rule in /etc/audit/rules.d
9be3b2
-
9be3b2
-- name: Search /etc/audit/rules.d for audit rule entries
9be3b2
-  find:
9be3b2
-    paths: /etc/audit/rules.d
9be3b2
-    recurse: false
9be3b2
-    contains: ^.*delete_module.*$
9be3b2
-    patterns: '*.rules'
9be3b2
-  register: find_delete_module
9be3b2
-
9be3b2
-- name: Use /etc/audit/rules.d/privileged.rules as the recipient for the rule
9be3b2
-  set_fact:
9be3b2
-    all_files:
9be3b2
-    - /etc/audit/rules.d/privileged.rules
9be3b2
-  when: find_delete_module.matched is defined and find_delete_module.matched == 0
9be3b2
-
9be3b2
-- name: Use matched file as the recipient for the rule
9be3b2
-  set_fact:
9be3b2
-    all_files:
9be3b2
-    - '{{ find_delete_module.files | map(attribute=''path'') | list | first }}'
9be3b2
-  when: find_delete_module.matched is defined and find_delete_module.matched > 0
9be3b2
-
9be3b2
-- name: Inserts/replaces the delete_module rule in rules.d
9be3b2
-  lineinfile:
9be3b2
-    path: '{{ all_files[0] }}'
9be3b2
-    line: '-a always,exit -F arch=b32 -S delete_module -k module-change'
9be3b2
-    state: present
9be3b2
-    create: true
9be3b2
-
9be3b2
-- name: Inserts/replaces the delete_module rule in rules.d on x86_64
9be3b2
-  lineinfile:
9be3b2
-    path: '{{ all_files[0] }}'
9be3b2
-    line: '-a always,exit -F arch=b64 -S delete_module -k module-change'
9be3b2
-    state: present
9be3b2
-    create: true
9be3b2
-  when: audit_arch is defined and audit_arch == 'b64'
9be3b2
-
9be3b2
-# Inserts/replaces the delete_modules rule in /etc/audit/audit.rules
9be3b2
-
9be3b2
-- name: Inserts/replaces the delete_module rule in audit.rules
9be3b2
-  lineinfile:
9be3b2
-    path: /etc/audit/audit.rules
9be3b2
-    line: '-a always,exit -F arch=b32 -S delete_module -k module-change'
9be3b2
-    create: true
9be3b2
-
9be3b2
-- name: Inserts/replaces the delete_module rule in audit.rules when on x86_64
9be3b2
-  lineinfile:
9be3b2
-    path: /etc/audit/audit.rules
9be3b2
-    line: '-a always,exit -F arch=b64 -S delete_module -k module-change'
9be3b2
-    create: true
9be3b2
-  when: audit_arch is defined and audit_arch == 'b64'
9be3b2
+- name: Perform remediattion of Audit rules for delete_module for x86 platform
9be3b2
+  block:
9be3b2
+    {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b32",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="",
9be3b2
+      syscalls=["delete_module"],
9be3b2
+      key="module-change",
9be3b2
+      syscall_grouping=[],
9be3b2
+      )|indent(4) }}}
9be3b2
+    {{{ ansible_audit_auditctl_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b32",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="",
9be3b2
+      syscalls=["delete_module"],
9be3b2
+      key="module-change",
9be3b2
+      syscall_grouping=[],
9be3b2
+      )|indent(4) }}}
9be3b2
+
9be3b2
+- name: Perform remediattion of Audit rules for delete_module for x86_64 platform
9be3b2
+  block:
9be3b2
+    {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b64",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="",
9be3b2
+      syscalls=["delete_module"],
9be3b2
+      key="module-change",
9be3b2
+      syscall_grouping=[],
9be3b2
+      )|indent(4) }}}
9be3b2
+    {{{ ansible_audit_auditctl_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b64",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="",
9be3b2
+      syscalls=["delete_module"],
9be3b2
+      key="module-change",
9be3b2
+      syscall_grouping=[],
9be3b2
+      )|indent(4) }}}
9be3b2
+  when: audit_arch == "b64"
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading_finit/ansible/shared.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading_finit/ansible/shared.yml
9be3b2
index 3f3c3e3d947..268f0a57f11 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading_finit/ansible/shared.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading_finit/ansible/shared.yml
9be3b2
@@ -10,54 +10,41 @@
9be3b2
   set_fact:
9be3b2
     audit_arch: "b{{ ansible_architecture | regex_replace('.*(\\d\\d$)','\\1') }}"
9be3b2
 
9be3b2
-# Inserts/replaces the rule in /etc/audit/rules.d
9be3b2
-
9be3b2
-- name: Search /etc/audit/rules.d for audit rule entries
9be3b2
-  find:
9be3b2
-    paths: /etc/audit/rules.d
9be3b2
-    recurse: false
9be3b2
-    contains: ^.*finit_module.*$
9be3b2
-    patterns: '*.rules'
9be3b2
-  register: find_finit_module
9be3b2
-
9be3b2
-- name: Use /etc/audit/rules.d/privileged.rules as the recipient for the rule
9be3b2
-  set_fact:
9be3b2
-    all_files:
9be3b2
-    - /etc/audit/rules.d/privileged.rules
9be3b2
-  when: find_finit_module.matched is defined and find_finit_module.matched == 0
9be3b2
-
9be3b2
-- name: Use matched file as the recipient for the rule
9be3b2
-  set_fact:
9be3b2
-    all_files:
9be3b2
-    - '{{ find_finit_module.files | map(attribute=''path'') | list | first }}'
9be3b2
-  when: find_finit_module.matched is defined and find_finit_module.matched > 0
9be3b2
-
9be3b2
-- name: Inserts/replaces the finit_module rule in rules.d
9be3b2
-  lineinfile:
9be3b2
-    path: '{{ all_files[0] }}'
9be3b2
-    line: '-a always,exit -F arch=b32 -S finit_module -k module-change'
9be3b2
-    state: present
9be3b2
-    create: true
9be3b2
-
9be3b2
-- name: Inserts/replaces the finit_module rule in rules.d on x86_64
9be3b2
-  lineinfile:
9be3b2
-    path: '{{ all_files[0] }}'
9be3b2
-    line: '-a always,exit -F arch=b64 -S finit_module -k module-change'
9be3b2
-    state: present
9be3b2
-    create: true
9be3b2
-  when: audit_arch is defined and audit_arch == 'b64'
9be3b2
-
9be3b2
-# Inserts/replaces the finit_modules rule in /etc/audit/audit.rules
9be3b2
-
9be3b2
-- name: Inserts/replaces the finit_module rule in audit.rules
9be3b2
-  lineinfile:
9be3b2
-    path: /etc/audit/audit.rules
9be3b2
-    line: '-a always,exit -F arch=b32 -S finit_module -k module-change'
9be3b2
-    create: true
9be3b2
-
9be3b2
-- name: Inserts/replaces the finit_module rule in audit.rules when on x86_64
9be3b2
-  lineinfile:
9be3b2
-    path: /etc/audit/audit.rules
9be3b2
-    line: '-a always,exit -F arch=b64 -S finit_module -k module-change'
9be3b2
-    create: true
9be3b2
-  when: audit_arch is defined and audit_arch == 'b64'
9be3b2
+- name: Perform remediattion of Audit rules for finit_module for x86 platform
9be3b2
+  block:
9be3b2
+    {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b32",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="",
9be3b2
+      syscalls=["finit_module"],
9be3b2
+      key="module-change",
9be3b2
+      syscall_grouping=["init_module","finit_module"],
9be3b2
+      )|indent(4) }}}
9be3b2
+    {{{ ansible_audit_auditctl_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b32",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="",
9be3b2
+      syscalls=["finit_module"],
9be3b2
+      key="module-change",
9be3b2
+      syscall_grouping=["init_module","finit_module"],
9be3b2
+      )|indent(4) }}}
9be3b2
+
9be3b2
+- name: Perform remediattion of Audit rules for finit_module for x86_64 platform
9be3b2
+  block:
9be3b2
+    {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b64",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="",
9be3b2
+      syscalls=["finit_module"],
9be3b2
+      key="module-change",
9be3b2
+      syscall_grouping=["init_module","finit_module"],
9be3b2
+      )|indent(4) }}}
9be3b2
+    {{{ ansible_audit_auditctl_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b64",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="",
9be3b2
+      syscalls=["finit_module"],
9be3b2
+      key="module-change",
9be3b2
+      syscall_grouping=["init_module","finit_module"],
9be3b2
+      )|indent(4) }}}
9be3b2
+  when: audit_arch == "b64"
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading_init/ansible/shared.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading_init/ansible/shared.yml
9be3b2
index 3f58125065b..2155a1835c6 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading_init/ansible/shared.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading_init/ansible/shared.yml
9be3b2
@@ -10,53 +10,41 @@
9be3b2
   set_fact:
9be3b2
     audit_arch: "b{{ ansible_architecture | regex_replace('.*(\\d\\d$)','\\1') }}"
9be3b2
 
9be3b2
-# Inserts/replaces the rule in /etc/audit/rules.d
9be3b2
-
9be3b2
-- name: Search /etc/audit/rules.d for audit rule entries
9be3b2
-  find:
9be3b2
-    paths: /etc/audit/rules.d
9be3b2
-    recurse: false
9be3b2
-    contains: ^.*init_module.*$
9be3b2
-    patterns: '*.rules'
9be3b2
-  register: find_init_module
9be3b2
-
9be3b2
-- name: Use /etc/audit/rules.d/privileged.rules as the recipient for the rule
9be3b2
-  set_fact:
9be3b2
-    all_files:
9be3b2
-    - /etc/audit/rules.d/privileged.rules
9be3b2
-  when: find_init_module.matched is defined and find_init_module.matched == 0
9be3b2
-
9be3b2
-- name: Use matched file as the recipient for the rule
9be3b2
-  set_fact:
9be3b2
-    all_files:
9be3b2
-    - '{{ find_init_module.files | map(attribute=''path'') | list | first }}'
9be3b2
-  when: find_init_module.matched is defined and find_init_module.matched > 0
9be3b2
-
9be3b2
-- name: Inserts/replaces the init_module rule in rules.d
9be3b2
-  lineinfile:
9be3b2
-    path: '{{ all_files[0] }}'
9be3b2
-    line: '-a always,exit -F arch=b32 -S init_module -k module-change'
9be3b2
-    state: present
9be3b2
-    create: true
9be3b2
-
9be3b2
-- name: Inserts/replaces the init_module rule in rules.d on x86_64
9be3b2
-  lineinfile:
9be3b2
-    path: '{{ all_files[0] }}'
9be3b2
-    line: '-a always,exit -F arch=b64 -S init_module -k module-change'
9be3b2
-    state: present
9be3b2
-    create: true
9be3b2
-  when: audit_arch is defined and audit_arch == 'b64'
9be3b2
-
9be3b2
-# Inserts/replaces the init_modules rule in /etc/audit/audit.rules
9be3b2
-
9be3b2
-- name: Inserts/replaces the init_module rule in audit.rules
9be3b2
-  lineinfile:
9be3b2
-    path: /etc/audit/audit.rules
9be3b2
-    line: '-a always,exit -F arch=b32 -S init_module -k module-change'
9be3b2
-    create: true
9be3b2
-- name: Inserts/replaces the init_module rule in audit.rules when on x86_64
9be3b2
-  lineinfile:
9be3b2
-    path: /etc/audit/audit.rules
9be3b2
-    line: '-a always,exit -F arch=b64 -S init_module -k module-change'
9be3b2
-    create: true
9be3b2
-  when: audit_arch is defined and audit_arch == 'b64'
9be3b2
+- name: Perform remediattion of Audit rules for init_module for x86 platform
9be3b2
+  block:
9be3b2
+    {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b32",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="",
9be3b2
+      syscalls=["init_module"],
9be3b2
+      key="module-change",
9be3b2
+      syscall_grouping=["init_module","finit_module"],
9be3b2
+      )|indent(4) }}}
9be3b2
+    {{{ ansible_audit_auditctl_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b32",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="",
9be3b2
+      syscalls=["init_module"],
9be3b2
+      key="module-change",
9be3b2
+      syscall_grouping=["init_module","finit_module"],
9be3b2
+      )|indent(4) }}}
9be3b2
+
9be3b2
+- name: Perform remediattion of Audit rules for init_module for x86_64 platform
9be3b2
+  block:
9be3b2
+    {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b64",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="",
9be3b2
+      syscalls=["init_module"],
9be3b2
+      key="module-change",
9be3b2
+      syscall_grouping=["init_module","finit_module"],
9be3b2
+      )|indent(4) }}}
9be3b2
+    {{{ ansible_audit_auditctl_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit -F arch=b64",
9be3b2
+      other_filters="",
9be3b2
+      auid_filters="",
9be3b2
+      syscalls=["init_module"],
9be3b2
+      key="module-change",
9be3b2
+      syscall_grouping=["init_module","finit_module"],
9be3b2
+      )|indent(4) }}}
9be3b2
+  when: audit_arch == "b64"
9be3b2
9be3b2
From 98843a14147ea7db9d6ef96580ed4b8e9c15f67f Mon Sep 17 00:00:00 2001
9be3b2
From: Watson Sato <wsato@redhat.com>
9be3b2
Date: Tue, 17 Aug 2021 19:31:15 +0200
9be3b2
Subject: [PATCH 21/31] Update directory_access_var_log_audit to use Ansible
9be3b2
 macro
9be3b2
9be3b2
Also fix a bug in Bash remediation, there should be no arch.
9be3b2
---
9be3b2
 .../ansible/shared.yml                        | 51 +++++++------------
9be3b2
 .../bash/shared.sh                            |  2 +-
9be3b2
 2 files changed, 19 insertions(+), 34 deletions(-)
9be3b2
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/directory_access_var_log_audit/ansible/shared.yml b/linux_os/guide/system/auditing/auditd_configure_rules/directory_access_var_log_audit/ansible/shared.yml
9be3b2
index 31b65a0833c..bc6e929372f 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/directory_access_var_log_audit/ansible/shared.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/directory_access_var_log_audit/ansible/shared.yml
9be3b2
@@ -3,36 +3,21 @@
9be3b2
 # strategy = restrict
9be3b2
 # complexity = low
9be3b2
 # disruption = low
9be3b2
-- name: Search /etc/audit/rules.d for audit rule entries
9be3b2
-  find:
9be3b2
-    paths: /etc/audit/rules.d
9be3b2
-    recurse: false
9be3b2
-    contains: ^.*dir=/var/log/audit/.*$
9be3b2
-    patterns: '*.rules'
9be3b2
-  register: find_var_log_audit
9be3b2
-
9be3b2
-- name: Use /etc/audit/rules.d/access-audit-trail.rules as the recipient for the rule
9be3b2
-  set_fact:
9be3b2
-    all_files:
9be3b2
-    - /etc/audit/rules.d/access-audit-trail.rules
9be3b2
-  when: find_var_log_audit.matched == 0
9be3b2
-
9be3b2
-- name: Use matched file as the recipient for the rule
9be3b2
-  set_fact:
9be3b2
-    all_files:
9be3b2
-    - '{{ find_var_log_audit.files | map(attribute=''path'') | list | first }}'
9be3b2
-  when: find_var_log_audit.matched > 0
9be3b2
-
9be3b2
-- name: Inserts/replaces the /var/log/audit/ rule in rules.d
9be3b2
-  lineinfile:
9be3b2
-    path: '{{ all_files[0] }}'
9be3b2
-    line: -a always,exit -F dir=/var/log/audit/ -F perm=r -F auid>={{{ auid }}} -F auid!=unset
9be3b2
-      -F key=access-audit-trail
9be3b2
-    create: true
9be3b2
-
9be3b2
-- name: Inserts/replaces the /var/log/audit/ rule in audit.rules
9be3b2
-  lineinfile:
9be3b2
-    path: /etc/audit/audit.rules
9be3b2
-    line: -a always,exit -F dir=/var/log/audit/ -F perm=r -F auid>={{{ auid }}} -F auid!=unset
9be3b2
-      -F key=access-audit-trail
9be3b2
-    create: true
9be3b2
+- name: Perform remediattion of Audit rules for /var/log/audit
9be3b2
+  block:
9be3b2
+    {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit",
9be3b2
+      other_filters="-F dir=/var/log/audit/ -F perm=r",
9be3b2
+      auid_filters="-F auid>="~auid~" -F auid!=unset",
9be3b2
+      syscalls=[],
9be3b2
+      key="access-audit-trail",
9be3b2
+      syscall_grouping=[],
9be3b2
+      )|indent(4) }}}
9be3b2
+    {{{ ansible_audit_auditctl_add_syscall_rule(
9be3b2
+      action_arch_filters="-a always,exit",
9be3b2
+      other_filters="-F dir=/var/log/audit/ -F perm=r",
9be3b2
+      auid_filters="-F auid>="~auid~" -F auid!=unset",
9be3b2
+      syscalls=[],
9be3b2
+      key="access-audit-trail",
9be3b2
+      syscall_grouping=[],
9be3b2
+      )|indent(4) }}}
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/directory_access_var_log_audit/bash/shared.sh b/linux_os/guide/system/auditing/auditd_configure_rules/directory_access_var_log_audit/bash/shared.sh
9be3b2
index 0c4e8ffdbd3..a8e4a71a9f8 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/directory_access_var_log_audit/bash/shared.sh
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/directory_access_var_log_audit/bash/shared.sh
9be3b2
@@ -3,7 +3,7 @@
9be3b2
 # Include source function library.
9be3b2
 . /usr/share/scap-security-guide/remediation_functions
9be3b2
 
9be3b2
-ACTION_ARCH_FILTERS="-a always,exit -F arch=$ARCH"
9be3b2
+ACTION_ARCH_FILTERS="-a always,exit"
9be3b2
 OTHER_FILTERS="-F dir=/var/log/audit/ -F perm=r"
9be3b2
 AUID_FILTERS="-F auid>={{{ auid }}} -F auid!=unset"
9be3b2
 SYSCALL=""
9be3b2
9be3b2
From 78664de349a993b36f02c17e25c5042ed075d9a7 Mon Sep 17 00:00:00 2001
9be3b2
From: Watson Sato <wsato@redhat.com>
9be3b2
Date: Tue, 17 Aug 2021 19:38:39 +0200
9be3b2
Subject: [PATCH 22/31] Python style fixes
9be3b2
9be3b2
---
9be3b2
 shared/templates/audit_rules_dac_modification/template.py      | 2 +-
9be3b2
 shared/templates/audit_rules_file_deletion_events/template.py  | 3 +--
9be3b2
 shared/templates/audit_rules_path_syscall/template.py          | 2 +-
9be3b2
 .../audit_rules_unsuccessful_file_modification/template.py     | 3 +--
9be3b2
 4 files changed, 4 insertions(+), 6 deletions(-)
9be3b2
9be3b2
diff --git a/shared/templates/audit_rules_dac_modification/template.py b/shared/templates/audit_rules_dac_modification/template.py
9be3b2
index eebd0b6f4ee..17187826e62 100644
9be3b2
--- a/shared/templates/audit_rules_dac_modification/template.py
9be3b2
+++ b/shared/templates/audit_rules_dac_modification/template.py
9be3b2
@@ -10,7 +10,7 @@ def preprocess(data, lang):
9be3b2
     elif lang == "ansible":
9be3b2
         if "attr" in data:
9be3b2
             # Tranform the syscall into a Ansible list
9be3b2
-            data["attr"] = [ data["attr"] ]
9be3b2
+            data["attr"] = [data["attr"]]
9be3b2
         if "syscall_grouping" not in data:
9be3b2
             # Ensure that syscall_grouping is a list
9be3b2
             data["syscall_grouping"] = []
9be3b2
diff --git a/shared/templates/audit_rules_file_deletion_events/template.py b/shared/templates/audit_rules_file_deletion_events/template.py
9be3b2
index 1141a99826b..4916d892521 100644
9be3b2
--- a/shared/templates/audit_rules_file_deletion_events/template.py
9be3b2
+++ b/shared/templates/audit_rules_file_deletion_events/template.py
9be3b2
@@ -10,7 +10,7 @@ def _audit_rules_file_deletion_events(data, lang):
9be3b2
         if "name" in data:
9be3b2
             # Tranform the syscall into a Ansible list
9be3b2
             # The syscall is under 'name'
9be3b2
-            data["name"] = [ data["name"] ]
9be3b2
+            data["name"] = [data["name"]]
9be3b2
         if "syscall_grouping" not in data:
9be3b2
             # Ensure that syscall_grouping is a list
9be3b2
             data["syscall_grouping"] = []
9be3b2
@@ -19,4 +19,3 @@ def _audit_rules_file_deletion_events(data, lang):
9be3b2
 
9be3b2
 def preprocess(data, lang):
9be3b2
     return _audit_rules_file_deletion_events(data, lang)
9be3b2
-
9be3b2
diff --git a/shared/templates/audit_rules_path_syscall/template.py b/shared/templates/audit_rules_path_syscall/template.py
9be3b2
index c13f34b94e0..0f2966335b0 100644
9be3b2
--- a/shared/templates/audit_rules_path_syscall/template.py
9be3b2
+++ b/shared/templates/audit_rules_path_syscall/template.py
9be3b2
@@ -14,7 +14,7 @@ def preprocess(data, lang):
9be3b2
     elif lang == "ansible":
9be3b2
         if "syscall" in data:
9be3b2
             # Tranform the syscall into a Ansible list
9be3b2
-            data["syscall"] = [ data["syscall"] ]
9be3b2
+            data["syscall"] = [data["syscall"]]
9be3b2
         if "syscall_grouping" not in data:
9be3b2
             # Ensure that syscall_grouping is a list
9be3b2
             data["syscall_grouping"] = []
9be3b2
diff --git a/shared/templates/audit_rules_unsuccessful_file_modification/template.py b/shared/templates/audit_rules_unsuccessful_file_modification/template.py
9be3b2
index 62abfad9a2c..dd9714457a2 100644
9be3b2
--- a/shared/templates/audit_rules_unsuccessful_file_modification/template.py
9be3b2
+++ b/shared/templates/audit_rules_unsuccessful_file_modification/template.py
9be3b2
@@ -10,7 +10,7 @@ def _audit_rules_unsuccessful_file_modification(data, lang):
9be3b2
         if "name" in data:
9be3b2
             # Tranform the syscall into a Ansible list
9be3b2
             # The syscall is under 'name'
9be3b2
-            data["name"] = [ data["name"] ]
9be3b2
+            data["name"] = [data["name"]]
9be3b2
         if "syscall_grouping" not in data:
9be3b2
             # Ensure that syscall_grouping is a list
9be3b2
             data["syscall_grouping"] = []
9be3b2
@@ -19,4 +19,3 @@ def _audit_rules_unsuccessful_file_modification(data, lang):
9be3b2
 
9be3b2
 def preprocess(data, lang):
9be3b2
     return _audit_rules_unsuccessful_file_modification(data, lang)
9be3b2
-
9be3b2
9be3b2
From 16df69710c8872bd6d348a60a0542fb2cafb0dc3 Mon Sep 17 00:00:00 2001
9be3b2
From: Watson Sato <wsato@redhat.com>
9be3b2
Date: Wed, 18 Aug 2021 10:22:32 +0200
9be3b2
Subject: [PATCH 23/31] Fix typo in Ansible remediarion for
9be3b2
 unsuccessful_file_modification
9be3b2
9be3b2
---
9be3b2
 .../audit_rules_unsuccessful_file_modification/bash/shared.sh | 4 ++--
9be3b2
 1 file changed, 2 insertions(+), 2 deletions(-)
9be3b2
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification/bash/shared.sh b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification/bash/shared.sh
9be3b2
index bf931e46430..5cb4dbe6f4a 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification/bash/shared.sh
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_file_modification/audit_rules_unsuccessful_file_modification/bash/shared.sh
9be3b2
@@ -12,7 +12,7 @@ do
9be3b2
 
9be3b2
 	# First fix the -EACCES requirement
9be3b2
 	ACTION_ARCH_FILTERS="-a always,exit -F arch=$ARCH"
9be3b2
-	OTHER_FILTERS="-F exit=EACCES"
9be3b2
+	OTHER_FILTERS="-F exit=-EACCES"
9be3b2
 	AUID_FILTERS="-F auid>={{{ auid }}} -F auid!=unset"
9be3b2
 	SYSCALL="creat open openat open_by_handle_at truncate ftruncate"
9be3b2
 	KEY="access"
9be3b2
@@ -24,7 +24,7 @@ do
9be3b2
 	# Then fix the -EPERM requirement
9be3b2
 	# No need to change content of $GROUP variable - it's the same as for -EACCES case above
9be3b2
 	ACTION_ARCH_FILTERS="-a always,exit -F arch=$ARCH"
9be3b2
-	OTHER_FILTERS="-F exit=EPERM"
9be3b2
+	OTHER_FILTERS="-F exit=-EPERM"
9be3b2
 	AUID_FILTERS="-F auid>={{{ auid }}} -F auid!=unset"
9be3b2
 	SYSCALL="creat open openat open_by_handle_at truncate ftruncate"
9be3b2
 	KEY="access"
9be3b2
9be3b2
From d761a6498f8e3e64810e7b06cbf04837d0ae8975 Mon Sep 17 00:00:00 2001
9be3b2
From: Watson Sato <wsato@redhat.com>
9be3b2
Date: Wed, 18 Aug 2021 10:23:50 +0200
9be3b2
Subject: [PATCH 24/31] Check all relevant syscalls in Ansible macro
9be3b2
9be3b2
The Ansible macros for audit syscall rules should check the target
9be3b2
syscall and the groupable syscalls during 'find' task.
9be3b2
9be3b2
When 'syscall_grouping' was empty, the remediation would simply
9be3b2
execute the 'Add a new rule' task.
9be3b2
If the key was different, a new duplicate rule would be added.
9be3b2
9be3b2
Also removes extra syscalls declaration task.
9be3b2
---
9be3b2
 shared/macros-ansible.jinja | 8 ++------
9be3b2
 1 file changed, 2 insertions(+), 6 deletions(-)
9be3b2
9be3b2
diff --git a/shared/macros-ansible.jinja b/shared/macros-ansible.jinja
9be3b2
index a067742b1f4..1af5ed3dd95 100644
9be3b2
--- a/shared/macros-ansible.jinja
9be3b2
+++ b/shared/macros-ansible.jinja
9be3b2
@@ -420,7 +420,7 @@ The macro requires following parameters:
9be3b2
     contains: '{{{ action_arch_filters }}}(( -S |,)\w+)*(( -S |,){{ item }})+(( -S |,)\w+)*{{{ other_filters }}}{{{ auid_filters }}} (-k\s+|-F\s+key=)\S+\s*$'
9be3b2
     patterns: '*.rules'
9be3b2
   register: find_command
9be3b2
-  loop: '{{ syscall_grouping }}'
9be3b2
+  loop: '{{ (syscall_grouping + syscalls) | unique }}'
9be3b2
 
9be3b2
 - name: Declare syscalls found per file
9be3b2
   set_fact: syscalls_per_file="{{ syscalls_per_file | default({}) | combine( {item.files[0].path :[item.item]+(syscalls_per_file | default({})).get(item.files[0].path, []) } ) }}"
9be3b2
@@ -504,7 +504,7 @@ The macro requires following parameters:
9be3b2
     contains: '{{{ action_arch_filters }}}(( -S |,)\w+)*(( -S |,){{ item }})+(( -S |,)\w+)*{{{ other_filters }}}{{{ auid_filters }}} (-k\s+|-F\s+key=)\S+\s*$'
9be3b2
     patterns: 'audit.rules'
9be3b2
   register: find_command
9be3b2
-  loop: '{{ syscall_grouping }}'
9be3b2
+  loop: '{{ (syscall_grouping + syscalls) | unique }}'
9be3b2
 
9be3b2
 - name: Set path to /etc/audit/rules.d/{{{ key }}}.rules
9be3b2
   set_fact: audit_file="/etc/audit/audit.rules"
9be3b2
@@ -532,10 +532,6 @@ The macro requires following parameters:
9be3b2
     create: true
9be3b2
     state: present
9be3b2
   when: syscalls_found | length == 0
9be3b2
-- name: Declare list of syscals
9be3b2
-  set_fact:
9be3b2
-    syscalls: {{{ syscalls }}}
9be3b2
-
9be3b2
 {{%- endmacro %}}
9be3b2
 
9be3b2
 {{% macro ansible_sssd_ldap_config(parameter, value) -%}}
9be3b2
9be3b2
From 2a2697e49809f14c0f1af81940c6198691e9af94 Mon Sep 17 00:00:00 2001
9be3b2
From: Watson Sato <wsato@redhat.com>
9be3b2
Date: Wed, 18 Aug 2021 10:35:10 +0200
9be3b2
Subject: [PATCH 25/31] Improve task titles of audit macros and templates
9be3b2
9be3b2
---
9be3b2
 shared/macros-ansible.jinja                                 | 6 +++---
9be3b2
 .../templates/audit_rules_dac_modification/ansible.template | 6 +++---
9be3b2
 .../audit_rules_file_deletion_events/ansible.template       | 6 +++---
9be3b2
 shared/templates/audit_rules_path_syscall/ansible.template  | 6 +++---
9be3b2
 .../ansible.template                                        | 6 +++---
9be3b2
 5 files changed, 15 insertions(+), 15 deletions(-)
9be3b2
9be3b2
diff --git a/shared/macros-ansible.jinja b/shared/macros-ansible.jinja
9be3b2
index 1af5ed3dd95..b5574da29ac 100644
9be3b2
--- a/shared/macros-ansible.jinja
9be3b2
+++ b/shared/macros-ansible.jinja
9be3b2
@@ -414,7 +414,7 @@ The macro requires following parameters:
9be3b2
     syscalls: {{{ syscalls }}}
9be3b2
     syscall_grouping: {{{ syscall_grouping }}}
9be3b2
 
9be3b2
-- name: Check existence of syscalls for in /etc/audit/rules.d/
9be3b2
+- name: Check existence of {{{ syscalls | join(", ") }}} in /etc/audit/rules.d/
9be3b2
   find:
9be3b2
     paths: /etc/audit/rules.d
9be3b2
     contains: '{{{ action_arch_filters }}}(( -S |,)\w+)*(( -S |,){{ item }})+(( -S |,)\w+)*{{{ other_filters }}}{{{ auid_filters }}} (-k\s+|-F\s+key=)\S+\s*$'
9be3b2
@@ -498,7 +498,7 @@ The macro requires following parameters:
9be3b2
     syscalls: {{{ syscalls }}}
9be3b2
     syscall_grouping: {{{ syscall_grouping }}}
9be3b2
 
9be3b2
-- name: Check existence of syscalls for in /etc/audit/rules.d/
9be3b2
+- name: Check existence of {{{ syscalls | join(", ") }}} in /etc/audit/audit.rules
9be3b2
   find:
9be3b2
     paths: /etc/audit
9be3b2
     contains: '{{{ action_arch_filters }}}(( -S |,)\w+)*(( -S |,){{ item }})+(( -S |,)\w+)*{{{ other_filters }}}{{{ auid_filters }}} (-k\s+|-F\s+key=)\S+\s*$'
9be3b2
@@ -506,7 +506,7 @@ The macro requires following parameters:
9be3b2
   register: find_command
9be3b2
   loop: '{{ (syscall_grouping + syscalls) | unique }}'
9be3b2
 
9be3b2
-- name: Set path to /etc/audit/rules.d/{{{ key }}}.rules
9be3b2
+- name: Set path to /etc/audit/audit.rules
9be3b2
   set_fact: audit_file="/etc/audit/audit.rules"
9be3b2
 
9be3b2
 - name: Declare found syscalls
9be3b2
diff --git a/shared/templates/audit_rules_dac_modification/ansible.template b/shared/templates/audit_rules_dac_modification/ansible.template
9be3b2
index d2ce6c50052..ea6fd94ff4b 100644
9be3b2
--- a/shared/templates/audit_rules_dac_modification/ansible.template
9be3b2
+++ b/shared/templates/audit_rules_dac_modification/ansible.template
9be3b2
@@ -7,11 +7,11 @@
9be3b2
 #
9be3b2
 # What architecture are we on?
9be3b2
 #
9be3b2
-- name: Set architecture for audit {{{ ATTR }}} tasks
9be3b2
+- name: Set architecture for audit {{{ ATTR | join(", ") }}} tasks
9be3b2
   set_fact:
9be3b2
     audit_arch: "b{{ ansible_architecture | regex_replace('.*(\\d\\d$)','\\1') }}"
9be3b2
 
9be3b2
-- name: Perform remediattion of Audit rules for {{{ ATTR }}} for x86 platform
9be3b2
+- name: Perform remediattion of Audit rules for {{{ ATTR | join(", ") }}} for x86 platform
9be3b2
   block:
9be3b2
     {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
       action_arch_filters="-a always,exit -F arch=b32",
9be3b2
@@ -48,7 +48,7 @@
9be3b2
       )|indent(4) }}}
9be3b2
 {{%- endif %}}
9be3b2
 
9be3b2
-- name: Perform remediattion of Audit rules for {{{ ATTR }}} for x86_64 platform
9be3b2
+- name: Perform remediattion of Audit rules for {{{ ATTR | join(", ") }}} for x86_64 platform
9be3b2
   block:
9be3b2
     {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
       action_arch_filters="-a always,exit -F arch=b64",
9be3b2
diff --git a/shared/templates/audit_rules_file_deletion_events/ansible.template b/shared/templates/audit_rules_file_deletion_events/ansible.template
9be3b2
index ec732133838..0044dc459dc 100644
9be3b2
--- a/shared/templates/audit_rules_file_deletion_events/ansible.template
9be3b2
+++ b/shared/templates/audit_rules_file_deletion_events/ansible.template
9be3b2
@@ -7,11 +7,11 @@
9be3b2
 #
9be3b2
 # What architecture are we on?
9be3b2
 #
9be3b2
-- name: Set architecture for audit {{{ NAME }}} tasks
9be3b2
+- name: Set architecture for audit {{{ NAME| join(", ")  }}} tasks
9be3b2
   set_fact:
9be3b2
     audit_arch: "b{{ ansible_architecture | regex_replace('.*(\\d\\d$)','\\1') }}"
9be3b2
 
9be3b2
-- name: Perform remediattion of Audit rules for {{{ NAME }}} for x86 platform
9be3b2
+- name: Perform remediattion of Audit rules for {{{ NAME| join(", ")  }}} for x86 platform
9be3b2
   block:
9be3b2
     {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
       action_arch_filters="-a always,exit -F arch=b32",
9be3b2
@@ -30,7 +30,7 @@
9be3b2
       syscall_grouping=SYSCALL_GROUPING,
9be3b2
       )|indent(4) }}}
9be3b2
 
9be3b2
-- name: Perform remediattion of Audit rules for {{{ NAME }}} for x86_64 platform
9be3b2
+- name: Perform remediattion of Audit rules for {{{ NAME| join(", ")  }}} for x86_64 platform
9be3b2
   block:
9be3b2
     {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
       action_arch_filters="-a always,exit -F arch=b64",
9be3b2
diff --git a/shared/templates/audit_rules_path_syscall/ansible.template b/shared/templates/audit_rules_path_syscall/ansible.template
9be3b2
index 20440a36237..2875aff3573 100644
9be3b2
--- a/shared/templates/audit_rules_path_syscall/ansible.template
9be3b2
+++ b/shared/templates/audit_rules_path_syscall/ansible.template
9be3b2
@@ -7,11 +7,11 @@
9be3b2
 #
9be3b2
 # What architecture are we on?
9be3b2
 #
9be3b2
-- name: Set architecture for audit {{{ SYSCALL }}} tasks
9be3b2
+- name: Set architecture for audit {{{ SYSCALL | join(", ") }}} tasks
9be3b2
   set_fact:
9be3b2
     audit_arch: "b{{ ansible_architecture | regex_replace('.*(\\d\\d$)','\\1') }}"
9be3b2
 
9be3b2
-- name: Perform remediattion of Audit rules for {{{ SYSCALL }}} for x86 platform
9be3b2
+- name: Perform remediattion of Audit rules for {{{ SYSCALL | join(", ") }}} for x86 platform
9be3b2
   block:
9be3b2
     {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
       action_arch_filters="-a always,exit -F arch=b32",
9be3b2
@@ -30,7 +30,7 @@
9be3b2
       syscall_grouping=SYSCALL_GROUPING,
9be3b2
       )|indent(4) }}}
9be3b2
 
9be3b2
-- name: Perform remediattion of Audit rules for {{{ SYSCALL }}} for x86_64 platform
9be3b2
+- name: Perform remediattion of Audit rules for {{{ SYSCALL | join(", ") }}} for x86_64 platform
9be3b2
   block:
9be3b2
     {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
       action_arch_filters="-a always,exit -F arch=b64",
9be3b2
diff --git a/shared/templates/audit_rules_unsuccessful_file_modification/ansible.template b/shared/templates/audit_rules_unsuccessful_file_modification/ansible.template
9be3b2
index cb5decc6a6e..a8fdc3978b1 100644
9be3b2
--- a/shared/templates/audit_rules_unsuccessful_file_modification/ansible.template
9be3b2
+++ b/shared/templates/audit_rules_unsuccessful_file_modification/ansible.template
9be3b2
@@ -7,12 +7,12 @@
9be3b2
 #
9be3b2
 # What architecture are we on?
9be3b2
 #
9be3b2
-- name: Set architecture for audit {{{ NAME }}} tasks
9be3b2
+- name: Set architecture for audit {{{ NAME | join(", ") }}} tasks
9be3b2
   set_fact:
9be3b2
     audit_arch: "b{{ ansible_architecture | regex_replace('.*(\\d\\d$)','\\1') }}"
9be3b2
 
9be3b2
 {{% for EXIT_CODE in ["EACCES","EPERM"] %}}
9be3b2
-- name: Perform remediation of Audit rules for {{{ NAME }}} {{{ EXIT_CODE}}} for x86 platform
9be3b2
+- name: Perform remediation of Audit rules for {{{ NAME | join(", ") }}} {{{ EXIT_CODE}}} for x86 platform
9be3b2
   block:
9be3b2
     {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
       action_arch_filters="-a always,exit -F arch=b32",
9be3b2
@@ -31,7 +31,7 @@
9be3b2
       syscall_grouping=SYSCALL_GROUPING,
9be3b2
       )|indent(4) }}}
9be3b2
 
9be3b2
-- name: Perform remediattion of Audit rules for {{{ NAME }}} {{{ EXIT_CODE }}} for x86_64 platform
9be3b2
+- name: Perform remediattion of Audit rules for {{{ NAME | join(", ") }}} {{{ EXIT_CODE }}} for x86_64 platform
9be3b2
   block:
9be3b2
     {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
       action_arch_filters="-a always,exit -F arch=b64",
9be3b2
9be3b2
From 6dd2a0388e025bbbb00bea15c999cc09e140afce Mon Sep 17 00:00:00 2001
9be3b2
From: Watson Sato <wsato@redhat.com>
9be3b2
Date: Wed, 18 Aug 2021 13:49:07 +0200
9be3b2
Subject: [PATCH 26/31] Fix typo in audit task block title
9be3b2
9be3b2
---
9be3b2
 .../ansible/shared.yml                                        | 4 ++--
9be3b2
 .../ansible/shared.yml                                        | 4 ++--
9be3b2
 .../audit_rules_kernel_module_loading_init/ansible/shared.yml | 4 ++--
9be3b2
 .../directory_access_var_log_audit/ansible/shared.yml         | 2 +-
9be3b2
 .../templates/audit_rules_dac_modification/ansible.template   | 4 ++--
9be3b2
 .../audit_rules_file_deletion_events/ansible.template         | 4 ++--
9be3b2
 shared/templates/audit_rules_path_syscall/ansible.template    | 4 ++--
9be3b2
 .../audit_rules_privileged_commands/ansible.template          | 2 +-
9be3b2
 .../ansible.template                                          | 2 +-
9be3b2
 9 files changed, 15 insertions(+), 15 deletions(-)
9be3b2
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading_delete/ansible/shared.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading_delete/ansible/shared.yml
9be3b2
index 863ba6f0134..f5469c0ebf9 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading_delete/ansible/shared.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading_delete/ansible/shared.yml
9be3b2
@@ -10,7 +10,7 @@
9be3b2
   set_fact:
9be3b2
     audit_arch: "b{{ ansible_architecture | regex_replace('.*(\\d\\d$)','\\1') }}"
9be3b2
 
9be3b2
-- name: Perform remediattion of Audit rules for delete_module for x86 platform
9be3b2
+- name: Perform remediation of Audit rules for delete_module for x86 platform
9be3b2
   block:
9be3b2
     {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
       action_arch_filters="-a always,exit -F arch=b32",
9be3b2
@@ -29,7 +29,7 @@
9be3b2
       syscall_grouping=[],
9be3b2
       )|indent(4) }}}
9be3b2
 
9be3b2
-- name: Perform remediattion of Audit rules for delete_module for x86_64 platform
9be3b2
+- name: Perform remediation of Audit rules for delete_module for x86_64 platform
9be3b2
   block:
9be3b2
     {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
       action_arch_filters="-a always,exit -F arch=b64",
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading_finit/ansible/shared.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading_finit/ansible/shared.yml
9be3b2
index 268f0a57f11..2e0780af564 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading_finit/ansible/shared.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading_finit/ansible/shared.yml
9be3b2
@@ -10,7 +10,7 @@
9be3b2
   set_fact:
9be3b2
     audit_arch: "b{{ ansible_architecture | regex_replace('.*(\\d\\d$)','\\1') }}"
9be3b2
 
9be3b2
-- name: Perform remediattion of Audit rules for finit_module for x86 platform
9be3b2
+- name: Perform remediation of Audit rules for finit_module for x86 platform
9be3b2
   block:
9be3b2
     {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
       action_arch_filters="-a always,exit -F arch=b32",
9be3b2
@@ -29,7 +29,7 @@
9be3b2
       syscall_grouping=["init_module","finit_module"],
9be3b2
       )|indent(4) }}}
9be3b2
 
9be3b2
-- name: Perform remediattion of Audit rules for finit_module for x86_64 platform
9be3b2
+- name: Perform remediation of Audit rules for finit_module for x86_64 platform
9be3b2
   block:
9be3b2
     {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
       action_arch_filters="-a always,exit -F arch=b64",
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading_init/ansible/shared.yml b/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading_init/ansible/shared.yml
9be3b2
index 2155a1835c6..6f6bd1826bc 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading_init/ansible/shared.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/audit_kernel_module_loading/audit_rules_kernel_module_loading_init/ansible/shared.yml
9be3b2
@@ -10,7 +10,7 @@
9be3b2
   set_fact:
9be3b2
     audit_arch: "b{{ ansible_architecture | regex_replace('.*(\\d\\d$)','\\1') }}"
9be3b2
 
9be3b2
-- name: Perform remediattion of Audit rules for init_module for x86 platform
9be3b2
+- name: Perform remediation of Audit rules for init_module for x86 platform
9be3b2
   block:
9be3b2
     {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
       action_arch_filters="-a always,exit -F arch=b32",
9be3b2
@@ -29,7 +29,7 @@
9be3b2
       syscall_grouping=["init_module","finit_module"],
9be3b2
       )|indent(4) }}}
9be3b2
 
9be3b2
-- name: Perform remediattion of Audit rules for init_module for x86_64 platform
9be3b2
+- name: Perform remediation of Audit rules for init_module for x86_64 platform
9be3b2
   block:
9be3b2
     {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
       action_arch_filters="-a always,exit -F arch=b64",
9be3b2
diff --git a/linux_os/guide/system/auditing/auditd_configure_rules/directory_access_var_log_audit/ansible/shared.yml b/linux_os/guide/system/auditing/auditd_configure_rules/directory_access_var_log_audit/ansible/shared.yml
9be3b2
index bc6e929372f..ec17adf5525 100644
9be3b2
--- a/linux_os/guide/system/auditing/auditd_configure_rules/directory_access_var_log_audit/ansible/shared.yml
9be3b2
+++ b/linux_os/guide/system/auditing/auditd_configure_rules/directory_access_var_log_audit/ansible/shared.yml
9be3b2
@@ -3,7 +3,7 @@
9be3b2
 # strategy = restrict
9be3b2
 # complexity = low
9be3b2
 # disruption = low
9be3b2
-- name: Perform remediattion of Audit rules for /var/log/audit
9be3b2
+- name: Perform remediation of Audit rules for /var/log/audit
9be3b2
   block:
9be3b2
     {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
       action_arch_filters="-a always,exit",
9be3b2
diff --git a/shared/templates/audit_rules_dac_modification/ansible.template b/shared/templates/audit_rules_dac_modification/ansible.template
9be3b2
index ea6fd94ff4b..2c006b451c4 100644
9be3b2
--- a/shared/templates/audit_rules_dac_modification/ansible.template
9be3b2
+++ b/shared/templates/audit_rules_dac_modification/ansible.template
9be3b2
@@ -11,7 +11,7 @@
9be3b2
   set_fact:
9be3b2
     audit_arch: "b{{ ansible_architecture | regex_replace('.*(\\d\\d$)','\\1') }}"
9be3b2
 
9be3b2
-- name: Perform remediattion of Audit rules for {{{ ATTR | join(", ") }}} for x86 platform
9be3b2
+- name: Perform remediation of Audit rules for {{{ ATTR | join(", ") }}} for x86 platform
9be3b2
   block:
9be3b2
     {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
       action_arch_filters="-a always,exit -F arch=b32",
9be3b2
@@ -48,7 +48,7 @@
9be3b2
       )|indent(4) }}}
9be3b2
 {{%- endif %}}
9be3b2
 
9be3b2
-- name: Perform remediattion of Audit rules for {{{ ATTR | join(", ") }}} for x86_64 platform
9be3b2
+- name: Perform remediation of Audit rules for {{{ ATTR | join(", ") }}} for x86_64 platform
9be3b2
   block:
9be3b2
     {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
       action_arch_filters="-a always,exit -F arch=b64",
9be3b2
diff --git a/shared/templates/audit_rules_file_deletion_events/ansible.template b/shared/templates/audit_rules_file_deletion_events/ansible.template
9be3b2
index 0044dc459dc..3bb07579463 100644
9be3b2
--- a/shared/templates/audit_rules_file_deletion_events/ansible.template
9be3b2
+++ b/shared/templates/audit_rules_file_deletion_events/ansible.template
9be3b2
@@ -11,7 +11,7 @@
9be3b2
   set_fact:
9be3b2
     audit_arch: "b{{ ansible_architecture | regex_replace('.*(\\d\\d$)','\\1') }}"
9be3b2
 
9be3b2
-- name: Perform remediattion of Audit rules for {{{ NAME| join(", ")  }}} for x86 platform
9be3b2
+- name: Perform remediation of Audit rules for {{{ NAME| join(", ")  }}} for x86 platform
9be3b2
   block:
9be3b2
     {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
       action_arch_filters="-a always,exit -F arch=b32",
9be3b2
@@ -30,7 +30,7 @@
9be3b2
       syscall_grouping=SYSCALL_GROUPING,
9be3b2
       )|indent(4) }}}
9be3b2
 
9be3b2
-- name: Perform remediattion of Audit rules for {{{ NAME| join(", ")  }}} for x86_64 platform
9be3b2
+- name: Perform remediation of Audit rules for {{{ NAME| join(", ")  }}} for x86_64 platform
9be3b2
   block:
9be3b2
     {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
       action_arch_filters="-a always,exit -F arch=b64",
9be3b2
diff --git a/shared/templates/audit_rules_path_syscall/ansible.template b/shared/templates/audit_rules_path_syscall/ansible.template
9be3b2
index 2875aff3573..fcd2bda3bab 100644
9be3b2
--- a/shared/templates/audit_rules_path_syscall/ansible.template
9be3b2
+++ b/shared/templates/audit_rules_path_syscall/ansible.template
9be3b2
@@ -11,7 +11,7 @@
9be3b2
   set_fact:
9be3b2
     audit_arch: "b{{ ansible_architecture | regex_replace('.*(\\d\\d$)','\\1') }}"
9be3b2
 
9be3b2
-- name: Perform remediattion of Audit rules for {{{ SYSCALL | join(", ") }}} for x86 platform
9be3b2
+- name: Perform remediation of Audit rules for {{{ SYSCALL | join(", ") }}} for x86 platform
9be3b2
   block:
9be3b2
     {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
       action_arch_filters="-a always,exit -F arch=b32",
9be3b2
@@ -30,7 +30,7 @@
9be3b2
       syscall_grouping=SYSCALL_GROUPING,
9be3b2
       )|indent(4) }}}
9be3b2
 
9be3b2
-- name: Perform remediattion of Audit rules for {{{ SYSCALL | join(", ") }}} for x86_64 platform
9be3b2
+- name: Perform remediation of Audit rules for {{{ SYSCALL | join(", ") }}} for x86_64 platform
9be3b2
   block:
9be3b2
     {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
       action_arch_filters="-a always,exit -F arch=b64",
9be3b2
diff --git a/shared/templates/audit_rules_privileged_commands/ansible.template b/shared/templates/audit_rules_privileged_commands/ansible.template
9be3b2
index b1788b59b8a..e9ef084984a 100644
9be3b2
--- a/shared/templates/audit_rules_privileged_commands/ansible.template
9be3b2
+++ b/shared/templates/audit_rules_privileged_commands/ansible.template
9be3b2
@@ -7,7 +7,7 @@
9be3b2
 # complexity = low
9be3b2
 # disruption = low
9be3b2
 
9be3b2
-- name: Perform remediattion of Audit rules for {{{ PATH }}}
9be3b2
+- name: Perform remediation of Audit rules for {{{ PATH }}}
9be3b2
   block:
9be3b2
     {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
       action_arch_filters="-a always,exit",
9be3b2
diff --git a/shared/templates/audit_rules_unsuccessful_file_modification/ansible.template b/shared/templates/audit_rules_unsuccessful_file_modification/ansible.template
9be3b2
index a8fdc3978b1..6cf90e11863 100644
9be3b2
--- a/shared/templates/audit_rules_unsuccessful_file_modification/ansible.template
9be3b2
+++ b/shared/templates/audit_rules_unsuccessful_file_modification/ansible.template
9be3b2
@@ -31,7 +31,7 @@
9be3b2
       syscall_grouping=SYSCALL_GROUPING,
9be3b2
       )|indent(4) }}}
9be3b2
 
9be3b2
-- name: Perform remediattion of Audit rules for {{{ NAME | join(", ") }}} {{{ EXIT_CODE }}} for x86_64 platform
9be3b2
+- name: Perform remediation of Audit rules for {{{ NAME | join(", ") }}} {{{ EXIT_CODE }}} for x86_64 platform
9be3b2
   block:
9be3b2
     {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
       action_arch_filters="-a always,exit -F arch=b64",
9be3b2
9be3b2
From fe88dfbf2b4c7acd0a196512d2868f19b9b89f33 Mon Sep 17 00:00:00 2001
9be3b2
From: Watson Sato <wsato@redhat.com>
9be3b2
Date: Wed, 18 Aug 2021 17:21:32 +0200
9be3b2
Subject: [PATCH 27/31] Reset the tracking of syscalls found per file
9be3b2
9be3b2
When running a playbook profile, they were accumulating over the entire
9be3b2
run.
9be3b2
---
9be3b2
 shared/macros-ansible.jinja | 9 +++++++--
9be3b2
 1 file changed, 7 insertions(+), 2 deletions(-)
9be3b2
9be3b2
diff --git a/shared/macros-ansible.jinja b/shared/macros-ansible.jinja
9be3b2
index b5574da29ac..b26966238a2 100644
9be3b2
--- a/shared/macros-ansible.jinja
9be3b2
+++ b/shared/macros-ansible.jinja
9be3b2
@@ -422,15 +422,20 @@ The macro requires following parameters:
9be3b2
   register: find_command
9be3b2
   loop: '{{ (syscall_grouping + syscalls) | unique }}'
9be3b2
 
9be3b2
+- name: Reset syscalls found per file
9be3b2
+  set_fact:
9be3b2
+    syscalls_per_file: {}
9be3b2
+    found_paths_dict: {}
9be3b2
+
9be3b2
 - name: Declare syscalls found per file
9be3b2
-  set_fact: syscalls_per_file="{{ syscalls_per_file | default({}) | combine( {item.files[0].path :[item.item]+(syscalls_per_file | default({})).get(item.files[0].path, []) } ) }}"
9be3b2
+  set_fact: syscalls_per_file="{{ syscalls_per_file | combine( {item.files[0].path :[item.item] + syscalls_per_file.get(item.files[0].path, []) } ) }}"
9be3b2
   loop: "{{ find_command.results | selectattr('matched') | list}}"
9be3b2
 
9be3b2
 - name: Declare files where syscalls where found
9be3b2
   set_fact: found_paths="{{ find_command.results | map(attribute='files') | flatten | map(attribute='path') | list }}"
9be3b2
 
9be3b2
 - name: Count occurrences of syscalls in paths
9be3b2
-  set_fact: found_paths_dict="{{ found_paths_dict | default({}) | combine({ item:1+(found_paths_dict | default({})).get(item, 0) }) }}"
9be3b2
+  set_fact: found_paths_dict="{{ found_paths_dict | combine({ item:1+found_paths_dict.get(item, 0) }) }}"
9be3b2
   loop: "{{ find_command.results | map(attribute='files') | flatten | map(attribute='path') | list }}"
9be3b2
 
9be3b2
 - name: Get path with most syscalls
9be3b2
9be3b2
From 34a66912886e979fac132346074e556c36336b0c Mon Sep 17 00:00:00 2001
9be3b2
From: Watson Sato <wsato@redhat.com>
9be3b2
Date: Thu, 19 Aug 2021 12:32:25 +0200
9be3b2
Subject: [PATCH 28/31] Create audit rules without permissions for others
9be3b2
9be3b2
---
9be3b2
 shared/bash_remediation_functions/fix_audit_syscall_rule.sh | 1 +
9be3b2
 shared/macros-ansible.jinja                                 | 2 ++
9be3b2
 2 files changed, 3 insertions(+)
9be3b2
9be3b2
diff --git a/shared/bash_remediation_functions/fix_audit_syscall_rule.sh b/shared/bash_remediation_functions/fix_audit_syscall_rule.sh
9be3b2
index 5cc130a0236..d95aedba395 100644
9be3b2
--- a/shared/bash_remediation_functions/fix_audit_syscall_rule.sh
9be3b2
+++ b/shared/bash_remediation_functions/fix_audit_syscall_rule.sh
9be3b2
@@ -204,6 +204,7 @@ then
9be3b2
 	local auid_string=$([[ $auid_filters ]] && echo " $auid_filters")
9be3b2
 	local full_rule="${action_arch_filters}${syscall_string}${other_string}${auid_string} -F key=${key}"
9be3b2
 	echo "$full_rule" >> "$default_file"
9be3b2
+	chmod o-rwx ${default_file}
9be3b2
 else
9be3b2
 	# Check if the syscalls are declared as a comma separated list or
9be3b2
 	# as multiple -S parameters
9be3b2
diff --git a/shared/macros-ansible.jinja b/shared/macros-ansible.jinja
9be3b2
index b26966238a2..6c9c53a07db 100644
9be3b2
--- a/shared/macros-ansible.jinja
9be3b2
+++ b/shared/macros-ansible.jinja
9be3b2
@@ -467,6 +467,7 @@ The macro requires following parameters:
9be3b2
     path: '{{ audit_file }}'
9be3b2
     line: "{{{ action_arch_filters }}}{{{ syscall_flag }}}{{ syscalls | join(',') }}{{{ other_filters }}}{{{ auid_filters}}} -F key={{{ key }}}"
9be3b2
     create: true
9be3b2
+    mode: o-rwx
9be3b2
     state: present
9be3b2
   when: syscalls_found | length == 0
9be3b2
 {{%- endmacro %}}
9be3b2
@@ -535,6 +536,7 @@ The macro requires following parameters:
9be3b2
     path: '{{ audit_file }}'
9be3b2
     line: "{{{ action_arch_filters }}}{{{ syscall_flag }}}{{ syscalls | join(',') }}{{{ other_filters }}}{{{ auid_filters}}} -F key={{{ key }}}"
9be3b2
     create: true
9be3b2
+    mode: o-rwx
9be3b2
     state: present
9be3b2
   when: syscalls_found | length == 0
9be3b2
 {{%- endmacro %}}
9be3b2
9be3b2
From 181a0f9aacbcf7340ce0931907bd7ae1db0cf478 Mon Sep 17 00:00:00 2001
9be3b2
From: Watson Sato <wsato@redhat.com>
9be3b2
Date: Thu, 19 Aug 2021 14:48:08 +0200
9be3b2
Subject: [PATCH 29/31] Remove trailing space from perm field
9be3b2
9be3b2
Otherwise the rule will be added with two spaces between other_filters
9be3b2
and auid_filters.
9be3b2
---
9be3b2
 shared/templates/audit_rules_privileged_commands/bash.template | 2 +-
9be3b2
 1 file changed, 1 insertion(+), 1 deletion(-)
9be3b2
9be3b2
diff --git a/shared/templates/audit_rules_privileged_commands/bash.template b/shared/templates/audit_rules_privileged_commands/bash.template
9be3b2
index b5879085a45..5af362df800 100644
9be3b2
--- a/shared/templates/audit_rules_privileged_commands/bash.template
9be3b2
+++ b/shared/templates/audit_rules_privileged_commands/bash.template
9be3b2
@@ -1,5 +1,5 @@
9be3b2
 {{%- if product in ["rhel8", "rhel9", "sle12", "sle15"] %}}
9be3b2
-  {{%- set perm_x=" -F perm=x " %}}
9be3b2
+  {{%- set perm_x=" -F perm=x" %}}
9be3b2
 {{%- endif %}}
9be3b2
 # platform = multi_platform_rhel,multi_platform_fedora,multi_platform_ol,multi_platform_rhv
9be3b2
 
9be3b2
9be3b2
From c94454fd4409b69e24012b006266637e17982be8 Mon Sep 17 00:00:00 2001
9be3b2
From: Watson Sato <wsato@redhat.com>
9be3b2
Date: Thu, 19 Aug 2021 14:54:57 +0200
9be3b2
Subject: [PATCH 30/31] Fix typos in task titles
9be3b2
9be3b2
---
9be3b2
 shared/macros-ansible.jinja                                 | 2 +-
9be3b2
 .../audit_rules_file_deletion_events/ansible.template       | 6 +++---
9be3b2
 2 files changed, 4 insertions(+), 4 deletions(-)
9be3b2
9be3b2
diff --git a/shared/macros-ansible.jinja b/shared/macros-ansible.jinja
9be3b2
index 6c9c53a07db..ed3881d054c 100644
9be3b2
--- a/shared/macros-ansible.jinja
9be3b2
+++ b/shared/macros-ansible.jinja
9be3b2
@@ -431,7 +431,7 @@ The macro requires following parameters:
9be3b2
   set_fact: syscalls_per_file="{{ syscalls_per_file | combine( {item.files[0].path :[item.item] + syscalls_per_file.get(item.files[0].path, []) } ) }}"
9be3b2
   loop: "{{ find_command.results | selectattr('matched') | list}}"
9be3b2
 
9be3b2
-- name: Declare files where syscalls where found
9be3b2
+- name: Declare files where syscalls were found
9be3b2
   set_fact: found_paths="{{ find_command.results | map(attribute='files') | flatten | map(attribute='path') | list }}"
9be3b2
 
9be3b2
 - name: Count occurrences of syscalls in paths
9be3b2
diff --git a/shared/templates/audit_rules_file_deletion_events/ansible.template b/shared/templates/audit_rules_file_deletion_events/ansible.template
9be3b2
index 3bb07579463..f09ce12d87a 100644
9be3b2
--- a/shared/templates/audit_rules_file_deletion_events/ansible.template
9be3b2
+++ b/shared/templates/audit_rules_file_deletion_events/ansible.template
9be3b2
@@ -7,11 +7,11 @@
9be3b2
 #
9be3b2
 # What architecture are we on?
9be3b2
 #
9be3b2
-- name: Set architecture for audit {{{ NAME| join(", ")  }}} tasks
9be3b2
+- name: Set architecture for audit {{{ NAME | join(", ") }}} tasks
9be3b2
   set_fact:
9be3b2
     audit_arch: "b{{ ansible_architecture | regex_replace('.*(\\d\\d$)','\\1') }}"
9be3b2
 
9be3b2
-- name: Perform remediation of Audit rules for {{{ NAME| join(", ")  }}} for x86 platform
9be3b2
+- name: Perform remediation of Audit rules for {{{ NAME | join(", ") }}} for x86 platform
9be3b2
   block:
9be3b2
     {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
       action_arch_filters="-a always,exit -F arch=b32",
9be3b2
@@ -30,7 +30,7 @@
9be3b2
       syscall_grouping=SYSCALL_GROUPING,
9be3b2
       )|indent(4) }}}
9be3b2
 
9be3b2
-- name: Perform remediation of Audit rules for {{{ NAME| join(", ")  }}} for x86_64 platform
9be3b2
+- name: Perform remediation of Audit rules for {{{ NAME | join(", ") }}} for x86_64 platform
9be3b2
   block:
9be3b2
     {{{ ansible_audit_augenrules_add_syscall_rule(
9be3b2
       action_arch_filters="-a always,exit -F arch=b64",
9be3b2
9be3b2
From a5e99060b4856298ffc9f2a75a611a2eefb9b4de Mon Sep 17 00:00:00 2001
9be3b2
From: Watson Sato <wsato@redhat.com>
9be3b2
Date: Thu, 19 Aug 2021 15:35:25 +0200
9be3b2
Subject: [PATCH 31/31] Fix Ansible linter issue
9be3b2
9be3b2
Variables should have spaces before and after
9be3b2
---
9be3b2
 shared/macros-ansible.jinja | 2 +-
9be3b2
 1 file changed, 1 insertion(+), 1 deletion(-)
9be3b2
9be3b2
diff --git a/shared/macros-ansible.jinja b/shared/macros-ansible.jinja
9be3b2
index ed3881d054c..b9536439c50 100644
9be3b2
--- a/shared/macros-ansible.jinja
9be3b2
+++ b/shared/macros-ansible.jinja
9be3b2
@@ -429,7 +429,7 @@ The macro requires following parameters:
9be3b2
 
9be3b2
 - name: Declare syscalls found per file
9be3b2
   set_fact: syscalls_per_file="{{ syscalls_per_file | combine( {item.files[0].path :[item.item] + syscalls_per_file.get(item.files[0].path, []) } ) }}"
9be3b2
-  loop: "{{ find_command.results | selectattr('matched') | list}}"
9be3b2
+  loop: "{{ find_command.results | selectattr('matched') | list }}"
9be3b2
 
9be3b2
 - name: Declare files where syscalls were found
9be3b2
   set_fact: found_paths="{{ find_command.results | map(attribute='files') | flatten | map(attribute='path') | list }}"