This role provides numerous security-related configurations, providing all-round base protection. It is intended to be compliant with the [DevSec Linux Baseline](https://github.com/dev-sec/linux-baseline).
If you're using Docker / Kubernetes+Docker you'll need to override the ipv4 ip forward sysctl setting.
```yaml
- hosts: localhost
roles:
- devsec.hardening.os_hardening
vars:
sysctl_overwrite:
# Enable IPv4 traffic forwarding.
net.ipv4.ip_forward: 1
```
### hidepid on RHEL/CentOS 7
When having `polkit-0.112-18.el7` (and later) installed and `/proc` mounted with `hidepid=2`, every time someone uses `systemctl` the following error is displayed, but systemctl runs successfully.
```
Error registering authentication agent: GDBus.Error:org.freedesktop.PolicyKit1.Error.Failed: Cannot determine user of subject (polkit-error-quark, 0)
```
We decided to set `hidepid=0` to remove the error message, if you want to use the other proposed workaround, you have to setup the user yourself and set our option to `hidepid_option: 2` via Ansible vars.
For further details see [RedHat: "GDBus.Error:org.freedesktop.PolicyKit1.Error.Failed: Cannot determine user of subject" seen when executing systemctl command](https://access.redhat.com/solutions/5005111) or [#364: hidepid=2 gives error when running systemctl on EL7](https://github.com/dev-sec/ansible-collection-hardening/issues/364)
### sysctl - vm.mmap_rnd_bits
We are setting this sysctl to a default of `32`, some systems only support smaller values and this will generate an error. Unfortunately we cannot determine the correct applicable maximum. If you encounter this error you have to override this sysctl in your playbook.
```yaml
- hosts: localhost
roles:
- devsec.hardening.os_hardening
vars:
sysctl_overwrite:
vm.mmap_rnd_bits: 16
```
## Testing with inspec
If you're using inspec to test your machines after applying this role, please make sure to add the connecting user to the `os_ignore_users`-variable.
Otherwise inspec will fail. For more information, see [issue #124](https://github.com/dev-sec/ansible-os-hardening/issues/124).
We know that this is the case on Raspberry Pi.
## Changing sysctl variables
If you want to override sysctl-variables, you can use the `sysctl_overwrite` variable (in older versions you had to override the whole `sysctl_dict`).
So for example if you want to change the IPv4 traffic forwarding variable to `1`, do it like this:
```yaml
- hosts: localhost
roles:
- devsec.hardening.os_hardening
vars:
sysctl_overwrite:
# Enable IPv4 traffic forwarding.
net.ipv4.ip_forward: 1
```
Alternatively you can change Ansible's [hash-behaviour](https://docs.ansible.com/ansible/latest/reference_appendices/config.html#default-hash-behaviour) to `merge`, then you only have to overwrite the single hash you need to. But please be aware that changing the hash-behaviour changes it for all your playbooks and is not recommended by Ansible.
## Improving Kernel Audit logging
By default, any process that starts before the `auditd` daemon will have an AUID of `4294967295`. To improve this and provide more accurate logging, it's recommended to add the kernel boot parameter `audit=1` to you configuration. Without doing this, you will find that your `auditd` logs fail to properly audit all processes.
For more information, please see this [upstream documentation](https://www.kernel.org/doc/html/latest/admin-guide/kernel-parameters.html) and your system's boot loader documentation for how to configure additional kernel parameters.
## PAM configuration
We use specific PAM configuration for every linux distribution. This is a very diverse area, since every vendor seems to push their own system for managing PAM. We used following guides and sources for our configuration.
- on Debian/Ubuntu we use [pam-config-framework](https://wiki.ubuntu.com/PAMConfigFrameworkSpec)
- RHEL8 and compatible use information from [authselect](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/configuring_authentication_and_authorization_in_rhel/configuring-user-authentication-using-authselect_configuring-authentication-and-authorization-in-rhel), but our setup disables the configuration from authselect
- RHEL 6/7 and compatible use [authconfig](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system-level_authentication_guide/authconfig-install), but our setup disables the configuration from authconfig
- for RHEL 6/7 we also use information from [Desktop Security](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/security_guide/chap-hardening_your_system_with_tools_and_services#sec-Desktop_Security)
## Acknowledgements
This role is mostly based on guides by:
- [Arch Linux wiki, Sysctl hardening](https://wiki.archlinux.org/index.php/Sysctl)
- [NSA: Guide to the Secure Configuration of Red Hat Enterprise Linux 5](http://www.nsa.gov/ia/_files/os/redhat/rhel5-guide-i731.pdf)
- Description: Set to false to disable installing and configuring apt.
- Type: bool
- Required: no
-`os_auditd_action_mail_acct`
- Default: `root`
- Description: If `space_left_action` or `admin_space_left_action` are set to `email`, uses the address or alias to send the email using `/usr/lib/sendmail`. of events created on one system but reported/analyzed on another system.
- Type: str
- Required: no
-`os_auditd_admin_space_left`
- Default: `50`
- Description: This is a numeric value in megabytes that tells the audit daemon when to perform a configurable action because the system is running low on disk space.
- Type: int
- Required: no
-`os_auditd_admin_space_left_action`
- Default: `SUSPEND`
- Description: This parameter tells the system what action to take when the system has detected that it is low on disk space. Valid values are ignore, syslog, rotate, email, exec, suspend, single, and halt.
- Type: str
- Required: no
-`os_auditd_disk_error_action`
- Default: `SUSPEND`
- Description: This parameter tells the system what action to take whenever there is an error detected when writing audit events to disk or rotating logs. Valid values are ignore, syslog, exec, suspend, single, and halt.
- Type: str
- Required: no
-`os_auditd_disk_full_action`
- Default: `SUSPEND`
- Description: This parameter tells the system what action to take when the system has detected that the partition to which log files are written has become full. Valid values are ignore, syslog, rotate, exec, suspend, single, and halt.
- Description: Set to false to disable installing and configuring auditd.
- Type: bool
- Required: no
-`os_auditd_flush`
- Default: `INCREMENTAL`
- Description: Valid values are none, incremental, incremental_async, data, and sync.
- Type: str
- Required: no
-`os_auditd_log_format`
- Default: `RAW`
- Description: Describes how the information should be stored on disk. There are 2 options - raw and enriched.
- Type: str
- Required: no
-`os_auditd_log_group`
- Default: `root`
- Description: specifies the group that is applied to the log file's permissions. The group name can be either numeric or spelled out.
- Type: str
- Required: no
-`os_auditd_max_log_file`
- Default: `6`
- Description: This keyword specifies the maximum file size in megabytes. When this limit is reached, it will trigger a configurable action. The value given must be numeric.
- Type: int
- Required: no
-`os_auditd_max_log_file_action`
- Default: `keep_logs`
- Description: Defines the behaviour of auditd when its log file is filled up. Possible other values are described in the auditd.conf man page. The most common alternative to the default may be `rotate`.
- Description: This keyword specifies the number of log files to keep if `rotate` is given as the max_log_file_action. The value given must be numeric.
- Type: int
- Required: no
-`os_auditd_space_left`
- Default: `75`
- Description: If the free space in the filesystem containing log_file drops below this value, the audit daemon takes the action specified by space_left_action.
- Type: int
- Required: no
-`os_auditd_space_left_action`
- Default: `SYSLOG`
- Description: This parameter tells the system what action to take when the system has detected that it is starting to get low on disk space. Valid values are ignore, syslog, rotate, email, exec, suspend, single, and halt.
- Description: If /etc/subuid exists, the commands useradd and newusers (unless the user already have subordinate group IDs) allocate SUB_GID_COUNT unused group IDs from the range SUB_GID_MIN to SUB_GID_MAX for each new user. See also `os_auth_sub_gid_min` and `os_auth_sub_gid_max`.
- Type: int
- Required: no
-`os_auth_sub_gid_max`
- Default: `600100000`
- Description: maximum number for automatic subordinate gid selection in useradd and newusers.
- Type: int
- Required: no
-`os_auth_sub_gid_min`
- Default: `100000`
- Description: minimum number for automatic subordinate gid selection in useradd and newusers.
- Type: int
- Required: no
-`os_auth_sub_uid_count`
- Default: `65536`
- Description: If /etc/subuid exists, the commands useradd and newusers (unless the user already have subordinate user IDs) allocate SUB_UID_COUNT unused user IDs from the range SUB_UID_MIN to SUB_UID_MAX for each new user. See also `os_auth_sub_uid_min` and `os_auth_sub_uid_max`.
- Type: int
- Required: no
-`os_auth_sub_uid_max`
- Default: `600100000`
- Description: maximum number for automatic subordinate uid selection in useradd and newusers.
- Type: int
- Required: no
-`os_auth_sub_uid_min`
- Default: `100000`
- Description: minimum number for automatic subordinate uid selection in useradd and newusers.
- Type: int
- Required: no
-`os_auth_timeout`
- Default: `60`
- Description: authentication timeout in seconds, so login will exit if this time passes.
- Type: int
- Required: no
-`os_auth_uid_max`
- Default: `60000`
- Description: maximum number for automatic uid selection in useradd.
- Type: int
- Required: no
-`os_auth_uid_min`
- Default: `1000`
- Description: minimum number for automatic uid selection in useradd.
- Type: int
- Required: no
-`os_chfn_restrict`
- Default: `''`
- Description: Indicate which fields are changeable by chfn.
- Description: Single-user mode is intended as a system recovery method, providing a single user root access to the system by providing a boot option at startup. By default, no authentication is performed if single-user mode is selected. To require entry of the root password even if the system is started in single-user mode, set this to false
- Description: true if you want to reduce SUID/SGID bits. There is already a list of items which are searched for configured, but you can also add your own.
- Description: true if you want to remove SUID/SGID bits from any file, that is not explicitly configured in a `blacklist`. This will make every Ansible-run search through the mounted filesystems looking for SUID/SGID bits that are not configured in the default and user blacklist. If it finds an SUID/SGID bit, it will be removed, unless this file is in your `whitelist`.
- Description: Set to false to disable installing and configuring selinux.
- Type: bool
- Required: no
-`os_selinux_policy`
- Default: `targeted`
- Description: Set the SELinux polixy.
- Type: str
- Required: no
-`os_selinux_state`
- Default: `enforcing`
- Description: Set the SELinux state, can be either disabled, permissive, or enforcing.
- Type: str
- Required: no
-`os_sha_crypt_max_rounds`
- Default: `640000`
- Description: Define the number of maximum SHA rounds. With a lot of rounds brute forcing the password is more difficult. But note also that it more CPU resources will be needed to authenticate users. The values must be inside the 1000-999999999 range.
- Type: int
- Required: no
-`os_sha_crypt_min_rounds`
- Default: `640000`
- Description: Define the number of minimum SHA rounds. With a lot of rounds brute forcing the password is more difficult. But note also that it more CPU resources will be needed to authenticate users. The values must be inside the 1000-999999999 range.
- Description: Define which netfilter modules to load
- Type: str
- Required: no
-`ufw_ipt_sysctl`
- Default: `''`
- Description: by default it disables IPT_SYSCTL in /etc/default/ufw. If you want to overwrite /etc/sysctl.conf values using ufw - set it to your sysctl dictionary, for example `/etc/ufw/sysctl.conf`.
- Type: str
- Required: no
-`ufw_manage_builtins`
- Default: `no`
- Description: If this variable is set to 'yes', on stop and reload the built-in chains are flushed. If it is set to 'no', on stop and reload the ufw secondary chains are removed and the ufw primary chains are flushed