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'
69 - name: "Set password hash to SHA512"
72 regexp: '^ENCRYPT_METHOD[\s]*[a-z0-9]*$'
73 line: 'ENCRYPT_METHOD SHA512'
75 - name: "Set minimum number of password hash rounds"
78 regexp: '^SHA_CRYPT_MIN_ROUNDS[\s]*[0-9]*$'
79 line: 'SHA_CRYPT_MIN_ROUNDS 5000'
82 # Linux Failed password attempts
84 - name: "Ensure authconfig is properly configured"
85 command: authconfig --updateall
87 - /etc/pam.d/system-auth-ac
88 - /etc/pam.d/password-auth-ac
89 when: not (item|exists and item|is_file)
93 - name: "Set Deny for failed password attempts 1"
96 insertbefore: '^auth[\s]*sufficient[\s]*pam_unix.so'
97 line: 'auth required pam_faillock.so preauth silent audit deny=3 unlock_time=3600 fail_interval=900'
99 - /etc/pam.d/system-auth-ac
100 - /etc/pam.d/password-auth-ac
104 - name: "Set Deny for failed password attempts 2"
107 insertafter: '^auth[\s]*sufficient[\s]*pam_unix.so'
108 line: 'auth [default=die] pam_faillock.so authfail audit deny=3 unlock_time=3600 fail_interval=900'
110 - /etc/pam.d/system-auth-ac
111 - /etc/pam.d/password-auth-ac
115 - name: "Set Deny for failed password attempts 3"
118 insertbefore: '^account[\s]*required[\s]*pam_unix.so'
119 line: 'account required pam_faillock.so'
121 - /etc/pam.d/system-auth-ac
122 - /etc/pam.d/password-auth-ac
126 - name: "Set Account expiration following inactivity"
129 path: "/etc/default/useradd"
139 - name: "Ensure YUM Removes Previous Package Versions"
142 insertafter: '^[#\s]*\[main\]'
143 line: 'clean_requirements_on_remove = 1'
145 - name: "Ensure gpgcheck Enabled for Local Packages"
148 insertafter: '^[#\s]*\[main\]'
149 line: 'localpkg_gpgcheck = 1'
152 # Setting Ctrl-Alt-Del action
155 - name: "Disable Ctrl-Alt-Del Burst Action"
157 path: /etc/systemd/system.conf
158 insertafter: '^[#\s]*CtrlAltDelBurstAction'
159 line: 'CtrlAltDelBurstAction=none'
161 - name: "Disable Ctrl-Alt-Del Reboot Activation"
162 command: systemctl mask ctrl-alt-del.target
165 # Configure kernel modules
168 - name: "kernel module setting"
171 dest="/etc/modprobe.d/{{item}}.conf"
173 line="install {{item}} /bin/true"
188 # Disable interactive boot
191 - name: Verify that Interactive Boot is Disabled GRUB_CMDLINE_LINUX Setting
193 path: /etc/default/grub
195 regexp: '^GRUB_CMDLINE_LINUX=(.*)systemd\.confirm_spawn=(1|yes|true|on)\s*(.*)$'
196 line: 'GRUB_CMDLINE_LINUX=\1\3'
198 - name: Verify that Interactive Boot is Disabled GRUB_CMDLINE_LINUX_DEFAULT Setting
200 path: /etc/default/grub
202 regexp: '^GRUB_CMDLINE_LINUX_DEFAULT=(.*)systemd\.confirm_spawn=(1|yes|true|on)\s*(.*)$'
203 line: 'GRUB_CMDLINE_LINUX_DEFAULT=\1\3'
206 # Set file permissions
209 - name: "Check files exist to determine the proper location of grub.cfg on UEFI systems"
212 - /boot/efi/EFI/centos/grub.cfg
213 - /boot/grub2/grub.cfg
218 - name: "Set the 600 file permissions"
220 path: "{{item.item}}"
223 with_items: "{{ file_stat.results }}"
225 - item.stat.exists == true
228 # Disable direct root login
231 - name: "Direct root Logins Not Allowed"
232 shell: echo > /etc/securetty
234 - name: Change 'root' shell to nologin
239 - name: Lock 'root' password
248 - name: Disable ipv6 support if the ipv6 is not needed
249 when: ansible_default_ipv6|length == 0
251 name: net.ipv6.conf.all.disable_ipv6
256 - name: Disable Support for udp6
257 when: ansible_default_ipv6|length == 0
263 - name: Disable Support for tcp6
264 when: ansible_default_ipv6|length == 0
270 - name: Disable automatic ipv6 configuration
271 when: ansible_default_ipv6|length > 0
273 name: "{{ item.name }}"
274 value: "{{ item.value }}"
278 - { name: 'net.ipv6.conf.all.accept_source_route', value: 0 }
279 - { name: 'net.ipv6.conf.all.accept_ra', value: 0 }
280 - { name: 'net.ipv6.conf.default.accept_ra', value: 0 }
281 - { name: 'net.ipv6.conf.all.accept_redirects', value: 0 }
282 - { name: 'net.ipv6.conf.default.accept_redirects', value: 0 }
283 - { name: 'net.ipv6.conf.default.accept_source_route', value: 0 }
284 - { name: 'net.ipv6.conf.all.forwarding', value: 0 }
287 # Configure kernel parameters
290 - name: Configure the kernel parameters
292 name: "{{ item.name }}"
293 value: "{{ item.value }}"
297 - { name: 'net.ipv4.conf.default.send_redirects', value: 0 }
298 - { name: 'net.ipv4.conf.all.send_redirects', value: 0 }
299 - { name: 'net.ipv4.ip_forward', value: 0 }
300 - { name: 'net.ipv4.conf.all.accept_redirects', value: 0 }
301 - { name: 'net.ipv4.conf.all.secure_redirects', value: 0 }
302 - { name: 'net.ipv4.conf.all.log_martians', value: 1 }
303 - { name: 'net.ipv4.conf.default.log_martians', value: 1 }
304 - { name: 'net.ipv4.conf.default.accept_redirects', value: 0 }
305 - { name: 'net.ipv4.conf.default.secure_redirects', value: 0 }
306 - { name: 'net.ipv4.icmp_echo_ignore_broadcasts', value: 1 }
307 - { name: 'net.ipv4.icmp_ignore_bogus_error_responses', value: 1 }
308 - { name: 'net.ipv4.tcp_syncookies', value: 1 }
309 - { name: 'fs.suid_dumpable', value: 0 }
310 - { name: 'kernel.dmesg_restrict', value: 1 }
311 - { name: 'kernel.core_uses_pid', value: 1 }
312 - { name: 'kernel.randomize_va_space', value: 2 }
313 - { name: 'kernel.core_pattern', value: '/var/core/core'}
314 - { name: 'kernel.kptr_restrict', value: 2 }
317 # Configure core dump
320 - name: "Disable core dump for all user"
322 path: /etc/security/limits.conf
323 insertbefore: '^[a-z].*'
324 line: '* hard core 0'
326 - name: "Configure systemd not to store core dumps"
328 path: /etc/systemd/coredump.conf
329 insertafter: '^\[Coredump\]'
335 - name: "Stop rsyslog Service"
336 shell: systemctl stop rsyslog.service
338 - name: "Disable rsyslog Service"
339 shell: systemctl disable rsyslog.service
341 - name: "Ensure the /var/log/boot.log Rotated by logrotate"
343 path: /etc/logrotate.d/syslog
344 insertbefore: 'cron$'
345 line: /var/log/boot.log
347 - name: "Set the umasks by profile file"
350 regexp: '{{ item.old }}'
351 line: '{{ item.new }}'
353 - { old: 'umask 002', new: umask 027 }
354 - { old: 'umask 022', new: umask 077 }
360 - name: Set the max_request_body_size in the keystone.conf
362 path: /etc/keystone/keystone.conf
363 insertafter: 'DEFAULT'
364 line: "# enforced by optional sizelimit middleware (keystone.middleware:RequestBodySizeLimiter)\nmax_request_body_size = 114688\n"
366 - name: Set the insecure_debug in the keystone.conf
368 path: /etc/keystone/keystone.conf
369 insertafter: 'DEFAULT'
370 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"
373 #Setting bootloader password
375 - name: set host os variable
376 when: host_os is defined
378 grub2_pass: "{{ host_os.grub2_password | default('Empty') }}"
380 - name: protect grub with root password
381 when: grub2_pass is defined and grub2_pass != 'Empty'
383 dest: /etc/grub.d/40_custom
388 set superusers="root"
390 password_pbkdf2 root "{{ grub2_pass }}"
392 - name: check whether grub-efi exists
394 path: /boot/efi/EFI/centos/grub.cfg
395 register: grub_efi_file_stat
397 - name: generate grub config
398 when: grub2_pass is defined and grub2_pass != 'Empty'
399 command: /usr/sbin/grub2-mkconfig -o /boot/grub2/grub.cfg
401 - name: generate grub-efi config
402 command: /usr/sbin/grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg
404 - grub2_pass is defined and grub2_pass != 'Empty'
405 - grub_efi_file_stat.stat.exists == true
408 #Setting the noexec option to the /dev/shm mount dir
411 - name: get back device associated to mountpoint
412 shell: mount | grep ' /dev/shm ' |cut -d ' ' -f 1
413 register: device_name
416 - name: get back device previous mount option
417 shell: mount | grep ' /dev/shm ' | sed -re 's:.*\((.*)\):\1:'
418 register: device_cur_mountoption
421 - name: get back device fstype
422 shell: mount | grep ' /dev/shm ' | cut -d ' ' -f 5
423 register: device_fstype
426 - name: Ensure permission noexec are set on /dev/shm
429 src: "{{device_name.stdout}}"
430 opts: "{{device_cur_mountoption.stdout}},noexec"
432 fstype: "{{device_fstype.stdout}}"
435 # Disable NFS service
438 - name: disable NFS related services
452 - name: remove nfs-utils package
458 # tighten USB permissions
460 - name: Set USBGuard RestoreControllerDeviceState to false
462 path: /etc/usbguard/usbguard-daemon.conf
463 regexp: '^[#\s]*RestoreControllerDeviceState\s*=\s*[a-z\-]*\s*$'
464 line: 'RestoreControllerDeviceState=false'
466 - name: Set USBGuard ImplicitPolicyTarget to block
468 path: /etc/usbguard/usbguard-daemon.conf
469 regexp: '^[#\s]*ImplicitPolicyTarget\s*=\s*[a-z\-]*\s*$'
470 line: 'ImplicitPolicyTarget=block'
472 - name: Apply USBGuard policy in all cases
474 path: /etc/usbguard/usbguard-daemon.conf
475 regexp: "^[#\\s]*{{ item }}\\s*=\\s*[a-z\\-]*\\s*$"
476 line: "{{ item }}=apply-policy"
478 - PresentControllerPolicy
479 - PresentDevicePolicy
480 - InsertedDevicePolicy
482 - name: Limit USBGuard IPC to root
484 path: /etc/usbguard/usbguard-daemon.conf
485 regexp: "^[#\\s]*IPCAllowed{{item}}\\s*="
486 line: "IPCAllowed{{item}}=root"
491 - Name: Ban suspect USB devices
493 # this isn't the optimal way to do this, i know, but i don't
494 # want to create a whole new template tree just to add this.
495 path: /etc/usbguard/rules.conf
501 # rules.conf doesn't seem to allow comments
504 # the akraino REC is targeted at server installs; as such
505 # we're liberal about allowing standard devices on the
506 # assumption we will be deployed in a relatively secure
507 # environment. The values below were chosen based on the
508 # devices that appear on a nokia OE19 with the virtual console
510 # xHCI controller/hub
511 allow with-interface equals { 09:00:00 }
512 # mass media — sites may want to consider restricting
513 # this to 08:06:50 to just get the virtual CDROM and ban
515 allow with-interface equals { 08:*:* }
517 allow with-interface equals { 02:02:ff }
519 allow with-interface one-of { 03:00:01 03:01:01 }
520 # per usbguard-rules.conf manpage: ban keyboard devices
521 # that expose other, suspicious, interfaces
522 reject with-interface all-of { 08:*:* 03:00:* }
523 reject with-interface all-of { 08:*:* 03:01:* }
524 reject with-interface all-of { 08:*:* e0:*:* }
525 reject with-interface all-of { 08:*:* 02:*:* }
527 # Setting file permissions
530 #- name: "Remove the other user write permission from the system directorys"
531 # command: find / -xdev \( -perm -0002 -a ! -perm -1000 \) -type d -exec chmod o-w {} \;
533 #- name: "Remove the other user write permission from the system files"
534 # command: find / -xdev -perm -0002 -type f -exec chmod o-w {} \;
536 #- name: "Modified the unauthorized SUID/SGID system executables"
537 # command: sudo chmod -s $(sudo find / -xdev \( -perm -4000 -o -perm -2000 \) -type f | grep -v sudo)