Skip to content
This repository was archived by the owner on Dec 26, 2020. It is now read-only.

Commit 9c8b783

Browse files
committed
Merge remote-tracking branch 'upstream/master' into feature/2fa_auth
2 parents 4d3f10f + 5a96607 commit 9c8b783

File tree

9 files changed

+199
-48
lines changed

9 files changed

+199
-48
lines changed

.kitchen.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ driver:
99
transport:
1010
max_ssh_sessions: 5
1111

12-
transport:
13-
max_ssh_sessions: 5
14-
15-
1612
provisioner:
1713
name: ansible_playbook
1814
hosts: all
@@ -26,6 +22,7 @@ provisioner:
2622
http_proxy: <%= ENV['http_proxy'] || nil %>
2723
https_proxy: <%= ENV['https_proxy'] || nil %>
2824
playbook: default.yml
25+
ansible_diff: true
2926
ansible_extra_flags:
3027
- "--skip-tags=sysctl"
3128

CHANGELOG.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,36 @@
11
# Change Log
22

3+
## [4.3.1](https://github.com/dev-sec/ansible-ssh-hardening/tree/4.3.1) (2017-08-14)
4+
[Full Changelog](https://github.com/dev-sec/ansible-ssh-hardening/compare/4.3.0...4.3.1)
5+
6+
**Implemented enhancements:**
7+
8+
- Remove duplicate ssh\_use\_dns [\#130](https://github.com/dev-sec/ansible-ssh-hardening/pull/130) ([MagnusEnger](https://github.com/MagnusEnger))
9+
10+
**Fixed bugs:**
11+
12+
- ssh\_use\_dns used twice in defaults/main.yml [\#129](https://github.com/dev-sec/ansible-ssh-hardening/issues/129)
13+
14+
**Closed issues:**
15+
16+
- role creates duplicate parameter/values after run [\#124](https://github.com/dev-sec/ansible-ssh-hardening/issues/124)
17+
18+
## [4.3.0](https://github.com/dev-sec/ansible-ssh-hardening/tree/4.3.0) (2017-08-03)
19+
[Full Changelog](https://github.com/dev-sec/ansible-ssh-hardening/compare/4.1.3...4.3.0)
20+
21+
**Implemented enhancements:**
22+
23+
- Fix ansible.cfg settings [\#122](https://github.com/dev-sec/ansible-ssh-hardening/pull/122) ([fazlearefin](https://github.com/fazlearefin))
24+
- Finish 94 [\#116](https://github.com/dev-sec/ansible-ssh-hardening/pull/116) ([rndmh3ro](https://github.com/rndmh3ro))
25+
26+
**Merged pull requests:**
27+
28+
- Don't overwrite ssh\_host\_key\_files if set manually [\#125](https://github.com/dev-sec/ansible-ssh-hardening/pull/125) ([oakey-b1](https://github.com/oakey-b1))
29+
- Add comment filter to {{ansible\_managed}} string [\#121](https://github.com/dev-sec/ansible-ssh-hardening/pull/121) ([fazlearefin](https://github.com/fazlearefin))
30+
31+
## [4.1.3](https://github.com/dev-sec/ansible-ssh-hardening/tree/4.1.3) (2017-06-30)
32+
[Full Changelog](https://github.com/dev-sec/ansible-ssh-hardening/compare/4.2.0...4.1.3)
33+
334
## [4.2.0](https://github.com/dev-sec/ansible-ssh-hardening/tree/4.2.0) (2017-06-30)
435
[Full Changelog](https://github.com/dev-sec/ansible-ssh-hardening/compare/4.1.2...4.2.0)
536

@@ -264,4 +295,4 @@
264295

265296

266297

267-
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
298+
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,21 @@ Warning: This role disables root-login on the target server! Please make sure yo
2727
|`ssh_server_ports` | ['22'] |ports on which ssh-server should listen|
2828
|`ssh_client_port` | '22' |port to which ssh-client should connect|
2929
|`ssh_listen_to` | ['0.0.0.0'] |one or more ip addresses, to which ssh-server should listen to. Default is all adresseses, but should be configured to specific addresses for security reasons!|
30-
|`ssh_host_key_files` | ['/etc/ssh/ssh_host_rsa_key', '/etc/ssh/ssh_host_dsa_key', '/etc/ssh/ssh_host_ecdsa_key'] |Host keys to look for when starting sshd.|
30+
|`ssh_host_key_files` | [] |Host keys for sshd. If empty ['/etc/ssh/ssh_host_rsa_key', '/etc/ssh/ssh_host_ecdsa_key', '/etc/ssh/ssh_host_ed25519_key'] will be used, as far as supported by the installed sshd version|
3131
|`ssh_client_alive_interval` | 600 | specifies an interval for sending keepalive messages |
3232
|`ssh_client_alive_count` | 3 | defines how often keep-alive messages are sent |
3333
|`ssh_permit_tunnel` | false | true if SSH Port Tunneling is required |
3434
|`ssh_remote_hosts` | [] | one or more hosts and their custom options for the ssh-client. Default is empty. See examples in `defaults/main.yml`.|
3535
|`ssh_allow_root_with_key` | false | false to disable root login altogether. Set to true to allow root to login via key-based mechanism.|
3636
|`ssh_allow_tcp_forwarding` | false | false to disable TCP Forwarding. Set to true to allow TCP Forwarding.|
37+
|`ssh_gateway_ports` | `false` | `false` to disable binding forwarded ports to non-loopback addresses. Set to `true` to force binding on wildcard address. Set to `clientspecified` to allow the client to specify which address to bind to.|
3738
|`ssh_allow_agent_forwarding` | false | false to disable Agent Forwarding. Set to true to allow Agent Forwarding.|
3839
|`ssh_use_pam` | false | false to disable pam authentication.|
3940
|`ssh_deny_users` | '' | if specified, login is disallowed for user names that match one of the patterns.|
4041
|`ssh_allow_users` | '' | if specified, login is allowed only for user names that match one of the patterns.|
4142
|`ssh_deny_groups` | '' | if specified, login is disallowed for users whose primary group or supplementary group list matches one of the patterns.|
4243
|`ssh_allow_groups` | '' | if specified, login is allowed only for users whose primary group or supplementary group list matches one of the patterns.|
44+
|`ssh_authorized_keys_file` | '' | change default file that contains the public keys that can be used for user authentication.|
4345
|`ssh_print_motd` | false | false to disable printing of the MOTD|
4446
|`ssh_print_last_log` | false | false to disable display of last login information|
4547
|`sftp_enabled` | false | true to enable sftp configuration|
@@ -49,7 +51,22 @@ Warning: This role disables root-login on the target server! Please make sure yo
4951
|`ssh_challengeresponseauthentication` | false | Specifies whether challenge-response authentication is allowed (e.g. via PAM) |
5052
|`ssh_client_password_login` | false | `true` to allow password-based authentication with the ssh client |
5153
|`ssh_server_password_login` | false | `true` to allow password-based authentication with the ssh server |
54+
<<<<<<< HEAD
5255
|`ssh_google_auth` | false | `true` to enable google authenticator based TOTP 2FA |
56+
=======
57+
|`ssh_banner` | `false` | `true` to print a banner on login |
58+
|`ssh_client_hardening` | `true` | `false` to stop harden the client |
59+
|`ssh_client_port` | `'22'` | Specifies the port number to connect on the remote host. |
60+
|`ssh_compression` | `false` | Specifies whether compression is enabled after the user has authenticated successfully. |
61+
|`ssh_max_auth_retries` | `2` | Specifies the maximum number of authentication attempts permitted per connection. |
62+
|`ssh_print_debian_banner` | `false` | `true` to print debian specific banner |
63+
|`ssh_server_enabled` | `true` | `false` to disable the opensshd server |
64+
|`ssh_server_hardening` | `true` | `false` to stop harden the server |
65+
|`ssh_server_match_group` | '' | Introduces a conditional block. If all of the criteria on the Match line are satisfied, the keywords on the following lines override those set in the global section of the config file, until either another Match line or the end of the file. |
66+
|`ssh_server_match_user` | '' | Introduces a conditional block. If all of the criteria on the Match line are satisfied, the keywords on the following lines override those set in the global section of the config file, until either another Match line or the end of the file. |
67+
|`ssh_server_permit_environment_vars` | `false` | `true` to specify that ~/.ssh/environment and environment= options in ~/.ssh/authorized_keys are processed by sshd |
68+
|`ssh_use_dns` | `false` | Specifies whether sshd should look up the remote host name, and to check that the resolved host name for the remote IP address maps back to the very same IP address. |
69+
>>>>>>> upstream/master
5370
|`ssh_server_revoked_keys` | [] | a list of revoked public keys that the ssh server will always reject, useful to revoke known weak or compromised keys.|
5471

5572
## Example Playbook

ansible.cfg

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
# finds first
99

1010
[defaults]
11-
ansible_managed = Ansible managed: {file} modified on %Y-%m-%d by {uid} on {host}
11+
ansible_managed = Ansible managed: {file} modified by {uid} on {host}
12+
roles_path = /vagrant
1213

13-
role_path = /vagrant
14+
[ssh_connection]
1415
scp_if_ssh = True

default.yml

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,52 @@
1313
- "openssh-server"
1414
ignore_errors: true
1515
- file: path="/var/run/sshd" state=directory
16+
- name: create ssh host keys
17+
command: "ssh-keygen -A"
18+
when: not ((ansible_os_family in ['Oracle Linux', 'RedHat']) and ansible_distribution_major_version < '7')
19+
1620
roles:
1721
- ansible-ssh-hardening
1822
vars:
1923
network_ipv6_enable: true
2024
ssh_allow_root_with_key: true
25+
ssh_allow_tcp_forwarding: true
26+
ssh_gateway_ports: true
27+
ssh_allow_agent_forwarding: true
28+
ssh_server_permit_environment_vars: ['PWD','HTTP_PROXY']
29+
ssh_client_alive_interval: 100
30+
ssh_client_alive_count: 10
2131
ssh_client_password_login: true
2232
ssh_client_cbc_required: true
23-
ssh_server_weak_hmac: true
2433
ssh_client_weak_kex: true
34+
ssh_challengeresponseauthentication: true
35+
ssh_compression: true
36+
ssh_allow_users: 'root kitchen vagrant'
37+
ssh_allow_groups: 'root kitchen vagrant'
38+
ssh_deny_users: 'foo bar'
39+
ssh_deny_groups: 'foo bar'
40+
ssh_authorized_keys_file: '/etc/ssh/authorized_keys/%u'
41+
ssh_max_auth_retries: 10
42+
ssh_permit_tunnel: true
43+
ssh_print_motd: true
44+
ssh_print_last_log: true
45+
ssh_banner: true
46+
ssh_server_password_login: true
47+
ssh_server_weak_hmac: true
48+
sftp_enabled: true
49+
ssh_server_match_group:
50+
- group: 'root'
51+
rules: 'AllowTcpForwarding yes'
52+
ssh_server_match_user:
53+
- user: 'root'
54+
rules: 'AllowTcpForwarding yes'
2555
ssh_remote_hosts:
2656
- names: ['example.com', 'example2.com']
2757
options: ['Port 2222', 'ForwardAgent yes']
2858
- names: ['example3.com']
2959
options: ['StrictHostKeyChecking no']
60+
ssh_use_dns: true
61+
ssh_use_pam: true
3062

3163
- name: wrapper playbook for kitchen testing "ansible-ssh-hardening" with default settings
3264
hosts: localhost

defaults/main.yml

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# true if IPv6 is needed
22
network_ipv6_enable: false # sshd + ssh
33

4+
# true if sshd should be started and enabled
5+
ssh_server_enabled: true # sshd
6+
7+
# true if DNS resolutions are needed, look up the remote host name, defaults to false from 6.8, see: http://www.openssh.com/txt/release-6.8
8+
ssh_use_dns: false # sshd
9+
10+
# true or value if compression is needed
11+
ssh_compression: false # sshd
12+
413
# For which components (client and server) to generate the configuration for. Can be useful when running against a client without an SSH server.
514
ssh_client_hardening: true # ssh
615
ssh_server_hardening: true # sshd
@@ -31,7 +40,7 @@ ssh_client_port: '22' # ssh
3140
ssh_listen_to: ['0.0.0.0'] # sshd
3241

3342
# Host keys to look for when starting sshd.
34-
ssh_host_key_files: ['/etc/ssh/ssh_host_rsa_key', '/etc/ssh/ssh_host_ecdsa_key', '/etc/ssh/ssh_host_ed25519_key'] # sshd
43+
ssh_host_key_files: [] # sshd
3544

3645
# Specifies the maximum number of authentication attempts permitted per connection. Once the number of failures reaches half this value, additional failures are logged.
3746
ssh_max_auth_retries: 2
@@ -57,6 +66,10 @@ ssh_allow_root_with_key: false # sshd
5766
# false to disable TCP Forwarding. Set to true to allow TCP Forwarding.
5867
ssh_allow_tcp_forwarding: false # sshd
5968

69+
# false to disable binding forwarded ports to non-loopback addresses. Set to true to force binding on wildcard address.
70+
# Set to 'clientspecified' to allow the client to specify which address to bind to.
71+
ssh_gateway_ports: false # sshd
72+
6073
# false to disable Agent Forwarding. Set to true to allow Agent Forwarding.
6174
ssh_allow_agent_forwarding: false # sshd
6275

@@ -78,6 +91,9 @@ ssh_deny_groups: '' # sshd
7891
# if specified, login is allowed only for users whose primary group or supplementary group list matches one of the patterns.
7992
ssh_allow_groups: '' # sshd
8093

94+
# change default file that contains the public keys that can be used for user authentication.
95+
ssh_authorized_keys_file: '' # sshd
96+
8197
# false to disable printing of the MOTD
8298
ssh_print_motd: false # sshd
8399

@@ -99,6 +115,14 @@ sftp_chroot_dir: /home/%u
99115
# enable experimental client roaming
100116
ssh_client_roaming: false
101117

118+
# list of hashes (containing user and rules) to generate Match User blocks for.
119+
ssh_server_match_user: false # sshd
120+
121+
# list of hashes (containing group and rules) to generate Match Group blocks for.
122+
ssh_server_match_group: false # sshd
123+
124+
ssh_server_permit_environment_vars: false
125+
102126

103127
ssh_ps53: 'yes'
104128
ssh_ps59: 'sandbox'
@@ -161,8 +185,5 @@ sshd_moduli_minimum: 2048
161185
# disable ChallengeResponseAuthentication
162186
ssh_challengeresponseauthentication: false
163187

164-
# look up the remote host name, defaults to false from 6.8, see: http://www.openssh.com/txt/release-6.8
165-
ssh_use_dns: false
166-
167188
# a list of public keys that are never accepted by the ssh server
168189
ssh_server_revoked_keys: []

handlers/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
- name: restart sshd
22
service: name={{ sshd_service_name }} state=restarted
3+
when: "(ssh_server_enabled|bool)"

tasks/main.yml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,26 @@
99

1010
- name: get openssh-version
1111
shell: ssh -V 2>&1 | sed -r 's/.*_([0-9]*\.[0-9]).*/\1/g'
12+
args:
13+
executable: /bin/sh
1214
changed_when: false
1315
register: sshd_version
1416
check_mode: no
1517

1618
- name: set hostkeys according to openssh-version
1719
set_fact:
18-
ssh_host_key_files: ['/etc/ssh/ssh_host_rsa_key']
19-
when: sshd_version.stdout >= '5.3'
20+
ssh_host_key_files: ['/etc/ssh/ssh_host_rsa_key', '/etc/ssh/ssh_host_ecdsa_key', '/etc/ssh/ssh_host_ed25519_key']
21+
when: sshd_version.stdout >= '6.3' and not ssh_host_key_files
2022

2123
- name: set hostkeys according to openssh-version
2224
set_fact:
2325
ssh_host_key_files: ['/etc/ssh/ssh_host_rsa_key', '/etc/ssh/ssh_host_ecdsa_key']
24-
when: sshd_version.stdout >= '6.0'
26+
when: sshd_version.stdout >= '6.0' and not ssh_host_key_files
2527

2628
- name: set hostkeys according to openssh-version
2729
set_fact:
28-
ssh_host_key_files: ['/etc/ssh/ssh_host_rsa_key', '/etc/ssh/ssh_host_ecdsa_key', '/etc/ssh/ssh_host_ed25519_key']
29-
when: sshd_version.stdout >= '6.3'
30+
ssh_host_key_files: ['/etc/ssh/ssh_host_rsa_key']
31+
when: sshd_version.stdout >= '5.3' and not ssh_host_key_files
3032

3133
- name: create revoked_keys and set permissions to root/600
3234
template: src='revoked_keys.j2' dest='/etc/ssh/revoked_keys' mode=0600 owner="{{ ssh_owner }}" group="{{ ssh_group }}"
@@ -54,13 +56,14 @@
5456
notify: restart sshd
5557
when: sshd_register_moduli.stdout
5658

57-
- name: test to see if selinux is running
59+
- name: test to see if selinux is installed and running
5860
command: getenforce
5961
register: sestatus
6062
failed_when: false
6163
changed_when: false
6264
check_mode: no
6365

66+
<<<<<<< HEAD
6467
# Install the 2FA packages and setup the config in PAM and SSH
6568

6669
- block:
@@ -101,7 +104,7 @@
101104
- ssh_google_auth
102105

103106

104-
- block: # only runs when selinux is running
107+
- block: # only runs when selinux is installed
105108
- name: install selinux dependencies when selinux is installed on RHEL or Oracle Linux
106109
package: name="{{item}}" state=installed
107110
with_items:
@@ -143,7 +146,7 @@
143146

144147
when: not ssh_use_pam and sestatus.stdout != 'Disabled' and ssh_password_module.stdout.find('ssh_password') != 0
145148

146-
# The following tasks only get executed when selinux is in state enforcing, UsePam is "yes" and the ssh_password module is installed.
149+
# The following tasks only get executed when selinux is installed, UsePam is "yes" and the ssh_password module is installed.
147150
- name: remove selinux-policy when Pam is used, because Allowing sshd to read the shadow file directly is considered a potential security risk (http://danwalsh.livejournal.com/12333.html)
148151
command: semodule -r ssh_password
149152
when: ssh_use_pam and ssh_password_module.stdout.find('ssh_password') == 0

0 commit comments

Comments
 (0)