2022-01-07 09:06:18 +00:00
|
|
|
---
|
2022-02-02 11:25:03 +00:00
|
|
|
|
2022-01-07 09:06:18 +00:00
|
|
|
# Preliminary tasks that should always be run
|
|
|
|
|
# List users in order to look files inside each home directory
|
|
|
|
|
- name: "PRELIM | List users accounts"
|
2023-01-13 12:10:18 +00:00
|
|
|
ansible.builtin.shell: "awk -F: '{print $1}' /etc/passwd"
|
2022-01-13 16:51:17 +00:00
|
|
|
changed_when: false
|
|
|
|
|
check_mode: false
|
2022-01-07 09:06:18 +00:00
|
|
|
register: users
|
2022-02-02 11:25:03 +00:00
|
|
|
tags:
|
|
|
|
|
- level1-server
|
|
|
|
|
- level1-workstation
|
|
|
|
|
- users
|
2022-01-07 09:06:18 +00:00
|
|
|
|
2023-01-25 11:35:47 +00:00
|
|
|
- name: "PRELIM | capture /etc/password variables"
|
|
|
|
|
ansible.builtin.include_tasks: parse_etc_password.yml
|
|
|
|
|
tags:
|
|
|
|
|
- rule_5.5.2
|
|
|
|
|
- rule_5.6.2
|
|
|
|
|
- rule_6.2.9
|
|
|
|
|
- rule_6.2.10
|
|
|
|
|
- rule_6.2.11
|
|
|
|
|
- rhel9cis_section5
|
|
|
|
|
- rhel9cis_section6
|
|
|
|
|
- level1-server
|
|
|
|
|
|
2023-01-19 16:25:34 +00:00
|
|
|
- name: "PRELIM | Interactive User accounts"
|
|
|
|
|
ansible.builtin.shell: 'cat /etc/passwd | grep -Ev "nologin|/sbin" | cut -d: -f6'
|
|
|
|
|
changed_when: false
|
|
|
|
|
register: interactive_users_home
|
|
|
|
|
tags:
|
|
|
|
|
- always
|
|
|
|
|
|
2022-01-07 09:06:18 +00:00
|
|
|
- name: "PRELIM | Gather accounts with empty password fields"
|
2023-01-13 12:10:18 +00:00
|
|
|
ansible.builtin.shell: "cat /etc/shadow | awk -F: '($2 == \"\" ) {j++;print $1; } END {exit j}'"
|
2022-01-13 16:51:17 +00:00
|
|
|
changed_when: false
|
|
|
|
|
check_mode: false
|
2022-01-07 09:06:18 +00:00
|
|
|
register: empty_password_accounts
|
2022-02-02 11:25:03 +00:00
|
|
|
tags:
|
|
|
|
|
- level1-server
|
|
|
|
|
- level1-workstation
|
|
|
|
|
- passwords
|
2022-01-07 09:06:18 +00:00
|
|
|
|
|
|
|
|
- name: "PRELIM | Gather UID 0 accounts other than root"
|
2023-01-13 12:10:18 +00:00
|
|
|
ansible.builtin.shell: "cat /etc/passwd | awk -F: '($3 == 0 && $1 != \"root\") {i++;print $1 } END {exit i}'"
|
2022-01-13 16:51:17 +00:00
|
|
|
changed_when: false
|
|
|
|
|
check_mode: false
|
2022-04-01 15:26:13 +01:00
|
|
|
register: rhel9cis_uid_zero_accounts_except_root
|
2022-02-02 11:25:03 +00:00
|
|
|
tags:
|
2023-01-25 09:33:14 +00:00
|
|
|
- rule_6.2.9
|
2022-02-02 11:25:03 +00:00
|
|
|
- level1-server
|
|
|
|
|
- level1-workstation
|
|
|
|
|
- users
|
2022-01-07 09:06:18 +00:00
|
|
|
|
2022-02-02 11:25:03 +00:00
|
|
|
- name: "PRELIM | Setup crypto-policy"
|
|
|
|
|
block:
|
|
|
|
|
- name: "PRELIM | Install crypto-policies"
|
2023-01-13 12:10:18 +00:00
|
|
|
ansible.builtin.package:
|
2022-02-02 11:25:03 +00:00
|
|
|
name:
|
|
|
|
|
- crypto-policies
|
|
|
|
|
- crypto-policies-scripts
|
|
|
|
|
state: present
|
|
|
|
|
|
|
|
|
|
- name: "PRELIM | Gather system-wide crypto-policy"
|
2023-01-13 12:10:18 +00:00
|
|
|
ansible.builtin.shell: update-crypto-policies --show
|
2022-02-02 11:25:03 +00:00
|
|
|
changed_when: false
|
|
|
|
|
check_mode: false
|
|
|
|
|
register: system_wide_crypto_policy
|
|
|
|
|
when:
|
2022-04-01 17:09:53 +01:00
|
|
|
- rhel9cis_rule_1_10
|
2022-02-02 11:25:03 +00:00
|
|
|
tags:
|
|
|
|
|
- level1-server
|
|
|
|
|
- level1-workstation
|
2022-04-01 17:09:53 +01:00
|
|
|
- rule_1.10
|
2022-02-02 11:25:03 +00:00
|
|
|
- crypto
|
2022-01-07 09:06:18 +00:00
|
|
|
|
|
|
|
|
- name: "PRELIM | if systemd coredump"
|
2023-01-13 12:10:18 +00:00
|
|
|
ansible.builtin.stat:
|
2022-01-07 09:06:18 +00:00
|
|
|
path: /etc/systemd/coredump.conf
|
|
|
|
|
register: systemd_coredump
|
|
|
|
|
when:
|
2022-04-01 17:09:53 +01:00
|
|
|
- rhel9cis_rule_1_5_1
|
2022-02-02 11:25:03 +00:00
|
|
|
tags:
|
|
|
|
|
- level1-server
|
|
|
|
|
- level1-workstation
|
2022-04-01 17:09:53 +01:00
|
|
|
- rule_1.5.1
|
2022-02-02 11:25:03 +00:00
|
|
|
- systemd
|
2022-01-07 09:06:18 +00:00
|
|
|
|
|
|
|
|
- name: "PRELIM | Section 1.1 | Create list of mount points"
|
2023-01-13 12:10:18 +00:00
|
|
|
ansible.builtin.set_fact:
|
2022-01-07 09:06:18 +00:00
|
|
|
mount_names: "{{ ansible_mounts | map(attribute='mount') | list }}"
|
2022-02-02 11:25:03 +00:00
|
|
|
tags:
|
|
|
|
|
- level1-server
|
|
|
|
|
- level1-workstation
|
2022-01-07 09:06:18 +00:00
|
|
|
|
2022-06-17 11:24:14 +01:00
|
|
|
- name: "PRELIM | Ensure python3-libselinux is installed"
|
2023-01-13 12:10:18 +00:00
|
|
|
ansible.builtin.package:
|
2022-06-17 11:24:14 +01:00
|
|
|
name: python3-libselinux
|
|
|
|
|
state: present
|
|
|
|
|
when:
|
|
|
|
|
- '"python3-libselinux" not in ansible_facts.packages'
|
|
|
|
|
|
2022-06-21 14:16:58 +01:00
|
|
|
- name: "PRELIM | Set facts based on boot type"
|
|
|
|
|
block:
|
|
|
|
|
- name: "PRELIM | Check whether machine is UEFI-based"
|
2023-01-13 12:10:18 +00:00
|
|
|
ansible.builtin.stat:
|
2022-06-21 14:16:58 +01:00
|
|
|
path: /sys/firmware/efi
|
|
|
|
|
register: rhel_09_efi_boot
|
|
|
|
|
|
2023-01-25 11:35:47 +00:00
|
|
|
- name: "PRELIM | set legacy boot and grub path | Bios"
|
2023-01-13 12:10:18 +00:00
|
|
|
ansible.builtin.set_fact:
|
2022-06-21 14:16:58 +01:00
|
|
|
rhel9cis_legacy_boot: true
|
|
|
|
|
grub2_path: /etc/grub2.cfg
|
|
|
|
|
when: not rhel_09_efi_boot.stat.exists
|
|
|
|
|
|
|
|
|
|
- name: "PRELIM | set grub fact | UEFI"
|
2023-01-13 12:10:18 +00:00
|
|
|
ansible.builtin.set_fact:
|
2022-06-21 14:16:58 +01:00
|
|
|
grub2_path: /etc/grub2-efi.cfg
|
|
|
|
|
when: rhel_09_efi_boot.stat.exists
|
|
|
|
|
|
2023-01-13 13:59:53 +00:00
|
|
|
- name: "PRELIM | Update to latest gpg keys"
|
|
|
|
|
ansible.builtin.package:
|
|
|
|
|
name: "{{ ansible_distribution | lower }}-gpg-keys"
|
|
|
|
|
state: latest
|
|
|
|
|
when:
|
|
|
|
|
- rhel9cis_rule_1_2_4
|
2023-01-20 17:14:24 +00:00
|
|
|
- ansible_distribution != 'RedHat'
|
2023-01-13 13:59:53 +00:00
|
|
|
|
2022-01-07 09:06:18 +00:00
|
|
|
- name: "PRELIM | Section 4.1 | Configure System Accounting (auditd)"
|
2023-01-13 12:10:18 +00:00
|
|
|
ansible.builtin.package:
|
2022-01-07 09:06:18 +00:00
|
|
|
name: audit
|
|
|
|
|
state: present
|
2022-01-13 11:27:26 +00:00
|
|
|
become: true
|
2022-04-05 10:24:47 +01:00
|
|
|
when:
|
2022-01-13 16:51:17 +00:00
|
|
|
- '"auditd" not in ansible_facts.packages'
|
2022-02-02 11:25:03 +00:00
|
|
|
- rhel9cis_rule_4_1_1_1
|
|
|
|
|
tags:
|
|
|
|
|
- level2-server
|
|
|
|
|
- level2-workstation
|
|
|
|
|
- patch
|
|
|
|
|
- rule_4.1.1.1
|
|
|
|
|
- auditd
|
2022-01-07 09:06:18 +00:00
|
|
|
|
2023-01-12 11:39:37 +00:00
|
|
|
- name: "PRELIM | 4.1.4.5 | Audit conf and rules files | list files"
|
|
|
|
|
ansible.builtin.find:
|
|
|
|
|
path: /etc/audit
|
|
|
|
|
file_type: file
|
|
|
|
|
recurse: true
|
|
|
|
|
patterns: '*.conf,*.rules'
|
|
|
|
|
register: auditd_conf_files
|
|
|
|
|
when:
|
|
|
|
|
- rhel9cis_rule_4_1_4_5 or
|
|
|
|
|
rhel9cis_rule_4_1_4_6 or
|
|
|
|
|
rhel9cis_rule_4_1_4_7
|
2022-01-07 09:06:18 +00:00
|
|
|
tags:
|
2023-01-12 11:39:37 +00:00
|
|
|
- level2-server
|
|
|
|
|
- level2-workstation
|
|
|
|
|
- patch
|
|
|
|
|
- auditd
|
|
|
|
|
- rule_4.1.4.5
|
|
|
|
|
- rule_4.1.4.6
|
|
|
|
|
- rule_4.1.4.7
|
2022-01-07 09:06:18 +00:00
|
|
|
|
|
|
|
|
- name: "PRELIM | Section 5.1 | Configure cron"
|
2023-01-13 12:10:18 +00:00
|
|
|
ansible.builtin.package:
|
2022-01-07 09:06:18 +00:00
|
|
|
name: cronie
|
|
|
|
|
state: present
|
2022-01-13 11:27:26 +00:00
|
|
|
become: true
|
2022-02-02 11:25:03 +00:00
|
|
|
when:
|
2022-01-13 11:27:26 +00:00
|
|
|
- rhel9cis_rule_5_1_1
|
|
|
|
|
- '"cronie" not in ansible_facts.packages'
|
2022-02-02 11:25:03 +00:00
|
|
|
tags:
|
|
|
|
|
- level1-server
|
|
|
|
|
- level1-workstation
|
|
|
|
|
- rule_5.1.1
|
|
|
|
|
- cron
|
2022-01-07 09:06:18 +00:00
|
|
|
|
|
|
|
|
- name: "PRELIM | Install authconfig"
|
2023-01-13 12:10:18 +00:00
|
|
|
ansible.builtin.package:
|
2022-01-07 09:06:18 +00:00
|
|
|
name: authconfig
|
|
|
|
|
state: present
|
2022-01-13 11:27:26 +00:00
|
|
|
become: true
|
2022-01-07 09:06:18 +00:00
|
|
|
when:
|
|
|
|
|
- rhel9cis_use_authconfig
|
|
|
|
|
- rhel9cis_rule_5_3_1 or
|
|
|
|
|
rhel9cis_rule_5_3_2 or
|
2022-01-13 11:27:26 +00:00
|
|
|
rhel9cis_rule_5_3_3 or
|
2022-02-02 11:25:03 +00:00
|
|
|
'"authconfig" not in ansible_facts.packages or
|
|
|
|
|
"auditd-lib" not in ansible_facts.packages'
|
|
|
|
|
tags:
|
|
|
|
|
- level1-server
|
|
|
|
|
- level1-workstation
|
|
|
|
|
- rule_5.3.1 or
|
|
|
|
|
rule_5.3.2 or
|
|
|
|
|
rule_5.3.3
|
|
|
|
|
- authconfig
|
|
|
|
|
- auditd
|
2022-01-07 09:06:18 +00:00
|
|
|
|
2022-04-01 15:26:13 +01:00
|
|
|
- name: "PRELIM | 5.3.4 | Find all sudoers files."
|
2023-01-13 12:10:18 +00:00
|
|
|
ansible.builtin.shell: "find /etc/sudoers /etc/sudoers.d/ -type f ! -name '*~' ! -name '*.*'"
|
2022-04-01 15:26:13 +01:00
|
|
|
changed_when: false
|
|
|
|
|
failed_when: false
|
|
|
|
|
check_mode: false
|
|
|
|
|
register: rhel9cis_sudoers_files
|
|
|
|
|
when:
|
|
|
|
|
- rhel9cis_rule_5_3_4 or
|
|
|
|
|
rhel9cis_rule_5_3_5
|
|
|
|
|
tags:
|
|
|
|
|
- rule_5.3.4
|
|
|
|
|
- rule_5.3.5
|
|
|
|
|
|
2023-01-25 11:35:47 +00:00
|
|
|
- name: "PRELIM | Check sugroup exists if used"
|
2023-01-25 09:29:19 +00:00
|
|
|
block:
|
2023-01-25 11:35:47 +00:00
|
|
|
- name: "PRELIM | Check su group exists if defined"
|
2023-01-25 09:29:19 +00:00
|
|
|
ansible.builtin.shell: grep -w "{{ rhel9cis_sugroup }}" /etc/group
|
|
|
|
|
register: sugroup_exists
|
|
|
|
|
changed_when: false
|
|
|
|
|
failed_when: sugroup_exists.rc >= 2
|
|
|
|
|
tags:
|
|
|
|
|
- skip_ansible_lint
|
|
|
|
|
|
2023-01-25 11:35:47 +00:00
|
|
|
- name: "PRELIM | Check sugroup if defined exists before continuing"
|
2023-01-25 09:29:19 +00:00
|
|
|
ansible.builtin.assert:
|
|
|
|
|
that: sugroup_exists.rc == 0
|
|
|
|
|
msg: "The variable rhel9cis_sugroup is defined but does not exist please rectify"
|
|
|
|
|
when:
|
|
|
|
|
- rhel9cis_sugroup is defined
|
|
|
|
|
- rhel9cis_rule_5_7
|
|
|
|
|
tags:
|
|
|
|
|
- rule_5.7
|
|
|
|
|
|
2023-01-25 11:35:47 +00:00
|
|
|
- name: "PRELIM | Discover Interactive UID MIN and MIN from logins.def"
|
2022-02-02 11:25:03 +00:00
|
|
|
block:
|
2023-01-25 11:35:47 +00:00
|
|
|
- name: "PRELIM | Capture UID_MIN information from logins.def"
|
2023-01-13 12:10:18 +00:00
|
|
|
ansible.builtin.shell: grep -w "^UID_MIN" /etc/login.defs | awk '{print $NF}'
|
2022-02-02 11:25:03 +00:00
|
|
|
changed_when: false
|
|
|
|
|
register: uid_min_id
|
2022-04-05 10:24:47 +01:00
|
|
|
|
2023-01-25 11:35:47 +00:00
|
|
|
- name: "PRELIM | Capture UID_MAX information from logins.def"
|
2023-01-13 12:10:18 +00:00
|
|
|
ansible.builtin.shell: grep -w "^UID_MAX" /etc/login.defs | awk '{print $NF}'
|
2022-02-02 11:25:03 +00:00
|
|
|
changed_when: false
|
|
|
|
|
register: uid_max_id
|
|
|
|
|
|
2023-01-25 11:35:47 +00:00
|
|
|
- name: "PRELIM | Capture GID_MIN information from logins.def"
|
2023-01-13 12:10:18 +00:00
|
|
|
ansible.builtin.shell: grep -w "^GID_MIN" /etc/login.defs | awk '{print $NF}'
|
2022-02-02 11:25:03 +00:00
|
|
|
changed_when: false
|
|
|
|
|
register: gid_min_id
|
|
|
|
|
|
2023-01-25 11:35:47 +00:00
|
|
|
- name: "PRELIM | set_facts for interactive uid/gid"
|
2023-01-13 12:10:18 +00:00
|
|
|
ansible.builtin.set_fact:
|
2022-02-02 11:25:03 +00:00
|
|
|
min_int_uid: "{{ uid_min_id.stdout }}"
|
|
|
|
|
max_int_uid: "{{ uid_max_id.stdout }}"
|
|
|
|
|
min_int_gid: "{{ gid_min_id.stdout }}"
|
2022-09-16 11:04:19 +01:00
|
|
|
|
2023-01-25 11:35:47 +00:00
|
|
|
- name: "PRELIM | Output of uid findings"
|
2023-01-13 12:10:18 +00:00
|
|
|
ansible.builtin.debug:
|
2022-04-05 10:24:47 +01:00
|
|
|
msg: "{{ min_int_uid }} {{ max_int_uid }}"
|
2022-02-02 11:25:03 +00:00
|
|
|
|
|
|
|
|
when:
|
|
|
|
|
- not discover_int_uid
|
2023-01-25 11:35:47 +00:00
|
|
|
|
|
|
|
|
- name: "PRELIM | Gather the package facts after prelim"
|
|
|
|
|
ansible.builtin.package_facts:
|
|
|
|
|
manager: auto
|
|
|
|
|
tags:
|
|
|
|
|
- always
|