Execution
Date
08 Dec 2025 13:27:39 +0000
Duration
00:05:33.94
Controller
aio1.openstack.local
User
root
Versions
Ansible
2.18.6
ara
1.7.4 / 1.7.4
Python
3.12.3
Summary
2
Hosts
316
Tasks
313
Results
18
Plays
136
Files
0
Records
File: /home/zuul/src/opendev.org/openstack/ansible-hardening/tasks/rhel7stig/lsm.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | --- # Copyright 2016, Rackspace US, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - name: Check apparmor_status output ansible.builtin.command: apparmor_status register: apparmor_status_output check_mode: false changed_when: false failed_when: false when: - ansible_facts['pkg_mgr'] in ['apt', 'zypper'] - security_rhel7_enable_linux_security_module | bool tags: - high - V-71989 # NOTE(mhayden): The systemd unit file for apparmor just calls an old SysV # init script and exits. It's not possible to ask systemd if apparmor is # running and if we tell systemd to start apparmor, it will tell us that it # started apparmor each time. This breaks idempotency and we check # systemd's status directly as an alternative. - name: Check if apparmor is running ansible.builtin.command: "systemctl status apparmor" register: systemctl_apparmor_status check_mode: false changed_when: false failed_when: false when: - ansible_facts['pkg_mgr'] in ['apt', 'zypper'] - security_rhel7_enable_linux_security_module | bool tags: - high - V-71989 - name: Ensure AppArmor is enabled at boot time ansible.builtin.service: name: apparmor enabled: true when: - ansible_facts['pkg_mgr'] in ['apt', 'zypper'] - security_rhel7_enable_linux_security_module | bool - not check_mode tags: - high - V-71989 # NOTE(mhayden): Since the AppArmor systemd unit calls a SysV init script, the # unit will always say AppArmor is dead. This means that the following task # will always start the unit every time it runs (which breaks idempotency). - name: Ensure AppArmor is running ansible.builtin.service: name: apparmor state: started changed_when: - '"active (exited)" not in systemctl_apparmor_status.stdout' when: - ansible_facts['pkg_mgr'] in ['apt', 'zypper'] - security_rhel7_enable_linux_security_module | bool - not check_mode - '"apparmor filesystem is not mounted" not in apparmor_status_output.stderr' tags: - high - V-71989 # NOTE(mhayden): The "changed_when" is required here because this task will # always show as changed when SELinux is completely disabled. It's not possible # to switch to permissive/enforcing in an online way when SELinux is completely # disabled at boot time. - name: Ensure SELinux is in enforcing mode on the next reboot ansible.posix.selinux: state: enforcing policy: targeted register: selinux_status_change changed_when: selinux_status_change is changed and ansible_facts['selinux']['status'] != 'disabled' when: - ansible_facts['os_family'] == "RedHat" - security_rhel7_enable_linux_security_module | bool tags: - high - V-71989 - V-71991 - name: Relabel files on next boot if SELinux mode changed ansible.builtin.file: path: /.autorelabel state: touch mode: "0644" when: - ansible_facts['os_family'] == "RedHat" - security_rhel7_enable_linux_security_module | bool - selinux_status_change is changed tags: - high - V-71989 - V-71991 # NOTE(mhayden): Ansible's find module doesn't support searching for files # based on SELinux contexts yet. - name: Check for unlabeled device files ansible.builtin.command: "find /dev -context '*unlabeled_t*'" register: unlabeled_devices changed_when: false check_mode: false when: - ansible_facts['os_family'] == 'RedHat' - ansible_facts['selinux']['status'] == 'enabled' tags: - lsm - medium - V-72039 - name: V-72039 - All system device files must be correctly labeled to prevent unauthorized modification. ansible.builtin.debug: msg: | Devices were found without SELinux labels: {% for device in unlabeled_devices.stdout_lines %} {{ device }} {% endfor %} when: - ansible_facts['os_family'] == 'RedHat' - unlabeled_devices.stdout is defined - unlabeled_devices.stdout | length > 0 tags: - lsm - medium - V-72039 |