Selaa lähdekoodia

More secure defaults for ssh.

Ciphers, Kex and MAC can be set via defaults.var
fengor 9 vuotta sitten
vanhempi
commit
39566abb6c

+ 6
- 2
roles/common/tasks/security.yml Näytä tiedosto

@@ -16,6 +16,10 @@
16 16
 - name: Ensure fail2ban is started
17 17
   service: name=fail2ban state=started
18 18
 
19
-- name: Update sshd config to disallow root logins
20
-  lineinfile: dest=/etc/ssh/sshd_config regexp=^PermitRootLogin line="PermitRootLogin no" state=present
19
+- name: Update sshd config for PFS and more secure defaults
20
+  template: src=sshd.j2 dest=/etc/ssh/sshd_config
21 21
   notify: restart ssh
22
+  
23
+- name: Update ssh config for more secure defaults
24
+  template: src=ssh.j2 dest=/etc/ssh/ssh_config
25
+

+ 10
- 0
roles/common/templates/ssh.j2 Näytä tiedosto

@@ -0,0 +1,10 @@
1
+    Ciphers {{ ciphers }}
2
+    #KexAlgorithms curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256
3
+    KexAlgorithms {{ kex_algorithms }}
4
+    SendEnv LANG LC_*
5
+    HashKnownHosts yes
6
+    GSSAPIAuthentication yes
7
+    GSSAPIDelegateCredentials no
8
+    MACs {{ macs }}
9
+    PasswordAuthentication no
10
+

+ 72
- 0
roles/common/templates/sshd.j2 Näytä tiedosto

@@ -0,0 +1,72 @@
1
+# What ports, IPs and protocols we listen for
2
+Port 22
3
+# Use these options to restrict which interfaces/protocols sshd will bind to
4
+#ListenAddress ::
5
+#ListenAddress 0.0.0.0
6
+
7
+Protocol 2
8
+
9
+# HostKeys for protocol version 2
10
+HostKey /etc/ssh/ssh_host_rsa_key
11
+#Privilege Separation is turned on for security
12
+UsePrivilegeSeparation yes
13
+
14
+KexAlgorithms {{ kex_algorithms }}
15
+Ciphers {{ ciphers }}
16
+MACs {{ macs }}
17
+
18
+# Lifetime and size of ephemeral version 1 server key
19
+KeyRegenerationInterval 3600
20
+ServerKeyBits 768
21
+
22
+# Logging
23
+SyslogFacility AUTH
24
+LogLevel INFO
25
+
26
+# Authentication:
27
+LoginGraceTime 120
28
+PermitRootLogin no
29
+StrictModes yes
30
+
31
+RSAAuthentication yes
32
+PubkeyAuthentication yes
33
+
34
+# Don't read the user's ~/.rhosts and ~/.shosts files
35
+IgnoreRhosts yes
36
+# For this to work you will also need host keys in /etc/ssh_known_hosts
37
+RhostsRSAAuthentication no
38
+# similar for protocol version 2
39
+HostbasedAuthentication no
40
+
41
+PermitEmptyPasswords no
42
+
43
+# Change to yes to enable challenge-response passwords (beware issues with
44
+# some PAM modules and threads)
45
+ChallengeResponseAuthentication yes
46
+
47
+# Change to no to disable tunnelled clear text passwords
48
+PasswordAuthentication no
49
+
50
+
51
+X11Forwarding yes
52
+X11DisplayOffset 10
53
+PrintMotd no
54
+PrintLastLog yes
55
+TCPKeepAlive yes
56
+
57
+# Allow client to pass locale environment variables
58
+AcceptEnv LANG LC_*
59
+
60
+Subsystem sftp /usr/lib/openssh/sftp-server
61
+
62
+# Set this to 'yes' to enable PAM authentication, account processing,
63
+# and session processing. If this is enabled, PAM authentication will
64
+# be allowed through the ChallengeResponseAuthentication and
65
+# PasswordAuthentication.  Depending on your PAM configuration,
66
+# PAM authentication via ChallengeResponseAuthentication may bypass
67
+# the setting of "PermitRootLogin without-password".
68
+# If you just want the PAM account and session checks to run without
69
+# PAM authentication, then enable this but set PasswordAuthentication
70
+# and ChallengeResponseAuthentication to 'no'.
71
+UsePAM yes
72
+

+ 5
- 0
vars/defaults.yml Näytä tiedosto

@@ -13,6 +13,11 @@ main_user_shell: "/bin/bash"
13 13
 friendly_networks:
14 14
   - ""
15 15
 
16
+# ssh
17
+kex_algorithms: "diffie-hellman-group-exchange-sha256"
18
+ciphers: "aes256-ctr,aes192-ctr,aes128-ctr"
19
+macs: "hmac-sha2-512,hmac-sha2-256,hmac-ripemd160"
20
+
16 21
 # ntp
17 22
 ntp_servers:
18 23
   # use nearby ntp servers by default

Loading…
Peruuta
Tallenna