From 4a40facca9a8ca5858abe57f33f874025bbfab27 Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Mon, 10 Apr 2023 13:48:47 -0400 Subject: [PATCH 01/16] Readme Update, Yamllint Update Signed-off-by: Stephen Williams --- .github/workflows/linux_benchmark_testing.yml | 2 +- .yamllint | 50 ++-- README.md | 231 ++++++++++++++++-- collections/requirements.yml | 6 +- site.yml | 4 +- tasks/section_1/cis_1.1.2.x.yml | 2 +- tasks/section_1/cis_1.1.8.x.yml | 2 +- tasks/section_1/cis_1.1.x.yml | 2 +- 8 files changed, 249 insertions(+), 50 deletions(-) diff --git a/.github/workflows/linux_benchmark_testing.yml b/.github/workflows/linux_benchmark_testing.yml index ca8c237f..9d32eced 100644 --- a/.github/workflows/linux_benchmark_testing.yml +++ b/.github/workflows/linux_benchmark_testing.yml @@ -5,7 +5,7 @@ name: linux_benchmark_pipeline # Controls when the action will run. # Triggers the workflow on push or pull request # events but only for the devel branch -on: +on: # yamllint disable-line rule:truthy pull_request_target: types: [opened, reopened, synchronize] branches: diff --git a/.yamllint b/.yamllint index 5dc8a985..ec469292 100644 --- a/.yamllint +++ b/.yamllint @@ -1,25 +1,33 @@ --- -# Based on ansible-lint config extends: default +ignore: | + tests/ + molecule/ + .github/ + .gitlab-ci.yml + *molecule.yml + rules: - braces: {max-spaces-inside: 1, level: error} - brackets: {max-spaces-inside: 1, level: error} - colons: {max-spaces-after: -1, level: error} - commas: {max-spaces-after: -1, level: error} - comments: disable - comments-indentation: disable - document-start: disable - empty-lines: {max: 3, level: error} - hyphens: {level: error} - indentation: - # Requiring 4 space indentation - spaces: 4 - # Requiring consistent indentation within a file, either indented or not - indent-sequences: consistent - key-duplicates: enable - line-length: disable - new-line-at-end-of-file: disable - new-lines: {type: unix} - trailing-spaces: disable - truthy: disable + indentation: + # Requiring 4 space indentation + spaces: 4 + # Requiring consistent indentation within a file, either indented or not + indent-sequences: consistent + braces: + max-spaces-inside: 1 + level: error + brackets: + max-spaces-inside: 1 + level: error + empty-lines: + max: 1 + line-length: disable + key-duplicates: enable + new-line-at-end-of-file: enable + new-lines: + type: unix + trailing-spaces: enable + truthy: + allowed-values: ['true', 'false'] + check-keys: false diff --git a/README.md b/README.md index 71e7636d..a819e4db 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,215 @@ - # RHEL 9 CIS + +## Configure a RHEL 9 machine to be [CIS](https://www.cisecurity.org/cis-benchmarks/) compliant + +### Based on [ CIS RedHat Enterprise Linux 9 Benchmark v1.0.0 - 11-30-2022 ](https://www.cisecurity.org/cis-benchmarks/) + +--- + +![Org Stars](https://img.shields.io/github/stars/ansible-lockdown?label=Org%20Stars&style=social) +![Stars](https://img.shields.io/github/stars/ansible-lockdown/RHEL9-CIS?label=Repo%20Stars&style=social) +![Forks](https://img.shields.io/github/forks/ansible-lockdown/RHEL9-CIS?style=social) +![followers](https://img.shields.io/github/followers/ansible-lockdown?style=social) +[![Twitter URL](https://img.shields.io/twitter/url/https/twitter.com/AnsibleLockdown.svg?style=social&label=Follow%20%40AnsibleLockdown)](https://twitter.com/AnsibleLockdown) + +![Ansible Galaxy Quality](https://img.shields.io/ansible/quality/61781?label=Quality&&logo=ansible) +![Discord Badge](https://img.shields.io/discord/925818806838919229?logo=discord) + +![Devel Build Status](https://img.shields.io/github/actions/workflow/status/ansible-lockdown/RHEL9-CIS/linux_benchmark_testing.yml?label=Devel%20Build%20Status) +![Devel Commits](https://img.shields.io/github/commit-activity/m/ansible-lockdown/RHEL9-CIS/devel?color=dark%20green&label=Devel%20Branch%20commits) + +![Release Branch](https://img.shields.io/badge/Release%20Branch-Main-brightgreen) +![Main Build Status](https://img.shields.io/github/actions/workflow/status/ansible-lockdown/RHEL9-CIS/linux_benchmark_testing.yml?label=Build%20Status) +![Main Release Date](https://img.shields.io/github/release-date/ansible-lockdown/RHEL9-CIS?label=Release%20Date) +![Release Tag](https://img.shields.io/github/v/tag/ansible-lockdown/RHEL9-CIS?label=Release%20Tag&&color=success) + +![Issues Open](https://img.shields.io/github/issues-raw/ansible-lockdown/RHEL9-CIS?label=Open%20Issues) +![Issues Closed](https://img.shields.io/github/issues-closed-raw/ansible-lockdown/RHEL9-CIS?label=Closed%20Issues&&color=success) +![Pull Requests](https://img.shields.io/github/issues-pr/ansible-lockdown/RHEL9-CIS?label=Pull%20Requests) + +![License](https://img.shields.io/github/license/ansible-lockdown/RHEL9-CIS?label=License) + +--- + +## Looking for support? + +[Lockdown Enterprise](https://www.lockdownenterprise.com#GH_AL_RH9_cis) + +[Ansible support](https://www.mindpointgroup.com/cybersecurity-products/ansible-counselor#GH_AL_RH9_cis) + +### Community + +Join us on our [Discord Server](https://discord.io/ansible-lockdown) to ask questions, discuss features, or just chat with other Ansible-Lockdown users. + +--- + +## Caution(s) + +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. + +Check Mode is not supported! The role will complete in check mode without errors, but it is not supported and should be used with caution. The RHEL8-CIS-Audit role or a compliance scanner should be used for compliance checking over check mode. + +This role was developed against a clean install of the Operating System. If you are implementing to an existing system please review this role for any site specific changes that are needed. + +To use release version please point to main branch and relevant release for the cis benchmark you wish to work with. + +--- + +## Matching a security Level for CIS + +It is possible to to only run level 1 or level 2 controls for CIS. +This is managed using tags: + +- level1_server +- level1_workstation +- level2_server +- level2_workstation + +The control found in defaults main also need to reflect this as this control the testing thet takes place if you are using the audit component. + +## Coming from a previous release + +CIS release always contains changes, it is highly recommended to review the new references and available variables. This have changed significantly since ansible-lockdown initial release. +This is now compatible with python3 if it is found to be the default interpreter. This does come with pre-requisites which it configures the system accordingly. + +Further details can be seen in the [Changelog](./ChangeLog.md) + +## Auditing (new) + +This can be turned on or off within the defaults/main.yml file with the variable rhel8cis_run_audit. The value is false by default, please refer to the wiki for more details. The defaults file also populates the goss checks to check only the controls that have been enabled in the ansible role. + +This is a much quicker, very lightweight, checking (where possible) config compliance and live/running settings. + +A new form of auditing has been developed, by using a small (12MB) go binary called [goss](https://github.com/goss-org/goss) along with the relevant configurations to check. Without the need for infrastructure or other tooling. +This audit will not only check the config has the correct setting but aims to capture if it is running with that configuration also trying to remove [false positives](https://www.mindpointgroup.com/blog/is-compliance-scanning-still-relevant/) in the process. + +Refer to [RHEL9-CIS-Audit](https://github.com/ansible-lockdown/RHEL9-CIS-Audit). + +## Documentation + +- [Read The Docs](https://ansible-lockdown.readthedocs.io/en/latest/) +- [Getting Started](https://www.lockdownenterprise.com/docs/getting-started-with-lockdown#GH_AL_RH9_cis) +- [Customizing Roles](https://www.lockdownenterprise.com/docs/customizing-lockdown-enterprise#GH_AL_RH9_cis) +- [Per-Host Configuration](https://www.lockdownenterprise.com/docs/per-host-lockdown-enterprise-configuration#GH_AL_RH9_cis) +- [Getting the Most Out of the Role](https://www.lockdownenterprise.com/docs/get-the-most-out-of-lockdown-enterprise#GH_AL_RH9_cis) + +## Requirements + +RHEL 9 +Almalinux 9 +Rocky 9 +OracleLinux 9 + +ansible 2.10 +jmespath +relevant collections + +- Access to download or add the goss binary and content to the system if using auditing (other options are available on how to get the content to the system.) + +**General:** + +- Basic knowledge of Ansible, below are some links to the Ansible documentation to help get started if you are unfamiliar with Ansible + + - [Main Ansible documentation page](https://docs.ansible.com) + - [Ansible Getting Started](https://docs.ansible.com/ansible/latest/user_guide/intro_getting_started.html) + - [Tower User Guide](https://docs.ansible.com/ansible-tower/latest/html/userguide/index.html) + - [Ansible Community Info](https://docs.ansible.com/ansible/latest/community/index.html) +- Functioning Ansible and/or Tower Installed, configured, and running. This includes all of the base Ansible/Tower configurations, needed packages installed, and infrastructure setup. +- Please read through the tasks in this role to gain an understanding of what each control is doing. Some of the tasks are disruptive and can have unintended consiquences in a live production system. Also familiarize yourself with the variables in the defaults/main.yml file. + +**Technical Dependencies:** + +- Python3 +- Ansible 2.9+ +- python-def (should be included in RHEL 9) +- libselinux-python +- pip packages + - jmespath ( complete list found in requirements.txt) +- collections found in collections/requirememnts.yml + +## Role Variables + +This role is designed that the end user should not have to edit the tasks themselves. All customizing should be done by overriding the required varaibles as found in defaults/main.yml file. e.g. using inventory, group_vars, extra_vars + +## Tags + +There are many tags available for added control precision. Each control has it's own set of tags noting what level, if it's scored/notscored, what OS element it relates to, if it's a patch or audit, and the rule number. + +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 services, this task will be skipped. The opposite can also happen where you run only controls tagged with services. + +```sh + tags: + - level1-server + - level1-workstation + - scored + - avahi + - services + - patch + - rule_2.2.4 +``` + +## Community Contribution + +We encourage you (the community) to contribute to this role. Please read the rules below. + +- Your work is done in your own individual branch. Make sure to Signed-off and GPG sign all commits you intend to merge. +- All community Pull Requests are pulled into the devel branch +- Pull Requests into devel will confirm your commits have a GPG signature, Signed-off, and a functional test before being approved +- Once your changes are merged and a more detailed review is complete, an authorized member will merge your changes into the main branch for a new release + +## Known Issues + +CIS 1.2.4 - repo_gpgcheck is not carried out for RedHat hosts as the default repos do not have this function. This also affect EPEL(not covered by var). + - Rocky and Alma not affected. +Variable used to unset. +rhel9cis_rhel_default_repo: true # to be set to false if using repo that does have this ability + +## Pipeline Testing + +uses: + +- ansible-core 2.12 +- ansible collections - pulls in the latest version based on requirements file +- runs the audit using the devel branch +- This is an automated test that occurs on pull requests into devel + +## Local Testing + +ansible-base 2.10.17 - python 3.8 +ansible-core 2.13.4 - python 3.10 + +- makefile - this is there purely for testing and initial setup purposes. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ## v1.0.0 - released Dec 2022 @@ -7,9 +217,7 @@ ![Build Status](https://img.shields.io/github/workflow/status/ansible-lockdown/RHEL9-CIS/DevelToMain?label=Main%20Build%20Status&style=plastic) ![Release](https://img.shields.io/github/v/release/ansible-lockdown/RHEL9-CIS?style=plastic) -Configure RHEL 9 machine to be [CIS](https://www.cisecurity.org/cis-benchmarks/) -Based on [CIS RedHat Enterprise Linux 9 Benchmark v1.0.0. - 11-30-2022 ](https://www.cisecurity.org/cis-benchmarks/) ## Join us @@ -73,26 +281,9 @@ ansible-core 2.13.4 - python 3.10 - jmespath ( complete list found in requirements.txt) - collections found in collections/requirememnts.yml -## Role Variables - -This role is designed that the end user should not have to edit the tasks themselves. All customizing should be done by overriding the required varaibles as found in defaults/main.yml file. e.g. using inventory, group_vars, extra_vars -## Tags -There are many tags available for added control precision. Each control has it's own set of tags noting what level, if it's scored/notscored, what OS element it relates to, if it's a patch or audit, and the rule number. - -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 services, this task will be skipped. The opposite can also happen where you run only controls tagged with services. -```txt - tags: - - level1-server - - level1-workstation - - scored - - avahi - - services - - patch - - rule_2.2.4 -``` ### Known Issues diff --git a/collections/requirements.yml b/collections/requirements.yml index d35b7e97..3f594d0b 100644 --- a/collections/requirements.yml +++ b/collections/requirements.yml @@ -1,5 +1,5 @@ --- collections: -- name: community.general -- name: community.crypto -- name: ansible.posix + - name: community.general + - name: community.crypto + - name: ansible.posix diff --git a/site.yml b/site.yml index 148ca0b7..c56b473f 100644 --- a/site.yml +++ b/site.yml @@ -1,7 +1,7 @@ --- - -- hosts: all +- hosts: all # noqa: name[play] become: true + roles: - role: "{{ playbook_dir }}" diff --git a/tasks/section_1/cis_1.1.2.x.yml b/tasks/section_1/cis_1.1.2.x.yml index b4e18889..780d7da0 100644 --- a/tasks/section_1/cis_1.1.2.x.yml +++ b/tasks/section_1/cis_1.1.2.x.yml @@ -26,7 +26,7 @@ "1.1.2.2 | PATCH | Ensure nodev option set on /tmp partition" "1.1.2.3 | PATCH | Ensure noexec option set on /tmp partition" "1.1.2.4 | PATCH | Ensure nosuid option set on /tmp partition" - ansible.builtin.mount: + ansible.posix.mount: name: /tmp src: "{{ item.device }}" fstype: "{{ item.fstype }}" diff --git a/tasks/section_1/cis_1.1.8.x.yml b/tasks/section_1/cis_1.1.8.x.yml index 3b85af37..2bf9fc1f 100644 --- a/tasks/section_1/cis_1.1.8.x.yml +++ b/tasks/section_1/cis_1.1.8.x.yml @@ -28,7 +28,7 @@ "1.1.8.2 | PATCH | Ensure nodev option set on /dev/shm partition | Set nodev option 1.1.8.3 | PATCH | Ensure noexec option set on /dev/shm partition | Set nosuid option 1.1.8.4 | PATCH | Ensure nosuid option set on /dev/shm partition | Set noexec option" - ansible.builtin.mount: + ansible.posix.mount: name: /dev/shm src: tmpfs fstype: tmpfs diff --git a/tasks/section_1/cis_1.1.x.yml b/tasks/section_1/cis_1.1.x.yml index 0496300b..4a616228 100644 --- a/tasks/section_1/cis_1.1.x.yml +++ b/tasks/section_1/cis_1.1.x.yml @@ -13,7 +13,7 @@ mode: 0600 - name: "1.1.9 | PATCH | Disable USB Storage | Edit modprobe config" - ansible.builtin.modprobe: + community.general.modprobe: name: usb-storage state: absent From b9e17f74d1bf7f089cffd82be2c0e82338838e23 Mon Sep 17 00:00:00 2001 From: Mark Bolwell Date: Wed, 12 Apr 2023 13:05:26 +0100 Subject: [PATCH 02/16] updated controls Signed-off-by: Mark Bolwell --- tasks/section_6/cis_6.1.x.yml | 73 ++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 23 deletions(-) diff --git a/tasks/section_6/cis_6.1.x.yml b/tasks/section_6/cis_6.1.x.yml index 298492d9..24fc9ab6 100644 --- a/tasks/section_6/cis_6.1.x.yml +++ b/tasks/section_6/cis_6.1.x.yml @@ -160,22 +160,27 @@ label: "{{ item.mount }}" when: item['device'].startswith('/dev') and not 'bind' in item['options'] + - name: "6.1.10 | AUDIT | Ensure no unowned files or directories exist | set fact" + ansible.builtin.set_fact: + rhel_09_6_1_10_unowned_files_found: true + loop: "{{ rhel_09_6_1_10_audit.results }}" + when: + - item.stdout | length > 0 + - name: "6.1.10 | AUDIT | Ensure no unowned files or directories exist | Displaying any unowned files or directories" ansible.builtin.debug: - msg: "Warning !! Manual intervention is required -- missing owner on items in {{ item.item.mount }}: {{ item.stdout_lines | join(', ') }}" - loop: "{{ rhel_09_6_1_10_audit.results }}" + msg: "Warning!! Missing owner on items in {{ rhel_09_6_1_10_audit | json_query('results[*].stdout_lines[*]') | flatten }}" when: - - item.stdout_lines is defined - - item.stdout_lines | length > 0 + - rhel_09_6_1_10_unowned_files_found - name: "6.1.10 | AUDIT | Ensure no unowned files or directories exist | warning" ansible.builtin.import_tasks: warning_facts.yml vars: warn_control_id: '6.1.10' when: - - item.stdout_lines is defined - - item.stdout_lines | length > 0 - + - rhel_09_6_1_10_unowned_files_found + vars: + rhel_09_6_1_10_unowned_files_found: false when: - rhel9cis_rule_6_1_10 tags: @@ -199,21 +204,27 @@ label: "{{ item.mount }}" when: item['device'].startswith('/dev') and not 'bind' in item['options'] + - name: "6.1.11 | AUDIT | Ensure no ungrouped files or directories exist | set fact" + ansible.builtin.set_fact: + rhel_09_6_1_11_ungrouped_files_found: true + loop: "{{ rhel_09_6_1_11_audit.results }}" + when: + - item.stdout | length > 0 + - name: "6.1.11 | AUDIT | Ensure no ungrouped files or directories exist | Displaying all ungrouped files or directories" ansible.builtin.debug: - msg: "Warning !! Manual intervention is required -- missing group on items in {{ item.item.mount }}: {{ item.stdout_lines | join(', ') }}" - loop: "{{ rhel_09_6_1_11_audit.results }}" + msg: "Warning!! Missing group on items in {{ rhel_09_6_1_11_audit | json_query('results[*].stdout_lines[*]') | flatten }}" when: - - item.stdout_lines is defined - - item.stdout_lines | length > 0 + - rhel_09_6_1_11_ungrouped_files_found - name: "6.1.11 | AUDIT | Ensure no ungrouped files or directories exist | warning" ansible.builtin.import_tasks: warning_facts.yml vars: warn_control_id: '6.1.11' when: - - item.stdout_lines is defined - - item.stdout_lines | length > 0 + - rhel_09_6_1_11_ungrouped_files_found + vars: + - rhel_09_6_1_11_ungrouped_files_found: false when: - rhel9cis_rule_6_1_11 tags: @@ -244,24 +255,32 @@ ansible.builtin.shell: df {{ item.mount }} -P | awk {'if (NR!=1) print $6'} | xargs -I '{}' find '{}' -xdev -type f -perm -4000 failed_when: false changed_when: false - register: rhel_09_6_1_13_perms_results + register: rhel_09_6_1_13_suid_perms loop: "{{ ansible_mounts }}" loop_control: label: "{{ item.mount }}" + - name: "6.1.13 | AUDIT | Audit SUID executables | set fact SUID executables" + ansible.builtin.set_fact: + rhel8cis_6_1_13_suid_found: true + loop: "{{ rhel_09_6_1_13_suid_perms.results }}" + when: + - item.stdout | length > 0 + - name: "6.1.13 | AUDIT | Audit SUID executables | Alert SUID executables exist" ansible.builtin.debug: - msg: "Warning!! Manual intervention is required -- SUID set on items in {{ item.item.mount }}: {{ item.stout_lines | join(', ') }}" - loop: "{{ rhel_09_6_1_13_perms_results.stdout_lines }}" + msg: "Warning!! SUID set on items in {{ rhel_09_6_1_13_suid_perms | json_query('results[*].stdout_lines[*]') | flatten }}" when: - - rhel_09_6_1_13_perms_results.stdout is defined + - rhel8cis_6_1_13_suid_found - name: "6.1.13 | AUDIT | Audit SUID executables | Alert SUID executables exist | warning" ansible.builtin.import_tasks: warning_facts.yml vars: warn_control_id: '6.1.13' when: - - rhel_09_6_1_13_perms_results.stdout is defined + - rhel8cis_6_1_13_suid_found + vars: + rhel8cis_6_1_13_suid_found: false when: - rhel9cis_rule_6_1_13 tags: @@ -278,24 +297,32 @@ ansible.builtin.shell: df {{ item.mount }} -P | awk {'if (NR!=1) print $6'} | xargs -I '{}' find '{}' -xdev -type f -perm -2000 failed_when: false changed_when: false - register: rhel_09_6_1_14_perms_results + register: rhel_09_6_1_14_sgid_perms loop: "{{ ansible_mounts }}" loop_control: label: "{{ item.mount }}" + - name: "6.1.14 | AUDIT | Audit SGID executables | Set fact SGID executables" + ansible.builtin.set_fact: + rhel8cis_6_1_14_sgid_found: true + loop: "{{ rhel_09_6_1_14_sgid_perms.results }}" + when: + - item.stdout | length > 0 + - name: "6.1.14 | AUDIT | Audit SGID executables | Alert SGID executables exist" ansible.builtin.debug: - msg: "Manual intervention is required -- SGID set on items in {{ item.item.mount }}: {{ item.stout_lines | join(', ') }}" - loop: "{{ rhel_09_6_1_14_perms_results.stdout_lines }}" + msg: "Warning!! SGID set on items in {{ rhel_09_6_1_14_sgid_perms | json_query('results[*].stdout_lines[*]') | flatten }}" when: - - rhel_09_6_1_14_perms_results.stdout is defined + - rhel8cis_6_1_14_sgid_found - name: "6.1.14 | AUDIT | Audit SGID executables| warning" ansible.builtin.import_tasks: warning_facts.yml vars: warn_control_id: '6.1.14' when: - - rhel_09_6_1_14_perms_results.stdout is defined + - rhel8cis_6_1_14_sgid_found + vars: + rhel8cis_6_1_14_sgid_found: false when: - rhel9cis_rule_6_1_14 tags: From f66c74f60138249ffcbfc70a1e50790d37adeb71 Mon Sep 17 00:00:00 2001 From: Mark Bolwell Date: Wed, 12 Apr 2023 13:05:35 +0100 Subject: [PATCH 03/16] updated Signed-off-by: Mark Bolwell --- Changelog.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Changelog.md b/Changelog.md index 05609016..5f990a39 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,10 @@ # Changes to rhel9CIS +## 1.0.7 + +lint and yamll updates +improvemnst to 6.1.10, 6.1.11, 6.1.13, 6.1.14 + ## 1.0.6 updated ymlalint as galaxy doenst honouyr local settings From 120a0ea7514b8a0484e7abe1c19be2edaa44fc17 Mon Sep 17 00:00:00 2001 From: Mark Bolwell Date: Wed, 12 Apr 2023 13:10:42 +0100 Subject: [PATCH 04/16] updated layout Signed-off-by: Mark Bolwell --- tasks/section_6/cis_6.1.x.yml | 36 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/tasks/section_6/cis_6.1.x.yml b/tasks/section_6/cis_6.1.x.yml index 24fc9ab6..480329af 100644 --- a/tasks/section_6/cis_6.1.x.yml +++ b/tasks/section_6/cis_6.1.x.yml @@ -164,21 +164,18 @@ ansible.builtin.set_fact: rhel_09_6_1_10_unowned_files_found: true loop: "{{ rhel_09_6_1_10_audit.results }}" - when: - - item.stdout | length > 0 + when: item.stdout | length > 0 - name: "6.1.10 | AUDIT | Ensure no unowned files or directories exist | Displaying any unowned files or directories" ansible.builtin.debug: msg: "Warning!! Missing owner on items in {{ rhel_09_6_1_10_audit | json_query('results[*].stdout_lines[*]') | flatten }}" - when: - - rhel_09_6_1_10_unowned_files_found + when: rhel_09_6_1_10_unowned_files_found - name: "6.1.10 | AUDIT | Ensure no unowned files or directories exist | warning" ansible.builtin.import_tasks: warning_facts.yml vars: warn_control_id: '6.1.10' - when: - - rhel_09_6_1_10_unowned_files_found + when: rhel_09_6_1_10_unowned_files_found vars: rhel_09_6_1_10_unowned_files_found: false when: @@ -208,21 +205,18 @@ ansible.builtin.set_fact: rhel_09_6_1_11_ungrouped_files_found: true loop: "{{ rhel_09_6_1_11_audit.results }}" - when: - - item.stdout | length > 0 + when: item.stdout | length > 0 - name: "6.1.11 | AUDIT | Ensure no ungrouped files or directories exist | Displaying all ungrouped files or directories" ansible.builtin.debug: msg: "Warning!! Missing group on items in {{ rhel_09_6_1_11_audit | json_query('results[*].stdout_lines[*]') | flatten }}" - when: - - rhel_09_6_1_11_ungrouped_files_found + when: rhel_09_6_1_11_ungrouped_files_found - name: "6.1.11 | AUDIT | Ensure no ungrouped files or directories exist | warning" ansible.builtin.import_tasks: warning_facts.yml vars: warn_control_id: '6.1.11' - when: - - rhel_09_6_1_11_ungrouped_files_found + when: rhel_09_6_1_11_ungrouped_files_found vars: - rhel_09_6_1_11_ungrouped_files_found: false when: @@ -264,21 +258,18 @@ ansible.builtin.set_fact: rhel8cis_6_1_13_suid_found: true loop: "{{ rhel_09_6_1_13_suid_perms.results }}" - when: - - item.stdout | length > 0 + when: item.stdout | length > 0 - name: "6.1.13 | AUDIT | Audit SUID executables | Alert SUID executables exist" ansible.builtin.debug: msg: "Warning!! SUID set on items in {{ rhel_09_6_1_13_suid_perms | json_query('results[*].stdout_lines[*]') | flatten }}" - when: - - rhel8cis_6_1_13_suid_found + when: rhel8cis_6_1_13_suid_found - name: "6.1.13 | AUDIT | Audit SUID executables | Alert SUID executables exist | warning" ansible.builtin.import_tasks: warning_facts.yml vars: warn_control_id: '6.1.13' - when: - - rhel8cis_6_1_13_suid_found + when: rhel8cis_6_1_13_suid_found vars: rhel8cis_6_1_13_suid_found: false when: @@ -306,21 +297,18 @@ ansible.builtin.set_fact: rhel8cis_6_1_14_sgid_found: true loop: "{{ rhel_09_6_1_14_sgid_perms.results }}" - when: - - item.stdout | length > 0 + when: item.stdout | length > 0 - name: "6.1.14 | AUDIT | Audit SGID executables | Alert SGID executables exist" ansible.builtin.debug: msg: "Warning!! SGID set on items in {{ rhel_09_6_1_14_sgid_perms | json_query('results[*].stdout_lines[*]') | flatten }}" - when: - - rhel8cis_6_1_14_sgid_found + when: rhel8cis_6_1_14_sgid_found - name: "6.1.14 | AUDIT | Audit SGID executables| warning" ansible.builtin.import_tasks: warning_facts.yml vars: warn_control_id: '6.1.14' - when: - - rhel8cis_6_1_14_sgid_found + when: rhel8cis_6_1_14_sgid_found vars: rhel8cis_6_1_14_sgid_found: false when: From a5df4c2f3847e5e6b3a28de26004132c14dfc4dc Mon Sep 17 00:00:00 2001 From: Mark Bolwell Date: Thu, 13 Apr 2023 09:23:10 +0100 Subject: [PATCH 05/16] fix_typos Signed-off-by: Mark Bolwell --- tasks/section_6/cis_6.1.x.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tasks/section_6/cis_6.1.x.yml b/tasks/section_6/cis_6.1.x.yml index 480329af..8da977d2 100644 --- a/tasks/section_6/cis_6.1.x.yml +++ b/tasks/section_6/cis_6.1.x.yml @@ -256,22 +256,22 @@ - name: "6.1.13 | AUDIT | Audit SUID executables | set fact SUID executables" ansible.builtin.set_fact: - rhel8cis_6_1_13_suid_found: true + rhel9_6_1_13_suid_found: true loop: "{{ rhel_09_6_1_13_suid_perms.results }}" when: item.stdout | length > 0 - name: "6.1.13 | AUDIT | Audit SUID executables | Alert SUID executables exist" ansible.builtin.debug: msg: "Warning!! SUID set on items in {{ rhel_09_6_1_13_suid_perms | json_query('results[*].stdout_lines[*]') | flatten }}" - when: rhel8cis_6_1_13_suid_found + when: rhel9_6_1_13_suid_found - name: "6.1.13 | AUDIT | Audit SUID executables | Alert SUID executables exist | warning" ansible.builtin.import_tasks: warning_facts.yml vars: warn_control_id: '6.1.13' - when: rhel8cis_6_1_13_suid_found + when: rhel9_6_1_13_suid_found vars: - rhel8cis_6_1_13_suid_found: false + rhel9_6_1_13_suid_found: false when: - rhel9cis_rule_6_1_13 tags: @@ -295,22 +295,22 @@ - name: "6.1.14 | AUDIT | Audit SGID executables | Set fact SGID executables" ansible.builtin.set_fact: - rhel8cis_6_1_14_sgid_found: true + rhel9_6_1_14_sgid_found: true loop: "{{ rhel_09_6_1_14_sgid_perms.results }}" when: item.stdout | length > 0 - name: "6.1.14 | AUDIT | Audit SGID executables | Alert SGID executables exist" ansible.builtin.debug: msg: "Warning!! SGID set on items in {{ rhel_09_6_1_14_sgid_perms | json_query('results[*].stdout_lines[*]') | flatten }}" - when: rhel8cis_6_1_14_sgid_found + when: rhel9_6_1_14_sgid_found - name: "6.1.14 | AUDIT | Audit SGID executables| warning" ansible.builtin.import_tasks: warning_facts.yml vars: warn_control_id: '6.1.14' - when: rhel8cis_6_1_14_sgid_found + when: rhel9_6_1_14_sgid_found vars: - rhel8cis_6_1_14_sgid_found: false + rhel9_6_1_14_sgid_found: false when: - rhel9cis_rule_6_1_14 tags: From fb4216be9f52f4d0eb27984d1dbb9de97f1752d2 Mon Sep 17 00:00:00 2001 From: Jay Olinares Date: Thu, 13 Apr 2023 13:50:15 +1000 Subject: [PATCH 06/16] use var values for pam_faillock Signed-off-by: Jay Olinares --- tasks/section_5/cis_5.5.x.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks/section_5/cis_5.5.x.yml b/tasks/section_5/cis_5.5.x.yml index 13ac418b..cf5d6b89 100644 --- a/tasks/section_5/cis_5.5.x.yml +++ b/tasks/section_5/cis_5.5.x.yml @@ -38,8 +38,8 @@ regexp: "{{ item.regexp }}" line: "{{ item.line }}" loop: - - { regexp: '^\s*deny\s*=\s*[1-5]\b', line: 'deny = 5' } - - { regexp: '^\s*unlock_time\s*=\s*(0|9[0-9][0-9]|[1-9][0-9][0-9][0-9]+)\b', line: 'unlock_time = 900' } + - { regexp: '^\s*deny\s*=\s*[1-5]\b', line: 'deny = {{ rhel9cis_pam_faillock.deny }}' } + - { regexp: '^\s*unlock_time\s*=\s*(0|9[0-9][0-9]|[1-9][0-9][0-9][0-9]+)\b', line: 'unlock_time = {{ rhel9cis_pam_faillock.unlock_time }}' } when: - rhel9cis_rule_5_5_2 From 02c9c76a83694bec3e0a45f3166e627e5a6fc15a Mon Sep 17 00:00:00 2001 From: Jay Olinares Date: Fri, 21 Apr 2023 09:04:13 +1000 Subject: [PATCH 07/16] Molecule test on container is failing due to modprobe Signed-off-by: Jay Olinares --- tasks/section_1/cis_1.1.x.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/tasks/section_1/cis_1.1.x.yml b/tasks/section_1/cis_1.1.x.yml index 4a616228..c4826c93 100644 --- a/tasks/section_1/cis_1.1.x.yml +++ b/tasks/section_1/cis_1.1.x.yml @@ -16,6 +16,7 @@ community.general.modprobe: name: usb-storage state: absent + when: not system_is_container - name: "1.1.9 | PATCH | Disable USB Storage | blacklist" ansible.builtin.lineinfile: From 2317abd1d291d89652a56e89facd13883ebdb523 Mon Sep 17 00:00:00 2001 From: Jay Olinares Date: Thu, 4 May 2023 11:37:57 +1000 Subject: [PATCH 08/16] fix https://github.com/ansible-lockdown/RHEL9-CIS/issues/58 Signed-off-by: Jay Olinares --- tasks/section_5/cis_5.5.x.yml | 43 +++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/tasks/section_5/cis_5.5.x.yml b/tasks/section_5/cis_5.5.x.yml index cf5d6b89..d46d59c9 100644 --- a/tasks/section_5/cis_5.5.x.yml +++ b/tasks/section_5/cis_5.5.x.yml @@ -33,13 +33,42 @@ - rule_5.5.1 - name: "5.5.2 | PATCH | Ensure lockout for failed password attempts is configured" - ansible.builtin.lineinfile: - path: /etc/security/faillock.conf - regexp: "{{ item.regexp }}" - line: "{{ item.line }}" - loop: - - { regexp: '^\s*deny\s*=\s*[1-5]\b', line: 'deny = {{ rhel9cis_pam_faillock.deny }}' } - - { regexp: '^\s*unlock_time\s*=\s*(0|9[0-9][0-9]|[1-9][0-9][0-9][0-9]+)\b', line: 'unlock_time = {{ rhel9cis_pam_faillock.unlock_time }}' } + block: + - name: "5.5.2 | PATCH | Ensure lockout for failed password attempts is configured | Set faillock.conf configs" + ansible.builtin.lineinfile: + path: /etc/security/faillock.conf + regexp: "{{ item.regexp }}" + line: "{{ item.line }}" + loop: + - { regexp: '^\s*deny\s*=\s*[1-5]\b', line: 'deny = {{ rhel9cis_pam_faillock.deny }}' } + - { regexp: '^\s*unlock_time\s*=\s*(0|9[0-9][0-9]|[1-9][0-9][0-9][0-9]+)\b', line: 'unlock_time = {{ rhel9cis_pam_faillock.unlock_time }}' } + - name: "5.5.2 | PATCH | Ensure lockout for failed password attempts is configured | Set preauth" + ansible.builtin.lineinfile: + path: "{{ item }}" + regexp: '^auth\s*(sufficient|required)\s*pam_faillock.so\s*preauth(.*)' + line: "auth required pam_faillock.so preauth silent audit deny={{ rhel9cis_pam_faillock.deny }} unlock_time={{ rhel9cis_pam_faillock.unlock_time}}" + insertafter: 'auth\s*(sufficient|required)\s*pam_env.so$' + loop: + - "/etc/pam.d/system-auth" + - "/etc/pam.d/password-auth" + - name: "5.5.2 | PATCH | Ensure lockout for failed password attempts is configured | Set authfail" + ansible.builtin.lineinfile: + path: "{{ item }}" + regexp: '^auth\s*(sufficient|required)\s*pam_faillock.so\s*authfail(.*)' + line: "auth required pam_faillock.so authfail audit deny={{ rhel9cis_pam_faillock.deny }} unlock_time={{ rhel9cis_pam_faillock.unlock_time}}" + insertbefore: 'auth\s*(sufficient|required)\s*pam_deny.so$' + loop: + - "/etc/pam.d/system-auth" + - "/etc/pam.d/password-auth" + - name: "5.5.2 | PATCH | Ensure lockout for failed password attempts is configured | Load account faillock.so" + ansible.builtin.lineinfile: + path: "{{ item }}" + regexp: '^account\s*(sufficient|required)\s*pam_faillock.so$' + line: "account required pam_faillock.so" + insertbefore: '^account\s*(sufficient|required)\s*pam_unix.so$' + loop: + - "/etc/pam.d/system-auth" + - "/etc/pam.d/password-auth" when: - rhel9cis_rule_5_5_2 From 2380cd46c990d5ac489fee7e82fa45de24fb872c Mon Sep 17 00:00:00 2001 From: Thomas Merkel Date: Tue, 25 Apr 2023 19:27:37 +0200 Subject: [PATCH 09/16] Use correct backtick for regex escape Depends on the ansible version regex escape (via slash) require correct backticks to work. Otherwise it would result in a syntax error. Signed-off-by: Thomas Merkel --- tasks/section_4/cis_4.2.2.x.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/section_4/cis_4.2.2.x.yml b/tasks/section_4/cis_4.2.2.x.yml index 2c9355b3..84513b2c 100644 --- a/tasks/section_4/cis_4.2.2.x.yml +++ b/tasks/section_4/cis_4.2.2.x.yml @@ -185,7 +185,7 @@ - name: "4.2.2.7 | PATCH | Ensure journald default file permissions configured | Set permission" ansible.builtin.lineinfile: path: "{{ systemd_conf_file | default('/usr/lib/tmpfiles.d/systemd.conf') }}" - regexp: "^z \/var\/log\/journal\/%m\/system.journal (!?06(0|4)0) root" + regexp: '^z \/var\/log\/journal\/%m\/system.journal (!?06(0|4)0) root' line: 'z /var/log/journal/%m/system.journal 0640 root systemd-journal - -' when: From 7f9b45cea352e045c0b9580e866c29f39674ac52 Mon Sep 17 00:00:00 2001 From: Jay Olinares Date: Fri, 12 May 2023 12:46:50 +1000 Subject: [PATCH 10/16] tags added Signed-off-by: Jay Olinares --- tasks/section_5/cis_5.5.x.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tasks/section_5/cis_5.5.x.yml b/tasks/section_5/cis_5.5.x.yml index d46d59c9..b8749b31 100644 --- a/tasks/section_5/cis_5.5.x.yml +++ b/tasks/section_5/cis_5.5.x.yml @@ -71,6 +71,11 @@ - "/etc/pam.d/password-auth" when: - rhel9cis_rule_5_5_2 + tags: + - level1-server + - level1-workstation + - patch + - rule_5.5.2 - name: "5.5.3 | PATCH | Ensure password reuse is limited" block: From 7c09b264a15032d705586cd43bc7f404ecad618d Mon Sep 17 00:00:00 2001 From: Mark Bolwell Date: Tue, 16 May 2023 08:52:18 +0100 Subject: [PATCH 11/16] fixed layout Signed-off-by: Mark Bolwell --- tasks/section_5/cis_5.4.x.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tasks/section_5/cis_5.4.x.yml b/tasks/section_5/cis_5.4.x.yml index cb370246..52c1f709 100644 --- a/tasks/section_5/cis_5.4.x.yml +++ b/tasks/section_5/cis_5.4.x.yml @@ -54,9 +54,9 @@ line: "{{ item.line }}" insertbefore: "{{ item.before }}" loop: - - { 'regexp': '^auth\s+required\s+pam_faillock.so preauth silent deny=.*unlock_time=.*', 'line': 'auth required pam_faillock.so preauth silent deny={{ rhel9cis_pam_faillock.deny }} unlock_time={{ rhel9cis_pam_faillock.unlock_time }}', 'before':'^auth\s+sufficient\s+pam_unix.so try_first_pass'} - - { 'regexp': '^auth\s+required\s+pam_faillock.so authfail deny=.*unlock_time=.*', 'line': 'auth required pam_faillock.so authfail deny={{ rhel9cis_pam_faillock.deny }} unlock_time={{ rhel9cis_pam_faillock.unlock_time }}', 'before':'^auth\s+required\s+pam_deny.so'} - - { 'regexp': '^account\s+required\s+pam_faillock.so', 'line': 'account required pam_faillock.so', 'before':'^account required pam_unix.so'} + - { 'regexp': '^auth\s+required\s+pam_faillock.so preauth silent deny=.*unlock_time=.*', 'line': 'auth required pam_faillock.so preauth silent deny={{ rhel9cis_pam_faillock.deny }} unlock_time={{ rhel9cis_pam_faillock.unlock_time }}', 'before':'^auth\s+sufficient\s+pam_unix.so try_first_pass'} + - { 'regexp': '^auth\s+required\s+pam_faillock.so authfail deny=.*unlock_time=.*', 'line': 'auth required pam_faillock.so authfail deny={{ rhel9cis_pam_faillock.deny }} unlock_time={{ rhel9cis_pam_faillock.unlock_time }}', 'before':'^auth\s+required\s+pam_deny.so'} + - { 'regexp': '^account\s+required\s+pam_faillock.so', 'line': 'account required pam_faillock.so', 'before':'^account required pam_unix.so'} when: - rhel9cis_add_faillock_without_authselect - rhel9cis_5_4_2_risks == 'ACCEPT' From 195e42e3eae5acb12370d5c0b13cfe57837beee4 Mon Sep 17 00:00:00 2001 From: Mark Bolwell Date: Tue, 16 May 2023 08:52:45 +0100 Subject: [PATCH 12/16] removed line and updated requirement #53 Signed-off-by: Mark Bolwell --- tasks/section_5/cis_5.5.x.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tasks/section_5/cis_5.5.x.yml b/tasks/section_5/cis_5.5.x.yml index b8749b31..566823ad 100644 --- a/tasks/section_5/cis_5.5.x.yml +++ b/tasks/section_5/cis_5.5.x.yml @@ -82,14 +82,14 @@ - name: "5.5.3 | PATCH | Ensure password reuse is limited | pwquality" ansible.builtin.lineinfile: path: /etc/pam.d/system-auth - line: "password requisite pam_pwhistory.so try_first_pass local_users_only enforce_for_root retry=3 remember={{ rhel9cis_pam_faillock.remember }}" + line: "password requisite pam_pwhistory.so try_first_pass enforce_for_root retry=3 remember={{ rhel9cis_pam_faillock.remember }}" insertafter: '^password\s*requisite\s*pam_pwquality.so' - name: "5.5.3 | PATCH | Ensure password reuse is limited | pam_unix" ansible.builtin.replace: path: /etc/pam.d/system-auth - regexp: '^password\s*(sufficient|requisite|sufficient)\s*pam_unix.so.*$' - replace: 'password requisite pam_unix.so sha512 shadow try_first_pass use_authtok remember={{ rhel9cis_pam_faillock.remember }}' + regexp: '^password\s*sufficient\s*pam_unix.so.*$' + replace: 'password sufficient pam_unix.so sha512 shadow try_first_pass use_authtok remember={{ rhel9cis_pam_faillock.remember }}' when: - rhel9cis_rule_5_5_3 tags: From 2da0d870c890bf4d1d4386bc3e43e8ea0310c432 Mon Sep 17 00:00:00 2001 From: Mark Bolwell Date: Tue, 16 May 2023 11:56:07 +0100 Subject: [PATCH 13/16] #57 great catch Signed-off-by: Mark Bolwell --- tasks/section_5/cis_5.6.x.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks/section_5/cis_5.6.x.yml b/tasks/section_5/cis_5.6.x.yml index 56b3d5f1..3e49a46c 100644 --- a/tasks/section_5/cis_5.6.x.yml +++ b/tasks/section_5/cis_5.6.x.yml @@ -13,7 +13,7 @@ - item.id != "shutdown" - item.id != "halt" - item.id != "nfsnobody" - - item.gid < min_int_uid | int + - item.uid < min_int_uid | int - item.shell != " /bin/false" - item.shell != " /usr/sbin/nologin" loop_control: @@ -30,7 +30,7 @@ - item.id != "sync" - item.id != "root" - item.id != "nfsnobody" - - item.gid < min_int_uid | int + - item.uid < min_int_uid | int - item.shell != " /bin/false" - item.shell != " /usr/sbin/nologin" loop_control: From c7d72b564b9280126f0e92b5af1ec12048d8bf61 Mon Sep 17 00:00:00 2001 From: Mark Bolwell Date: Wed, 17 May 2023 15:42:30 +0100 Subject: [PATCH 14/16] 4.1.3.6 command improvement Signed-off-by: Mark Bolwell --- tasks/section_4/cis_4.1.3.x.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/section_4/cis_4.1.3.x.yml b/tasks/section_4/cis_4.1.3.x.yml index 922ea616..ec925bb7 100644 --- a/tasks/section_4/cis_4.1.3.x.yml +++ b/tasks/section_4/cis_4.1.3.x.yml @@ -69,7 +69,7 @@ - name: "4.1.3.6 | PATCH | Ensure use of privileged commands is collected" block: - name: "4.1.3.6 | PATCH | Ensure use of privileged commands is collected" - ansible.builtin.shell: for i in $(df | grep '^/dev' | awk '{ print $NF }'); do find $i -xdev -type f -perm -4000 -o -type f -perm -2000 2>/dev/null; done + ansible.builtin.shell: for i in $(df | grep '^/dev' | awk '{ print $NF }'); do find $i -xdev -type f -perm /6000 2>/dev/null; done changed_when: false failed_when: false check_mode: false From 3ee1923f382390bfbe7d5095be0b74e3e6e9e322 Mon Sep 17 00:00:00 2001 From: Mark Bolwell Date: Wed, 17 May 2023 15:42:43 +0100 Subject: [PATCH 15/16] updated Signed-off-by: Mark Bolwell --- Changelog.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Changelog.md b/Changelog.md index 5f990a39..ef5157be 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,8 +2,9 @@ ## 1.0.7 -lint and yamll updates -improvemnst to 6.1.10, 6.1.11, 6.1.13, 6.1.14 +lint and yaml updates +improvements to 6.1.10, 6.1.11, 6.1.13, 6.1.14 +4.1.3.6 updated on process discovery ## 1.0.6 From 626c76236a08f330241b2f10448dc9d27a14d7cf Mon Sep 17 00:00:00 2001 From: Jimmy Conner Date: Wed, 31 May 2023 10:56:33 -0500 Subject: [PATCH 16/16] Fix Policy Number for Grub Boot Password Signed-off-by: Jimmy Conner --- defaults/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/defaults/main.yml b/defaults/main.yml index 7ea583d0..ee4f51b3 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -370,7 +370,7 @@ rhel9cis_rhnsd_required: false # 1.2.4 repo_gpgcheck rhel9cis_rhel_default_repo: true -# 1.4.2 Bootloader password +# 1.4.1 Bootloader password rhel9cis_bootloader_password_hash: 'grub.pbkdf2.sha512.10000.9306A36764A7BEA3BF492D1784396B27F52A71812E9955A58709F94EE70697F9BD5366F36E07DEC41B52279A056E2862A93E42069D7BBB08F5DFC2679CD43812.6C32ADA5449303AD5E67A4C150558592A05381331DE6B33463469A236871FA8E70738C6F9066091D877EF88A213C86825E093117F30E9E1BF158D0DB75E7581B' rhel9cis_bootloader_password: random rhel9cis_set_boot_pass: true