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

Commit 6d9f217

Browse files
author
Sebastian Gumprich
committed
finish PR
1 parent be67b1f commit 6d9f217

File tree

4 files changed

+66
-28
lines changed

4 files changed

+66
-28
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@ Warning: This role disables root-login on the target server! Please make sure yo
4949
|`ssh_challengeresponseauthentication` | false | Specifies whether challenge-response authentication is allowed (e.g. via PAM) |
5050
|`ssh_client_password_login` | false | `true` to allow password-based authentication with the ssh client |
5151
|`ssh_server_password_login` | false | `true` to allow password-based authentication with the ssh server |
52+
|`ssh_banner` | `false` | `true` to print a banner on login |
53+
|`ssh_client_hardening` | `true` | `false` to stop harden the client |
54+
|`ssh_client_port` | `'22'` | Specifies the port number to connect on the remote host. |
55+
|`ssh_compression` | `false` | Specifies whether compression is enabled after the user has authenticated successfully. |
56+
|`ssh_max_auth_retries` | `2` | Specifies the maximum number of authentication attempts permitted per connection. |
57+
|`ssh_print_debian_banner` | `false` | `true` to print debian specific banner |
58+
|`ssh_server_enabled` | `true` | `false` to disable the opensshd server |
59+
|`ssh_server_hardening` | `true` | `false` to stop harden the server |
60+
|`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. |
61+
|`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. |
62+
|`ssh_server_permit_environment_vars` | `false` | `true` to specify that ~/.ssh/environment and environment= options in ~/.ssh/authorized_keys are processed by sshd |
63+
|`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. |
64+
5265

5366
## Example Playbook
5467

default.yml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,42 @@
1818
vars:
1919
network_ipv6_enable: true
2020
ssh_allow_root_with_key: true
21+
ssh_allow_tcp_forwarding: true
22+
ssh_allow_agent_forwarding: true
23+
ssh_server_permit_environment_vars: 'PWD'
24+
ssh_client_alive_interval: 100
25+
ssh_client_alive_count: 10
2126
ssh_client_password_login: true
2227
ssh_client_cbc_required: true
23-
ssh_server_weak_hmac: true
2428
ssh_client_weak_kex: true
29+
ssh_challengeresponseauthentication: true
30+
ssh_compression: 'yes'
31+
ssh_allow_users: 'root kitchen vagrant'
32+
ssh_allow_groups: 'root kitchen vagrant'
33+
ssh_deny_users: 'foo bar'
34+
ssh_deny_groups: 'foo bar'
35+
ssh_max_auth_retries: 10
36+
ssh_permit_tunnel: true
37+
ssh_print_motd: true
38+
ssh_print_last_log: true
39+
ssh_banner: true
40+
ssh_server_password_login: true
41+
ssh_server_enabled: false
42+
ssh_server_weak_hmac: true
43+
sftp_enabled: true
44+
ssh_server_match_group:
45+
- group: 'root'
46+
rules: 'AllowTcpForwarding yes'
47+
ssh_server_match_user:
48+
- user: 'root'
49+
rules: 'AllowTcpForwarding yes'
2550
ssh_remote_hosts:
2651
- names: ['example.com', 'example2.com']
2752
options: ['Port 2222', 'ForwardAgent yes']
2853
- names: ['example3.com']
2954
options: ['StrictHostKeyChecking no']
55+
ssh_use_dns: true
56+
ssh_use_pam: true
3057

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

defaults/main.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
network_ipv6_enable: false # sshd + ssh
33

44
# true if sshd should be started and enabled
5-
ssh_server_enabled: false # sshd
5+
ssh_server_enabled: true # sshd
66

7-
# true if DNS resolutions are needed
8-
ssh_use_dns: true # sshd
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
99

1010
# true or value if compression is needed
1111
ssh_compression: false # sshd
@@ -111,6 +111,8 @@ ssh_server_match_user: false # sshd
111111
# list of hashes (containing group and rules) to generate Match Group blocks for.
112112
ssh_server_match_group: false # sshd
113113

114+
ssh_server_permit_environment_vars: false
115+
114116

115117
ssh_ps53: 'yes'
116118
ssh_ps59: 'sandbox'
@@ -172,6 +174,3 @@ sshd_moduli_minimum: 2048
172174

173175
# disable ChallengeResponseAuthentication
174176
ssh_challengeresponseauthentication: false
175-
176-
# look up the remote host name, defaults to false from 6.8, see: http://www.openssh.com/txt/release-6.8
177-
ssh_use_dns: false

templates/opensshd.conf.j2

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,7 @@ PermitUserEnvironment no
204204
# Misc. configuration
205205
# ===================
206206

207-
{% if ssh_compression %}
208-
Compression {{ ssh_compression }}
209-
{% endif %}
207+
Compression {{ 'yes' if ssh_compression else 'no' }}
210208

211209
UseDNS {{ 'yes' if ssh_use_dns else 'no' }}
212210

@@ -222,6 +220,25 @@ Banner {{ '/etc/ssh/banner.txt' if ssh_banner else 'none' }}
222220
DebianBanner {{ 'yes' if ssh_print_debian_banner else 'no' }}
223221
{% endif %}
224222

223+
# SFTP matching configuration
224+
# ===========================
225+
{% if sftp_enabled %}
226+
# Configuration, in case SFTP is used
227+
# override default of no subsystems
228+
# Subsystem sftp /opt/app/openssh5/libexec/sftp-server
229+
Subsystem sftp internal-sftp -l INFO -f LOCAL6
230+
231+
# These lines must appear at the *end* of sshd_config
232+
Match Group sftponly
233+
ForceCommand internal-sftp -l INFO -f LOCAL6
234+
ChrootDirectory {{ sftp_chroot_dir }}
235+
AllowTcpForwarding no
236+
AllowAgentForwarding no
237+
PasswordAuthentication no
238+
PermitRootLogin no
239+
X11Forwarding no
240+
{% endif %}
241+
225242
# Group matching configuration
226243
# ============================
227244

@@ -242,21 +259,3 @@ Match User {{ item.user }}
242259
{% endfor %}
243260
{% endif %}
244261

245-
# SFTP matching configuration
246-
# ===========================
247-
{% if sftp_enabled %}
248-
# Configuration, in case SFTP is used
249-
# override default of no subsystems
250-
# Subsystem sftp /opt/app/openssh5/libexec/sftp-server
251-
Subsystem sftp internal-sftp -l INFO -f LOCAL6
252-
253-
# These lines must appear at the *end* of sshd_config
254-
Match Group sftponly
255-
ForceCommand internal-sftp -l INFO -f LOCAL6
256-
ChrootDirectory {{ sftp_chroot_dir }}
257-
AllowTcpForwarding no
258-
AllowAgentForwarding no
259-
PasswordAuthentication no
260-
PermitRootLogin no
261-
X11Forwarding no
262-
{% endif %}

0 commit comments

Comments
 (0)