Skip to content

Commit

Permalink
Merge pull request #71 from ansible-lockdown/devel
Browse files Browse the repository at this point in the history
Addressed Issue 55, 57, 58,  61, 65, 66, and 67
  • Loading branch information
carnells authored Dec 4, 2020
2 parents f0fc48c + 1973e0d commit ab52c71
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 197 deletions.
207 changes: 58 additions & 149 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,169 +4,78 @@ RHEL 8 CIS
![Build Status](https://img.shields.io/github/workflow/status/ansible-lockdown/RHEL8-CIS/CommunityToDevel?label=Devel%20Build%20Status&style=plastic)


Configure RHEL/Centos 8 machine to be [CIS](https://www.cisecurity.org/cis-benchmarks/) compliant. Level 1 and 2 findings will be corrected by default.
Configure RHEL/Centos 8 machine to be [CIS](https://www.cisecurity.org/cis-benchmarks/) compliant

This role **will make changes to the system** that could break things. This is not an auditing tool but rather a remediation tool to be used after an audit has been conducted.
Based on [CIS RedHat Enterprise Linux 8 Benchmark v1.0.0 - 09-30-2019 ](https://www.cisecurity.org/cis-benchmarks/)

Based on [CIS RedHat Enterprise Linux 8 Benchmark v2.1.1 - 01-31-2017 ](https://community.cisecurity.org/collab/public/index.php).
Caution(s)
-------
This role **will make changes to the system** which may have unintended concequences. This is not an auditing tool but rather a remediation tool to be used after an audit has been conducted.

This role was developed against a clean install of the Operating System. If you are implimenting to an existing system please review this role for any site specific changes that are needed.

Requirements
------------

You should carefully read through the tasks to make sure these changes will not break your systems before running this playbook.
If you want to do a dry run without changing anything, set the below sections (rhel8cis_section1-6) to false.

Role Variables
--------------
There are many role variables defined in defaults/main.yml. This list shows the most important.

**rhel8cis_notauto**: Run CIS checks that we typically do NOT want to automate due to the high probability of breaking the system (Default: false)

**rhel8cis_section1**: CIS - General Settings (Section 1) (Default: true)

**rhel8cis_section2**: CIS - Services settings (Section 2) (Default: true)

**rhel8cis_section3**: CIS - Network settings (Section 3) (Default: true)

**rhel8cis_section4**: CIS - Logging and Auditing settings (Section 4) (Default: true)

**rhel8cis_section5**: CIS - Access, Authentication and Authorization settings (Section 5) (Default: true)

**rhel8cis_section6**: CIS - System Maintenance settings (Section 6) (Default: true)

##### Disable all selinux functions
`rhel8cis_selinux_disable: false`

##### Service variables:
###### These control whether a server should or should not be allowed to continue to run these services

```
rhel8cis_avahi_server: false
rhel8cis_cups_server: false
rhel8cis_dhcp_server: false
rhel8cis_ldap_server: false
rhel8cis_telnet_server: false
rhel8cis_nfs_server: false
rhel8cis_rpc_server: false
rhel8cis_ntalk_server: false
rhel8cis_rsyncd_server: false
rhel8cis_tftp_server: false
rhel8cis_rsh_server: false
rhel8cis_nis_server: false
rhel8cis_snmp_server: false
rhel8cis_squid_server: false
rhel8cis_smb_server: false
rhel8cis_dovecot_server: false
rhel8cis_httpd_server: false
rhel8cis_vsftpd_server: false
rhel8cis_named_server: false
rhel8cis_bind: false
rhel8cis_vsftpd: false
rhel8cis_httpd: false
rhel8cis_dovecot: false
rhel8cis_samba: false
rhel8cis_squid: false
rhel8cis_net_snmp: false
```

##### Designate server as a Mail server
`rhel8cis_is_mail_server: false`


##### System network parameters (host only OR host and router)
`rhel8cis_is_router: false`


##### IPv6 required
`rhel8cis_ipv6_required: true`


##### AIDE
`rhel8cis_config_aide: true`

###### AIDE cron settings
```
rhel8cis_aide_cron:
cron_user: root
cron_file: /etc/crontab
aide_job: '/usr/sbin/aide --check'
aide_minute: 0
aide_hour: 5
aide_day: '*'
aide_month: '*'
aide_weekday: '*'
```
To use release version please point to main branch

##### SELinux policy
`rhel8cis_selinux_pol: targeted`
Documentation
-------------
[Getting Started](https://www.lockdownenterprise.com/docs/getting-started-with-lockdown)<br>
[Customizing Roles](https://www.lockdownenterprise.com/docs/customizing-lockdown-enterprise)<br>
[Per-Host Configuration](https://www.lockdownenterprise.com/docs/per-host-lockdown-enterprise-configuration)<br>
[Getting the Most Out of the Role](https://www.lockdownenterprise.com/docs/get-the-most-out-of-lockdown-enterprise)<br>
[Wiki](https://github.com/ansible-lockdown/RHEL8-CIS/wiki)<br>
[Repo GitHub Page](https://ansible-lockdown.github.io/RHEL8-CIS/)<br>


##### Set to 'true' if X Windows is needed in your environment
`rhel8cis_xwindows_required: no`


##### Client application requirements
```
rhel8cis_openldap_clients_required: false
rhel8cis_telnet_required: false
rhel8cis_talk_required: false
rhel8cis_rsh_required: false
rhel8cis_ypbind_required: false
```

##### Time Synchronization
```
rhel8cis_time_synchronization: chrony
rhel8cis_time_Synchronization: ntp
rhel8cis_time_synchronization_servers:
- 0.pool.ntp.org
- 1.pool.ntp.org
- 2.pool.ntp.org
- 3.pool.ntp.org
```

##### 3.4.2 | PATCH | Ensure /etc/hosts.allow is configured
```
rhel8cis_host_allow:
- "10.0.0.0/255.0.0.0"
- "172.16.0.0/255.240.0.0"
- "192.168.0.0/255.255.0.0"
```

```
rhel8cis_firewall: firewalld
rhel8cis_firewall: iptables
```


Dependencies
Requirements
------------

Ansible > 2.6.5

Example Playbook
-------------------------

This sample playbook should be run in a folder that is above the main RHEL8-CIS / RHEL8-CIS-devel folder.
**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 or the [Main Variables Wiki Page](https://github.com/ansible-lockdown/RHEL8-CIS/wiki/Main-Variables).

**Technical Dependencies:**
- Running Ansible/Tower setup (this role is tested against Ansible version 2.9.1 and newer)
- Python3 Ansible run environment
- python-def (should be included in RHEL/CentOS 8)
- libselinux-python

```
- name: Harden Server
hosts: servers
become: yes
Role Variables
--------------
This role is designed that the end user should not have to edit the tasks themselves. All customizing should be done via the defaults/main.yml file or with extra vars within the project, job, workflow, etc. These variables can be found [here](https://github.com/ansible-lockdown/RHEL8-CIS/wiki/Main-Variables) in the Main Variables Wiki page. All variables are listed there along with descriptions.

roles:
- RHEL8-CIS
```

Tags
----
Many tags are available for precise control of what is and is not changed.

Some examples of using 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.
```
# Audit and patch the site
ansible-playbook site.yml --tags="patch"
tags:
- level1
- scored
- avahi
- services
- patch
- rule_2.2.4
```

Branches
-------
**devel** - This is the default branch and the working development branch. Community pull requests will pull into this branch<br>
**main** - This is the release branch<br>
**reports** - This is a protected branch for our scoring reports, no code should ever go here<br>
**all other branches** - Individual community member branches<br>

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
4 changes: 2 additions & 2 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -461,10 +461,10 @@ rhel8cis_authselect:
options: with-sudo with-faillock without-nullok

# 5.3.1 Enable automation to creat custom profile settings, using the setings above
rhel8cis_authselect_custom_profile_create: true
rhel8cis_authselect_custom_profile_create: false

# 5.3.2 Enable autmoation to select custom profile options, using the settings above
rhel8cis_authselect_custom_profile_select: true
rhel8cis_authselect_custom_profile_select: false

rhel8cis_pass:
max_days: 365
Expand Down
4 changes: 2 additions & 2 deletions tasks/parse_etc_password.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
- name: "PRELIM | {{ rhel8cis_passwd_tasks }} | Parse /etc/passwd"
- name: "PRELIM | 5.5.2 | 6.2.7 | 6.2.8 6.2.20 | Parse /etc/passwd"
block:
- name: "PRELIM | {{ rhel8cis_passwd_tasks }} | Parse /etc/passwd"
command: cat /etc/passwd
changed_when: no
check_mode: no
register: rhel8cis_passwd_file_audit

- name: "PRELIM | {{ rhel8cis_passwd_tasks }} | Split passwd entries"
- name: "PRELIM | 5.5.2 | 6.2.7 | 6.2.8 6.2.20 | Split passwd entries"
set_fact:
rhel8cis_passwd: "{{ rhel8cis_passwd_file_audit.stdout_lines | map('regex_replace', ld_passwd_regex, ld_passwd_yaml) | map('from_yaml') | list }}"

Expand Down
9 changes: 9 additions & 0 deletions tasks/prelim.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@
name: cronie
state: present

- name: "PRELIM | Install authconfig"
dnf:
name: authconfig
state: present
when:
- rhel8cis_rule_5_3_1 or
rhel8cis_rule_5_3_2 or
rhel8cis_rule_5_3_3

- name: "PRELIM | Check if prelink package is installed"
command: rpm -q prelink
args:
Expand Down
2 changes: 1 addition & 1 deletion tasks/section1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@
enabled: no
when:
- ansible_distribution == "RedHat" and rhnsd_service_status.stdout == "loaded" and not rhel8cis_rhnsd_required
- rhel8cis_rule_1_2_5
- rhel8cis_rule_1_2_2
tags:
- level1
- notscored
Expand Down
16 changes: 0 additions & 16 deletions tasks/section2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,6 @@
- patch
- rule_2.2.1.2

- name: "SCORED | 2.2.1.3 | PATCH | Ensure chrony is configured | modify /etc/sysconfig/chronyd | 1"
lineinfile:
dest: /etc/sysconfig/chronyd
regexp: "^(#)?OPTIONS"
line: "OPTIONS=\"-u chrony\""
state: present
create: yes
when:
- rhel8cis_time_synchronization == "chrony"
- rhel8cis_rule_2_2_1_3
- not rhel8cis_system_is_container
tags:
- level1
- patch
- rule_2.2.1.3

- name: "SCORED | 2.2.2 | PATCH | Ensure X Window System is not installed"
shell: dnf -y remove xorg-x11*
when:
Expand Down
4 changes: 2 additions & 2 deletions tasks/section4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,9 @@
- patch
- rule_4.1.11

- name: "SCORED | 4.1.12 | PATCH | Ensure use of privileged commands is collected"
- name: "SCORED | 4.1.12 | PATCH | Ensure successful file system mounts are collected"
block:
- name: "SCORED | 4.1.12 | PATCH | Ensure use of privileged commands is collected"
- name: "SCORED | 4.1.12 | PATCH | Ensure successful file system mounts are collected"
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
register: priv_procs
changed_when: no
Expand Down
26 changes: 1 addition & 25 deletions tasks/section5.yml
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@
shell: sed -ri "s/^\s*(CRYPTO_POLICY\s*=.*)$/# \1/" /etc/sysconfig/sshd
notify: restart sshd
when:
- rhel8cis_rule_5_2_19
- rhel8cis_rule_5_2_20
tags:
- level1
- patch
Expand Down Expand Up @@ -632,30 +632,6 @@
- rule_5.4.3
- rule_5.4.4

- name: "SCORED | 5.4.5 | PATCH | Ensure default user shell timeout is 900 seconds or less"
blockinfile:
create: yes
mode: 0644
dest: "{{ item.dest }}"
state: "{{ item.state }}"
marker: "# {mark} ANSIBLE MANAGED"
block: |
# Set session timeout - CIS ID RHEL-08-5.4.5
TMOUT={{ rhel8cis_shell_session_timeout.timeout }}
readonly TMOUT
export TMOUT
with_items:
- dest: "{{ rhel8cis_shell_session_timeout.file }}"
state: present
- dest: /etc/profile
state: "{{ (rhel8cis_shell_session_timeout.file == '/etc/profile') | ternary('present', 'absent') }}"
when:
- rhel8cis_rule_5_4_5
tags:
- level2
- patch
- rule_5.4.5

- name: "SCORED | 5.5.1.1 | PATCH | Ensure password expiration is 365 days or less"
lineinfile:
state: present
Expand Down

0 comments on commit ab52c71

Please sign in to comment.