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/accounts.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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | --- # Copyright 2017, 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 if /etc/security/pwquality.conf exists ansible.builtin.stat: path: /etc/security/pwquality.conf check_mode: false register: pwquality_config_check tags: - always - name: Set password quality requirements ansible.builtin.blockinfile: dest: /etc/security/pwquality.conf backup: true insertbefore: EOF marker: "# {mark} Added by ansible-hardening role" state: present block: "{{ lookup('template', 'pwquality.conf.j2') }}" when: - pwquality_config_check.stat.exists tags: - accounts - medium - V-71903 - V-71905 - V-71907 - V-71909 - V-71911 - V-71913 - V-71915 - V-71917 - V-71935 - name: Check for SHA512 password storage in PAM ansible.builtin.command: "grep pam_unix.so {{ pam_password_file }}" register: password_sha512_check changed_when: false check_mode: false tags: - always - name: Print warning if PAM is not using SHA512 for password storage ansible.builtin.debug: msg: > PAM is not using SHA512 for password storage. This is a security issue. when: - password_sha512_check is defined - "'sha512' not in password_sha512_check.stdout" tags: - accounts - medium - V-71919 - name: Ensure libuser is storing passwords using SHA512 community.general.ini_file: dest: /etc/libuser.conf section: defaults option: crypt_style value: sha512 backup: true mode: "0644" when: - security_libuser_crypt_style_sha512 | bool - ansible_facts['os_family'] | lower == 'redhat' tags: - accounts - medium - V-71923 # NOTE(mhayden): The "is mapping" check is required below because some users # may be attached to a Kerberos realm and they may not have shadow data on the # system. See bug 1659232 for more details. - name: Set minimum password lifetime limit to 24 hours for interactive accounts ansible.builtin.command: "chage -m 1 {{ item.name }}" changed_when: false when: - item.shadow is mapping - item.shadow.min_days != 1 - security_set_minimum_password_lifetime | bool with_items: - "{{ interactive_user_list.users }}" tags: - accounts - medium - V-71927 # NOTE(mhayden): The "is mapping" check is required below because some users # may be attached to a Kerberos realm and they may not have shadow data on the # system. See bug 1659232 for more details. - name: Set maximum password lifetime limit to 60 days for interactive accounts ansible.builtin.command: "chage -M 60 {{ item.name }}" changed_when: false when: - item.shadow is mapping - item.shadow.max_days > 60 - security_set_maximum_password_lifetime | bool with_items: - "{{ interactive_user_list.users }}" tags: - accounts - medium - V-71931 - name: Ensure that users cannot reuse one of their last 5 passwords ansible.builtin.lineinfile: dest: "{{ pam_password_file }}" regexp: "^(password\\s+[a-z0-9\\=\\[\\] ]+\\s+pam_unix\\.so.+?)\\s+(?:remember=\\d+)?$" line: "\\1 remember={{ security_password_remember_password }}" backrefs: true state: present when: - security_password_remember_password is defined tags: - accounts - medium - V-71933 - name: Ensure accounts are disabled if the password expires ansible.builtin.lineinfile: dest: /etc/default/useradd regexp: "^[#\\s]*INACTIVE" line: "INACTIVE=0" when: - security_disable_account_if_password_expires | bool tags: - accounts - medium - V-71941 - name: Apply shadow-utils configurations ansible.builtin.lineinfile: dest: /etc/login.defs regexp: "^{{ item.parameter }}" line: "{{ item.parameter }} {{ item.value }}" state: present when: - item.value is truthy(convert_bool=True) - item.os_family == 'all' or item.os_family == ansible_facts['os_family'] with_items: "{{ shadow_utils_rhel7 }}" tags: - accounts - medium - V-71921 - V-71925 - V-71929 - V-71951 - V-71995 - V-72013 - name: Print warning for groups in /etc/passwd that are not in /etc/group ansible.builtin.debug: msg: > The following users have GIDs in /etc/passwd that do not exist in /etc/group: {{ hardening_user_list.users | selectattr('group', 'equalto', False) | map(attribute='name') | join(', ') }} when: - hardening_user_list is defined - hardening_user_list.users | selectattr('group', 'equalto', False) | list | length > 0 tags: - accounts - low - V-72003 - name: Get all accounts with UID 0 shell: "awk -F: '$3 == 0 {print $1}' /etc/passwd" changed_when: false check_mode: false register: root_user_check tags: - accounts - high - V-72005 - skip_ansible_lint - name: Print warnings for non-root users with UID 0 ansible.builtin.fail: msg: | Only the 'root' user should have UID 0. Other users were found: {{ root_user_check.stdout_lines | join(', ') }}" when: - root_user_check.stdout != 'root' tags: - accounts - high - V-72005 - name: Print warning for local interactive users without a home directory assigned ansible.builtin.debug: msg: | The following users do not have a home directory assigned: {{ hardening_user_list.users | selectattr('dir', 'equalto', '') | map(attribute='name') | join(', ') }} when: - hardening_user_list is defined - hardening_user_list.users | selectattr('dir', 'equalto', '') | map(attribute='name') | list | length > 0 tags: - accounts - medium - V-72011 - name: Check each user to see if its home directory exists on the filesystem ansible.builtin.stat: path: "{{ item['dir'] }}" when: - item['dir'] | length > 0 with_items: "{{ hardening_user_list.users }}" register: home_directory_checks tags: - accounts - medium - V-72015 - name: Print warning for users with an assigned home directory that does not exist ansible.builtin.debug: msg: | These users have a home directory assigned, but the directory does not exist: {% for check in home_directory_checks.results %} {% if not check.stat.exists %} {{ check.item.name }} ({{ check.item.dir }} does not exist) {% endif %} {% endfor %} when: - home_directory_checks.results | selectattr('stat.exists', 'sameas', false) | list | length > 0 tags: - accounts - medium - V-72015 - name: Use pwquality when passwords are changed or created ansible.builtin.lineinfile: dest: /etc/pam.d/passwd line: "password required pam_pwquality.so retry=3" state: present when: - security_enable_pwquality_password_set | bool tags: - accounts - medium - V-73159 |