-
Notifications
You must be signed in to change notification settings - Fork 2
/
init.sls
89 lines (79 loc) · 2.7 KB
/
init.sls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
{# SSH-Config based on https://infosec.mozilla.org/guidelines/openssh.html
snapshot of 2023-11-1: Modern (OpenSSH 6.7+)
removed KexAlgorithms: ecdh-sha2-nistp521,ecdh-sha2-nistp384,ecdh-sha2-nistp256
removed Ciphers: aes256-ctr,aes192-ctr,aes128-ctr
#}
openssh:
pkg.installed:
- pkgs:
{% if grains['os_family'] == "Debian" %}
- openssh-client
- openssh-server
{% elif grains['os_family'] == "Arch" %}
- openssh
{% endif %}
openssh-server:
service.running:
{% if grains['os_family'] == "Debian" %}
- name: ssh
{% elif grains['os_family'] == "Arch" %}
- name: sshd
{% endif %}
- enable: True
- require:
- pkg: openssh
{% set minimum_moduli= 3071 %}
{% for p,r in [
("UseDNS", "UseDNS no"),
("AuthenticationMethods", "AuthenticationMethods publickey"),
("PasswordAuthentication", "PasswordAuthentication no"),
("PermitRootLogin", "PermitRootLogin prohibit-password"),
("KexAlgorithms", "KexAlgorithms curve25519-sha256,[email protected],diffie-hellman-group-exchange-sha256"),
("MACs", "MACs [email protected],[email protected],[email protected],hmac-sha2-512,hmac-sha2-256,[email protected]"),
("Subsystem\s+sftp", "Subsystem sftp /usr/lib/ssh/sftp-server -f AUTHPRIV -l INFO"),
("LogLevel", "LogLevel VERBOSE"),
] %}
/etc/ssh/sshd_config_{{ p }}:
file.replace:
- name: /etc/ssh/sshd_config
- pattern: |
^\s*{{ p }}.*
- repl: |
{{ r }}
- append_if_not_found: true
- require:
- pkg: openssh
- watch_in:
- service: openssh-server
{% endfor %}
/etc/ssh/sshd_config_hostkeys:
file.prepend:
- name: /etc/ssh/sshd_config
- text: |
# Supported HostKey algorithms by order of preference.
HostKey /etc/ssh/ssh_host_ed25519_key
HostKey /etc/ssh/ssh_host_rsa_key
# disabled: HostKey /etc/ssh/ssh_host_ecdsa_key
- watch_in:
- service: openssh-server
filter_weak_moduli:
cmd.run:
- name: awk '$5 >= {{ minimum_moduli }}' /etc/ssh/moduli > /etc/ssh/moduli.tmp && mv /etc/ssh/moduli.tmp /etc/ssh/moduli
- unless: grep -v "^#" /etc/ssh/moduli | awk '$5 < {{ minimum_moduli }} { exit 1 }'
- require:
- pkg: openssh
- watch_in:
- service: openssh-server
/etc/sudoers.d/ssh_auth:
file.managed:
- makedirs: True
- mode: "0440"
- contents: |
Defaults env_keep += "SSH_AUTH_SOCK"
{% from "ssh/lib.sls" import ssh_keys_update %}
{{ ssh_keys_update('root',
salt['pillar.get']('ssh_authorized_keys', False),
salt['pillar.get']('ssh_deprecated_keys', False)
)
}}