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

Commit 974746e

Browse files
jbendenSebastian Gumprich
authored andcommitted
Template additional configuration options
All additional options are backwards compatible, and should not introduce any unwanted vulnerability or side effect. * PermitUserEnvironment/AcceptEnv now supports a list of accepted environment variables from the client. * Compression is now configurable. * UseDNS is now configurable. * Both Match Group and Match User are now configurable. * SSHD now supports being enabled and started.
1 parent 4324838 commit 974746e

File tree

2 files changed

+58
-7
lines changed

2 files changed

+58
-7
lines changed

defaults/main.yml

Lines changed: 15 additions & 0 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: false # sshd
6+
7+
# true if DNS resolutions are needed
8+
ssh_use_dns: true # 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
@@ -96,6 +105,12 @@ sftp_chroot_dir: /home/%u
96105
# enable experimental client roaming
97106
ssh_client_roaming: false
98107

108+
# list of hashes (containing user and rules) to generate Match User blocks for.
109+
ssh_server_match_user: false # sshd
110+
111+
# list of hashes (containing group and rules) to generate Match Group blocks for.
112+
ssh_server_match_group: false # sshd
113+
99114

100115
ssh_ps53: 'yes'
101116
ssh_ps59: 'sandbox'

templates/opensshd.conf.j2

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ LogLevel VERBOSE
113113
UseLogin no
114114
UsePrivilegeSeparation {% if (ansible_distribution == 'Debian' and ansible_distribution_major_version <= '6') or (ansible_os_family in ['Oracle Linux', 'RedHat'] and ansible_distribution_major_version <= '6') -%}{{ssh_ps53}}{% else %}{{ssh_ps59}}{% endif %}
115115

116-
PermitUserEnvironment no
117116
LoginGraceTime 30s
118117
MaxAuthTries {{ssh_max_auth_retries}}
119118
MaxSessions 10
@@ -190,12 +189,27 @@ GatewayPorts no
190189
X11Forwarding no
191190
X11UseLocalhost yes
192191

193-
# Look up the remote host name, defaults to false from 6.8, see: http://www.openssh.com/txt/release-6.8
194-
UseDNS {{ 'yes' if ssh_use_dns else 'no' }}
192+
# User environment configuration
193+
# ==============================
194+
195+
{% if ssh_server_permit_environment_vars %}
196+
PermitUserEnvironment yes
197+
{% for item in ssh_server_permit_environment_vars %}
198+
AcceptEnv {{ item }}
199+
{% endfor %}
200+
{% else %}
201+
PermitUserEnvironment no
202+
{% endif %}
195203

196204
# Misc. configuration
197205
# ===================
198206

207+
{% if ssh_compression %}
208+
Compression {{ ssh_compression }}
209+
{% endif %}
210+
211+
UseDNS {{ 'yes' if ssh_use_dns else 'no' }}
212+
199213
PrintMotd {{ 'yes' if ssh_print_motd else 'no' }}
200214

201215
{% if ansible_os_family != 'FreeBSD' %}
@@ -208,13 +222,35 @@ Banner {{ '/etc/ssh/banner.txt' if ssh_banner else 'none' }}
208222
DebianBanner {{ 'yes' if ssh_print_debian_banner else 'no' }}
209223
{% endif %}
210224

225+
# Group matching configuration
226+
# ============================
227+
228+
{% if ssh_server_match_group %}
229+
{% for item in ssh_server_match_group %}
230+
Match Group {{ item.group }}
231+
{{ item.rules | indent(4) }}
232+
{% endfor %}
233+
{% endif %}
234+
235+
# User matching configuration
236+
# ===========================
237+
238+
{% if ssh_server_match_user %}
239+
{% for item in ssh_server_match_user %}
240+
Match User {{ item.user }}
241+
{{ item.rules | indent(4) }}
242+
{% endfor %}
243+
{% endif %}
244+
245+
# SFTP matching configuration
246+
# ===========================
211247
{% if sftp_enabled %}
212248
# Configuration, in case SFTP is used
213-
## override default of no subsystems
214-
## Subsystem sftp /opt/app/openssh5/libexec/sftp-server
249+
# override default of no subsystems
250+
# Subsystem sftp /opt/app/openssh5/libexec/sftp-server
215251
Subsystem sftp internal-sftp -l INFO -f LOCAL6
216-
#
217-
## These lines must appear at the *end* of sshd_config
252+
253+
# These lines must appear at the *end* of sshd_config
218254
Match Group sftponly
219255
ForceCommand internal-sftp -l INFO -f LOCAL6
220256
ChrootDirectory {{ sftp_chroot_dir }}

0 commit comments

Comments
 (0)