2022-01-07 09:06:18 +00:00
---
# tasks file for RHEL9-CIS
2022-02-02 11:25:03 +00:00
2022-01-07 09:06:18 +00:00
- name : Check OS version and family
2023-01-13 12:10:18 +00:00
ansible.builtin.assert :
2024-02-20 15:43:43 +00:00
that : (ansible_facts.distribution != 'CentOS' and ansible_facts.os_family == 'RedHat' or ansible_facts.os_family == "Rocky") and ansible_facts.distribution_major_version is version_compare('9', '==')
2023-09-06 08:44:23 +01:00
fail_msg : "This role can only be run against Supported OSs. {{ ansible_facts.distribution }} {{ ansible_facts.distribution_major_version }} is not supported."
success_msg : "This role is running against a supported OS {{ ansible_facts.distribution }} {{ ansible_facts.distribution_major_version }}"
2022-04-05 10:24:47 +01:00
when :
- os_check
2022-01-07 09:06:18 +00:00
tags :
2022-02-02 11:25:03 +00:00
- always
2022-01-07 09:06:18 +00:00
- name : Check ansible version
2023-01-13 12:10:18 +00:00
ansible.builtin.assert :
2022-02-02 11:25:03 +00:00
that : ansible_version.full is version_compare(min_ansible_version, '>=')
fail_msg : "You must use Ansible {{ min_ansible_version }} or greater"
success_msg : "This role is running a supported version of ansible {{ ansible_version.full }} >= {{ min_ansible_version }}"
2022-01-07 09:06:18 +00:00
tags :
2022-02-02 11:25:03 +00:00
- always
2023-06-07 09:24:32 +01:00
- name : "Check password set for {{ ansible_env.SUDO_USER }}"
2022-09-07 13:35:36 +01:00
block :
2023-06-07 09:24:32 +01:00
- name : "Check password set for {{ ansible_env.SUDO_USER }} | password state"
2024-02-13 15:37:39 +00:00
ansible.builtin.shell : "(grep {{ ansible_env.SUDO_USER }} /etc/shadow || echo 'not found:not found') | awk -F: '{print $2}'"
2022-09-16 11:04:19 +01:00
changed_when : false
failed_when : false
check_mode : false
2023-06-07 09:24:32 +01:00
register : rhel9cis_ansible_user_password_set
2022-09-16 11:04:19 +01:00
2024-02-13 15:37:39 +00:00
- name : "Check for local account {{ ansible_env.SUDO_USER }} | Check for local account"
ansible.builtin.debug :
msg : "No local account found for {{ ansible_env.SUDO_USER }} user. Skipping local account checks."
when :
2024-02-15 10:17:41 +00:00
- rhel9cis_ansible_user_password_set.stdout == "not found"
2024-02-19 12:03:08 +00:00
2024-02-13 15:37:39 +00:00
- name : "Check local account"
block :
2024-02-15 10:17:41 +00:00
- name : "Check password set for {{ ansible_env.SUDO_USER }} | Assert local password set"
ansible.builtin.assert :
that :
- rhel9cis_ansible_user_password_set.stdout | length != 0
- rhel9cis_ansible_user_password_set.stdout != "!!"
fail_msg : "You have {{ sudo_password_rule }} enabled but the user = {{ ansible_env.SUDO_USER }} has no password set - It can break access"
success_msg : "You have a password set for the {{ ansible_env.SUDO_USER }} user"
2024-02-19 12:03:08 +00:00
2024-02-15 10:17:41 +00:00
- name : "Check account is not locked for {{ ansible_env.SUDO_USER }} | Assert local account not locked"
ansible.builtin.assert :
that :
- not rhel9cis_ansible_user_password_set.stdout.startswith("!")
fail_msg : "You have {{ sudo_password_rule }} enabled but the user = {{ ansible_env.SUDO_USER }} is locked - It can break access"
success_msg : "The local account is not locked for {{ ansible_env.SUDO_USER }} user"
2024-02-13 15:37:39 +00:00
when :
2024-02-15 10:17:41 +00:00
- rhel9cis_ansible_user_password_set.stdout != "not found"
2022-09-07 13:35:36 +01:00
when :
- rhel9cis_rule_5_3_4
2023-07-26 08:50:53 +01:00
- ansible_env.SUDO_USER is defined
2022-09-07 13:35:36 +01:00
- not system_is_ec2
tags :
- user_passwd
2023-06-07 09:24:32 +01:00
- rule_5.3.4
2024-02-13 15:37:39 +00:00
vars :
sudo_password_rule: rhel9cis_rule_5_3_4 # pragma : allowlist secret
2022-09-07 13:35:36 +01:00
2023-08-10 08:28:43 +01:00
- name : Ensure root password is set
2023-01-27 11:02:01 +00:00
block :
2023-08-10 08:28:43 +01:00
- name : Ensure root password is set
2024-02-20 15:43:43 +00:00
ansible.builtin.shell : passwd -S root | egrep -e "(Password set, SHA512 crypt|Password locked)"
2023-01-27 11:02:01 +00:00
changed_when : false
register : root_passwd_set
2023-08-10 08:28:43 +01:00
- name : Ensure root password is set
2023-01-27 11:02:01 +00:00
ansible.builtin.assert :
that : root_passwd_set.rc == 0
fail_msg : "You have rule 5.6.6 enabled this requires that you have a root password set"
success_msg : "You have a root password set"
when :
- rhel9cis_rule_5_6_6
tags :
- level1-server
- level1-workstation
- patch
- accounts
- root
- rule_5.6.6
2022-02-02 11:25:03 +00:00
- name : Setup rules if container
block :
- name : Discover and set container variable if required
2023-01-13 12:10:18 +00:00
ansible.builtin.set_fact :
2022-02-02 11:25:03 +00:00
system_is_container : true
- name : Load variable for container
2023-01-13 12:10:18 +00:00
ansible.builtin.include_vars :
2022-02-02 11:25:03 +00:00
file : "{{ container_vars_file }}"
2022-04-05 10:24:47 +01:00
2023-01-13 12:10:18 +00:00
- name : Output if discovered is a container
ansible.builtin.debug :
2022-02-02 11:25:03 +00:00
msg : system has been discovered as a container
when :
- system_is_container
when :
- ansible_connection == 'docker' or
2024-02-20 15:43:43 +00:00
ansible_facts.virtualization_type in ["docker", "lxc", "openvz", "podman", "container"]
2022-02-02 11:25:03 +00:00
tags :
- container_discovery
- always
2022-01-07 09:06:18 +00:00
- name : Check crypto-policy input
2023-01-13 12:10:18 +00:00
ansible.builtin.assert :
2022-01-07 09:06:18 +00:00
that : rhel9cis_crypto_policy in rhel9cis_allowed_crypto_policies
2022-01-13 11:40:59 +00:00
fail_msg : "Crypto policy is not a permitted version"
success_msg : "Crypto policy is a permitted version"
2022-01-07 09:06:18 +00:00
2023-06-06 14:36:38 +01:00
- name : Check crypto-policy module input
ansible.builtin.assert :
that : rhel9cis_crypto_policy_module in rhel9cis_allowed_crypto_policies_modules
fail_msg : "Crypto policy module is not a permitted version"
success_msg : "Crypto policy module is a permitted version"
when :
- rhel9cis_rule_1_10
- rhel9cis_crypto_policy_module | length > 0
tags :
- rule_1.10
2022-01-07 09:06:18 +00:00
- name : Check rhel9cis_bootloader_password_hash variable has been changed
2023-01-13 12:10:18 +00:00
ansible.builtin.assert :
2023-09-21 15:36:05 +01:00
that: rhel9cis_bootloader_password_hash.find('grub.pbkdf2.sha512') != -1 and rhel9cis_bootloader_password_hash != 'grub.pbkdf2.sha512.changethispassword' # pragma : allowlist secret
2022-04-25 16:58:11 +01:00
msg : "This role will not be able to run single user password commands as rhel9cis_bootloader_password_hash variable has not been set correctly"
2022-01-07 09:06:18 +00:00
when :
2022-04-05 10:24:47 +01:00
- rhel9cis_set_boot_pass
2022-04-25 16:58:11 +01:00
- rhel9cis_rule_1_4_1
2022-04-26 16:01:56 +01:00
tags :
2022-04-25 16:58:11 +01:00
- always
2022-01-07 09:06:18 +00:00
2022-01-13 11:27:38 +00:00
- name : Gather the package facts
2023-01-13 12:10:18 +00:00
ansible.builtin.package_facts :
2022-01-13 11:27:38 +00:00
manager : auto
tags :
2022-04-05 10:24:47 +01:00
- always
2022-01-13 11:27:38 +00:00
2022-02-02 11:25:03 +00:00
- name : Include OS specific variables
2023-09-06 08:44:23 +01:00
ansible.builtin.include_vars : "{{ ansible_facts.distribution }}.yml"
2022-02-02 11:25:03 +00:00
tags :
2022-04-05 10:24:47 +01:00
- always
2022-02-02 11:25:03 +00:00
2022-01-13 11:27:38 +00:00
- name : Include preliminary steps
2023-09-21 14:55:00 +01:00
ansible.builtin.import_tasks :
file : prelim.yml
2022-01-07 09:06:18 +00:00
tags :
2022-04-05 10:24:47 +01:00
- prelim_tasks
- always
2022-01-07 09:06:18 +00:00
2024-03-06 16:52:38 +00:00
- name : Run Section 1 tasks
2023-09-21 14:55:00 +01:00
ansible.builtin.import_tasks :
file : section_1/main.yml
2022-01-07 09:06:18 +00:00
when : rhel9cis_section1
tags :
2022-04-05 10:24:47 +01:00
- rhel9cis_section1
2022-01-07 09:06:18 +00:00
2024-03-06 16:52:38 +00:00
- name : Run Section 2 tasks
2023-09-21 14:55:00 +01:00
ansible.builtin.import_tasks :
file : section_2/main.yml
2022-01-07 09:06:18 +00:00
when : rhel9cis_section2
2022-02-02 11:25:03 +00:00
tags :
2022-04-05 10:24:47 +01:00
- rhel9cis_section2
2022-01-07 09:06:18 +00:00
2024-03-06 16:52:38 +00:00
- name : Run Section 3 tasks
2023-09-21 14:55:00 +01:00
ansible.builtin.import_tasks :
file : section_3/main.yml
2022-01-07 09:06:18 +00:00
when : rhel9cis_section3
2022-02-02 11:25:03 +00:00
tags :
2022-04-05 10:24:47 +01:00
- rhel9cis_section3
2022-01-07 09:06:18 +00:00
2024-03-06 16:52:38 +00:00
- name : Run Section 4 tasks
2023-09-21 14:55:00 +01:00
ansible.builtin.import_tasks :
file : section_4/main.yml
2022-01-07 09:06:18 +00:00
when : rhel9cis_section4
2022-02-02 11:25:03 +00:00
tags :
2022-04-05 10:24:47 +01:00
- rhel9cis_section4
2022-01-07 09:06:18 +00:00
2024-03-06 16:52:38 +00:00
- name : Run Section 5 tasks
2023-09-21 14:55:00 +01:00
ansible.builtin.import_tasks :
file : section_5/main.yml
2022-01-07 09:06:18 +00:00
when : rhel9cis_section5
2022-02-02 11:25:03 +00:00
tags :
2022-04-05 10:24:47 +01:00
- rhel9cis_section5
2022-01-07 09:06:18 +00:00
2024-03-06 16:52:38 +00:00
- name : Run Section 6 tasks
2023-09-21 14:55:00 +01:00
ansible.builtin.import_tasks :
file : section_6/main.yml
2022-01-07 09:06:18 +00:00
when : rhel9cis_section6
2022-02-02 11:25:03 +00:00
tags :
2022-04-05 10:24:47 +01:00
- rhel9cis_section6
2022-01-07 09:06:18 +00:00
2024-03-06 16:52:38 +00:00
- name : Run auditd logic
2023-09-21 14:55:00 +01:00
ansible.builtin.import_tasks :
file : auditd.yml
2023-01-25 09:41:47 +00:00
when : update_audit_template
2022-06-20 17:07:39 +01:00
tags :
- always
2024-03-06 16:52:38 +00:00
- name : Run post remediation tasks
2023-09-21 14:55:00 +01:00
ansible.builtin.import_tasks :
file : post.yml
2022-01-07 09:06:18 +00:00
tags :
2022-04-05 10:24:47 +01:00
- post_tasks
- always
2022-01-07 09:06:18 +00:00
2024-03-06 16:52:38 +00:00
- name : Run post_remediation audit
2023-09-21 14:55:00 +01:00
ansible.builtin.import_tasks :
file : post_remediation_audit.yml
2022-01-07 09:06:18 +00:00
when :
2022-04-05 10:24:47 +01:00
- run_audit
2022-01-07 09:06:18 +00:00
- name : Show Audit Summary
2023-01-13 12:10:18 +00:00
ansible.builtin.debug :
2022-01-07 09:06:18 +00:00
msg : "{{ audit_results.split('\n') }}"
2023-01-25 09:41:47 +00:00
when : run_audit
2022-07-20 17:13:33 +01:00
2022-07-25 11:28:50 +01:00
- name : If Warnings found Output count and control IDs affected
2023-01-13 12:10:18 +00:00
ansible.builtin.debug :
2023-01-13 11:05:25 +00:00
msg : "You have {{ warn_count }} Warning(s) that require investigating that are related to the following benchmark ID(s) {{ warn_control_list }}"
2022-07-25 13:26:29 +01:00
when : warn_count != 0
2022-07-20 17:13:33 +01:00
tags :
- always