You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: roles/os_hardening/README.md
+90-87
Original file line number
Diff line number
Diff line change
@@ -53,6 +53,96 @@ We disable the following filesystems, because they're most likely not used:
53
53
54
54
To prevent some of the filesystems from being disabled, add them to the `os_filesystem_whitelist` variable.
55
55
56
+
## Known Limitations
57
+
58
+
### Docker support
59
+
60
+
If you're using Docker / Kubernetes+Docker you'll need to override the ipv4 ip forward sysctl setting.
61
+
62
+
```yaml
63
+
- hosts: localhost
64
+
roles:
65
+
- devsec.hardening.os_hardening
66
+
vars:
67
+
sysctl_overwrite:
68
+
# Enable IPv4 traffic forwarding.
69
+
net.ipv4.ip_forward: 1
70
+
```
71
+
72
+
### hidepid on RHEL/CentOS 7
73
+
74
+
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.
75
+
76
+
```
77
+
Error registering authentication agent: GDBus.Error:org.freedesktop.PolicyKit1.Error.Failed: Cannot determine user of subject (polkit-error-quark, 0)
78
+
```
79
+
80
+
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.
81
+
82
+
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)
83
+
84
+
### sysctl - vm.mmap_rnd_bits
85
+
86
+
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.
87
+
88
+
```yaml
89
+
- hosts: localhost
90
+
roles:
91
+
- devsec.hardening.os_hardening
92
+
vars:
93
+
sysctl_overwrite:
94
+
vm.mmap_rnd_bits: 16
95
+
```
96
+
97
+
## Testing with inspec
98
+
99
+
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.
100
+
Otherwise inspec will fail. For more information, see [issue #124](https://github.com/dev-sec/ansible-os-hardening/issues/124).
101
+
102
+
We know that this is the case on Raspberry Pi.
103
+
104
+
## Changing sysctl variables
105
+
106
+
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`).
107
+
So for example if you want to change the IPv4 traffic forwarding variable to `1`, do it like this:
108
+
109
+
```yaml
110
+
- hosts: localhost
111
+
roles:
112
+
- devsec.hardening.os_hardening
113
+
vars:
114
+
sysctl_overwrite:
115
+
# Enable IPv4 traffic forwarding.
116
+
net.ipv4.ip_forward: 1
117
+
```
118
+
119
+
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.
120
+
121
+
## Improving Kernel Audit logging
122
+
123
+
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.
124
+
125
+
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.
126
+
127
+
## PAM configuration
128
+
129
+
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.
130
+
131
+
- on Debian/Ubuntu we use [pam-config-framework](https://wiki.ubuntu.com/PAMConfigFrameworkSpec)
132
+
- 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
133
+
- 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
134
+
- 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)
135
+
136
+
137
+
## Acknowledgements
138
+
139
+
This role is mostly based on guides by:
140
+
141
+
- [Arch Linux wiki, Sysctl hardening](https://wiki.archlinux.org/index.php/Sysctl)
142
+
- [NSA: Guide to the Secure Configuration of Red Hat Enterprise Linux 5](http://www.nsa.gov/ia/_files/os/redhat/rhel5-guide-i731.pdf)
- [Deutsche Telekom, Group IT Security, Security Requirements (German)](https://www.telekom.com/psa)
145
+
56
146
<!-- BEGIN_ANSIBLE_DOCS -->
57
147
58
148
## Supported Operating Systems
@@ -924,90 +1014,3 @@ None.
924
1014
```
925
1015
926
1016
<!-- END_ANSIBLE_DOCS -->
927
-
928
-
## Known Limitations
929
-
930
-
### Docker support
931
-
932
-
If you're using Docker / Kubernetes+Docker you'll need to override the ipv4 ip forward sysctl setting.
933
-
934
-
```yaml
935
-
- hosts: localhost
936
-
roles:
937
-
- devsec.hardening.os_hardening
938
-
vars:
939
-
sysctl_overwrite:
940
-
# Enable IPv4 traffic forwarding.
941
-
net.ipv4.ip_forward: 1
942
-
```
943
-
944
-
### hidepid on RHEL/CentOS 7
945
-
946
-
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.
947
-
948
-
```
949
-
Error registering authentication agent: GDBus.Error:org.freedesktop.PolicyKit1.Error.Failed: Cannot determine user of subject (polkit-error-quark, 0)
950
-
```
951
-
952
-
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.
953
-
954
-
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)
955
-
956
-
### sysctl - vm.mmap_rnd_bits
957
-
958
-
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.
959
-
960
-
```yaml
961
-
- hosts: localhost
962
-
roles:
963
-
- devsec.hardening.os_hardening
964
-
vars:
965
-
sysctl_overwrite:
966
-
vm.mmap_rnd_bits: 16
967
-
```
968
-
969
-
## Testing with inspec
970
-
971
-
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.
972
-
Otherwise inspec will fail. For more information, see [issue #124](https://github.com/dev-sec/ansible-os-hardening/issues/124).
973
-
974
-
We know that this is the case on Raspberry Pi.
975
-
976
-
## Changing sysctl variables
977
-
978
-
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`).
979
-
So for example if you want to change the IPv4 traffic forwarding variable to `1`, do it like this:
980
-
981
-
```yaml
982
-
- hosts: localhost
983
-
roles:
984
-
- devsec.hardening.os_hardening
985
-
vars:
986
-
sysctl_overwrite:
987
-
# Enable IPv4 traffic forwarding.
988
-
net.ipv4.ip_forward: 1
989
-
```
990
-
991
-
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.
992
-
993
-
## Improving Kernel Audit logging
994
-
995
-
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.
996
-
997
-
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.
998
-
999
-
## More information
1000
-
1001
-
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.
1002
-
1003
-
- on Debian/Ubuntu we use [pam-config-framework](https://wiki.ubuntu.com/PAMConfigFrameworkSpec)
1004
-
- 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
1005
-
- 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
1006
-
- 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)
1007
-
1008
-
This role is mostly based on guides by:
1009
-
1010
-
- [Arch Linux wiki, Sysctl hardening](https://wiki.archlinux.org/index.php/Sysctl)
1011
-
- [NSA: Guide to the Secure Configuration of Red Hat Enterprise Linux 5](http://www.nsa.gov/ia/_files/os/redhat/rhel5-guide-i731.pdf)
Copy file name to clipboardExpand all lines: roles/ssh_hardening/README.md
+27-28
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,33 @@ This role provides secure ssh-client and ssh-server configurations. It is intend
10
10
11
11
Warning: This role disables root-login on the target server! Please make sure you have another user with su or sudo permissions that can login into the server.
12
12
13
+
## Configuring settings not listed in role-variables
14
+
15
+
If you want to configure ssh options that are not listed above, you can use `ssh_custom_options` (for `/etc/ssh/ssh_config`) or `sshd_custom_options` (for `/etc/ssh/sshd_config`) to set them. These options will be set on the **beginning** of the file so you can override options further down in the file.
16
+
17
+
Example playbook:
18
+
19
+
```yml
20
+
- hosts: localhost
21
+
roles:
22
+
- devsec.hardening.ssh_hardening
23
+
vars:
24
+
ssh_custom_options:
25
+
- "Include /etc/ssh/ssh_config.d/*"
26
+
sshd_custom_options:
27
+
- "AcceptEnv LANG"
28
+
```
29
+
30
+
## After using the role Ansibles template/copy/file module does not work anymore
31
+
32
+
If you use this role to disable SFTP (`sftp_enabled: false`) you will get errors. Ansible uses by default SFTP to transfer files to the remote hosts. You have to set `scp_if_ssh = True` in your ansible.cfg. This way Ansible uses SCP to copy files. If your control node uses OpenSSH version 9.0 or above, you also need to set `scp_extra_args = "-O"`, since starting with that version the `scp` utility also defaults to using SFTP.
33
+
34
+
## Changing the default port and idempotency
35
+
36
+
This role uses the default port 22 or the port configured in the inventory to connect to the server. If the default `ssh` port is changed via `ssh_server_ports`, once the ssh server is restarted, it will still try to connect using the previous port. In order to run this role again on the same server the inventory will have to be updated to use the new ssh port.
37
+
38
+
If idempotency is important, please consider using role [`ssh-hardening-fallback`](https://github.com/nununo/ansible-ssh-hardening-fallback), which is a wrapper around this role that falls back to port 22 if the configured port is unreachable.
39
+
13
40
<!-- BEGIN_ANSIBLE_DOCS -->
14
41
15
42
## Supported Operating Systems
@@ -442,32 +469,4 @@ None.
442
469
roles:
443
470
- name: devsec.hardening.ssh_hardening
444
471
```
445
-
446
472
<!-- END_ANSIBLE_DOCS -->
447
-
448
-
## Configuring settings not listed in role-variables
449
-
450
-
If you want to configure ssh options that are not listed above, you can use `ssh_custom_options` (for `/etc/ssh/ssh_config`) or `sshd_custom_options` (for `/etc/ssh/sshd_config`) to set them. These options will be set on the **beginning** of the file so you can override options further down in the file.
451
-
452
-
Example playbook:
453
-
454
-
```yml
455
-
- hosts: localhost
456
-
roles:
457
-
- devsec.hardening.ssh_hardening
458
-
vars:
459
-
ssh_custom_options:
460
-
- "Include /etc/ssh/ssh_config.d/*"
461
-
sshd_custom_options:
462
-
- "AcceptEnv LANG"
463
-
```
464
-
465
-
## After using the role Ansibles template/copy/file module does not work anymore
466
-
467
-
If you use this role to disable SFTP (`sftp_enabled: false`) you will get errors. Ansible uses by default SFTP to transfer files to the remote hosts. You have to set `scp_if_ssh = True` in your ansible.cfg. This way Ansible uses SCP to copy files. If your control node uses OpenSSH version 9.0 or above, you also need to set `scp_extra_args = "-O"`, since starting with that version the `scp` utility also defaults to using SFTP.
468
-
469
-
## Changing the default port and idempotency
470
-
471
-
This role uses the default port 22 or the port configured in the inventory to connect to the server. If the default `ssh` port is changed via `ssh_server_ports`, once the ssh server is restarted, it will still try to connect using the previous port. In order to run this role again on the same server the inventory will have to be updated to use the new ssh port.
472
-
473
-
If idempotency is important, please consider using role [`ssh-hardening-fallback`](https://github.com/nununo/ansible-ssh-hardening-fallback), which is a wrapper around this role that falls back to port 22 if the configured port is unreachable.
0 commit comments