Skip to content

Commit

Permalink
Allow setting openssh_allow_users to restrict access.
Browse files Browse the repository at this point in the history
Update CI and documentation.
  • Loading branch information
robertdebock committed May 1, 2020
1 parent 1d8be48 commit 6779d88
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ This example is taken from `molecule/resources/converge.yml` and is tested on ea

roles:
- role: robertdebock.openssh
openssh_allow_users: root
```
The machine may need to be prepared using `molecule/resources/prepare.yml`:
Expand All @@ -43,6 +44,18 @@ For verification `molecule/resources/verify.yml` run after the role has been app
tasks:
- name: check if connection still works
ping:
- name: Check if AllowUsers is set
lineinfile:
path: /etc/ssh/sshd_config
line: AllowUsers root
check_mode: yes
register: openssh_check_if_allowusers_is_set
- name: assert results
assert:
that:
- openssh_check_if_allowusers_is_set is not changed
```

Also see a [full explanation and example](https://robertdebock.nl/how-to-use-these-roles.html) on how to use these roles.
Expand Down Expand Up @@ -151,6 +164,10 @@ openssh_accept_env:
- XMODIFIERS
openssh_subsystem: sftp /usr/libexec/openssh/sftp-server
# Restrict access to this (space separated list) of users.
# For example: `openssh_allow_users: root my_user`
# openssh_allow_users: root
```

## Requirements
Expand Down
4 changes: 4 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,7 @@ openssh_accept_env:
- XMODIFIERS

openssh_subsystem: sftp /usr/libexec/openssh/sftp-server

# Restrict access to this (space separated list) of users.
# For example: `openssh_allow_users: root my_user`
# openssh_allow_users: root
1 change: 1 addition & 0 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@

roles:
- role: ansible-role-openssh
openssh_allow_users: root
12 changes: 12 additions & 0 deletions molecule/default/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,15 @@
tasks:
- name: check if connection still works
ping:

- name: Check if AllowUsers is set
lineinfile:
path: /etc/ssh/sshd_config
line: AllowUsers root
check_mode: yes
register: openssh_check_if_allowusers_is_set

- name: assert results
assert:
that:
- openssh_check_if_allowusers_is_set is not changed
4 changes: 4 additions & 0 deletions templates/sshd_config_Alpine.j2
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,7 @@ AcceptEnv {{ item }}
{% endfor %}

Subsystem {{ openssh_subsystem }}

{% if openssh_allow_users is defined %}
AllowUsers {{ openssh_allow_users }}
{% endif %}
4 changes: 4 additions & 0 deletions templates/sshd_config_Archlinux.j2
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,7 @@ AcceptEnv {{ item }}
{% endfor %}

Subsystem {{ openssh_subsystem }}

{% if openssh_allow_users is defined %}
AllowUsers {{ openssh_allow_users }}
{% endif %}
4 changes: 4 additions & 0 deletions templates/sshd_config_Debian.j2
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,7 @@ AcceptEnv {{ item }}
{% endfor %}

Subsystem {{ openssh_subsystem }}

{% if openssh_allow_users is defined %}
AllowUsers {{ openssh_allow_users }}
{% endif %}
4 changes: 4 additions & 0 deletions templates/sshd_config_Fedora.j2
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,7 @@ AcceptEnv {{ item }}
{% endfor %}

Subsystem {{ openssh_subsystem }}

{% if openssh_allow_users is defined %}
AllowUsers {{ openssh_allow_users }}
{% endif %}
4 changes: 4 additions & 0 deletions templates/sshd_config_RedHat-7.j2
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,7 @@ AcceptEnv {{ item }}
{% endfor %}

Subsystem {{ openssh_subsystem }}

{% if openssh_allow_users is defined %}
AllowUsers {{ openssh_allow_users }}
{% endif %}
4 changes: 4 additions & 0 deletions templates/sshd_config_RedHat.j2
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,7 @@ Subsystem {{ openssh_subsystem }}
# AllowTcpForwarding no
# PermitTTY no
# ForceCommand cvs server

{% if openssh_allow_users is defined %}
AllowUsers {{ openssh_allow_users }}
{% endif %}
4 changes: 4 additions & 0 deletions templates/sshd_config_Suse.j2
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,7 @@ AcceptEnv {{ item }}
{% endfor %}

Subsystem {{ openssh_subsystem }}

{% if openssh_allow_users is defined %}
AllowUsers {{ openssh_allow_users }}
{% endif %}

0 comments on commit 6779d88

Please sign in to comment.