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

Commit beb77e4

Browse files
authored
Merge pull request #295 from aisbergg/feat-match-local-port
Add option to create 'LocalPort' match blocks
2 parents f560d51 + fb8ac0a commit beb77e4

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Warning: This role disables root-login on the target server! Please make sure yo
7070
|`ssh_server_match_address` | '' | 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. |
7171
|`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. |
7272
|`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. |
73+
|`ssh_server_match_local_port` | '' | 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. |
7374
|`ssh_server_permit_environment_vars` | `no` | `yes` to specify that ~/.ssh/environment and environment= options in ~/.ssh/authorized_keys are processed by sshd. With openssh version 7.8 it is possible to specify a whitelist of environment variable names in addition to global "yes" or "no" settings |
7475
|`ssh_server_accept_env_vars`| '' | Specifies what environment variables sent by the client will be copied into the session's enviroment, multiple environment variables may be separated by whitespace |
7576
|`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. |

defaults/main.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,18 @@ sftp_chroot_dir: /home/%u
155155
# enable experimental client roaming
156156
ssh_client_roaming: false
157157

158-
# list of hashes (containing user and rules) to generate Match User blocks for.
158+
# list of hashes (containing user and rules) to generate Match User blocks for
159159
ssh_server_match_user: false # sshd
160160

161-
# list of hashes (containing group and rules) to generate Match Group blocks for.
161+
# list of hashes (containing group and rules) to generate Match Group blocks for
162162
ssh_server_match_group: false # sshd
163163

164-
# list of hashes (containing addresses/subnets and rules) to generate Match Address blocks for.
164+
# list of hashes (containing addresses/subnets and rules) to generate Match Address blocks for
165165
ssh_server_match_address: false # sshd
166166

167+
# list of hashes (containing port and rules) to generate Match LocalPort blocks for
168+
ssh_server_match_local_port: false # sshd
169+
167170
ssh_server_permit_environment_vars: 'no'
168171
ssh_server_accept_env_vars : ''
169172

templates/opensshd.conf.j2

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ Match Group sftponly
261261
PermitRootLogin no
262262
X11Forwarding no
263263
{% endif %}
264-
265264
{% if ssh_server_match_address %}
265+
266266
# Address matching configuration
267267
# ============================
268268

@@ -273,8 +273,8 @@ Match Address {{ item.address }}
273273
{% endfor %}
274274
{% endfor %}
275275
{% endif %}
276-
277276
{% if ssh_server_match_group %}
277+
278278
# Group matching configuration
279279
# ============================
280280

@@ -285,8 +285,8 @@ Match Group {{ item.group }}
285285
{% endfor %}
286286
{% endfor %}
287287
{% endif %}
288-
289288
{% if ssh_server_match_user %}
289+
290290
# User matching configuration
291291
# ===========================
292292

@@ -297,3 +297,15 @@ Match User {{ item.user }}
297297
{% endfor %}
298298
{% endfor %}
299299
{% endif %}
300+
{% if ssh_server_match_local_port %}
301+
302+
# LocalPort matching configuration
303+
# ================================
304+
305+
{% for item in ssh_server_match_local_port %}
306+
Match LocalPort {{ item.port }}
307+
{% for rule in item.rules %}
308+
{{ rule | indent(4) }}
309+
{% endfor %}
310+
{% endfor %}
311+
{% endif %}

tests/default_custom.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@
7373
sftp_enabled: true
7474
sftp_chroot: true
7575
#ssh_server_enabled: false
76+
ssh_server_ports:
77+
- 22
78+
- 222
7679
ssh_server_match_address:
7780
- address: '192.168.1.1/24'
7881
rules:
@@ -88,6 +91,11 @@
8891
rules:
8992
- 'AllowTcpForwarding yes'
9093
- 'AllowAgentForwarding no'
94+
ssh_server_match_local_port:
95+
- port: 222
96+
rules:
97+
- 'AllowTcpForwarding yes'
98+
- 'AllowAgentForwarding no'
9199
ssh_remote_hosts:
92100
- names: ['example.com', 'example2.com']
93101
options: ['Port 2222', 'ForwardAgent yes']

0 commit comments

Comments
 (0)