5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 # Linux password hardening
21 - name: "Set Password Strength Minimum Digit Characters."
23 path: /etc/security/pwquality.conf
24 regexp: '^[#\s]*dcredit'
27 - name: "Set Password Minimum Length."
29 path: /etc/security/pwquality.conf
30 regexp: '^[#\s]*minlen'
33 - name: "Set Password Strength Minimum Uppercase Characters."
35 path: /etc/security/pwquality.conf
36 regexp: '^[#\s]*ucredit'
39 - name: "Set Password Strength Minimum Special Characters."
41 path: /etc/security/pwquality.conf
42 regexp: '^[#\s]*ocredit'
45 - name: "Set Password Strength Minimum Lowercase Characters."
47 path: /etc/security/pwquality.conf
48 regexp: '^[#\s]*lcredit'
51 - name: "Set Password Strength Minimum Different Categories."
53 path: /etc/security/pwquality.conf
54 regexp: '^[#\s]*minclass'
57 - name: "Set Password Minimum Length in login.defs"
60 regexp: '^PASS_MIN_LEN[\s]*[0-9]*$'
61 line: 'PASS_MIN_LEN 8'
63 - name: "Set Password Minimum Age"
66 regexp: '^PASS_MIN_DAYS[\s]*[0-9]*$'
67 line: 'PASS_MIN_DAYS 0'
70 # Linux Failed password attempts
73 - name: "Set Deny for failed password attempts 1"
76 insertbefore: '^auth[\s]*sufficient[\s]*pam_unix.so'
77 line: 'auth required pam_faillock.so preauth silent audit deny=3 unlock_time=3600 fail_interval=900'
79 - /etc/pam.d/system-auth-ac
80 - /etc/pam.d/password-auth-ac
84 - name: "Set Deny for failed password attempts 2"
87 insertafter: '^auth[\s]*sufficient[\s]*pam_unix.so'
88 line: 'auth [default=die] pam_faillock.so authfail audit deny=3 unlock_time=3600 fail_interval=900'
90 - /etc/pam.d/system-auth-ac
91 - /etc/pam.d/password-auth-ac
95 - name: "Set Deny for failed password attempts 3"
98 insertbefore: '^account[\s]*required[\s]*pam_unix.so'
99 line: 'account required pam_faillock.so'
101 - /etc/pam.d/system-auth-ac
102 - /etc/pam.d/password-auth-ac
106 - name: "Set Account expiration following inactivity"
109 path: "/etc/default/useradd"
119 - name: "Ensure YUM Removes Previous Package Versions"
122 insertafter: '^[#\s]*\[main\]'
123 line: 'clean_requirements_on_remove = 1'
125 - name: "Ensure gpgcheck Enabled for Local Packages"
128 insertafter: '^[#\s]*\[main\]'
129 line: 'localpkg_gpgcheck = 1'
132 # Setting Ctrl-Alt-Del action
135 - name: "Disable Ctrl-Alt-Del Burst Action"
137 path: /etc/systemd/system.conf
138 insertafter: '^[#\s]*CtrlAltDelBurstAction'
139 line: 'CtrlAltDelBurstAction=none'
141 - name: "Disable Ctrl-Alt-Del Reboot Activation"
142 command: systemctl mask ctrl-alt-del.target
145 # Configure kernel modules
148 - name: "kernel module setting"
151 dest="/etc/modprobe.d/{{item}}.conf"
153 line="install {{item}} /bin/true"
168 # Disable interactive boot
171 - name: Verify that Interactive Boot is Disabled GRUB_CMDLINE_LINUX Setting
173 path: /etc/default/grub
175 regexp: '^GRUB_CMDLINE_LINUX=(.*)systemd\.confirm_spawn=(1|yes|true|on)\s*(.*)$'
176 line: 'GRUB_CMDLINE_LINUX=\1\3'
178 - name: Verify that Interactive Boot is Disabled GRUB_CMDLINE_LINUX_DEFAULT Setting
180 path: /etc/default/grub
182 regexp: '^GRUB_CMDLINE_LINUX_DEFAULT=(.*)systemd\.confirm_spawn=(1|yes|true|on)\s*(.*)$'
183 line: 'GRUB_CMDLINE_LINUX_DEFAULT=\1\3'
186 # Set file permissions
189 - name: "Set set the 600 file permissions"
195 - /boot/grub2/grub.cfg
200 # Disable direct root login
203 - name: "Direct root Logins Not Allowed"
204 shell: echo > /etc/securetty
206 - name: Change 'root' shell to nologin
211 - name: Lock 'root' password
220 - name: Disable ipv6 support if the ipv6 is not needed
221 when: ansible_default_ipv6|length == 0
223 name: net.ipv6.conf.all.disable_ipv6
228 - name: Disable Support for udp6
229 when: ansible_default_ipv6|length == 0
235 - name: Disable Support for tcp6
236 when: ansible_default_ipv6|length == 0
242 - name: Disable automatic ipv6 configuration
243 when: ansible_default_ipv6|length > 0
245 name: "{{ item.name }}"
246 value: "{{ item.value }}"
250 - { name: 'net.ipv6.conf.all.accept_source_route', value: 0 }
251 - { name: 'net.ipv6.conf.all.accept_ra', value: 0 }
252 - { name: 'net.ipv6.conf.default.accept_ra', value: 0 }
253 - { name: 'net.ipv6.conf.all.accept_redirects', value: 0 }
254 - { name: 'net.ipv6.conf.default.accept_redirects', value: 0 }
255 - { name: 'net.ipv6.conf.default.accept_source_route', value: 0 }
256 - { name: 'net.ipv6.conf.all.forwarding', value: 0 }
259 # Configure kernel parameters
262 - name: Configure the kernel parameters
264 name: "{{ item.name }}"
265 value: "{{ item.value }}"
269 - { name: 'net.ipv4.conf.default.send_redirects', value: 0 }
270 - { name: 'net.ipv4.conf.all.send_redirects', value: 0 }
271 - { name: 'net.ipv4.ip_forward', value: 0 }
272 - { name: 'net.ipv4.conf.all.accept_redirects', value: 0 }
273 - { name: 'net.ipv4.conf.all.secure_redirects', value: 0 }
274 - { name: 'net.ipv4.conf.all.log_martians', value: 1 }
275 - { name: 'net.ipv4.conf.default.log_martians', value: 1 }
276 - { name: 'net.ipv4.conf.default.accept_redirects', value: 0 }
277 - { name: 'net.ipv4.conf.default.secure_redirects', value: 0 }
278 - { name: 'net.ipv4.icmp_echo_ignore_broadcasts', value: 1 }
279 - { name: 'net.ipv4.icmp_ignore_bogus_error_responses', value: 1 }
280 - { name: 'net.ipv4.tcp_syncookies', value: 1 }
281 - { name: 'fs.suid_dumpable', value: 0 }
282 - { name: 'kernel.dmesg_restrict', value: 1 }
283 - { name: 'kernel.core_uses_pid', value: 1 }
284 - { name: 'kernel.randomize_va_space', value: 2 }
285 - { name: 'kernel.core_pattern', value: '/var/core/core'}
288 # Configure core dump
291 - name: "Disable core dump for all user"
293 path: /etc/security/limits.conf
294 insertbefore: '^[a-z].*'
295 line: '* hard core 0'
297 - name: "Configure systemd not to store core dumps"
299 path: /etc/systemd/coredump.conf
300 insertafter: '^\[Coredump\]'
306 - name: "Stop rsyslog Service"
307 shell: systemctl stop rsyslog.service
309 - name: "Disable rsyslog Service"
310 shell: systemctl disable rsyslog.service
312 - name: "Ensure the /var/log/boot.log Rotated by logrotate"
314 path: /etc/logrotate.d/syslog
315 insertbefore: 'cron$'
316 line: /var/log/boot.log
318 - name: "Set the umasks by profile file"
321 regexp: '{{ item.old }}'
322 line: '{{ item.new }}'
324 - { old: 'umask 002', new: umask 027 }
325 - { old: 'umask 022', new: umask 077 }
331 - name: Set the max_request_body_size in the keystone.conf
333 path: /etc/keystone/keystone.conf
334 insertafter: 'DEFAULT'
335 line: "# enforced by optional sizelimit middleware (keystone.middleware:RequestBodySizeLimiter)\nmax_request_body_size = 114688\n"
337 - name: Set the insecure_debug in the keystone.conf
339 path: /etc/keystone/keystone.conf
340 insertafter: 'DEFAULT'
341 line: "# If set to true, then the server will return information in HTTP responses\n# that may allow an unauthenticated or authenticated user to get more\n# information than normal, such as additional details about why authentication\n# failed. This may be useful for debugging but is insecure. (boolean value)\ninsecure_debug = false\n"
344 #Setting bootloader password
346 - name: set host os variable
347 when: host_os is defined
349 grub2_pass: "{{ host_os.grub2_password | default('Empty') }}"
351 - name: protect grub with root password
352 when: grub2_pass is defined and grub2_pass != 'Empty'
354 dest: /etc/grub.d/40_custom
359 set superusers="root"
361 password_pbkdf2 root "{{ grub2_pass }}"
363 - name: generate grub config
364 when: grub2_pass is defined and grub2_pass != 'Empty'
365 command: /usr/sbin/grub2-mkconfig -o /boot/grub2/grub.cfg
368 #Setting the noexec option to the /dev/shm mount dir
371 - name: get back device associated to mountpoint
372 shell: mount | grep ' /dev/shm ' |cut -d ' ' -f 1
373 register: device_name
376 - name: get back device previous mount option
377 shell: mount | grep ' /dev/shm ' | sed -re 's:.*\((.*)\):\1:'
378 register: device_cur_mountoption
381 - name: get back device fstype
382 shell: mount | grep ' /dev/shm ' | cut -d ' ' -f 5
383 register: device_fstype
386 - name: Ensure permission noexec are set on /dev/shm
389 src: "{{device_name.stdout}}"
390 opts: "{{device_cur_mountoption.stdout}},noexec"
392 fstype: "{{device_fstype.stdout}}"
395 # Disable NFS service
398 - name: disable NFS related services
412 - name: remove nfs-utils package
418 # Setting file permissions
421 #- name: "Remove the other user write permission from the system directorys"
422 # command: find / -xdev \( -perm -0002 -a ! -perm -1000 \) -type d -exec chmod o-w {} \;
424 #- name: "Remove the other user write permission from the system files"
425 # command: find / -xdev -perm -0002 -type f -exec chmod o-w {} \;
427 #- name: "Modified the unauthorized SUID/SGID system executables"
428 # command: sudo chmod -s $(sudo find / -xdev \( -perm -4000 -o -perm -2000 \) -type f | grep -v sudo)