Browse Source

Merge pull request #339 from fengor/master

More secure defaults for ssh.
Alex Payne 9 years ago
parent
commit
3ff928c762

+ 10
- 0
roles/common/tasks/main.yml View File

@@ -31,6 +31,16 @@
31 31
     - vim
32 32
     - zsh
33 33
 
34
+- name: Set timezone to UTC
35
+  action: shell echo Etc/UTC > /etc/timezone
36
+
37
+- name: Set localtime to UTC
38
+  file: src=/usr/share/zoneinfo/Etc/UTC dest=/etc/localtime
39
+
40
+- name: Reconfigure tzdata
41
+  action: command dpkg-reconfigure -f noninteractive tzdata
42
+  when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'
43
+
34 44
 - name: Install unattended upgrades (Debian/Ubuntu only)
35 45
   apt: pkg=unattended-upgrades state=installed
36 46
   when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'

+ 6
- 2
roles/common/tasks/security.yml View File

@@ -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=etc_ssh_sshd_config.j2 dest=/etc/ssh/sshd_config
21 21
   notify: restart ssh
22
+  
23
+- name: Update ssh config for more secure defaults
24
+  template: src=etc_ssh_ssh_config.j2 dest=/etc/ssh/ssh_config
25
+

+ 9
- 0
roles/common/templates/etc_ssh_ssh_config.j2 View File

@@ -0,0 +1,9 @@
1
+    Ciphers {{ ciphers }}
2
+    KexAlgorithms {{ kex_algorithms }}
3
+    SendEnv LANG LC_*
4
+    HashKnownHosts yes
5
+    GSSAPIAuthentication yes
6
+    GSSAPIDelegateCredentials no
7
+    MACs {{ macs }}
8
+    PasswordAuthentication no
9
+

+ 72
- 0
roles/common/templates/etc_ssh_sshd_config.j2 View File

@@ -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 View File

@@ -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…
Cancel
Save