Compare commits

...
17 Commits
Author SHA1 Message Date
schurzi 99fe8b6969 Merge pull request #594 from dlouzan/fix/type-cast-variables
fix(os_hardening): cast expected int types in pam tasks
2022-10-27 20:43:17 +02:00
Diego Louzán f8295d5248 fix(os_hardening): cast expected int types in pam tasks
Signed-off-by: Diego Louzán <[email protected]>
2022-10-27 16:50:08 +02:00
dev-sec CI a1f75f877b update changelog 2022-10-26 08:33:13 +00:00
schurzi 901923bac2 Merge pull request #588 from dev-sec/support_more_os
Support more os
2022-10-26 10:13:40 +02:00
Martin Schurz c30ef42355 exclude el9 from vm tests
Signed-off-by: Martin Schurz <[email protected]>
2022-10-25 18:59:11 +02:00
Sebastian Gumprich e2b963d711 change baselines back to master
Signed-off-by: Sebastian Gumprich <[email protected]>
2022-10-25 18:59:11 +02:00
Sebastian Gumprich 414efd6125 use correct centos stream images, try to fix prepare step for debian tests
Signed-off-by: Sebastian Gumprich <[email protected]>
2022-10-25 18:59:11 +02:00
Sebastian Gumprich 87a461fc57 use forked mysql-baseline
Signed-off-by: Sebastian Gumprich <[email protected]>
2022-10-25 18:59:11 +02:00
Sebastian Gumprich dac66f4a88 simplify OS-vars files
Signed-off-by: Sebastian Gumprich <[email protected]>
2022-10-25 18:59:11 +02:00
Sebastian Gumprich 3b8b394f10 add ssh-vars for new OS
Signed-off-by: Sebastian Gumprich <[email protected]>
2022-10-25 18:59:11 +02:00
Sebastian Gumprich b27ffd08b0 add mysql-vars for new OS
Signed-off-by: Sebastian Gumprich <[email protected]>
2022-10-25 18:58:53 +02:00
dev-sec CI 8ee946a537 update changelog 2022-10-24 08:04:42 +00:00
Sebastian Gumprich a176443f22 add support for centos stream 8 and 9, rocky 9
Signed-off-by: Sebastian Gumprich <[email protected]>
2022-10-24 10:03:07 +02:00
Sebastian Gumprich 9d75e3b00e test crypto changes from ssh-baseline
Signed-off-by: Sebastian Gumprich <[email protected]>
2022-10-24 10:03:07 +02:00
schurzi a1b80fe657 adopt all current suggestions from ansible-lint (#592) 2022-10-24 09:42:23 +02:00
dev-sec CI 53be805099 update changelog 2022-10-21 09:07:46 +00:00
donestefan 464d8df8e8 add hardening of root user account(s) (#579) 2022-10-21 11:05:43 +02:00
40 changed files with 179 additions and 282 deletions

No files matched your search

+1
View File
@@ -11,6 +11,7 @@ exclude_paths:
skip_list:
- fqcn-builtins
- name[template]
mock_roles:
- geerlingguy.git
+3
View File
@@ -26,7 +26,10 @@ jobs:
matrix:
molecule_distro:
- centos7
- centosstream8
- centosstream9
- rocky8
- rocky9
- ubuntu1804
- ubuntu2004
- ubuntu2204
+3
View File
@@ -25,7 +25,10 @@ jobs:
matrix:
molecule_distro:
- centos7
- centosstream8
- centosstream9
- rocky8
- rocky9
- ubuntu1804
- ubuntu2004
- ubuntu2204
+3
View File
@@ -25,7 +25,10 @@ jobs:
matrix:
molecule_distro:
- centos7
- centosstream8
- centosstream9
- rocky8
- rocky9
- ubuntu1804
- ubuntu2004
- ubuntu2204
+4 -1
View File
@@ -25,14 +25,17 @@ jobs:
matrix:
molecule_distro:
- centos7
- centos8s
# - centos9s # problems with vagrant
- rocky8
# - rocky9 # problems with vagrant
- ubuntu1804
- ubuntu2004
- ubuntu2204
- debian10
- debian11
# - opensuse42 # opensuse currently cannot get an ip address
# - arch - arch is currently not supported by cinc-auditor
# - arch # arch is currently not supported by cinc-auditor
steps:
- name: Checkout repo
uses: actions/checkout@v3
+3
View File
@@ -25,7 +25,10 @@ jobs:
matrix:
molecule_distro:
- centos7
- centosstream8
- centosstream9
- rocky8
- rocky9
- fedora
- ubuntu1804
- ubuntu2004
@@ -25,7 +25,10 @@ jobs:
matrix:
molecule_distro:
- centos7
- centosstream8
- centosstream9
- rocky8
- rocky9
- fedora
- ubuntu1804
- ubuntu2004
+8 -2
View File
@@ -1,8 +1,12 @@
# Changelog
## [8.2.1](https://github.com/dev-sec/ansible-collection-hardening/tree/8.2.1) (2022-10-20)
## [8.3.0](https://github.com/dev-sec/ansible-collection-hardening/tree/8.3.0) (2022-10-26)
[Full Changelog](https://github.com/dev-sec/ansible-collection-hardening/compare/8.2.0...8.2.1)
[Full Changelog](https://github.com/dev-sec/ansible-collection-hardening/compare/8.2.0...8.3.0)
**Implemented enhancements:**
- add hardening of root user account\(s\) [\#579](https://github.com/dev-sec/ansible-collection-hardening/pull/579) [[os_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/os_hardening)] ([donestefan](https://github.com/donestefan))
**Fixed bugs:**
@@ -16,6 +20,8 @@
**Merged pull requests:**
- adopt all current suggestions from ansible-lint [\#592](https://github.com/dev-sec/ansible-collection-hardening/pull/592) [[mysql_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/mysql_hardening)] [[os_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/os_hardening)] [[ssh_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/ssh_hardening)] ([schurzi](https://github.com/schurzi))
- Support more os [\#588](https://github.com/dev-sec/ansible-collection-hardening/pull/588) [[mysql_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/mysql_hardening)] [[os_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/os_hardening)] [[ssh_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/ssh_hardening)] [[nginx_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/nginx_hardening)] ([rndmh3ro](https://github.com/rndmh3ro))
- run tests only on pushes to master or to PRs [\#581](https://github.com/dev-sec/ansible-collection-hardening/pull/581) [[mysql_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/mysql_hardening)] [[os_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/os_hardening)] [[ssh_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/ssh_hardening)] [[nginx_hardening](https://github.com/dev-sec/ansible-collection-hardening/labels/nginx_hardening)] ([rndmh3ro](https://github.com/rndmh3ro))
## [8.2.0](https://github.com/dev-sec/ansible-collection-hardening/tree/8.2.0) (2022-09-08)
-2
View File
@@ -16,8 +16,6 @@
- name: Run the equivalent of "apt-get update && apt-get upgrade"
apt:
name: "*"
state: latest
update_cache: true
when: ansible_os_family == 'Debian'
+4 -2
View File
@@ -59,12 +59,14 @@
- mysql_version.version.full is version('8.0.3', '>=')
- mysql_distribution == "mysql"
- include: configure.yml
- name: Include tasks for configuration
import_tasks: configure.yml
when: mysql_hardening_enabled | bool
tags:
- mysql_hardening
- include: mysql_secure_installation.yml
- name: Include tasks to secure mysql installation
import_tasks: mysql_secure_installation.yml
when: mysql_hardening_enabled | bool
tags:
- mysql_hardening
@@ -4,7 +4,7 @@
msg: 'ERROR - you have to change default mysql_root_password'
when: mysql_root_password == '-----====>SetR00tPa$$wordH3r3!!!<====-----'
- name: ensure that the root password is present
- name: Ensure that the root password is present
community.mysql.mysql_user:
name: 'root'
host_all: true
@@ -19,14 +19,14 @@
mode: '0400'
tags: my_cnf
- name: ensure that the test database is absent
- name: Ensure that the test database is absent
community.mysql.mysql_db:
name: test
state: absent
login_unix_socket: "{{ login_unix_socket | default(omit) }}"
when: mysql_remove_test_database
- name: ensure that anonymous users are absent
- name: Ensure that anonymous users are absent
community.mysql.mysql_user:
name: ''
state: absent
@@ -34,7 +34,7 @@
login_unix_socket: "{{ login_unix_socket | default(omit) }}"
when: mysql_remove_anonymous_users
- name: ensure that root can only login from localhost
- name: Ensure that root can only login from localhost
community.mysql.mysql_query:
query:
- DELETE
@@ -46,7 +46,7 @@
login_unix_socket: "{{ login_unix_socket | default(omit) }}"
when: mysql_remove_remote_root
- name: get all users that have no authentication_string on MySQL version >= 5.7.6 or Mariadb version >= 10.4.0
- name: Get all users that have no authentication_string on MySQL version >= 5.7.6 or Mariadb version >= 10.4.0
community.mysql.mysql_query:
query:
- SELECT GROUP_CONCAT(QUOTE(USER), '@', QUOTE(HOST) SEPARATOR ', ') AS users
@@ -62,7 +62,7 @@
- (mysql_distribution == "mysql" and mysql_version.version.full is version('5.7.6', '>=')) or
(mysql_distribution == "mariadb" and mysql_version.version.full is version('10.4.0', '>='))
- name: get all users that have no password or authentication_string on MySQL version < 5.7.6 or Mariadb version < 10.4.0
- name: Get all users that have no password or authentication_string on MySQL version < 5.7.6 or Mariadb version < 10.4.0
community.mysql.mysql_query:
query:
- SELECT GROUP_CONCAT(QUOTE(USER), '@', QUOTE(HOST) SEPARATOR ', ') AS users
@@ -80,21 +80,21 @@
- (mysql_distribution == "mysql" and mysql_version.version.full is version('5.7.6', '<')) or
(mysql_distribution == "mariadb" and mysql_version.version.full is version('10.4.0', '<'))
- name: create a fact for users without password or authentication_string
- name: Create a fact for users without password or authentication_string
set_fact:
users_wo_auth: "{{ mysql_users_wo_passwords_or_auth_string.query_result.0.0 | community.general.json_query('users') }}"
when:
- mysql_users_wo_passwords_or_auth_string.query_result is defined
- mysql_users_wo_passwords_or_auth_string.query_result != "" # noqa empty-string-compare
- name: create a fact for users without password
- name: Create a fact for users without password
set_fact:
users_wo_auth: "{{ mysql_users_wo_passwords.query_result.0.0 | community.general.json_query('users') }}"
when:
- mysql_users_wo_passwords.query_result is defined
- mysql_users_wo_passwords.query_result != "" # noqa empty-string-compare
- name: ensure that there are no users without password or authentication_string
- name: Ensure that there are no users without password or authentication_string
community.mysql.mysql_query:
query:
- "DROP USER {{ users_wo_auth }}"
-9
View File
@@ -1,9 +0,0 @@
---
mysql_daemon: mariadb
mysql_hardening_mysql_conf_file: '/etc/my.cnf'
mysql_hardening_mysql_confd_dir: '/etc/my.cnf.d'
mysql_cnf_owner: 'root' # owner of /etc/mysql/*.cnf files
mysql_cnf_group: 'mysql' # owner of /etc/mysql/*.cnf files
mysql_hardening_group: 'mysql'
-9
View File
@@ -1,9 +0,0 @@
---
mysql_daemon: mariadb
mysql_hardening_mysql_conf_file: '/etc/my.cnf'
mysql_hardening_mysql_confd_dir: '/etc/my.cnf.d'
mysql_cnf_owner: 'root' # owner of /etc/mysql/*.cnf files
mysql_cnf_group: 'mysql' # owner of /etc/mysql/*.cnf files
mysql_hardening_group: 'mysql'
-10
View File
@@ -1,10 +0,0 @@
---
mysql_daemon: mysql
mysql_hardening_mysql_conf_file: '/etc/mysql/my.cnf'
mysql_hardening_mysql_confd_dir: '/etc/mysql/conf.d'
mysql_cnf_owner: 'root' # owner of /etc/mysql/*.cnf files
mysql_cnf_group: 'mysql' # owner of /etc/mysql/*.cnf files
mysql_hardening_group: 'adm'
-10
View File
@@ -1,10 +0,0 @@
---
mysql_daemon: mysql
mysql_hardening_mysql_conf_file: '/etc/mysql/my.cnf'
mysql_hardening_mysql_confd_dir: '/etc/mysql/conf.d'
mysql_cnf_owner: 'root' # owner of /etc/mysql/*.cnf files
mysql_cnf_group: 'mysql' # owner of /etc/mysql/*.cnf files
mysql_hardening_group: 'adm'
-10
View File
@@ -1,10 +0,0 @@
---
mysql_daemon: mysql
mysql_hardening_mysql_conf_file: '/etc/mysql/my.cnf'
mysql_hardening_mysql_confd_dir: '/etc/mysql/conf.d'
mysql_cnf_owner: 'root' # owner of /etc/mysql/*.cnf files
mysql_cnf_group: 'mysql' # owner of /etc/mysql/*.cnf files
mysql_hardening_group: 'adm'
+10 -1
View File
@@ -230,6 +230,15 @@ We know that this is the case on Raspberry Pi.
- `os_ignore_home_folder_users`
- Default: `lost+found`
- Description: specify user home folders in `/home` that shouldn't be chmodded to 700
- `os_chmod_rootuser_home_folder`
- Default: `true`
- Description: Set to `false` to disable "chmod 700" of root's home folder
- `os_rootuser_pw_ageing`
- Default: `false`
- Description: Set to true to enforce password age settings for root user(s)
- `os_remove_additional_root_users`
- Default: `false`
- Description: When enabled and there are multiple users with UID=0, only "root" will be kept. Others will be deleted.
- `os_cron_enabled`
- Default: `true`
- Description: Set to false to disable installing and configuring cron.
@@ -241,7 +250,7 @@ We know that this is the case on Raspberry Pi.
- Description: Set to false to disable installing and configuring limits.
- `os_login_defs_enabled`
- Default: `true`
- Description: Set to false to disable installing and configuring login_defs.
- Description: Set to false to disable installing and configuring login_defs for newly created users.
- `os_minimize_access_enabled`
- Default: `true`
- Description: Set to false to disable installing and configuring minimize_access.
+10 -2
View File
@@ -15,13 +15,21 @@ os_auth_root_ttys: [console, tty1, tty2, tty3, tty4, tty5, tty6]
os_chfn_restrict: ''
# Set to false to disable chmod /home folders to 700
# Set to false to disable chmod userhome folders to 700
os_chmod_rootuser_home_folder: true
os_chmod_home_folders: true
# May contain: change_user
os_security_users_allow: []
# Specify user home folders in /home that shouldn't be chmodded to 700
os_ignore_home_folder_users: ['lost+found']
# Set to false to disable password age enforcement on existing users
os_rootuser_pw_ageing: false
# When enabled and there are multiple users with UID=0, only "root" will be kept. Others will be deleted.
os_remove_additional_root_users: false
# Specify system accounts whose login should not be disabled and password not changed
os_ignore_users: ['vagrant', 'kitchen']
os_security_kernel_enable_module_loading: true
@@ -338,7 +346,7 @@ os_ctrlaltdel_disabled: false
# Set to false to disable installing and configuring limits.
os_limits_enabled: true
# Set to false to disable installing and configuring login_defs.
# Set to false to disable installing and configuring login_defs for newly created users.
os_login_defs_enabled: true
# Set to false to disable installing and configuring minimize_access.
+1 -1
View File
@@ -2,7 +2,7 @@
- name: Update-initramfs
command: 'update-initramfs -u'
- name: restart-auditd
- name: Restart auditd
command:
cmd: 'service auditd restart' # rhel: see: https://access.redhat.com/solutions/2664811
warn: false # sadly 'service' module fails in that case also by using 'use: service'
+1 -1
View File
@@ -12,5 +12,5 @@
owner: 'root'
group: 'root'
mode: '0640'
notify: 'restart-auditd'
notify: Restart auditd
tags: auditd
+36 -18
View File
@@ -22,79 +22,97 @@
with_dict: '{{ os_vars }}'
tags: always
- import_tasks: auditd.yml
- name: Import tasks for auditd
import_tasks: auditd.yml
tags: auditd
when: os_auditd_enabled | bool
- import_tasks: cron.yml
- name: Import tasks for cron
import_tasks: cron.yml
tags: cron
when: os_cron_enabled | bool
- import_tasks: ctrlaltdel.yml
- name: Import tasks to configure ctrl+alt+del
import_tasks: ctrlaltdel.yml
tags: ctrlaltdel
when: os_ctrlaltdel_disabled | bool
- import_tasks: limits.yml
- name: Import tasks to configure limits
import_tasks: limits.yml
tags: limits
when: os_limits_enabled | bool
- import_tasks: login_defs.yml
- name: Import tasks to configure login_defs
import_tasks: login_defs.yml
tags: login_defs
when: os_login_defs_enabled | bool
- import_tasks: minimize_access.yml
- name: Import tasks to minimize access permissions
import_tasks: minimize_access.yml
tags: minimize_access
when: os_minimize_access_enabled | bool
- import_tasks: pam.yml
- name: Import tasks to configure PAM
import_tasks: pam.yml
tags: pam
when: os_pam_enabled | bool
- import_tasks: modprobe.yml
- name: Import tasks to configure modules
import_tasks: modprobe.yml
tags: modprobe
when: os_modprobe_enabled | bool
- import_tasks: profile.yml
- name: Import tasks to configure profile
import_tasks: profile.yml
tags: profile
when: os_profile_enabled | bool
- import_tasks: securetty.yml
- name: Import tasks to configure securetty
import_tasks: securetty.yml
tags: securetty
when: os_securetty_enabled | bool
- import_tasks: suid_sgid.yml
- name: Import tasks to set suid and sgid
import_tasks: suid_sgid.yml
when: os_security_suid_sgid_enforce | bool
tags: suid_sgid
- import_tasks: sysctl.yml
- name: Import tasks to configure sysctl
import_tasks: sysctl.yml
tags: sysctl
when: os_sysctl_enabled | bool
- import_tasks: user_accounts.yml
- name: Import tasks to harden user accounts
import_tasks: user_accounts.yml
tags: user_accounts
when: os_user_accounts_enabled | bool
- import_tasks: rhosts.yml
- name: Import tasks to configure rhosts
import_tasks: rhosts.yml
tags: rhosts
when: os_rhosts_enabled | bool
- import_tasks: netrc.yml
- name: Import tasks to configure netrc
import_tasks: netrc.yml
tags: netrc
when: os_netrc_enabled | bool
- import_tasks: yum.yml
- name: Import tasks to configure yum
import_tasks: yum.yml
tags: yum
when:
- ansible_facts.os_family == 'RedHat'
- os_yum_enabled | bool
- import_tasks: apt.yml
- name: Import tasks to configure apt
import_tasks: apt.yml
tags: apt
when:
- ansible_facts.os_family == 'Debian'
- os_apt_enabled | bool
- import_tasks: selinux.yml
- name: Import tasks to configure selinux
import_tasks: selinux.yml
tags: selinux
when:
- ansible_facts.selinux.status == 'enabled'
+6 -7
View File
@@ -1,5 +1,6 @@
---
- name: disable coredumps
- name: Disable coredumps
when: not os_security_kernel_enable_core_dump | bool
block:
- name: Create limits.d-directory if it does not exist | sysctl-31a, sysctl-31b
file:
@@ -28,7 +29,7 @@
modification_time: preserve
access_time: preserve
- name: create coredump.conf.d-directory if it does not exist
- name: Create coredump.conf.d-directory if it does not exist
file:
path: '/etc/systemd/coredump.conf.d'
owner: root
@@ -37,7 +38,7 @@
state: directory
when: ansible_service_mgr == "systemd"
- name: create custom.conf for disabling coredumps
- name: Create custom.conf for disabling coredumps
template:
src: 'etc/systemd/coredump.conf.d/coredumps.conf.j2'
dest: '/etc/systemd/coredump.conf.d/custom.conf'
@@ -47,9 +48,8 @@
when: ansible_service_mgr == "systemd"
notify: Reload systemd
when: not os_security_kernel_enable_core_dump | bool
- name: enable coredumps
- name: Enable coredumps
when: os_security_kernel_enable_core_dump | bool
block:
- name: Remove coredump.conf.d directory with files
file:
@@ -62,4 +62,3 @@
file:
path: /etc/security/limits.d/10.hardcore.conf
state: absent
when: os_security_kernel_enable_core_dump | bool
+2 -1
View File
@@ -1,5 +1,6 @@
---
- include_tasks: hardening.yml
- name: Include hardening tasks
include_tasks: hardening.yml
when: os_hardening_enabled | bool
tags:
- always
+4 -2
View File
@@ -17,11 +17,13 @@
when:
- ansible_facts.os_family != 'Archlinux'
- import_tasks: pam_debian.yml
- name: Import tasks for Debian PAM
import_tasks: pam_debian.yml
when:
- ansible_facts.os_family == 'Debian'
- import_tasks: pam_rhel.yml
- name: Import tasks for RedHat PAM
import_tasks: pam_rhel.yml
when:
- ansible_facts.os_family == 'RedHat'
+14 -14
View File
@@ -22,9 +22,12 @@
name: 'libpam-modules'
state: 'present'
when:
- os_auth_retries > 0
- os_auth_retries|int > 0
- name: Manage tally on Debian stable
when:
- "'libpam-modules' in ansible_facts.packages"
- "ansible_facts.packages['libpam-modules'][0].version is version('1.4.0', '<')"
block:
- name: Configure tally2
template:
@@ -34,26 +37,26 @@
owner: 'root'
group: 'root'
when:
- os_auth_retries > 0
- os_auth_retries|int > 0
- name: Delete tally2 when retries is 0
file:
path: '{{ tally2_path }}'
state: 'absent'
when:
- os_auth_retries == 0
when:
- "'libpam-modules' in ansible_facts.packages"
- "ansible_facts.packages['libpam-modules'][0].version is version('1.4.0', '<')"
- os_auth_retries|int == 0
- name: Manage tally/faillock on Debian unstable
when:
- "'libpam-modules' in ansible_facts.packages"
- "ansible_facts.packages['libpam-modules'][0].version is version('1.4.0', '>=')"
block:
- name: Delete tally2
file:
path: '{{ tally2_path }}'
state: 'absent'
- name: create tally directory
- name: Create tally directory
file:
path: '/var/run/faillock'
state: 'directory'
@@ -77,7 +80,7 @@
owner: 'root'
group: 'root'
when:
- os_auth_retries > 0
- os_auth_retries|int > 0
- name: Configure faillock pam authfail
template:
@@ -87,24 +90,21 @@
owner: 'root'
group: 'root'
when:
- os_auth_retries > 0
- os_auth_retries|int > 0
- name: Delete faillock when retries is 0
file:
path: '/usr/share/pam-configs/faillock'
state: 'absent'
when:
- os_auth_retries == 0
- os_auth_retries|int == 0
- name: Delete faillock authfail when retries is 0
file:
path: '/usr/share/pam-configs/faillock_authfail'
state: 'absent'
when:
- os_auth_retries == 0
when:
- "'libpam-modules' in ansible_facts.packages"
- "ansible_facts.packages['libpam-modules'][0].version is version('1.4.0', '>=')"
- os_auth_retries|int == 0
- name: Update pam on Debian systems
command: 'pam-auth-update --package'
+1 -1
View File
@@ -42,6 +42,7 @@
register: initramfs
- name: Change sysctls
when: ansible_virtualization_type not in ['docker', 'lxc', 'openvz']
block:
- name: Create a combined sysctl-dict if os-dependent sysctls are defined
set_fact:
@@ -69,7 +70,6 @@
ignoreerrors: true
with_dict: '{{ sysctl_config }}'
when: item.key not in sysctl_unsupported_entries | default()
when: ansible_virtualization_type not in ['docker', 'lxc', 'openvz']
- name: Apply ufw defaults
template:
+44 -3
View File
@@ -1,4 +1,45 @@
---
- name: Read local linux user database
getent:
database: passwd
# creates a dict for each user containing UID/HOMEDIR etc...
when: getent_passwd is undefined # skip this task if "getent" has run before
- name: Extract root account(s) from local user database
loop: "{{ getent_passwd.keys() | list }}"
when:
- getent_passwd[item][1]|int == 0
set_fact:
root_users: "{{ root_users | default([]) + [item] }}"
- name: Set ownership of root user home directory(s) to 0700
file:
mode: 0700
owner: "{{ item }}"
path: "{{ getent_passwd[item][4] }}"
state: directory
loop: "{{ root_users }}"
when:
- os_chmod_rootuser_home_folder | bool
- name: Set password ageing for root user(s)
user:
name: "{{ item }}"
password_expire_min: "{{ os_auth_pw_min_age }}"
password_expire_max: "{{ os_auth_pw_max_age }}"
loop: "{{ root_users }}"
when: os_rootuser_pw_ageing|bool
- name: Remove additional users with UID=0 ("root" user is not touched)
user:
name: "{{ item }}"
state: absent
loop: "{{ root_users }}"
when:
- os_remove_additional_root_users|bool
- root_users|length > 1
- item != "root"
- name: Get UID_MIN from login.defs
shell: awk '/^\s*UID_MIN\s*([0-9]*).*?$/ {print $2}' /etc/login.defs
args:
@@ -25,7 +66,7 @@
when: uid_max is not defined
- name: Get all system accounts
command: awk -F'':'' '{ if ( $3 <= {{ uid_max|quote }} ) print $1}' /etc/passwd
command: awk -F'':'' '{ if ( $3 <= {{ uid_max | quote }} ) print $1}' /etc/passwd
args:
removes: /etc/passwd
changed_when: false
@@ -46,7 +87,7 @@
with_community.general.flattened:
- '{{ sys_accs_cond | default([]) | difference(os_ignore_users) | list }}'
- name: get all home directories in /home, but skip ignored users
- name: Get all home directories in /home, but skip ignored users
find:
paths: /home/
recurse: false
@@ -55,7 +96,7 @@
register: home_directories
when: os_chmod_home_folders | bool
- name: set ownership of /home directories to 0700
- name: Set ownership of /home directories to 0700
file:
mode: 0700
path: "{{ item.path }}"
@@ -4,7 +4,7 @@
#%PAM-1.0
auth required pam_env.so
auth required pam_faildelay.so delay=2000000
{% if os_auth_retries > 0 %}
{% if os_auth_retries|int > 0 %}
auth required pam_faillock.so preauth silent audit even_deny_root deny={{ os_auth_retries }} unlock_time={{ os_auth_lockout_time }}
{% endif %}
{% if (os_auth_pam_sssd_enable | bool) %}
@@ -16,12 +16,12 @@ auth sufficient pam_unix.so nullok try_first_pass
auth [default=1 ignore=ignore success=ok] pam_succeed_if.so uid >= 1000 quiet
auth sufficient pam_sss.so forward_pass
{% endif %}
{% if os_auth_retries > 0 %}
{% if os_auth_retries|int > 0 %}
auth required pam_faillock.so authfail audit even_deny_root deny={{ os_auth_retries }} unlock_time={{ os_auth_lockout_time }}
{% endif %}
auth required pam_deny.so
{% if os_auth_retries > 0 %}
{% if os_auth_retries|int > 0 %}
account required pam_faillock.so
{% endif %}
account required pam_unix.so
+1 -1
View File
@@ -33,7 +33,7 @@ os_auth_sub_gid_min: 100000
os_auth_sub_gid_max: 600100000
os_auth_sub_gid_count: 65536
os_auth_pam_sssd_enable: false
os_auth_pam_sssd_enable: true
# defaults for useradd
os_useradd_mail_dir: /var/spool/mail
-45
View File
@@ -1,45 +0,0 @@
---
os_packages_pam_ccreds: 'pam_ccreds'
os_nologin_shell_path: '/sbin/nologin'
# Different distros use different standards for /etc/shadow perms, e.g.
# RHEL derivatives use root:root 0000, whereas Debian-based use root:shadow 0640.
# You must provide key/value pairs for owner, group, and mode if overriding.
os_shadow_perms:
owner: root
group: root
mode: '0000'
os_passwd_perms:
owner: root
group: root
mode: '0644'
os_env_umask: '077'
os_auth_uid_min: 1000
os_auth_uid_max: 60000
os_auth_gid_min: 1000
os_auth_gid_max: 60000
os_auth_sys_uid_min: 201
os_auth_sys_uid_max: 999
os_auth_sys_gid_min: 201
os_auth_sys_gid_max: 999
os_auth_sub_uid_min: 100000
os_auth_sub_uid_max: 600100000
os_auth_sub_uid_count: 65536
os_auth_sub_gid_min: 100000
os_auth_sub_gid_max: 600100000
os_auth_sub_gid_count: 65536
os_auth_pam_sssd_enable: true
# defaults for useradd
os_useradd_mail_dir: /var/spool/mail
os_useradd_create_home: true
modprobe_package: 'module-init-tools'
auditd_package: 'audit'
hidepid_option: '2' # allowed values: 0, 1, 2
-45
View File
@@ -1,45 +0,0 @@
---
os_packages_pam_ccreds: 'pam_ccreds'
os_nologin_shell_path: '/sbin/nologin'
# Different distros use different standards for /etc/shadow perms, e.g.
# RHEL derivatives use root:root 0000, whereas Debian-based use root:shadow 0640.
# You must provide key/value pairs for owner, group, and mode if overriding.
os_shadow_perms:
owner: root
group: root
mode: '0000'
os_passwd_perms:
owner: root
group: root
mode: '0644'
os_env_umask: '077'
os_auth_uid_min: 1000
os_auth_uid_max: 60000
os_auth_gid_min: 1000
os_auth_gid_max: 60000
os_auth_sys_uid_min: 201
os_auth_sys_uid_max: 999
os_auth_sys_gid_min: 201
os_auth_sys_gid_max: 999
os_auth_sub_uid_min: 100000
os_auth_sub_uid_max: 600100000
os_auth_sub_uid_count: 65536
os_auth_sub_gid_min: 100000
os_auth_sub_gid_max: 600100000
os_auth_sub_gid_count: 65536
os_auth_pam_sssd_enable: true
# defaults for useradd
os_useradd_mail_dir: /var/spool/mail
os_useradd_create_home: true
modprobe_package: 'module-init-tools'
auditd_package: 'audit'
hidepid_option: '2' # allowed values: 0, 1, 2
+2 -1
View File
@@ -1,5 +1,6 @@
---
- include_tasks: hardening.yml
- name: Include hardening tasks
include_tasks: hardening.yml
args:
apply:
become: true
+1 -1
View File
@@ -24,7 +24,7 @@
# The following tasks only get executed when selinux is in state enforcing,
# UsePam is 'no' and the ssh_password module is not installed. See this issue for
# more info: https://github.com/hardening-io/ansible-ssh-hardening/issues/23
- name: run selinux tasks
- name: Run selinux tasks
when:
- not (ssh_use_pam | bool)
- ('ssh_password' not in ssh_password_module.stdout)
-23
View File
@@ -1,23 +0,0 @@
---
sshd_path: /usr/sbin/sshd
ssh_host_keys_dir: '/etc/ssh'
sshd_service_name: sshd
ssh_owner: root
ssh_group: root
ssh_host_keys_owner: 'root'
ssh_host_keys_group: 'ssh_keys'
ssh_selinux_packages:
- policycoreutils-python-utils
- checkpolicy
# true if SSH support Kerberos
ssh_kerberos_support: true
# true if SSH has PAM support
ssh_pam_support: true
sshd_moduli_file: '/etc/ssh/moduli'
# disable CRYPTO_POLICY to take settings from sshd configuration
# see: https://access.redhat.com/solutions/4410591
sshd_disable_crypto_policy: true
-23
View File
@@ -1,23 +0,0 @@
---
sshd_path: /usr/sbin/sshd
ssh_host_keys_dir: '/etc/ssh'
sshd_service_name: sshd
ssh_owner: root
ssh_group: root
ssh_host_keys_owner: 'root'
ssh_host_keys_group: 'ssh_keys'
ssh_selinux_packages:
- policycoreutils-python-utils
- checkpolicy
# true if SSH support Kerberos
ssh_kerberos_support: true
# true if SSH has PAM support
ssh_pam_support: true
sshd_moduli_file: '/etc/ssh/moduli'
# disable CRYPTO_POLICY to take settings from sshd configuration
# see: https://access.redhat.com/solutions/4410591
sshd_disable_crypto_policy: true
+1 -1
View File
@@ -7,7 +7,7 @@ ssh_group: root
ssh_host_keys_owner: 'root'
ssh_host_keys_group: 'ssh_keys'
ssh_selinux_packages:
- policycoreutils-python
- policycoreutils-python-utils
- checkpolicy
# true if SSH support Kerberos
@@ -7,7 +7,7 @@ ssh_group: root
ssh_host_keys_owner: 'root'
ssh_host_keys_group: 'ssh_keys'
ssh_selinux_packages:
- python3-policycoreutils
- policycoreutils-python
- checkpolicy
# true if SSH support Kerberos
-23
View File
@@ -1,23 +0,0 @@
---
sshd_path: /usr/sbin/sshd
ssh_host_keys_dir: '/etc/ssh'
sshd_service_name: sshd
ssh_owner: root
ssh_group: root
ssh_host_keys_owner: 'root'
ssh_host_keys_group: 'ssh_keys'
ssh_selinux_packages:
- python3-policycoreutils
- checkpolicy
# true if SSH support Kerberos
ssh_kerberos_support: true
# true if SSH has PAM support
ssh_pam_support: true
sshd_moduli_file: '/etc/ssh/moduli'
# disable CRYPTO_POLICY to take settings from sshd configuration
# see: https://access.redhat.com/solutions/4410591
sshd_disable_crypto_policy: true