Skip to content

Commit 826c883

Browse files
authored
Merge branch 'master' into fix_pam
2 parents 7a6a0bf + e3273a8 commit 826c883

File tree

17 files changed

+2769
-733
lines changed

17 files changed

+2769
-733
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## [8.9.0](https://github.com/dev-sec/ansible-collection-hardening/tree/8.9.0) (2023-08-07)
4+
5+
[Full Changelog](https://github.com/dev-sec/ansible-collection-hardening/compare/8.8.0...8.9.0)
6+
7+
**Breaking changes:**
8+
9+
- add role argument spec for os, ssh, mysql [\#687](https://github.com/dev-sec/ansible-collection-hardening/pull/687) [[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))
10+
311
## [8.8.0](https://github.com/dev-sec/ansible-collection-hardening/tree/8.8.0) (2023-08-04)
412

513
[Full Changelog](https://github.com/dev-sec/ansible-collection-hardening/compare/8.7.0...8.8.0)

galaxy.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace: devsec
22
name: hardening
3-
version: 8.7.0
3+
version: 8.8.0
44
readme: README.md
55
authors:
66
- dev-sec <hello@dev-sec.io>

molecule/os_hardening_vm/verify.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
no_proxy: "{{ lookup('env', 'no_proxy') | default(omit) }}"
99
tasks:
1010

11-
- name: include PAM tests
12-
include_tasks: verify_tasks/pam.yml
13-
when: ansible_facts.distribution in ['Debian', 'Ubuntu'] or ansible_facts.os_family == 'RedHat'
11+
# temp. disabled - https://github.com/dev-sec/ansible-collection-hardening/issues/690
12+
# - name: include PAM tests
13+
# include_tasks: verify_tasks/pam.yml
14+
# when: ansible_facts.distribution in ['Debian', 'Ubuntu'] or ansible_facts.os_family == 'RedHat'
1415

1516
- name: include YUM tests
1617
include_tasks: verify_tasks/yum.yml

molecule/ssh_hardening_custom_tests/converge.yml

-5
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@
2020
- path: "/etc/ssh/auth_principals/root"
2121
principals:
2222
- "root"
23-
owner: "{{ ssh_owner }}"
24-
group: "{{ ssh_group }}"
25-
directoryowner: "{{ ssh_owner }}"
26-
directorygroup: "{{ ssh_group }}"
27-
directorymode: "0700"
2823
network_ipv6_enable: true
2924
ssh_allow_tcp_forwarding: 'yes'
3025
ssh_gateway_ports: true

roles/mysql_hardening/README.md

+104-48
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# devsec.mysql_hardening
22

3-
![devsec.mysql_hardening](https://github.com/dev-sec/ansible-os-hardening/workflows/devsec.mysql_hardening/badge.svg)
3+
![devsec.mysql_hardening](https://github.com/dev-sec/ansible-collection-hardening/workflows/devsec.mysql_hardening/badge.svg)
44

55
## Description
66

@@ -12,74 +12,130 @@ It configures:
1212
- Removes anonymous users, users without a password or authentication_string and test databases
1313
- various hardening options inside MySQL
1414

15+
Changes of options `log_error` or `datadir` in `mysql_hardening_options` will not be checked for correct permissions. Please change/set `log_error` or `datadir` with the installation role of MySQL before running this role, or you can run this role twice.
16+
17+
Further information is available at [Deutsche Telekom (German)](http://www.telekom.com/static/-/155996/7/technische-sicherheitsanforderungen-si) and [Symantec](http://www.symantec.com/connect/articles/securing-mysql-step-step)
18+
1519
## Requirements
1620

17-
- Ansible 2.9.0
18-
- An existing MySQL installation
21+
- An existing installation of MySQL or MariaDB.
1922
- python-jmespath on the ansible host
2023

21-
### Example playbook
24+
<!-- BEGIN_ANSIBLE_DOCS -->
2225

23-
```yml
24-
- hosts: localhost
25-
collections:
26-
- devsec.hardening
27-
roles:
28-
- mysql_hardening
29-
```
26+
## Supported Operating Systems
3027

31-
This role expects an existing installation of MySQL or MariaDB. Changes of options `log_error` or `datadir` in `mysql_hardening_options` will not be checked for correct permissions. Please change/set `log_error` or `datadir` with the installation role of MySQL before running this role, or you can run this role twice.
32-
Please ensure that the following variables are set accordingly:
33-
34-
- `mysql_hardening_enabled: yes` role is enabled by default and can be disabled without removing it from a playbook. You can use conditional variable, for example: `mysql_hardening_enabled: "{{ true if mysql_enabled else false }}"`
35-
- `mysql_hardening_user: 'mysql'` The user that mysql runs as.
36-
- `mysql_hardening_mysql_hardening_conf_file: '/etc/mysql/conf.d/hardening.cnf'` The path to the configuration file where the hardening will be performed
37-
- _deprecated: `mysql_datadir: '/var/lib/mysql'` The MySQL data directory_
38-
- `mysql_datadir` is no longer necessary, as MySQL data directory is automatically taken from `mysql_info`. But it can still be defined and will also be checked for correct permissions.
28+
| Platform | Versions |
29+
| -------- | -------------------- |
30+
| EL | 7, 8, 9 |
31+
| Ubuntu | bionic, focal, jammy |
32+
| Debian | bullseye, buster |
33+
| Amazon | |
34+
| opensuse | |
3935

4036
## Role Variables
4137

38+
- `mysql_daemon_enabled`
39+
- Default: `true`
40+
- Description: Whether to enable the MySQL-service so it starts on boot
41+
- Type: bool
42+
- Required: no
4243
- `mysql_hardening_chroot`
43-
- Default: ""
44+
- Default: ``
4445
- Description: [chroot](http://dev.mysql.com/doc/refman/5.7/en/server-options.html#option_mysqld_chroot)
46+
- Type: str
47+
- Required: no
48+
- `mysql_hardening_chroot.automatic-sp-privileges`
49+
- Default: `0`
50+
- Description: [automatic_sp_privileges](https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_automatic_sp_privileges)
51+
- Type: int
52+
- Required: no
53+
- `mysql_hardening_enabled`
54+
- Default: `true`
55+
- Description: Whether to run the hardening
56+
- Type: bool
57+
- Required: no
58+
- `mysql_hardening_options.allow-suspicious-udfs`
59+
- Default: `0`
60+
- Description: [allow-suspicious-udfs](https://dev.mysql.com/doc/refman/5.7/en/server-options.html#option_mysqld_allow-suspicious-udfs)
61+
- Type: int
62+
- Required: no
63+
- `mysql_hardening_options.local-infile`
64+
- Default: `0`
65+
- Description: [local-infile](http://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_local_infile)
66+
- Type: int
67+
- Required: no
4568
- `mysql_hardening_options.safe-user-create`
46-
- Default: 1
69+
- Default: `1`
4770
- Description: [safe-user-create](http://dev.mysql.com/doc/refman/5.7/en/server-options.html#option_mysqld_safe-user-create)
71+
- Type: int
72+
- Required: no
4873
- `mysql_hardening_options.secure-auth`
49-
- Default: 1
74+
- Default: `1`
5075
- Description: [secure-auth](http://dev.mysql.com/doc/refman/5.7/en/server-options.html#option_mysqld_secure-auth)
76+
- Type: int
77+
- Required: no
78+
- `mysql_hardening_options.secure-file-priv`
79+
- Default: `/tmp`
80+
- Description: [secure-file-priv](https://dev.mysql.com/doc/refman/5.7/en/server-options.html#option_mysqld_secure-file-priv)
81+
- Type: str
82+
- Required: no
5183
- `mysql_hardening_options.skip-symbolic-links`
52-
- Default: 1
84+
- Default: `1`
5385
- Description: [skip-symbolic-links](http://dev.mysql.com/doc/refman/5.7/en/server-options.html#option_mysqld_symbolic-links)
86+
- Type: int
87+
- Required: no
88+
- `mysql_hardening_restart_mysql`
89+
- Default: `true`
90+
- Description: Restart mysql after running this role
91+
- Type: bool
92+
- Required: no
5493
- `mysql_hardening_skip_grant_tables:`
55-
- Default: false
94+
- Default: `false`
5695
- Description: [skip-grant-tables](https://dev.mysql.com/doc/refman/5.7/en/server-options.html#option_mysqld_skip-grant-tables)
96+
- Type: bool
97+
- Required: no
5798
- `mysql_hardening_skip_show_database`
58-
- Default: 1
99+
- Default: `1`
59100
- Description: [skip-show-database](http://dev.mysql.com/doc/refman/5.7/en/server-options.html#option_mysqld_skip-show-database)
60-
- `mysql_hardening_options.local-infile`
61-
- Default: 0
62-
- Description: [local-infile](http://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_local_infile)
63-
- `mysql_hardening_options.allow-suspicious-udfs`
64-
- Default: 0
65-
- Description: [allow-suspicious-udfs](https://dev.mysql.com/doc/refman/5.7/en/server-options.html#option_mysqld_allow-suspicious-udfs)
66-
- `mysql_hardening_chroot.automatic-sp-privileges`
67-
- Default: 0
68-
- Description: [automatic_sp_privileges](https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_automatic_sp_privileges)
69-
- `mysql_hardening_options.secure-file-priv`
70-
- Default: /tmp
71-
- Description: [secure-file-priv](https://dev.mysql.com/doc/refman/5.7/en/server-options.html#option_mysqld_secure-file-priv)
72-
- `mysql_allow_remote_root`
73-
- Default: false
74-
- Description: delete remote root users
101+
- Type: int
102+
- Required: no
75103
- `mysql_remove_anonymous_users`
76-
- Default: true
77-
- Description: remove users without authentication
104+
- Default: `true`
105+
- Description: Set to `false` to keep users without authentication
106+
- Type: bool
107+
- Required: no
108+
- `mysql_remove_remote_root`
109+
- Default: `true`
110+
- Description: If `true`, root can only connect from localhost. Set to `false` to not remove remote root users.
111+
- Type: bool
112+
- Required: no
78113
- `mysql_remove_test_database`
79-
- Default: true
80-
- Description: remove test database
81-
- `mysql_hardening_restart_mysql`
82-
- Default: true
83-
- Description: Restart mysql after running this role
114+
- Default: `true`
115+
- Description: Set to `false` to keep the test database
116+
- Type: bool
117+
- Required: no
118+
- `mysql_root_password`
119+
- Default: `-----====>SetR00tPa$$wordH3r3!!!<====-----`
120+
- Description: The default password. Please change or overwrite it
121+
- Type: str
122+
- Required: no
123+
- `mysql_user_home`
124+
- Default: `{{ ansible_env.HOME }}`
125+
- Description: The path where the `.my.cnf` will be stored
126+
- Type: str
127+
- Required: no
84128

85-
Further information is available at [Deutsche Telekom (German)](http://www.telekom.com/static/-/155996/7/technische-sicherheitsanforderungen-si) and [Symantec](http://www.symantec.com/connect/articles/securing-mysql-step-step)
129+
## Dependencies
130+
131+
None.
132+
133+
## Example Playbook
134+
135+
```
136+
- hosts: all
137+
roles:
138+
- name: devsec.hardening.mysql_hardening
139+
```
140+
141+
<!-- END_ANSIBLE_DOCS -->

roles/mysql_hardening/defaults/main.yml

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ mysql_daemon_enabled: true
66

77
mysql_hardening_restart_mysql: true
88

9-
# general configuration
10-
mysql_hardening_mysql_hardening_conf_file: "{{ mysql_hardening_mysql_confd_dir }}/hardening.cnf"
119
# You have to change this to your own strong enough mysql root password
1210
mysql_root_password: "-----====>SetR00tPa$$wordH3r3!!!<====-----"
1311
# There .my.cnf with mysql root credentials will be installed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
argument_specs:
3+
main:
4+
short_description: The main entry point for the mysql hardening role.
5+
version_added: 8.8.0
6+
options:
7+
mysql_hardening_chroot:
8+
default: ''
9+
type: str
10+
description: '[chroot](http://dev.mysql.com/doc/refman/5.7/en/server-options.html#option_mysqld_chroot)'
11+
mysql_hardening_options.safe-user-create:
12+
default: 1
13+
type: int
14+
description: '[safe-user-create](http://dev.mysql.com/doc/refman/5.7/en/server-options.html#option_mysqld_safe-user-create)'
15+
mysql_hardening_options.secure-auth:
16+
default: 1
17+
type: int
18+
description: '[secure-auth](http://dev.mysql.com/doc/refman/5.7/en/server-options.html#option_mysqld_secure-auth)'
19+
mysql_hardening_options.skip-symbolic-links:
20+
default: 1
21+
type: int
22+
description: '[skip-symbolic-links](http://dev.mysql.com/doc/refman/5.7/en/server-options.html#option_mysqld_symbolic-links)'
23+
'mysql_hardening_skip_grant_tables:':
24+
default: false
25+
type: bool
26+
description: '[skip-grant-tables](https://dev.mysql.com/doc/refman/5.7/en/server-options.html#option_mysqld_skip-grant-tables)'
27+
mysql_hardening_skip_show_database:
28+
default: 1
29+
type: int
30+
description: '[skip-show-database](http://dev.mysql.com/doc/refman/5.7/en/server-options.html#option_mysqld_skip-show-database)'
31+
mysql_hardening_options.local-infile:
32+
default: 0
33+
type: int
34+
description: '[local-infile](http://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_local_infile)'
35+
mysql_hardening_options.allow-suspicious-udfs:
36+
default: 0
37+
type: int
38+
description: '[allow-suspicious-udfs](https://dev.mysql.com/doc/refman/5.7/en/server-options.html#option_mysqld_allow-suspicious-udfs)'
39+
mysql_hardening_chroot.automatic-sp-privileges:
40+
default: 0
41+
type: int
42+
description: '[automatic_sp_privileges](https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_automatic_sp_privileges)'
43+
mysql_hardening_options.secure-file-priv:
44+
default: /tmp
45+
type: str
46+
description: '[secure-file-priv](https://dev.mysql.com/doc/refman/5.7/en/server-options.html#option_mysqld_secure-file-priv)'
47+
mysql_remove_anonymous_users:
48+
default: true
49+
type: bool
50+
description: Set to `false` to keep users without authentication
51+
mysql_remove_test_database:
52+
default: true
53+
type: bool
54+
description: Set to `false` to keep the test database
55+
mysql_hardening_restart_mysql:
56+
default: true
57+
type: bool
58+
description: Restart mysql after running this role
59+
mysql_hardening_enabled:
60+
default: true
61+
type: bool
62+
description: Whether to run the hardening
63+
mysql_daemon_enabled:
64+
default: true
65+
type: bool
66+
description: Whether to enable the MySQL-service so it starts on boot
67+
mysql_root_password:
68+
default: '-----====>SetR00tPa$$wordH3r3!!!<====-----'
69+
type: str
70+
description: The default password. Please change or overwrite it
71+
mysql_user_home:
72+
default: '{{ ansible_env.HOME }}'
73+
type: str
74+
description: The path where the `.my.cnf` will be stored
75+
mysql_remove_remote_root:
76+
default: true
77+
type: bool
78+
description: If `true`, root can only connect from localhost. Set to `false`
79+
to not remove remote root users.

roles/mysql_hardening/tasks/configure.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
- name: Apply hardening configuration
5757
ansible.builtin.template:
5858
src: hardening.cnf.j2
59-
dest: "{{ mysql_hardening_mysql_hardening_conf_file }}"
59+
dest: "{{ mysql_hardening_mysql_confd_dir + '/hardening.cnf' }}"
6060
owner: "{{ mysql_cnf_owner }}"
6161
group: "{{ mysql_cnf_group }}"
6262
mode: "0640"

0 commit comments

Comments
 (0)