Skip to content

Commit ea9cdd7

Browse files
committed
Provide granular noop for shh configuration
We would like to have more fine grained options on applying or not specific configurations. This commit let the user choose to noop some configuration with a few new boolean variables. Motivation for theses options are we may configure ourselves some (ssh host key regeneration in a templating system) or we are not ready for others (ssh_kex will break dist-upgrades, letting the operator without ssh). Signed-off-by: seven beep <[email protected]>
1 parent 3f3e8cf commit ea9cdd7

File tree

5 files changed

+57
-7
lines changed

5 files changed

+57
-7
lines changed

roles/ssh_hardening/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ For more information, see [this issue](https://github.com/dev-sec/ansible-collec
138138
- Description: Specifies whether challenge-response authentication is allowed (e.g. via PAM).
139139
- Type: bool
140140
- Required: no
141+
- `ssh_ciphers_config`
142+
- Default: `true`
143+
- Description: Wether or not configuring the ciphers of the server.
144+
- Type: bool
145+
- Required: no
141146
- `ssh_ciphers`
142147
- Default: ``
143148
- Description: Change this list to overwrite ciphers. Defaults found in `defaults/main.yml`
@@ -238,6 +243,11 @@ For more information, see [this issue](https://github.com/dev-sec/ansible-collec
238243
- Description: Host certificates to look for when starting sshd
239244
- Type: list
240245
- Required: no
246+
- `ssh_host_key_config`
247+
- Default: `true`
248+
- Description: Wether or not configuring the host keys of that the server offers.
249+
- Type: bool
250+
- Required: no
241251
- `ssh_host_key_algorithms`
242252
- Default: ``
243253
- Description: Host key algorithms that the server offers. If empty the default list will be used. Otherwise overrides the setting with specified list of algorithms. Check `man sshd_config`, `ssh -Q HostKeyAlgorithms` or other sources for supported algorithms - make sure you check the correct version
@@ -258,6 +268,11 @@ For more information, see [this issue](https://github.com/dev-sec/ansible-collec
258268
- Description: Set to `true` if SSH has Kerberos support.
259269
- Type: bool
260270
- Required: no
271+
- `ssh_kex_config`
272+
- Default: `true`
273+
- Description: Wether or not configuring the kexs of the server.
274+
- Type: bool
275+
- Required: no
261276
- `ssh_kex`
262277
- Default: ``
263278
- Description: Change this list to overwrite kexs. Defaults found in `defaults/main.yml`
@@ -273,6 +288,11 @@ For more information, see [this issue](https://github.com/dev-sec/ansible-collec
273288
- Description: specifies the time allowed for successful authentication to the SSH server.
274289
- Type: str
275290
- Required: no
291+
- `ssh_macs_config`
292+
- Default: `true`
293+
- Description: Wether or not configuring the macs of the server.
294+
- Type: bool
295+
- Required: no
276296
- `ssh_macs`
277297
- Default: ``
278298
- Description: Change this list to overwrite macs. Defaults found in `defaults/main.yml`

roles/ssh_hardening/defaults/main.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ ssh_client_port: "22" # ssh
4040
# Default is empty, but should be configured for security reasons!
4141
ssh_listen_to: [0.0.0.0] # sshd
4242

43+
# Wether or not configuring and generating the host keys files
44+
ssh_host_key_config: true # sshd
45+
4346
# Host keys to look for when starting sshd.
4447
ssh_host_key_files: [] # sshd
4548

@@ -206,6 +209,10 @@ ssh_max_startups: 10:30:60 # sshd
206209

207210
ssh_ps59: sandbox
208211

212+
# Wether or not configuring the macs, cihers and kex algorythms
213+
ssh_macs_config: true # sshd
214+
ssh_ciphers_config: true
215+
ssh_kex_config: true
209216
ssh_macs: []
210217
ssh_ciphers: []
211218
ssh_kex: []

roles/ssh_hardening/meta/argument_specs.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ argument_specs:
2828
description: one or more ip addresses, to which ssh-server should listen to.
2929
Default is all IPv4 addresses, but should be configured to specific addresses
3030
for security reasons
31+
ssh_host_key_config:
32+
default: true
33+
type: bool
34+
description: Wether or not configuring the host keys of that the server offers.
3135
ssh_host_key_files:
3236
default: []
3337
type: list
@@ -317,14 +321,26 @@ argument_specs:
317321
default: 10:30:60
318322
description: Specifies the maximum number of concurrent unauthenticated connections
319323
to the SSH daemon.
324+
ssh_macs_config:
325+
default: true
326+
description: Wether or not configuring the macs of the server.
327+
type: bool
320328
ssh_macs:
321329
default: []
322330
type: list
323331
description: Change this list to overwrite macs. Defaults found in `defaults/main.yml`
332+
ssh_kex_config:
333+
default: true
334+
description: Wether or not configuring the kexs of the server.
335+
type: bool
324336
ssh_kex:
325337
default: []
326338
type: list
327339
description: Change this list to overwrite kexs. Defaults found in `defaults/main.yml`
340+
ssh_ciphers_config:
341+
default: true
342+
description: Wether or not configuring the ciphers of the server.
343+
type: bool
328344
ssh_ciphers:
329345
default: []
330346
type: list

roles/ssh_hardening/tasks/hardening.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,26 @@
3939
ansible.builtin.include_tasks: crypto_hostkeys.yml
4040
when:
4141
- ssh_server_hardening | bool
42+
- ssh_host_key_config
4243
- not ssh_host_key_files
4344

4445
- name: Set default for ssh_macs if not supplied
4546
ansible.builtin.include_tasks: crypto_macs.yml
46-
when: not ssh_macs
47+
when:
48+
- ssh_macs_config
49+
- not ssh_macs
4750

4851
- name: Set default for ssh_ciphers if not supplied
4952
ansible.builtin.include_tasks: crypto_ciphers.yml
50-
when: not ssh_ciphers
53+
when:
54+
- ssh_ciphers_config
55+
- not ssh_ciphers
5156

5257
- name: Set default for ssh_kex if not supplied
5358
ansible.builtin.include_tasks: crypto_kex.yml
54-
when: not ssh_kex
59+
when:
60+
- ssh_kex_config
61+
- not ssh_kex
5562

5663
- name: Create revoked_keys and set permissions to root/600
5764
ansible.builtin.template:

roles/ssh_hardening/templates/opensshd.conf.j2

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ ListenAddress {{ address }}
3434
{% endfor %}
3535

3636
# HostKeys are listed here.
37-
{% for key in ssh_host_key_files %}
37+
{% for key in ssh_host_key_files if ssh_host_key_config%}
3838
HostKey {{ key }}
3939
{% endfor %}
4040

@@ -73,14 +73,14 @@ LogLevel {{ sshd_log_level }}
7373
# -- see: (http://net-ssh.github.com/net-ssh/classes/Net/SSH/Transport/CipherFactory.html)
7474
#
7575
{# This outputs 'Ciphers <list-of-ciphers>' if ssh_ciphers is defined or '#Ciphers' if ssh_ciphers is undefined -#}
76-
{{ 'Ciphers ' ~ ssh_ciphers|join(',') if ssh_ciphers else 'Ciphers'|comment }}
76+
{{ 'Ciphers ' ~ ssh_ciphers|join(',') if ssh_ciphers and ssh_ciphers_config else 'Ciphers'|comment }}
7777

7878
# **Hash algorithms** -- SHA-1 is formally deprecated by NIST in 2011 because of security issues.
7979
# Weak HMAC is sometimes required if older package versions are used
8080
# eg Ruby's Net::SSH at around 2.2.* doesn't support sha2 for hmac, so this will have to be set true in this case.
8181
#
8282
{# This outputs 'MACs <list-of-macs>' if ssh_macs is defined or '#MACs' if ssh_macs is undefined -#}
83-
{{ 'MACs ' ~ ssh_macs|join(',') if ssh_macs else 'MACs'|comment }}
83+
{{ 'MACs ' ~ ssh_macs|join(',') if ssh_macs and ssh_macs_config else 'MACs'|comment }}
8484

8585
{% if sshd_version is version('5.9', '<') %}
8686
# Alternative setting, if OpenSSH version is below v5.9
@@ -93,7 +93,7 @@ LogLevel {{ sshd_log_level }}
9393
# based on: https://bettercrypto.org/static/applied-crypto-hardening.pdf
9494
#
9595
{# This outputs 'KexAlgorithms <list-of-algos>' if ssh_kex is defined or '#KexAlgorithms' if ssh_kex is undefined #}
96-
{{ 'KexAlgorithms ' ~ ssh_kex|join(',') if ssh_kex else 'KexAlgorithms'|comment }}
96+
{{ 'KexAlgorithms ' ~ ssh_kex|join(',') if ssh_kex and ssh_kex_config else 'KexAlgorithms'|comment }}
9797

9898
# Authentication
9999
# --------------

0 commit comments

Comments
 (0)