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

Commit fa499d1

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. The other main wrinkle is that most of our Macs are on 10.10.5, which ships an older OpenSSH (version 6.2p2) missing support for many of the newer cryptographic algorithms found in more recent versions, and which additionally uses a non-standard location for the actual sshd_config file itself, `/etc/sshd_config` not `/etc/ssh/sshd_config`. 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. However, while our machines are using 10.10.5, our Travis configuration of `osx_image: xcode7.3` loads a 10.11 image. Our actual builders have a variety of XCode versions, though most of them have XCode 7.2.1.
1 parent 0dcaec2 commit fa499d1

File tree

5 files changed

+87
-1
lines changed

5 files changed

+87
-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: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Most of our Macs have an older version of OpenSSH,
2+
# so specify alternate cryptographic settings for those machines
3+
{% if grains['os'] != 'MacOS' %}
4+
HostKey /etc/ssh/ssh_host_ed25519_key
5+
KexAlgorithms [email protected]
6+
7+
# No explicit MACs listed because poly1305 is a MAC
8+
{% else %}
9+
HostKey /etc/ssh/ssh_host_rsa_key
10+
KexAlgorithms diffie-hellman-group-exchange-sha256
11+
12+
13+
{% endif %}
14+
15+
# Only pubkey authentication is enabled, i.e. password logins are disabled
16+
PasswordAuthentication no
17+
ChallengeResponseAuthentication no
18+
PubkeyAuthentication yes
19+
AuthenticationMethods publickey
20+
# TODO: Disable root login after creating per-user accounts
21+
#PermitRootLogin no
22+
23+
MaxAuthTries 2
24+
LoginGraceTime 1m
25+
26+
{% if grains['kernel'] == 'Linux' %}
27+
UsePAM yes
28+
# PAM does this
29+
PrintMotd no
30+
{% endif %}
31+
32+
UsePrivilegeSeparation sandbox
33+
# LogLevel VERBOSE logs user's key fingerprint on login.
34+
# Needed to have a clear audit track of which key was using to log in.
35+
LogLevel VERBOSE

admin/init.sls

Lines changed: 26 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,19 @@ UTC:
2223
- mode: 644
2324
- source: salt://{{ tpldir }}/files/hosts
2425
26+
sshd_config:
27+
file.managed:
28+
{% if grains['os'] != 'MacOS' %}
29+
- name: /etc/ssh/sshd_config
30+
{% else %}
31+
- name: /etc/sshd_config
32+
{% endif %}
33+
- user: {{ root.user }}
34+
- group: {{ root.group }}
35+
- mode: 644
36+
- template: jinja
37+
- source: salt://{{ tpldir }}/files/sshd_config
38+
2539
sshkeys-dir:
2640
file.directory:
2741
- name: {{ root.home }}/.ssh
@@ -41,3 +55,14 @@ sshkeys:
4155
{% endfor %}
4256
- require:
4357
- file: sshkeys-dir
58+
59+
{% if grains['os'] != 'MacOS' %}
60+
sshd:
61+
service.running:
62+
- name: ssh
63+
- enable: True
64+
- require:
65+
- file: sshkeys
66+
- watch:
67+
- file: sshd_config
68+
{% endif %}

tests/sls/admin/__init__.py

Whitespace-only changes.

tests/sls/admin/valid_sshd_config.py

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

0 commit comments

Comments
 (0)