From 7e3e7421be8d4beea5be8941dc7b52ef8a02d3e0 Mon Sep 17 00:00:00 2001 From: Miha Purg Date: Wed, 8 Jan 2025 13:48:47 +0100 Subject: [PATCH] Fix auditd rule to watch apparmor instead of selinux on Ubuntu --- .../bash/shared.sh | 7 +++ .../oval/shared.xml | 59 +++++++++++++++---- .../audit_rules_mac_modification/rule.yml | 12 +++- .../tests/auditctl_correct.pass.sh | 5 ++ .../auditctl_correct_without_key.pass.sh | 5 ++ .../tests/augen_correct.pass.sh | 6 ++ .../tests/augen_correct_without_key.pass.sh | 5 ++ 7 files changed, 87 insertions(+), 12 deletions(-) diff --git a/linux_os/guide/auditing/auditd_configure_rules/audit_rules_mac_modification/bash/shared.sh b/linux_os/guide/auditing/auditd_configure_rules/audit_rules_mac_modification/bash/shared.sh index 67a97f3b3cc..90d4d210171 100644 --- a/linux_os/guide/auditing/auditd_configure_rules/audit_rules_mac_modification/bash/shared.sh +++ b/linux_os/guide/auditing/auditd_configure_rules/audit_rules_mac_modification/bash/shared.sh @@ -1,5 +1,12 @@ # platform = Red Hat Virtualization 4,multi_platform_fedora,multi_platform_ol,multi_platform_rhel,multi_platform_sle,multi_platform_slmicro,multi_platform_ubuntu # Perform the remediation for both possible tools: 'auditctl' and 'augenrules' +{{% if 'ubuntu' not in product %}} {{{ bash_fix_audit_watch_rule("auditctl", "/etc/selinux/", "wa", "MAC-policy") }}} {{{ bash_fix_audit_watch_rule("augenrules", "/etc/selinux/", "wa", "MAC-policy") }}} +{{% else %}} +{{{ bash_fix_audit_watch_rule("auditctl", "/etc/apparmor/", "wa", "MAC-policy") }}} +{{{ bash_fix_audit_watch_rule("augenrules", "/etc/apparmor/", "wa", "MAC-policy") }}} +{{{ bash_fix_audit_watch_rule("auditctl", "/etc/apparmor.d/", "wa", "MAC-policy") }}} +{{{ bash_fix_audit_watch_rule("augenrules", "/etc/apparmor.d/", "wa", "MAC-policy") }}} +{{% endif %}} diff --git a/linux_os/guide/auditing/auditd_configure_rules/audit_rules_mac_modification/oval/shared.xml b/linux_os/guide/auditing/auditd_configure_rules/audit_rules_mac_modification/oval/shared.xml index 55158b3a2e5..87f8179ebe6 100644 --- a/linux_os/guide/auditing/auditd_configure_rules/audit_rules_mac_modification/oval/shared.xml +++ b/linux_os/guide/auditing/auditd_configure_rules/audit_rules_mac_modification/oval/shared.xml @@ -1,40 +1,77 @@ +{{% set mac_name="SELinux" %}} +{{% set mac_used="selinux"%}} +{{% set mac_path="/etc/selinux" %}} +{{% if 'ubuntu' in product %}} + {{% set mac_name="AppArmor" %}} + {{% set mac_used="apparmor"%}} + {{% set mac_path="/etc/apparmor" %}} +{{% endif %}} + - {{{ oval_metadata("Audit rules that detect changes to the system's mandatory access controls (SELinux) are enabled.") }}} + {{{ oval_metadata("Audit rules that detect changes to the system's mandatory access controls (" + mac_name + ") are enabled.") }}} - + + {{% if 'ubuntu' in product %}} + + {{% endif %}} - + + {{% if 'ubuntu' in product %}} + + {{% endif %}} - - + + - + ^/etc/audit/rules\.d/.*\.rules$ - ^\-w[\s]+/etc/selinux/[\s]+\-p[\s]+\b([rx]*w[rx]*a[rx]*|[rx]*a[rx]*w[rx]*)\b.*$ + ^\-w[\s]+{{{ mac_path }}}/[\s]+\-p[\s]+\b([rx]*w[rx]*a[rx]*|[rx]*a[rx]*w[rx]*)\b.*$ 1 - - + + - + + /etc/audit/audit.rules + ^\-w[\s]+{{{ mac_path }}}/[\s]+\-p[\s]+\b([rx]*w[rx]*a[rx]*|[rx]*a[rx]*w[rx]*)\b.*$ + 1 + + + {{% if 'ubuntu' in product %}} + + + + + + ^/etc/audit/rules\.d/.*\.rules$ + ^\-w[\s]+{{{ mac_path }}}\.d/[\s]+\-p[\s]+\b([rx]*w[rx]*a[rx]*|[rx]*a[rx]*w[rx]*)\b.*$ + 1 + + + + + + + /etc/audit/audit.rules - ^\-w[\s]+/etc/selinux/[\s]+\-p[\s]+\b([rx]*w[rx]*a[rx]*|[rx]*a[rx]*w[rx]*)\b.*$ + ^\-w[\s]+{{{ mac_path }}}\.d/[\s]+\-p[\s]+\b([rx]*w[rx]*a[rx]*|[rx]*a[rx]*w[rx]*)\b.*$ 1 + {{% endif %}} diff --git a/linux_os/guide/auditing/auditd_configure_rules/audit_rules_mac_modification/rule.yml b/linux_os/guide/auditing/auditd_configure_rules/audit_rules_mac_modification/rule.yml index 0fd1441c3cb..263fef8a8ac 100644 --- a/linux_os/guide/auditing/auditd_configure_rules/audit_rules_mac_modification/rule.yml +++ b/linux_os/guide/auditing/auditd_configure_rules/audit_rules_mac_modification/rule.yml @@ -7,14 +7,24 @@ description: |- augenrules program to read audit rules during daemon startup (the default), add the following line to a file with suffix .rules in the directory /etc/audit/rules.d: + {{% if 'ubuntu' in product %}} +
-w /etc/apparmor/ -p wa -k MAC-policy
+
-w /etc/apparmor.d/ -p wa -k MAC-policy
+ {{% else %}}
-w /etc/selinux/ -p wa -k MAC-policy
+ {{% endif %}} If the auditd daemon is configured to use the auditctl utility to read audit rules during daemon startup, add the following line to /etc/audit/audit.rules file: + {{% if 'ubuntu' in product %}} +
-w /etc/apparmor/ -p wa -k MAC-policy
+
-w /etc/apparmor.d/ -p wa -k MAC-policy
+ {{% else %}}
-w /etc/selinux/ -p wa -k MAC-policy
+ {{% endif %}} rationale: |- - The system's mandatory access policy (SELinux) should not be + The system's mandatory access policy (SELinux or Apparmor) should not be arbitrarily changed by anything other than administrator action. All changes to MAC policy should be audited. diff --git a/linux_os/guide/auditing/auditd_configure_rules/audit_rules_mac_modification/tests/auditctl_correct.pass.sh b/linux_os/guide/auditing/auditd_configure_rules/audit_rules_mac_modification/tests/auditctl_correct.pass.sh index 16f737f85d1..ce766d772b0 100644 --- a/linux_os/guide/auditing/auditd_configure_rules/audit_rules_mac_modification/tests/auditctl_correct.pass.sh +++ b/linux_os/guide/auditing/auditd_configure_rules/audit_rules_mac_modification/tests/auditctl_correct.pass.sh @@ -4,4 +4,9 @@ # use auditctl {{{ setup_auditctl_environment() }}} +{{% if 'ubuntu' in product %}} +echo "-w /etc/apparmor/ -p wa -k MAC-policy" > /etc/audit/audit.rules +echo "-w /etc/apparmor.d/ -p wa -k MAC-policy" >> /etc/audit/audit.rules +{{% else %}} echo "-w /etc/selinux/ -p wa -k MAC-policy" > /etc/audit/audit.rules +{{% endif %}} diff --git a/linux_os/guide/auditing/auditd_configure_rules/audit_rules_mac_modification/tests/auditctl_correct_without_key.pass.sh b/linux_os/guide/auditing/auditd_configure_rules/audit_rules_mac_modification/tests/auditctl_correct_without_key.pass.sh index 8de58fdcf6f..836df3c1a1d 100644 --- a/linux_os/guide/auditing/auditd_configure_rules/audit_rules_mac_modification/tests/auditctl_correct_without_key.pass.sh +++ b/linux_os/guide/auditing/auditd_configure_rules/audit_rules_mac_modification/tests/auditctl_correct_without_key.pass.sh @@ -4,4 +4,9 @@ # use auditctl {{{ setup_auditctl_environment() }}} +{{% if 'ubuntu' in product %}} +echo "-w /etc/apparmor/ -p wa" > /etc/audit/audit.rules +echo "-w /etc/apparmor.d/ -p wa" >> /etc/audit/audit.rules +{{% else %}} echo "-w /etc/selinux/ -p wa" > /etc/audit/audit.rules +{{% endif %}} diff --git a/linux_os/guide/auditing/auditd_configure_rules/audit_rules_mac_modification/tests/augen_correct.pass.sh b/linux_os/guide/auditing/auditd_configure_rules/audit_rules_mac_modification/tests/augen_correct.pass.sh index 85df1015da1..70d8e4e5ffe 100644 --- a/linux_os/guide/auditing/auditd_configure_rules/audit_rules_mac_modification/tests/augen_correct.pass.sh +++ b/linux_os/guide/auditing/auditd_configure_rules/audit_rules_mac_modification/tests/augen_correct.pass.sh @@ -1,4 +1,10 @@ #!/bin/bash # packages = audit +{{% if 'ubuntu' in product %}} +echo "-w /etc/apparmor/ -p wa -k MAC-policy" > /etc/audit/rules.d/MAC-policy.rules +echo "-w /etc/apparmor.d/ -p wa -k MAC-policy" >> /etc/audit/rules.d/MAC-policy.rules +{{% else %}} echo "-w /etc/selinux/ -p wa -k MAC-policy" > /etc/audit/rules.d/MAC-policy.rules +{{% endif %}} + diff --git a/linux_os/guide/auditing/auditd_configure_rules/audit_rules_mac_modification/tests/augen_correct_without_key.pass.sh b/linux_os/guide/auditing/auditd_configure_rules/audit_rules_mac_modification/tests/augen_correct_without_key.pass.sh index 7fac367869e..b0f4a7a2b36 100644 --- a/linux_os/guide/auditing/auditd_configure_rules/audit_rules_mac_modification/tests/augen_correct_without_key.pass.sh +++ b/linux_os/guide/auditing/auditd_configure_rules/audit_rules_mac_modification/tests/augen_correct_without_key.pass.sh @@ -1,4 +1,9 @@ #!/bin/bash # packages = audit +{{% if 'ubuntu' in product %}} +echo "-w /etc/apparmor/ -p wa" > /etc/audit/rules.d/MAC-policy.rules +echo "-w /etc/apparmor.d/ -p wa" >> /etc/audit/rules.d/MAC-policy.rules +{{% else %}} echo "-w /etc/selinux/ -p wa" > /etc/audit/rules.d/MAC-policy.rules +{{% endif %}}