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

Commit ed07d5f

Browse files
committed
Manage sshd_config file
This is based on Mozilla's Modern sshd_config from: https://wiki.mozilla.org/Security/Guidelines/OpenSSH Note that root login is still allowed, because we have not yet set up per-user accounts. Add a test to ensure the sshd_config file is properly parsed and validated by the OpenSSH version on the machine to help guard against this behavior.
1 parent df07d3a commit ed07d5f

File tree

5 files changed

+69
-1
lines changed

5 files changed

+69
-1
lines changed

.travis/dispatch.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ else
137137
./test.py sls.servo-build-dependencies.android
138138
fi
139139

140+
./test.py sls.admin
140141
# Salt doesn't support timezone.system on OSX
141142
# See https://github.com/saltstack/salt/issues/31345
142143
if [[ ! "${SALT_NODE_ID}" =~ servo-mac* ]]; then

admin/files/sshd_config

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
HostKey /etc/ssh/ssh_host_ed25519_key
2+
KexAlgorithms [email protected]
3+
4+
5+
# Only pubkey authentication is enabled, i.e. password logins are disabled
6+
PasswordAuthentication no
7+
ChallengeResponseAuthentication no
8+
PubkeyAuthentication yes
9+
AuthenticationMethods publickey
10+
# TODO: Disable root login after creating per-user accounts
11+
PermitRootLogin yes
12+
13+
MaxAuthTries 2
14+
LoginGraceTime 1m
15+
16+
{% if grains['kernel'] == 'Linux' %}
17+
UsePAM yes
18+
# PAM does this
19+
PrintMotd no
20+
{% endif %}
21+
22+
UsePrivilegeSeparation sandbox
23+
# LogLevel VERBOSE logs user's key fingerprint on login.
24+
# Needed to have a clear audit track of which key was using to log in.
25+
LogLevel VERBOSE

admin/init.sls

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ admin-packages:
77
- tmux
88
- mosh
99
{% if grains['os'] != 'MacOS' %}
10-
- screen # Installed by default on OS X
10+
- openssh-server # Use default macOS version, not Homebrew's
11+
- screen # Installed by default on macOS
1112
{% endif %}
1213
1314
{% if grains['os'] != 'MacOS' and grains.get('virtual_subtype', '') != 'Docker' %}
@@ -22,6 +23,15 @@ UTC:
2223
- mode: 644
2324
- source: salt://{{ tpldir }}/files/hosts
2425
26+
sshd_config:
27+
file.managed:
28+
- name: /etc/ssh/sshd_config
29+
- user: {{ root.user }}
30+
- group: {{ root.group }}
31+
- mode: 644
32+
- template: jinja
33+
- source: salt://{{ tpldir }}/files/sshd_config
34+
2535
sshkeys-dir:
2636
file.directory:
2737
- name: {{ root.home }}/.ssh
@@ -41,3 +51,14 @@ sshkeys:
4151
{% endfor %}
4252
- require:
4353
- file: sshkeys-dir
54+
55+
{% if grains['os'] != 'MacOS' %}
56+
sshd:
57+
service.running:
58+
- name: ssh
59+
- enable: True
60+
- require:
61+
- file: sshkeys
62+
- watch:
63+
- file: sshd_config
64+
{% endif %}

tests/sls/admin/__init__.py

Whitespace-only changes.

tests/sls/admin/valid_sshd_config.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import subprocess
2+
import sys
3+
4+
from tests.util import Failure, Success
5+
6+
7+
def run():
8+
proc = subprocess.Popen(
9+
['sshd', '-T', '-f', '/etc/ssh/sshd_config'],
10+
stdout=subprocess.DEVNULL,
11+
stderr=subprocess.PIPE,
12+
universal_newlines=True
13+
)
14+
_, stderr = proc.communicate()
15+
16+
if proc.returncode != 0:
17+
return Failure(
18+
'Invalid sshd_config file:', stderr
19+
)
20+
21+
return Success('SSHD config file is valid')

0 commit comments

Comments
 (0)