2022-01-07 09:06:18 +00:00
|
|
|
---
|
|
|
|
|
# handlers file for RHEL9-CIS
|
|
|
|
|
|
2024-12-10 17:29:27 +00:00
|
|
|
- name: "Adding options for /tmp"
|
|
|
|
|
when: not rhel9cis_tmp_svc
|
|
|
|
|
vars:
|
|
|
|
|
mount_point: '/tmp'
|
|
|
|
|
ansible.posix.mount:
|
|
|
|
|
path: "{{ mount_point }}"
|
2024-12-11 10:22:33 +00:00
|
|
|
src: "{{ prelim_mount_point_fs_and_options[mount_point]['src'] }}"
|
2024-12-10 17:29:27 +00:00
|
|
|
state: present
|
2024-12-11 10:22:33 +00:00
|
|
|
fstype: "{{ prelim_mount_point_fs_and_options[mount_point]['fs_type'] }}"
|
|
|
|
|
opts: "{{ prelim_mount_point_fs_and_options[mount_point]['options'] | unique | join(',') }}"
|
2024-12-10 17:29:27 +00:00
|
|
|
listen: "Remount /tmp"
|
|
|
|
|
|
|
|
|
|
- name: "Remounting /tmp"
|
|
|
|
|
vars:
|
|
|
|
|
mount_point: '/tmp'
|
|
|
|
|
ansible.posix.mount:
|
|
|
|
|
path: "{{ mount_point }}"
|
|
|
|
|
state: remounted
|
|
|
|
|
listen: "Remount /tmp"
|
|
|
|
|
|
|
|
|
|
- name: "Remounting /tmp systemd"
|
|
|
|
|
vars:
|
|
|
|
|
mount_point: '/tmp'
|
|
|
|
|
ansible.builtin.systemd:
|
|
|
|
|
name: tmp.mount
|
|
|
|
|
state: restarted
|
|
|
|
|
daemon_reload: true
|
|
|
|
|
listen: "Remount /tmp"
|
|
|
|
|
|
|
|
|
|
- name: "Adding options for /dev/shm"
|
|
|
|
|
vars:
|
|
|
|
|
mount_point: '/dev/shm'
|
|
|
|
|
ansible.posix.mount:
|
|
|
|
|
path: "{{ mount_point }}"
|
2024-12-11 10:22:33 +00:00
|
|
|
src: "{{ prelim_mount_point_fs_and_options[mount_point]['src'] }}"
|
2024-12-10 17:29:27 +00:00
|
|
|
state: present
|
2024-12-11 10:22:33 +00:00
|
|
|
fstype: "{{ prelim_mount_point_fs_and_options[mount_point]['fs_type'] }}"
|
|
|
|
|
opts: "{{ prelim_mount_point_fs_and_options[mount_point]['options'] | unique | join(',') }}"
|
2024-12-10 17:29:27 +00:00
|
|
|
listen: "Remount /dev/shm"
|
|
|
|
|
|
|
|
|
|
- name: "Remounting /dev/shm"
|
|
|
|
|
vars:
|
|
|
|
|
mount_point: '/dev/shm'
|
|
|
|
|
ansible.posix.mount:
|
|
|
|
|
path: "{{ mount_point }}"
|
|
|
|
|
state: remounted
|
|
|
|
|
listen: "Remount /dev/shm"
|
|
|
|
|
|
|
|
|
|
- name: "Adding options for /home"
|
|
|
|
|
vars:
|
|
|
|
|
mount_point: '/home'
|
|
|
|
|
ansible.posix.mount:
|
|
|
|
|
path: "{{ mount_point }}"
|
2024-12-11 10:22:33 +00:00
|
|
|
src: "{{ prelim_mount_point_fs_and_options[mount_point]['src'] }}"
|
2024-12-10 17:29:27 +00:00
|
|
|
state: present
|
2024-12-11 10:22:33 +00:00
|
|
|
fstype: "{{ prelim_mount_point_fs_and_options[mount_point]['fs_type'] }}"
|
|
|
|
|
opts: "{{ prelim_mount_point_fs_and_options[mount_point]['options'] | unique | join(',') }}"
|
2024-12-10 17:29:27 +00:00
|
|
|
listen: "Remount /home"
|
|
|
|
|
|
|
|
|
|
- name: "Remounting /home"
|
|
|
|
|
vars:
|
|
|
|
|
mount_point: '/home'
|
|
|
|
|
ansible.posix.mount:
|
|
|
|
|
path: "{{ mount_point }}"
|
|
|
|
|
state: remounted
|
|
|
|
|
listen: "Remount /home"
|
|
|
|
|
|
|
|
|
|
- name: "Adding options for /var"
|
|
|
|
|
vars:
|
|
|
|
|
mount_point: '/var'
|
|
|
|
|
ansible.posix.mount:
|
|
|
|
|
path: "{{ mount_point }}"
|
2024-12-11 10:22:33 +00:00
|
|
|
src: "{{ prelim_mount_point_fs_and_options[mount_point]['src'] }}"
|
2024-12-10 17:29:27 +00:00
|
|
|
state: present
|
2024-12-11 10:22:33 +00:00
|
|
|
fstype: "{{ prelim_mount_point_fs_and_options[mount_point]['fs_type'] }}"
|
|
|
|
|
opts: "{{ prelim_mount_point_fs_and_options[mount_point]['options'] | unique | join(',') }}"
|
2024-12-10 17:29:27 +00:00
|
|
|
listen: "Remount /var"
|
|
|
|
|
|
|
|
|
|
- name: "Remounting /var"
|
|
|
|
|
vars:
|
|
|
|
|
mount_point: '/var'
|
|
|
|
|
ansible.posix.mount:
|
|
|
|
|
path: "{{ mount_point }}"
|
|
|
|
|
state: remounted
|
|
|
|
|
listen: "Remount /var"
|
|
|
|
|
|
|
|
|
|
- name: "Adding options for /var/tmp"
|
|
|
|
|
vars:
|
|
|
|
|
mount_point: '/var/tmp'
|
|
|
|
|
ansible.posix.mount:
|
|
|
|
|
path: "{{ mount_point }}"
|
2024-12-11 10:22:33 +00:00
|
|
|
src: "{{ prelim_mount_point_fs_and_options[mount_point]['src'] }}"
|
2024-12-10 17:29:27 +00:00
|
|
|
state: present
|
2024-12-11 10:22:33 +00:00
|
|
|
fstype: "{{ prelim_mount_point_fs_and_options[mount_point]['fs_type'] }}"
|
|
|
|
|
opts: "{{ prelim_mount_point_fs_and_options[mount_point]['options'] | unique | join(',') }}"
|
2024-12-10 17:29:27 +00:00
|
|
|
listen: "Remount /var/tmp"
|
|
|
|
|
|
|
|
|
|
- name: "Remounting /var/tmp"
|
|
|
|
|
vars:
|
|
|
|
|
mount_point: '/var/tmp'
|
|
|
|
|
ansible.posix.mount:
|
|
|
|
|
path: "{{ mount_point }}"
|
|
|
|
|
state: remounted
|
|
|
|
|
listen: "Remount /var/tmp"
|
|
|
|
|
|
|
|
|
|
- name: "Adding options for /var/log"
|
|
|
|
|
vars:
|
|
|
|
|
mount_point: '/var/log'
|
|
|
|
|
ansible.posix.mount:
|
|
|
|
|
path: "{{ mount_point }}"
|
2024-12-11 10:22:33 +00:00
|
|
|
src: "{{ prelim_mount_point_fs_and_options[mount_point]['src'] }}"
|
2024-12-10 17:29:27 +00:00
|
|
|
state: present
|
2024-12-11 10:22:33 +00:00
|
|
|
fstype: "{{ prelim_mount_point_fs_and_options[mount_point]['fs_type'] }}"
|
|
|
|
|
opts: "{{ prelim_mount_point_fs_and_options[mount_point]['options'] | unique | join(',') }}"
|
2024-12-10 17:29:27 +00:00
|
|
|
listen: "Remount /var/log"
|
|
|
|
|
|
|
|
|
|
- name: "Remounting /var/log"
|
|
|
|
|
vars:
|
|
|
|
|
mount_point: '/var/log'
|
|
|
|
|
ansible.posix.mount:
|
|
|
|
|
path: "{{ mount_point }}"
|
|
|
|
|
state: remounted
|
|
|
|
|
listen: "Remount /var/log"
|
|
|
|
|
|
|
|
|
|
- name: "Adding options for /var/log/audit"
|
|
|
|
|
vars:
|
|
|
|
|
mount_point: '/var/log/audit'
|
|
|
|
|
ansible.posix.mount:
|
|
|
|
|
path: "{{ mount_point }}"
|
2024-12-11 10:22:33 +00:00
|
|
|
src: "{{ prelim_mount_point_fs_and_options[mount_point]['src'] }}"
|
2024-12-10 17:29:27 +00:00
|
|
|
state: present
|
2024-12-11 10:22:33 +00:00
|
|
|
fstype: "{{ prelim_mount_point_fs_and_options[mount_point]['fs_type'] }}"
|
|
|
|
|
opts: "{{ prelim_mount_point_fs_and_options[mount_point]['options'] | unique | join(',') }}"
|
2024-12-10 17:29:27 +00:00
|
|
|
listen: "Remount /var/log/audit"
|
|
|
|
|
|
|
|
|
|
- name: "Remounting /var/log/audit"
|
|
|
|
|
vars:
|
|
|
|
|
mount_point: '/var/log/audit'
|
|
|
|
|
ansible.posix.mount:
|
|
|
|
|
path: "{{ mount_point }}"
|
|
|
|
|
state: remounted
|
|
|
|
|
listen: "Remount /var/log/audit"
|
|
|
|
|
|
2023-01-13 12:10:18 +00:00
|
|
|
- name: Reload sysctl
|
|
|
|
|
ansible.builtin.shell: sysctl --system
|
2022-06-20 17:05:59 +01:00
|
|
|
|
2023-01-13 12:10:18 +00:00
|
|
|
- name: Sysctl flush ipv4 route table
|
2024-07-24 14:02:05 +01:00
|
|
|
when:
|
|
|
|
|
- rhel9cis_flush_ipv4_route
|
|
|
|
|
- not system_is_container
|
2023-01-13 12:10:18 +00:00
|
|
|
ansible.posix.sysctl:
|
2024-07-24 14:02:05 +01:00
|
|
|
name: net.ipv4.route.flush
|
|
|
|
|
value: '1'
|
|
|
|
|
sysctl_set: true
|
2022-09-16 11:34:42 +01:00
|
|
|
ignore_errors: true # noqa ignore-errors
|
2022-01-07 09:06:18 +00:00
|
|
|
|
2023-01-13 12:10:18 +00:00
|
|
|
- name: Sysctl flush ipv6 route table
|
2022-09-16 11:04:19 +01:00
|
|
|
when:
|
2024-07-24 14:02:05 +01:00
|
|
|
- rhel9cis_flush_ipv6_route
|
|
|
|
|
- not system_is_container
|
|
|
|
|
ansible.posix.sysctl:
|
|
|
|
|
name: net.ipv6.route.flush
|
|
|
|
|
value: '1'
|
|
|
|
|
sysctl_set: true
|
2022-01-07 09:06:18 +00:00
|
|
|
|
2023-01-13 12:10:18 +00:00
|
|
|
- name: Systemd restart tmp.mount
|
|
|
|
|
ansible.builtin.systemd:
|
2024-07-24 14:02:05 +01:00
|
|
|
name: tmp.mount
|
|
|
|
|
daemon_reload: true
|
|
|
|
|
enabled: true
|
|
|
|
|
masked: false
|
|
|
|
|
state: reloaded
|
2022-01-07 09:06:18 +00:00
|
|
|
|
2024-07-19 17:01:23 +01:00
|
|
|
- name: Update Crypto Policy
|
|
|
|
|
ansible.builtin.set_fact:
|
2024-08-07 14:05:59 +01:00
|
|
|
rhel9cis_full_crypto_policy: "{{ rhel9cis_crypto_policy }}{% if rhel9cis_crypto_policy_module | length > 0 %}{{ rhel9cis_crypto_policy_module }}{% endif %}"
|
2024-07-19 17:01:23 +01:00
|
|
|
notify: Set Crypto Policy
|
|
|
|
|
|
|
|
|
|
- name: Set Crypto Policy
|
2024-08-07 10:30:45 +01:00
|
|
|
when: prelim_system_wide_crypto_policy.stdout != rhel9cis_full_crypto_policy
|
2024-07-19 17:01:23 +01:00
|
|
|
ansible.builtin.shell: |
|
|
|
|
|
update-crypto-policies --set "{{ rhel9cis_full_crypto_policy }}"
|
|
|
|
|
notify:
|
|
|
|
|
- Change_requires_reboot
|
|
|
|
|
- Restart sshd
|
|
|
|
|
|
2023-01-13 12:10:18 +00:00
|
|
|
- name: Restart firewalld
|
|
|
|
|
ansible.builtin.systemd:
|
2024-07-19 17:01:23 +01:00
|
|
|
name: firewalld
|
|
|
|
|
state: restarted
|
2022-01-07 09:06:18 +00:00
|
|
|
|
2023-01-13 12:10:18 +00:00
|
|
|
- name: Restart sshd
|
|
|
|
|
ansible.builtin.systemd:
|
2024-07-19 17:01:23 +01:00
|
|
|
name: sshd
|
|
|
|
|
state: restarted
|
2022-01-07 09:06:18 +00:00
|
|
|
|
2023-01-13 12:10:18 +00:00
|
|
|
- name: Restart postfix
|
|
|
|
|
ansible.builtin.systemd:
|
2024-07-19 17:01:23 +01:00
|
|
|
name: postfix
|
|
|
|
|
state: restarted
|
2022-01-07 09:06:18 +00:00
|
|
|
|
2023-01-13 12:10:18 +00:00
|
|
|
- name: Reload dconf
|
|
|
|
|
ansible.builtin.shell: dconf update
|
2022-01-07 09:06:18 +00:00
|
|
|
|
2023-01-25 09:41:32 +00:00
|
|
|
- name: Grub2cfg
|
2023-01-13 12:10:18 +00:00
|
|
|
ansible.builtin.shell: "grub2-mkconfig -o /boot/grub2/grub.cfg"
|
2022-09-16 11:34:42 +01:00
|
|
|
ignore_errors: true # noqa ignore-errors
|
2022-01-07 09:06:18 +00:00
|
|
|
|
2023-01-13 12:10:18 +00:00
|
|
|
- name: Restart rsyslog
|
|
|
|
|
ansible.builtin.systemd:
|
2024-07-19 17:01:23 +01:00
|
|
|
name: rsyslog
|
|
|
|
|
state: restarted
|
2022-01-07 09:06:18 +00:00
|
|
|
|
2023-01-13 12:10:18 +00:00
|
|
|
- name: Restart journald
|
|
|
|
|
ansible.builtin.systemd:
|
2024-07-19 17:01:23 +01:00
|
|
|
name: systemd-journald
|
|
|
|
|
state: restarted
|
2022-04-01 15:26:13 +01:00
|
|
|
|
2023-01-13 12:10:18 +00:00
|
|
|
- name: Restart systemd_journal_upload
|
|
|
|
|
ansible.builtin.systemd:
|
2024-07-19 17:01:23 +01:00
|
|
|
name: systemd-journal-upload
|
|
|
|
|
state: restarted
|
2022-01-07 09:06:18 +00:00
|
|
|
|
2023-01-25 09:41:32 +00:00
|
|
|
- name: Systemd daemon reload
|
2023-01-13 12:10:18 +00:00
|
|
|
ansible.builtin.systemd:
|
2024-07-19 17:01:23 +01:00
|
|
|
daemon-reload: true
|
2022-04-01 15:26:13 +01:00
|
|
|
|
2024-08-07 10:30:45 +01:00
|
|
|
- name: Authselect update
|
2024-07-19 17:01:23 +01:00
|
|
|
ansible.builtin.shell: authselect apply-changes
|
2024-06-05 09:46:14 +01:00
|
|
|
|
2022-07-29 17:08:38 +01:00
|
|
|
## Auditd tasks note order for handlers to run
|
|
|
|
|
|
2023-01-25 09:41:32 +00:00
|
|
|
- name: Auditd immutable check
|
2023-01-13 12:10:18 +00:00
|
|
|
ansible.builtin.shell: grep -c "^-e 2" /etc/audit/rules.d/99_auditd.rules
|
2022-07-29 17:08:38 +01:00
|
|
|
changed_when: false
|
2024-11-04 18:39:01 +00:00
|
|
|
register: discovered_auditd_immutable_check
|
2022-07-29 17:08:38 +01:00
|
|
|
|
2023-01-25 09:41:32 +00:00
|
|
|
- name: Audit immutable fact
|
2024-07-19 17:01:23 +01:00
|
|
|
when:
|
2024-11-04 18:39:01 +00:00
|
|
|
- discovered_auditd_immutable_check.stdout == '1'
|
2023-01-13 12:10:18 +00:00
|
|
|
ansible.builtin.debug:
|
2024-07-19 17:01:23 +01:00
|
|
|
msg: "Reboot required for auditd to apply new rules as immutable set"
|
2023-01-13 13:59:24 +00:00
|
|
|
notify: Change_requires_reboot
|
2022-07-29 17:08:38 +01:00
|
|
|
|
2024-12-10 10:09:46 +00:00
|
|
|
- name: Stop auditd process
|
|
|
|
|
ansible.builtin.shell: systemctl kill auditd
|
|
|
|
|
listen: Restart auditd
|
|
|
|
|
|
|
|
|
|
- name: Start auditd process
|
|
|
|
|
ansible.builtin.systemd_service:
|
|
|
|
|
name: auditd
|
|
|
|
|
state: started
|
|
|
|
|
listen: Restart auditd
|
2022-07-29 17:08:38 +01:00
|
|
|
|
2023-01-13 12:10:18 +00:00
|
|
|
- name: Change_requires_reboot
|
|
|
|
|
ansible.builtin.set_fact:
|
2024-07-19 17:01:23 +01:00
|
|
|
change_requires_reboot: true
|