Configure a RHEL 8 machine to be CIS compliant
Remediation role for RHEL 8 and compatible EL8 distributions (AlmaLinux, Rocky Linux, Oracle Linux), with an optional goss based audit that runs before and after remediation.
- Status
- Caution(s)
- Requirements
- Quick Start
- Customising the Role
- Auditing
- Documentation
- Looking for support?
- Testing
- Known Issues
- Credits and Thanks
This role will make changes to the system which may have unintended consequences. This is not an auditing tool but rather a remediation tool to be used after an audit has been conducted.
- Testing is the most important thing you can do. Did we mention testing?
- Check mode is not supported. The role will complete in check mode without errors, but use it with caution.
- This role was developed against a clean install of the operating system. If you are applying it to an existing system, review the role for any site specific changes that are needed.
- To use a release version, point to the main branch and the release for the benchmark you wish to work with.
- Some controls are disruptive and are only applied when
rhel8cis_disruption_high: true(defaultfalse), for example PAM/authselect changes and removing the GUI package group. Review them before enabling.
General:
- Basic knowledge of Ansible. If you are unfamiliar with Ansible, these links help get started:
- A functioning Ansible installation (or AWX / Automation Controller), configured and able to reach the target hosts.
- Read through the tasks in this role to understand what each control does. Some tasks are disruptive and can have
unintended consequences on a live production system. Also familiarise yourself with the variables in
defaults/main/main.yml.
Technical Dependencies:
- RHEL family OS 8
- ansible-core 2.16.1 or newer
- Collections listed in collections/requirements.yml:
community.general,ansible.posix - If using the audit: access to download or add the goss binary and audit content to the system (other options are available for getting the content onto the host)
- If generating your own bootloader password hash on the controller:
passlib
Install the collections, then point a playbook at the role:
ansible-galaxy collection install -r collections/requirements.yml- name: Apply CIS hardening
hosts: rhel8_servers
become: true
roles:
- role: RHEL8-CISThe repository includes a ready made site.yml that targets all hosts, or the hosts passed in the hosts variable:
ansible-playbook -i inventory site.yml -e hosts=rhel8_serversTo run the audit before and after remediation, set setup_audit: true and run_audit: true (see Auditing).
This role is designed so that the end user should not have to edit the tasks themselves. All customising should be done
by overriding variables from defaults/main/main.yml (remediation) and defaults/main/audit.yml (audit), for example
in group_vars, host_vars or with extra vars in the project, job or workflow.
- Every control has a toggle named after its ID, for example
rhel8cis_rule_1_1_1_1, so individual controls can be switched off. - Each section can be switched off with
rhel8cis_section1torhel8cis_section7.
It is possible to only run level 1 or level 2 controls for CIS. This is managed using tags:
- level1-server
- level1-workstation
- level2-server
- level2-workstation
Select a level with --tags, for example --tags level1-server. Do not use --skip-tags level2-server,level2-workstation
to leave out Level 2: a control that is Level 1 Server and Level 2 Workstation carries both tags and would be skipped too.
The level variables in defaults/main/main.yml also need to reflect this, as they control the testing that takes place if
you are using the audit component.
There are many tags available for added control precision. Each control has its own set of tags noting what level, what OS element it relates to, whether it is a patch or audit, and the rule number. NIST references follow a specific conversion format for consistency and clarity.
Below is an example of the tag section from a control within this role. Using this example, if you set your run to skip
all controls with the tag cramfs, this task will be skipped. The opposite can also happen where you run only controls
tagged with cramfs.
tags:
- level1-server
- level1-workstation
- automated
- patch
- rule_1.1.1.1
- NIST800-53R5_CM-7
- CCI-000381
- cramfsConversion format for NIST references:
- Standard prefix: all references are prefixed with "NIST".
- Standard types:
- "800-53" references are formatted as NIST800-53.
- "800-53r5" references are formatted as NIST800-53R5 (with 'R' capitalised).
- "800-171" references are formatted as NIST800-171.
- Details:
- Section and subsection numbers use periods (.) for numeric separators.
- Parenthetical elements are separated by underscores (_), e.g., IA-5(1)(d) becomes IA-5_1_d.
- Subsection letters (e.g., "b") are appended with an underscore.
This can be turned on or off with the variables setup_audit and run_audit in defaults/main/audit.yml. The value
is false by default, please refer to the wiki for more details. The role passes its variables to the audit, so only the
controls that are enabled in the role are checked.
The audit uses a small (16MB) go binary called goss along with the relevant configurations to check, without the need for infrastructure or other tooling. It is a quick, lightweight check of both the configuration and the live/running settings, which aims to remove false positives in the process.
Refer to RHEL8-CIS-Audit.
- Read The Docs
- Getting Started
- Customizing Roles
- Per-Host Configuration
- Getting the Most Out of the Role
- Changelog
On our Discord Server to ask questions, discuss features, or just chat with other Ansible-Lockdown users
Bug reports and feature requests are welcome from everyone, please raise an issue.
Pull requests are accepted from approved contributors only. To be onboarded, join the Discord Server and request contributor access. See CONTRIBUTING.md for the full process.
Automated tests run on pull requests into devel:
- self-hosted runners using OpenTofu
- ansible collections pulled at the latest version from the requirements file
- the audit runs using the devel branch
Molecule scenarios: default, localhost, wsl.
molecule test -s default- AlmaLinux BaseOS, EPEL and many cloud provider repositories do not support gpgcheck (rule_1.2.1.2) or repo_gpgcheck (rule_1.2.1.3). This will cause issues during the playbook unless a workaround is found.
Massive thanks to the fantastic community and all its members.
This includes a huge thanks and credit to the original authors and maintainers.
Mark Bolwell, George Nalen, Steve Williams, Fred Witty