2022-01-07 09:06:18 +00:00
---
# tasks file for RHEL9-CIS
2022-02-02 11:25:03 +00:00
2024-08-07 10:31:31 +01:00
- name : "Check OS version and family"
2024-12-04 11:45:13 +00:00
when : os_check
tags : always
2023-01-13 12:10:18 +00:00
ansible.builtin.assert :
2024-07-19 17:01:23 +01: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', '==')
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-01-07 09:06:18 +00:00
2024-08-07 10:31:31 +01:00
- name : "Check ansible version"
2024-12-04 11:45:13 +00:00
tags : always
2023-01-13 12:10:18 +00:00
ansible.builtin.assert :
2024-07-19 17:01:23 +01: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-02-02 11:25:03 +00:00
2024-08-07 10:31:31 +01:00
- name : "Setup rules if container"
when :
- ansible_connection == 'docker' or
ansible_facts.virtualization_type in ["docker", "lxc", "openvz", "podman", "container"]
tags :
- container_discovery
- always
block :
- name : "Discover and set container variable if required"
ansible.builtin.set_fact :
system_is_container : true
- name : "Load variable for container"
ansible.builtin.include_vars :
file : "{{ container_vars_file }}"
- name : "Output if discovered is a container"
2024-12-04 11:45:13 +00:00
when : system_is_container
2024-08-07 10:31:31 +01:00
ansible.builtin.debug :
msg : system has been discovered as a container
- name : "Check crypto-policy input"
ansible.builtin.assert :
that : rhel9cis_crypto_policy in rhel9cis_allowed_crypto_policies
fail_msg : "Crypto policy is not a permitted version"
success_msg : "Crypto policy is a permitted version"
- name : "Check rhel9cis_bootloader_password_hash variable has been changed"
when :
- rhel9cis_set_boot_pass
- rhel9cis_rule_1_4_1
2024-12-04 11:45:13 +00:00
tags : always
2024-08-07 10:31:31 +01:00
ansible.builtin.assert :
that: rhel9cis_bootloader_password_hash.find('grub.pbkdf2.sha512') != -1 and rhel9cis_bootloader_password_hash != 'grub.pbkdf2.sha512.changethispassword' # pragma : allowlist secret
msg : "This role will not be able to run single user password commands as rhel9cis_bootloader_password_hash variable has not been set correctly"
- name : "Check crypto-policy module input"
when :
- rhel9cis_rule_1_6_1
- rhel9cis_crypto_policy_module | length > 0
tags :
- rule_1.6.1
- crypto
- NIST800-53R5_SC-6
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"
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
when :
2024-08-07 10:31:31 +01:00
- rhel9cis_rule_5_2_4
2024-07-19 17:01:23 +01:00
- ansible_env.SUDO_USER is defined
- not system_is_ec2
2022-09-07 13:35:36 +01:00
tags :
2024-07-19 17:01:23 +01:00
- user_passwd
2024-08-07 10:31:31 +01:00
- rule_5.2.4
2024-02-13 15:37:39 +00:00
vars :
2024-08-07 10:31:31 +01:00
sudo_password_rule: rhel9cis_rule_5_2_4 # pragma : allowlist secret
2024-07-19 17:01:23 +01:00
block :
2024-12-04 11:45:13 +00:00
- name : "Check password set for {{ ansible_env.SUDO_USER }} | password state" # noqa name[template]
2024-07-19 17:01:23 +01:00
ansible.builtin.shell : "(grep {{ ansible_env.SUDO_USER }} /etc/shadow || echo 'not found:not found') | awk -F: '{print $2}'"
changed_when : false
failed_when : false
check_mode : false
2024-11-04 18:39:01 +00:00
register : prelim_ansible_user_password_set
2024-07-19 17:01:23 +01:00
2024-12-04 11:45:13 +00:00
- name : "Check for local account {{ ansible_env.SUDO_USER }} | Check for local account" # noqa name[template]
2024-11-04 18:39:01 +00:00
when : prelim_ansible_user_password_set.stdout == "not found"
2024-07-19 17:01:23 +01:00
ansible.builtin.debug :
msg : "No local account found for {{ ansible_env.SUDO_USER }} user. Skipping local account checks."
- name : "Check local account"
2024-12-04 11:45:13 +00:00
when : prelim_ansible_user_password_set.stdout != "not found"
2024-07-19 17:01:23 +01:00
block :
2024-12-04 11:45:13 +00:00
- name : "Check password set for {{ ansible_env.SUDO_USER }} | Assert local password set" # noqa name[template]
2024-07-19 17:01:23 +01:00
ansible.builtin.assert :
that :
2024-11-04 18:39:01 +00:00
- prelim_ansible_user_password_set.stdout | length != 0
- prelim_ansible_user_password_set.stdout != "!!"
2024-07-19 17:01:23 +01:00
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-12-04 11:45:13 +00:00
- name : "Check account is not locked for {{ ansible_env.SUDO_USER }} | Assert local account not locked" # noqa name[template]
2024-07-19 17:01:23 +01:00
ansible.builtin.assert :
that :
2024-11-04 18:39:01 +00:00
- not prelim_ansible_user_password_set.stdout.startswith("!")
2024-07-19 17:01:23 +01:00
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"
2022-09-07 13:35:36 +01:00
2024-12-23 14:14:46 +00:00
- name : "Check authselect profile is selected"
2024-12-04 11:45:13 +00:00
when : rhel9cis_allow_authselect_updates
tags : always
2024-08-08 11:08:09 +01:00
block :
2024-12-23 14:14:46 +00:00
- name : "Check authselect profile name has been updated | Ensure name from default is changed"
2024-08-09 13:47:38 +01:00
ansible.builtin.assert :
that : rhel9cis_authselect_custom_profile_name != 'cis_example_profile'
fail_msg : "You still have the default name for your authselect profile"
2024-12-23 14:14:46 +00:00
- name : "Check authselect profile is selected | Check current profile"
2025-04-01 08:14:02 +01:00
ansible.builtin.command : authselect list
2024-08-09 13:47:38 +01:00
changed_when : false
failed_when : prelim_authselect_current_profile.rc not in [ 0, 1 ]
register : prelim_authselect_current_profile
2024-08-07 10:31:31 +01:00
- name : "Ensure root password is set"
2024-12-04 11:45:13 +00:00
when : rhel9cis_rule_5_4_2_4
2024-07-19 17:01:23 +01:00
tags :
- level1-server
- level1-workstation
- patch
- accounts
- root
2024-08-07 10:31:31 +01:00
- rule_5.4.2.4
2024-07-19 17:01:23 +01:00
block :
2024-08-07 10:31:31 +01:00
- name : "Ensure root password is set"
2025-06-12 12:10:44 +01:00
ansible.builtin.shell : passwd -S root | grep -E "(Password set, SHA512 crypt|Password locked)"
2024-07-19 17:01:23 +01:00
changed_when : false
2025-06-16 10:01:10 +01:00
failed_when : prelim_root_passwd_set.rc not in [ 0, 1 ]
2024-11-04 18:39:01 +00:00
register : prelim_root_passwd_set
2024-07-19 17:01:23 +01:00
2024-08-07 10:31:31 +01:00
- name : "Ensure root password is set"
2024-07-19 17:01:23 +01:00
ansible.builtin.assert :
2024-11-04 18:39:01 +00:00
that : prelim_root_passwd_set.rc == 0
2024-08-07 10:31:31 +01:00
fail_msg : "You have rule 5.4.2.4 enabled this requires that you have a root password set"
2024-07-19 17:01:23 +01:00
success_msg : "You have a root password set"
2023-01-27 11:02:01 +00:00
2024-08-07 10:31:31 +01:00
- name : "Gather the package facts"
2024-12-04 11:45:13 +00:00
tags : always
2024-07-19 17:01:23 +01:00
ansible.builtin.package_facts :
manager : auto
2022-01-13 11:27:38 +00:00
2024-08-07 10:31:31 +01:00
- name : "Include OS specific variables"
2024-12-04 11:45:13 +00:00
tags : always
2024-07-19 17:01:23 +01:00
ansible.builtin.include_vars :
file : "{{ ansible_facts.distribution }}.yml"
2022-02-02 11:25:03 +00:00
2024-08-07 10:31:31 +01:00
- name : "Include preliminary steps"
2022-01-07 09:06:18 +00:00
tags :
2024-07-19 17:01:23 +01:00
- prelim_tasks
- always
ansible.builtin.import_tasks :
file : prelim.yml
2022-01-07 09:06:18 +00:00
2024-08-07 10:31:31 +01:00
- name : "Run Section 1 tasks"
2022-01-07 09:06:18 +00:00
when : rhel9cis_section1
2024-07-19 17:01:23 +01:00
ansible.builtin.import_tasks :
file : section_1/main.yml
2022-01-07 09:06:18 +00:00
2024-08-07 10:31:31 +01:00
- name : "Run Section 2 tasks"
2022-01-07 09:06:18 +00:00
when : rhel9cis_section2
2024-07-19 17:01:23 +01:00
ansible.builtin.import_tasks :
file : section_2/main.yml
2022-01-07 09:06:18 +00:00
2024-08-07 10:31:31 +01:00
- name : "Run Section 3 tasks"
2022-01-07 09:06:18 +00:00
when : rhel9cis_section3
2024-07-19 17:01:23 +01:00
ansible.builtin.import_tasks :
file : section_3/main.yml
2022-01-07 09:06:18 +00:00
2024-08-07 10:31:31 +01:00
- name : "Run Section 4 tasks"
2022-01-07 09:06:18 +00:00
when : rhel9cis_section4
2024-07-19 17:01:23 +01:00
ansible.builtin.import_tasks :
file : section_4/main.yml
2022-01-07 09:06:18 +00:00
2024-08-07 10:31:31 +01:00
- name : "Run Section 5 tasks"
2022-01-07 09:06:18 +00:00
when : rhel9cis_section5
2024-07-19 17:01:23 +01:00
ansible.builtin.import_tasks :
file : section_5/main.yml
2022-01-07 09:06:18 +00:00
2024-08-07 10:31:31 +01:00
- name : "Run Section 6 tasks"
2022-01-07 09:06:18 +00:00
when : rhel9cis_section6
2024-07-19 17:01:23 +01:00
ansible.builtin.import_tasks :
file : section_6/main.yml
2024-08-07 10:31:31 +01:00
- name : "Run Section 7 tasks"
when : rhel9cis_section7
ansible.builtin.import_tasks :
file : section_7/main.yml
2022-01-07 09:06:18 +00:00
2024-08-07 10:31:31 +01:00
- name : "Run auditd logic"
2023-01-25 09:41:47 +00:00
when : update_audit_template
2024-12-04 11:45:13 +00:00
tags : always
2024-07-19 17:01:23 +01:00
ansible.builtin.import_tasks :
file : auditd.yml
2022-06-20 17:07:39 +01:00
2024-08-07 10:31:31 +01:00
- name : "Run post remediation tasks"
2022-01-07 09:06:18 +00:00
tags :
2024-07-19 17:01:23 +01:00
- post_tasks
- always
ansible.builtin.import_tasks :
file : post.yml
2022-01-07 09:06:18 +00:00
2024-08-07 10:31:31 +01:00
- name : "Run post_remediation audit"
2024-12-04 11:45:13 +00:00
when : run_audit
2025-03-31 14:50:40 +01:00
tags : always
2024-07-19 17:01:23 +01:00
ansible.builtin.import_tasks :
file : post_remediation_audit.yml
2022-01-07 09:06:18 +00:00
2025-04-15 11:04:33 +01:00
- name : Add ansible file showing Benchmark and levels applied if audit details not present
when :
- create_benchmark_facts
- (post_audit_summary is defined) or
(ansible_local['compliance_facts']['lockdown_audit_details']['audit_summary'] is undefined and post_audit_summary is undefined)
2025-03-31 14:50:40 +01:00
tags :
2025-04-01 08:14:02 +01:00
- always
- benchmark
2025-03-31 14:50:40 +01:00
block :
2025-04-15 11:04:33 +01:00
- name : Create ansible facts directory if audit facts not present
2025-03-31 14:50:40 +01:00
ansible.builtin.file :
path : "{{ ansible_facts_path }}"
state : directory
owner : root
group : root
mode : 'u=rwx,go=rx'
2025-04-15 11:04:33 +01:00
- name : Create ansible facts file and levels applied if audit facts not present
2025-03-31 14:50:40 +01:00
ansible.builtin.template :
src : etc/ansible/compliance_facts.j2
dest : "{{ ansible_facts_path }}/compliance_facts.fact"
owner : root
group : root
2025-04-15 11:04:33 +01:00
mode : 'u-x,go=r'
2025-03-31 14:50:40 +01:00
- name : Fetch audit files
when :
- fetch_audit_output
- run_audit
tags : always
ansible.builtin.import_tasks :
file : fetch_audit_output.yml
2024-08-07 10:31:31 +01:00
- name : "Show Audit Summary"
2023-01-25 09:41:47 +00:00
when : run_audit
2025-03-31 14:50:40 +01:00
tags : always
2024-07-19 17:01:23 +01:00
ansible.builtin.debug :
msg : "{{ audit_results.split('\n') }}"
2022-07-20 17:13:33 +01:00
2024-08-07 10:31:31 +01:00
- name : "If Warnings found Output count and control IDs affected"
2022-07-25 13:26:29 +01:00
when : warn_count != 0
2024-12-04 11:45:13 +00:00
tags : always
2024-07-19 17:01:23 +01:00
ansible.builtin.debug :
msg : "You have {{ warn_count }} Warning(s) that require investigating that are related to the following benchmark ID(s) {{ warn_control_list }}"