Skip to content

Commit bffbca3

Browse files
authored
fix: include external config files first so they can override all options (#316)
* fix: include external config files first so they can override all options * test: replaced cipher option with usedns for tests_deprecated_sshd_variable
1 parent da322bf commit bffbca3

File tree

6 files changed

+15
-15
lines changed

6 files changed

+15
-15
lines changed

meta/options_body

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
Include
12
Port
23
AddressFamily
34
ListenAddress
@@ -51,7 +52,6 @@ HostbasedAcceptedKeyTypes
5152
HostbasedAcceptedAlgorithms
5253
HostbasedAuthentication
5354
HostbasedUsesNameFromPacketOnly
54-
Include
5555
IPQoS
5656
IgnoreRhosts
5757
IgnoreUserKnownHosts

meta/options_match

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
Include
12
AcceptEnv
23
AllowAgentForwarding
34
AllowGroups
@@ -29,7 +30,6 @@ HostbasedAcceptedAlgorithms
2930
HostbasedAuthentication
3031
HostbasedUsesNameFromPacketOnly
3132
IgnoreRhosts
32-
Include
3333
IPQoS
3434
KbdInteractiveAuthentication
3535
KerberosAuthentication

templates/sshd_config.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
{% if match_list is iterable %}
5252
{% for match in match_list %}
5353
Match {{ match["Condition"] }}
54+
{{ render_option("Include",match["Include"],true) -}}
5455
{{ render_option("AcceptEnv",match["AcceptEnv"],true) -}}
5556
{{ render_option("AllowAgentForwarding",match["AllowAgentForwarding"],true) -}}
5657
{{ render_option("AllowGroups",match["AllowGroups"],true) -}}
@@ -82,7 +83,6 @@ Match {{ match["Condition"] }}
8283
{{ render_option("HostbasedAuthentication",match["HostbasedAuthentication"],true) -}}
8384
{{ render_option("HostbasedUsesNameFromPacketOnly",match["HostbasedUsesNameFromPacketOnly"],true) -}}
8485
{{ render_option("IgnoreRhosts",match["IgnoreRhosts"],true) -}}
85-
{{ render_option("Include",match["Include"],true) -}}
8686
{{ render_option("IPQoS",match["IPQoS"],true) -}}
8787
{{ render_option("KbdInteractiveAuthentication",match["KbdInteractiveAuthentication"],true) -}}
8888
{{ render_option("KerberosAuthentication",match["KerberosAuthentication"],true) -}}
@@ -131,6 +131,7 @@ Match {{ match["Condition"] }}
131131
{{ match_block(match_list) -}}
132132
{% endif %}
133133
{% endmacro %}
134+
{{ body_option("Include",sshd_Include) -}}
134135
{{ body_option("Port",sshd_Port) -}}
135136
{{ body_option("AddressFamily",sshd_AddressFamily) -}}
136137
{{ body_option("ListenAddress",sshd_ListenAddress) -}}
@@ -184,7 +185,6 @@ Match {{ match["Condition"] }}
184185
{{ body_option("HostbasedAcceptedAlgorithms",sshd_HostbasedAcceptedAlgorithms) -}}
185186
{{ body_option("HostbasedAuthentication",sshd_HostbasedAuthentication) -}}
186187
{{ body_option("HostbasedUsesNameFromPacketOnly",sshd_HostbasedUsesNameFromPacketOnly) -}}
187-
{{ body_option("Include",sshd_Include) -}}
188188
{{ body_option("IPQoS",sshd_IPQoS) -}}
189189
{{ body_option("IgnoreRhosts",sshd_IgnoreRhosts) -}}
190190
{{ body_option("IgnoreUserKnownHosts",sshd_IgnoreUserKnownHosts) -}}

templates/sshd_config_snippet.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
{% if match_list is iterable %}
5050
{% for match in match_list %}
5151
Match {{ match["Condition"] }}
52+
{{ render_option("Include",match["Include"],true) -}}
5253
{{ render_option("AcceptEnv",match["AcceptEnv"],true) -}}
5354
{{ render_option("AllowAgentForwarding",match["AllowAgentForwarding"],true) -}}
5455
{{ render_option("AllowGroups",match["AllowGroups"],true) -}}
@@ -80,7 +81,6 @@ Match {{ match["Condition"] }}
8081
{{ render_option("HostbasedAuthentication",match["HostbasedAuthentication"],true) -}}
8182
{{ render_option("HostbasedUsesNameFromPacketOnly",match["HostbasedUsesNameFromPacketOnly"],true) -}}
8283
{{ render_option("IgnoreRhosts",match["IgnoreRhosts"],true) -}}
83-
{{ render_option("Include",match["Include"],true) -}}
8484
{{ render_option("IPQoS",match["IPQoS"],true) -}}
8585
{{ render_option("KbdInteractiveAuthentication",match["KbdInteractiveAuthentication"],true) -}}
8686
{{ render_option("KerberosAuthentication",match["KerberosAuthentication"],true) -}}
@@ -129,6 +129,7 @@ Match {{ match["Condition"] }}
129129
{{ match_block(match_list) -}}
130130
{% endif %}
131131
{% endmacro %}
132+
{{ body_option("Include",sshd_Include) -}}
132133
{{ body_option("Port",sshd_Port) -}}
133134
{{ body_option("AddressFamily",sshd_AddressFamily) -}}
134135
{{ body_option("ListenAddress",sshd_ListenAddress) -}}
@@ -182,7 +183,6 @@ Match {{ match["Condition"] }}
182183
{{ body_option("HostbasedAcceptedAlgorithms",sshd_HostbasedAcceptedAlgorithms) -}}
183184
{{ body_option("HostbasedAuthentication",sshd_HostbasedAuthentication) -}}
184185
{{ body_option("HostbasedUsesNameFromPacketOnly",sshd_HostbasedUsesNameFromPacketOnly) -}}
185-
{{ body_option("Include",sshd_Include) -}}
186186
{{ body_option("IPQoS",sshd_IPQoS) -}}
187187
{{ body_option("IgnoreRhosts",sshd_IgnoreRhosts) -}}
188188
{{ body_option("IgnoreUserKnownHosts",sshd_IgnoreUserKnownHosts) -}}

tests/tests_deprecated_sshd_variable.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
sshd:
1717
AcceptEnv: LANG
1818
Banner: /etc/issue
19-
Ciphers: aes256-ctr
2019
Subsystem: "sftp internal-sftp"
20+
UseDNS: true
2121
sshd_config_file: /etc/ssh/sshd_config
2222

2323
- name: Verify the options are correctly set
@@ -50,16 +50,16 @@
5050
that:
5151
- "'acceptenv LANG' in runtime.stdout"
5252
- "'banner /etc/issue' in runtime.stdout"
53-
- "'ciphers aes256-ctr' in runtime.stdout"
5453
- "'subsystem sftp internal-sftp' in runtime.stdout"
54+
- "'usedns yes' in runtime.stdout"
5555

5656
- name: Check the options are in configuration file
5757
ansible.builtin.assert:
5858
that:
5959
- "'AcceptEnv LANG' in config.content | b64decode"
6060
- "'Banner /etc/issue' in config.content | b64decode"
61-
- "'Ciphers aes256-ctr' in config.content | b64decode"
6261
- "'Subsystem sftp internal-sftp' in config.content | b64decode"
62+
- "'UseDNS yes' in config.content | b64decode"
6363

6464
- name: "Restore configuration files"
6565
ansible.builtin.include_tasks: tasks/restore.yml
@@ -80,8 +80,8 @@
8080
sshd:
8181
AcceptEnv: LANG
8282
Banner: /etc/issue
83-
Ciphers: aes256-ctr
8483
Subsystem: "sftp internal-sftp"
84+
UseDNS: true
8585
sshd_config_file: /etc/ssh/sshd_config
8686

8787
tasks:
@@ -107,16 +107,16 @@
107107
that:
108108
- "'acceptenv LANG' in runtime.stdout"
109109
- "'banner /etc/issue' in runtime.stdout"
110-
- "'ciphers aes256-ctr' in runtime.stdout"
111110
- "'subsystem sftp internal-sftp' in runtime.stdout"
111+
- "'usedns yes' in runtime.stdout"
112112

113113
- name: Check the options are in configuration file
114114
ansible.builtin.assert:
115115
that:
116116
- "'AcceptEnv LANG' in config.content | b64decode"
117117
- "'Banner /etc/issue' in config.content | b64decode"
118-
- "'Ciphers aes256-ctr' in config.content | b64decode"
119118
- "'Subsystem sftp internal-sftp' in config.content | b64decode"
119+
- "'UseDNS yes' in config.content | b64decode"
120120

121121
- name: "Restore configuration files"
122122
ansible.builtin.include_tasks: tasks/restore.yml

tests/tests_set_common.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
sshd_config:
1717
AcceptEnv: LANG
1818
Banner: /etc/issue
19-
Ciphers: aes256-ctr
2019
Subsystem: "sftp internal-sftp"
20+
UseDNS: true
2121
sshd_config_file: /etc/ssh/sshd_config
2222

2323
- name: Verify the options are correctly set
@@ -42,16 +42,16 @@
4242
that:
4343
- "'acceptenv LANG' in runtime.stdout"
4444
- "'banner /etc/issue' in runtime.stdout"
45-
- "'ciphers aes256-ctr' in runtime.stdout"
4645
- "'subsystem sftp internal-sftp' in runtime.stdout"
46+
- "'usedns yes' in runtime.stdout"
4747

4848
- name: Check the options are in configuration file
4949
ansible.builtin.assert:
5050
that:
5151
- "'AcceptEnv LANG' in config.content | b64decode"
5252
- "'Banner /etc/issue' in config.content | b64decode"
53-
- "'Ciphers aes256-ctr' in config.content | b64decode"
5453
- "'Subsystem sftp internal-sftp' in config.content | b64decode"
54+
- "'UseDNS yes' in config.content | b64decode"
5555

5656
- name: "Restore configuration files"
5757
ansible.builtin.include_tasks: tasks/restore.yml

0 commit comments

Comments
 (0)