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

Commit 4dcf553

Browse files
committed
Merge pull request #30 from hardening-io/if_constructs
Change oneliner if-statements to be more readable
2 parents 3a79dab + df8b205 commit 4dcf553

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

roles/ansible-ssh-hardening/templates/openssh.conf.j2

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
# ===================
1010

1111
# Address family should always be limited to the active network configuration.
12-
AddressFamily {% if network_ipv6_enable -%}any{% else -%}inet{% endif %}
13-
12+
AddressFamily {{ 'any' if network_ipv6_enable else 'inet' }}
1413
# Restrict the following configuration to be limited to this Host.
1514
{% for host in ssh_remote_hosts -%}
1615
Host {{host}}

roles/ansible-ssh-hardening/templates/opensshd.conf.j2

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,15 @@
99
# ===================
1010

1111
# Either disable or only allow root login via certificates.
12-
{% if ssh_allow_root_with_key -%}
13-
PermitRootLogin without-password
14-
{% else %}
15-
PermitRootLogin no
16-
{% endif %}
12+
PermitRootLogin {{ 'without-password' if ssh_allow_root_with_key else 'no' }}
1713

1814
# Define which port sshd should listen to. Default to `22`.
1915
{% for port in ssh_ports -%}
2016
Port {{port}}
2117
{% endfor %}
2218

2319
# Address family should always be limited to the active network configuration.
24-
AddressFamily {% if network_ipv6_enable -%}any{% else %}inet{% endif %}
20+
AddressFamily {{ 'any' if network_ipv6_enable else 'inet' }}
2521

2622
# Define which addresses sshd should listen to. Default to `0.0.0.0`, ie make sure you put your desired address in here, since otherwise sshd will listen to everyone.
2723
{% for address in ssh_listen_to -%}
@@ -138,7 +134,7 @@ IgnoreUserKnownHosts yes
138134
HostbasedAuthentication no
139135

140136
# Enable PAM to enforce system wide rules
141-
UsePAM {% if ssh_use_pam -%}yes{% else %}no{% endif %}
137+
UsePAM {{ 'yes' if ssh_use_pam else 'no' }}
142138

143139
# Disable password-based authentication, it can allow for potentially easier brute-force attacks.
144140
PasswordAuthentication no
@@ -187,11 +183,11 @@ PermitTunnel no
187183

188184
# Disable forwarding tcp connections.
189185
# no real advantage without denied shell access
190-
AllowTcpForwarding {% if ssh_allow_tcp_forwarding -%}yes{% else %}no{% endif %}
186+
AllowTcpForwarding {{ 'yes' if ssh_allow_tcp_forwarding else 'no' }}
191187

192188
# Disable agent formwarding, since local agent could be accessed through forwarded connection.
193189
# no real advantage without denied shell access
194-
AllowAgentForwarding {% if ssh_allow_agent_forwarding -%}yes{% else %}no{% endif %}
190+
AllowAgentForwarding {{ 'yes' if ssh_allow_agent_forwarding else 'no' }}
195191

196192
# Do not allow remote port forwardings to bind to non-loopback addresses.
197193
GatewayPorts no
@@ -204,9 +200,9 @@ X11UseLocalhost yes
204200
# Misc. configuration
205201
# ===================
206202

207-
PrintMotd {% if ssh_print_motd -%}yes{% else %}no{% endif %}
203+
PrintMotd {{ 'yes' if ssh_print_motd else 'no' }}
208204

209-
PrintLastLog {% if ssh_print_last_log -%}yes{% else %}no{% endif %}
205+
PrintLastLog {{ yes if ssh_print_last_log else 'no' }}
210206

211207
#Banner /etc/ssh/banner.txt
212208
#UseDNS yes

0 commit comments

Comments
 (0)