cis_ubuntu_20_04_ansible
Ansible CIS Ubuntu 20.04 LTS
CIS hardened Ubuntu: cyber attack and malware prevention for mission-critical systems CIS benchmarks lock down your systems by removing:
- non-secure programs.
- disabling unused filesystems.
- disabling unnecessary ports or services.
- auditing privileged operations.
- restricting administrative privileges.
CIS benchmark recommendations are adopted in virtual machines in public and private clouds. They are also used to secure on-premises deployments. For some industries, hardening a system against a publicly known standard is a criteria auditors look for. CIS benchmarks are often a system hardening choice recommended by auditors for industries requiring PCI-DSS and HIPPA compliance, such as banking, telecommunications and healthcare. If you are attempting to obtain compliance against an industry-accepted security standard, like PCI DSS, APRA or ISO 27001, then you need to demonstrate that you have applied documented hardening standards against all systems within the scope of assessment.
The Ubuntu CIS benchmarks are organised into different profiles, namely ‘Level 1’ and ‘Level 2’ intended for server and workstation environments.
A Level 1 profile is intended to be a practical and prudent way to secure a system without too much performance impact.
- Disabling unneeded filesystems,
- Restricting user permissions to files and directories,
- Disabling unneeded services.
- Configuring network firewalls.
A Level 2 profile is used where security is considered very important and it may have a negative impact on the performance of the system.
- Creating separate partitions,
- Auditing privileged operations
The Ubuntu CIS hardening tool allows you to select the desired level of hardening against a profile (Level1 or Level 2) and the work environment (server or workstation) for a system. Exmaple:
ansible-playbook -i inventory cis-ubuntu-20.yaml --tags="level_1_server"
You can list all tags by running the below command:
ansible-playbook -i host run.yaml --list-tags
I wrote all roles based on
CIS Ubuntu Linux 20.04 LTS Benchmark
v1.0.0 - 07-21-2020
Check Example dir
Requirements
You should carefully read through the tasks to make sure these changes will not break your systems before running this playbook.
You can download Free CIS Benchmark book from this URL Free Benchmark
To start working in this Role you just need to install Ansible. Installing Ansible
Role Variables
You have to review all default configuration before running this playbook, There are many role variables defined in defaults/main.yml.
- If you are considering applying this role to any servers, you should have a basic familiarity with the CIS Benchmark and an appreciation for the impact that it may have on a system.
- Read and change configurable default values.
Examples of config that should be immediately considered for exclusion:
5.1.8 Ensure cron is restricted to authorized users and 5.2.17 Ensure SSH access is limited, which by default effectively limit access to the host (including via ssh).
For example:
- CIS-Ubuntu-20.04-Ansible/defaults/main.yml
#Section 5
#5.1.8 Ensure cron is restricted to authorized users
allowd_hosts: "ALL: 0.0.0.0/0.0.0.0, 192.168.2.0/255.255.255.0"
# 5.2.17 Ensure SSH access is limited
allowed_users: root #Put None or list of users space between each user
If you need you to change file templates, you can find it under files/templates/*
Dependencies
- Ansible version > 2.9
Example Playbook
Below an example of a playbook
---
- hosts: host1
become: yes
remote_user: root
gather_facts: no
roles:
- { role: "CIS-Ubuntu-20.04-Ansible",}
Run all
If you want to run all tags use the below command:
ansible-playbook -i [inventoryfile] [playbook].yaml
Run specfic section
ansible-playbook -i host run.yaml -t section2
Run multi sections
ansible-playbook -i host run.yaml -t section2 -t 6.1.1
- Note: When run an individual task be sure from the dependencies between tasks, for example, if you run tag 4.1.1.2 Ensure auditd service is enabled before running 4.1.1.1 Ensure auditd is installed you will get an error at the run time.
Table of Roles:
1 Initial Setup
- 1.1 Filesystem Configuration
- 1.1.1 Disable unused filesystems
- 1.1.1.1 Ensure mounting of cramfs filesystems is disabled (Automated)
- 1.1.1.2 Ensure mounting of freevxfs filesystems is disabled - (Automated)
- 1.1.1.3 Ensure mounting of jffs2 filesystems is disabled (Automated)
- 1.1.1.4 Ensure mounting of hfs filesystems is disabled (Automated)
- 1.1.1.5 Ensure mounting of hfsplus filesystems is disabled - (Automated)
- 1.1.1.6 Ensure mounting of udf filesystems is disabled (Automated)
- 1.1.1.7 Ensure mounting of FAT filesystems is limited (Manual)
- 1.1.2 Ensure /tmp is configured (Automated)
- 1.1.3 Ensure nodev option set on /tmp partition (Automated)
- 1.1.4 Ensure nosuid option set on /tmp partition (Automated)
- 1.1.5 Ensure noexec option set on /tmp partition (Automated)
- 1.1.6 Ensure /dev/shm is configured (Automated)
- 1.1.7 Ensure nodev option set on /dev/shm partition (Automated)
- 1.1.8 Ensure nosuid option set on /dev/shm partition (Automated)
- 1.1.9 Ensure noexec option set on /dev/shm partition (Automated)
- 1.1.10 Ensure separate partition exists for /var (Automated)
- 1.1.11 Ensure separate partition exists for /var/tmp (Automated)
- 1.1.12 Ensure nodev option set on /var/tmp partition (Automated)
- 1.1.13 Ensure nosuid option set on /var/tmp partition (Automated)
- 1.1.14 Ensure noexec option set on /var/tmp partition (Automated)
- 1.1.15 Ensure separate partition exists for /var/log (Automated)
- 1.1.16 Ensure separate partition exists for /var/log/audit - (Automated)
- 1.1.17 Ensure separate partition exists for /home (Automated)
- 1.1.18 Ensure nodev option set on /home partition (Automated)
- 1.1.19 Ensure nodev option set on removable media partitions (Manual)
- 1.1.20 Ensure nosuid option set on removable media partitions - (Manual)
- 1.1.21 Ensure noexec option set on removable media partitions - (Manual)
- 1.1.22 Ensure sticky bit is set on all world-writable directories - (Automated)
- 1.1.23 Disable Automounting (Automated)
- 1.1.24 Disable USB Storage (Automated)
1.2 Configure Software Updates
- 1.2.1 Ensure package manager repositories are configured (Manual)
- 1.2.2 Ensure GPG keys are configured (Manual)
1.3 Configure sudo
- 1.3.1 Ensure sudo is installed (Automated)
- 1.3.2 Ensure sudo commands use pty (Automated)
- 1.3.3 Ensure sudo log file exists (Automated)
1.4 Filesystem Integrity Checking
- 1.4.1 Ensure AIDE is installed (Automated)
- 1.4.2 Ensure filesystem integrity is regularly checked (Automated)
1.5 Secure Boot Settings
- 1.5.1 Ensure bootloader password is set (Automated)
- 1.5.2 Ensure permissions on bootloader config are configured - (Automated)
- 1.5.3 Ensure authentication required for single user mode (Automated)
1.6 Additional Process Hardening
- 1.6.1 Ensure XD/NX support is enabled (Automated)
- 1.6.2 Ensure address space layout randomization (ASLR) is enabled - (Automated)
- 1.6.3 Ensure prelink is disabled (Automated)
- 1.6.4 Ensure core dumps are restricted (Automated)
1.7 Mandatory Access Control
- 1.7.1 Configure AppArmor
- 1.7.1.1 Ensure AppArmor is installed (Automated)
- 1.7.1.2 Ensure AppArmor is enabled in the bootloader configuration - (Automated)
- 1.7.1.3 Ensure all AppArmor Profiles are in enforce or complain mode - (Automated)
- 1.7.1.4 Ensure all AppArmor Profiles are enforcing (Automated)
1.8 Warning Banners
- 1.8.1 Command Line Warning Banners
- 1.8.1.1 Ensure message of the day is configured properly (Automated)
- 1.8.1.2 Ensure local login warning banner is configured properly - (Automated) 115
- 1.8.1.3 Ensure remote login warning banner is configured properly - (Automated)
- 1.8.1.4 Ensure permissions on /etc/motd are configured (Automated)
- 1.8.1.5 Ensure permissions on /etc/issue are configured (Automated)
- 1.8.1.6 Ensure permissions on /etc/issue.net are configured - (Automated)
- 1.9 Ensure updates, patches, and additional security software are - installed (Manual)
- 1.10 Ensure GDM is removed or login is configured (Automated)
2 Services
- 2.1 inetd Services
- 2.1.1 Ensure xinetd is not installed (Automated)
- 2.1.2 Ensure openbsd-inetd is not installed (Automated)
- 2.2 Special Purpose Services
- 2.2.1 Time Synchronization
- 2.2.1.1 Ensure time synchronization is in use (Automated)
- 2.2.1.2 Ensure systemd-timesyncd is configured (Manual)
- 2.2.1.3 Ensure chrony is configured (Automated)
- 2.2.1.4 Ensure ntp is configured (Automated)
- 2.2.2 Ensure X Window System is not installed (Automated)
- 2.2.3 Ensure Avahi Server is not installed (Automated)
- 2.2.4 Ensure CUPS is not installed (Automated)
- 2.2.5 Ensure DHCP Server is not installed (Automated)
- 2.2.6 Ensure LDAP server is not installed (Automated)
- 2.2.7 Ensure NFS is not installed (Automated)
- 2.2.8 Ensure DNS Server is not installed (Automated)
- 2.2.9 Ensure FTP Server is not installed (Automated)
- 2.2.10 Ensure HTTP server is not installed (Automated)
- 2.2.11 Ensure IMAP and POP3 server are not installed (Automated)
- 2.2.12 Ensure Samba is not installed (Automated)
- 2.2.13 Ensure HTTP Proxy Server is not installed (Automated)
- 2.2.14 Ensure SNMP Server is not installed (Automated)
- 2.2.15 Ensure mail transfer agent is configured for local-only mode - (Automated)
- 2.2.16 Ensure rsync service is not installed (Automated)
- 2.2.17 Ensure NIS Server is not installed (Automated)
2.3 Service Clients
- 2.3.1 Ensure NIS Client is not installed (Automated)
- 2.3.2 Ensure rsh client is not installed (Automated)
- 2.3.3 Ensure talk client is not installed (Automated)
- 2.3.4 Ensure telnet client is not installed (Automated)
- 2.3.5 Ensure LDAP client is not installed (Automated)
- 2.3.6 Ensure RPC is not installed (Automated)
- 2.4 Ensure nonessential services are removed or masked (Manual)
3 Network Configuration
- 3.1 Disable unused network protocols and devices
- 3.1.1 Disable IPv6 (Manual)
- 3.1.2 Ensure wireless interfaces are disabled (Automated)
3.2 Network Parameters (Host-Only)
- 3.2.1 Ensure packet redirect sending is disabled (Automated)
- 3.2.2 Ensure IP forwarding is disabled (Automated)
3.3 Network Parameters (Host and Router)
- 3.3.1 Ensure source-routed packets are not accepted (Automated)
- 3.3.2 Ensure ICMP redirects are not accepted (Automated)
- 3.3.3 Ensure secure ICMP redirects are not accepted (Automated)
- 3.3.4 Ensure suspicious packets are logged (Automated)
- 3.3.5 Ensure broadcast ICMP requests are ignored (Automated)
- 3.3.6 Ensure bogus ICMP responses are ignored (Automated)
- 3.3.7 Ensure Reverse Path Filtering is enabled (Automated)
- 3.3.8 Ensure TCP SYN Cookies is enabled (Automated)
- 3.3.9 Ensure IPv6 router advertisements are not accepted (Automated)
3.4 Uncommon Network Protocols
- 3.4.1 Ensure DCCP is disabled (Automated)
- 3.4.2 Ensure SCTP is disabled (Automated)
- 3.4.3 Ensure RDS is disabled (Automated)
- 3.4.4 Ensure TIPC is disabled (Automated)
3.5 Firewall Configuration
- 3.5.1 Configure UncomplicatedFirewall
- 3.5.1.1 Ensure Uncomplicated Firewall is installed (Automated)
- 3.5.1.2 Ensure iptables-persistent is not installed (Automated)
- 3.5.1.3 Ensure ufw service is enabled (Automated)
- 3.5.1.4 Ensure loopback traffic is configured (Automated)
- 3.5.1.5 Ensure outbound connections are configured (Manual)
- 3.5.1.6 Ensure firewall rules exist for all open ports (Manual)
- 3.5.1.7 Ensure default deny firewall policy (Automated)