diff --git a/controls/cis_sle12.yml b/controls/cis_sle12.yml index 9b982e53043..30fab7342ac 100644 --- a/controls/cis_sle12.yml +++ b/controls/cis_sle12.yml @@ -427,7 +427,10 @@ controls: levels: - l1_server - l1_workstation - status: manual # rule is missing + status: automated + rules: + - all_apparmor_profiles_in_enforce_complain_mode + - var_apparmor_mode=complain - id: 1.7.1.4 title: Ensure all AppArmor Profiles are enforcing (Automated) diff --git a/controls/cis_sle15.yml b/controls/cis_sle15.yml index afc4155e9d6..971d27af115 100644 --- a/controls/cis_sle15.yml +++ b/controls/cis_sle15.yml @@ -426,7 +426,10 @@ controls: levels: - l1_server - l1_workstation - status: manual # rule is missing + status: automated + rules: + - all_apparmor_profiles_in_enforce_complain_mode + - var_apparmor_mode=complain - id: 1.7.1.4 title: Ensure all AppArmor Profiles are enforcing (Automated) diff --git a/linux_os/guide/system/apparmor/all_apparmor_profiles_in_enforce_complain_mode/ansible/shared.yml b/linux_os/guide/system/apparmor/all_apparmor_profiles_in_enforce_complain_mode/ansible/shared.yml new file mode 100644 index 00000000000..3153ad9c4f8 --- /dev/null +++ b/linux_os/guide/system/apparmor/all_apparmor_profiles_in_enforce_complain_mode/ansible/shared.yml @@ -0,0 +1,30 @@ +# platform = multi_platform_sle +# reboot = false +# strategy = restrict +# complexity = low +# disruption = low + +{{{ ansible_instantiate_variables("var_apparmor_mode") }}} + +- name: {{{ rule_title }}} - Ensure all AppArmor Profiles are reloaded + ansible.builtin.command: apparmor_parser -q -r /etc/apparmor.d/ + +- name: {{{ rule_title }}} - Set all AppArmor profiles to enforce mode + ansible.builtin.command: aa-enforce /etc/apparmor.d/* + when: var_apparmor_mode == 'enforce' + +- name: {{{ rule_title }}} - Set all AppArmor profiles to complain mode + ansible.builtin.command: aa-complain /etc/apparmor.d/* + when: var_apparmor_mode == 'complain' + +- name: {{{ rule_title }}} - Collect unconfined processes + ansible.builtin.command: aa-unconfined + register: unconfined_processes + +- name: {{{ rule_title }}} - Provide details about unconfined processes + ansible.builtin.assert: + that: + - unconfined_processes.stdout_lines | length > 0 + success_msg: "The process {{ item }} may need to have a profile created or activated for them and then be restarted." + fail_msg: "" + with_items: "{{ unconfined_processes.stdout_lines }}" diff --git a/linux_os/guide/system/apparmor/all_apparmor_profiles_in_enforce_complain_mode/bash/shared.sh b/linux_os/guide/system/apparmor/all_apparmor_profiles_in_enforce_complain_mode/bash/shared.sh new file mode 100644 index 00000000000..6b7c170e769 --- /dev/null +++ b/linux_os/guide/system/apparmor/all_apparmor_profiles_in_enforce_complain_mode/bash/shared.sh @@ -0,0 +1,36 @@ +# platform = multi_platform_sle + +{{{ bash_instantiate_variables("var_apparmor_mode") }}} + + +# Reload all AppArmor profiles +apparmor_parser -q -r /etc/apparmor.d/ + +# Set the mode +APPARMOR_MODE="$var_apparmor_mode" + +if [ "$APPARMOR_MODE" = "enforce" ] +then + # Set all profiles to enforce mode + aa-enforce /etc/apparmor.d/* +fi + +if [ "$APPARMOR_MODE" = "complain" ] +then + # Set all profiles to complain mode + aa-complain /etc/apparmor.d/* +fi + +UNCONFINED=$(aa-unconfined) +if [ ! -z "$UNCONFINED" ] +then + echo -e "***WARNING***: There are some unconfined processes:" + echo -e "----------------------------" + echo "The may need to have a profile created or activated for them and then be restarted." + for PROCESS in "${UNCONFINED[@]}" + do + echo "$PROCESS" + done + echo -e "----------------------------" + echo "The may need to have a profile created or activated for them and then be restarted." +fi diff --git a/linux_os/guide/system/apparmor/all_apparmor_profiles_in_enforce_complain_mode/rule.yml b/linux_os/guide/system/apparmor/all_apparmor_profiles_in_enforce_complain_mode/rule.yml new file mode 100644 index 00000000000..f5fe363c9ca --- /dev/null +++ b/linux_os/guide/system/apparmor/all_apparmor_profiles_in_enforce_complain_mode/rule.yml @@ -0,0 +1,33 @@ +documentation_complete: true + +prodtype: sle12,sle15 + +title: 'All AppArmor Profiles are in enforce or complain mode' + +description: |- + AppArmor profiles define what resources applications are able to access. + To set all profiles to either enforce or complain mode + run the following command to set all profiles to enforce mode: +
$ sudo aa-enforce /etc/apparmor.d/*+ run the following command to set all profiles to complain mode: +
$ sudo aa-complain /etc/apparmor.d/*+ To list unconfined processes run the following command: +
$ sudo aa-unconfined+ Any unconfined processes may need to have a profile created or activated + for them and then be restarted. + +rationale: |- + Security configuration requirements vary from site to site. Some sites may + mandate a policy that is stricter than the default policy, which is perfectly + acceptable. This recommendation is intended to ensure that any policies that + exist on the system are activated. + +severity: medium + +identifiers: + cce@sle12: CCE-92356-5 + cce@sle15: CCE-92548-7 + +references: + cis@sle12: 1.7.1.3 + cis@sle15: 1.7.1.3 diff --git a/linux_os/guide/system/apparmor/all_apparmor_profiles_in_enforce_complain_mode/tests/correct_all_apparmor_profiles_in_complain.pass.sh b/linux_os/guide/system/apparmor/all_apparmor_profiles_in_enforce_complain_mode/tests/correct_all_apparmor_profiles_in_complain.pass.sh new file mode 100644 index 00000000000..345881aa5d8 --- /dev/null +++ b/linux_os/guide/system/apparmor/all_apparmor_profiles_in_enforce_complain_mode/tests/correct_all_apparmor_profiles_in_complain.pass.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +#Replace apparmor definitions +apparmor_parser -q -r /etc/apparmor.d/ +#Set all profiles in complain mode +aa-complain /etc/apparmor.d/* diff --git a/linux_os/guide/system/apparmor/all_apparmor_profiles_in_enforce_complain_mode/tests/correct_all_apparmor_profiles_in_enforce.pass.sh b/linux_os/guide/system/apparmor/all_apparmor_profiles_in_enforce_complain_mode/tests/correct_all_apparmor_profiles_in_enforce.pass.sh new file mode 100644 index 00000000000..e2651e31641 --- /dev/null +++ b/linux_os/guide/system/apparmor/all_apparmor_profiles_in_enforce_complain_mode/tests/correct_all_apparmor_profiles_in_enforce.pass.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +#Replace apparmor definitions +apparmor_parser -q -r /etc/apparmor.d/ +#Set all profiles in enforce mode +aa-enforce /etc/apparmor.d/* diff --git a/linux_os/guide/system/apparmor/all_apparmor_profiles_in_enforce_complain_mode/tests/incorrect_all_apparmor_profiles.fail.sh b/linux_os/guide/system/apparmor/all_apparmor_profiles_in_enforce_complain_mode/tests/incorrect_all_apparmor_profiles.fail.sh new file mode 100644 index 00000000000..9f23139ed3b --- /dev/null +++ b/linux_os/guide/system/apparmor/all_apparmor_profiles_in_enforce_complain_mode/tests/incorrect_all_apparmor_profiles.fail.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +#Configure the OS to unload all AppArmor profiles +aa-teardown diff --git a/linux_os/guide/system/apparmor/var_apparmor_mode.var b/linux_os/guide/system/apparmor/var_apparmor_mode.var new file mode 100644 index 00000000000..fa4a2f39ad3 --- /dev/null +++ b/linux_os/guide/system/apparmor/var_apparmor_mode.var @@ -0,0 +1,18 @@ +documentation_complete: true + +title: 'AppArmor profiles mode' + +description: |- + enforce - Set all AppArmor profiles to enforce mode