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

Commit a58fb13

Browse files
author
Sebastian Gumprich
committed
Merge branch 'master' of github.com:dev-sec/ansible-ssh-hardening into finish_94
2 parents 5e5b597 + 7f9245a commit a58fb13

File tree

8 files changed

+68
-18
lines changed

8 files changed

+68
-18
lines changed

CHANGELOG.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,36 @@
11
# Change Log
22

3+
## [4.2.0](https://github.com/dev-sec/ansible-ssh-hardening/tree/4.2.0) (2017-06-30)
4+
[Full Changelog](https://github.com/dev-sec/ansible-ssh-hardening/compare/4.1.2...4.2.0)
5+
6+
**Implemented enhancements:**
7+
8+
- Add support to specify a list of revoked public keys [\#120](https://github.com/dev-sec/ansible-ssh-hardening/pull/120) ([bachp](https://github.com/bachp))
9+
- use package instead of yum so the operation works on Fedora [\#119](https://github.com/dev-sec/ansible-ssh-hardening/pull/119) ([stenwt](https://github.com/stenwt))
10+
11+
**Fixed bugs:**
12+
13+
- fails in --check mode [\#111](https://github.com/dev-sec/ansible-ssh-hardening/issues/111)
14+
15+
**Merged pull requests:**
16+
17+
- Do not use shell when not needed + Lint whitespaces [\#118](https://github.com/dev-sec/ansible-ssh-hardening/pull/118) ([krhubert](https://github.com/krhubert))
18+
19+
## [4.1.2](https://github.com/dev-sec/ansible-ssh-hardening/tree/4.1.2) (2017-05-31)
20+
[Full Changelog](https://github.com/dev-sec/ansible-ssh-hardening/compare/4.1.1...4.1.2)
21+
22+
**Implemented enhancements:**
23+
24+
- added check\_mode: no to "get openssh-version" task, so it won't fail … [\#117](https://github.com/dev-sec/ansible-ssh-hardening/pull/117) ([wschaft](https://github.com/wschaft))
25+
26+
**Fixed bugs:**
27+
28+
- User login failed after running this module [\#114](https://github.com/dev-sec/ansible-ssh-hardening/issues/114)
29+
30+
**Closed issues:**
31+
32+
- Update readme to include baselines [\#110](https://github.com/dev-sec/ansible-ssh-hardening/issues/110)
33+
334
## [4.1.1](https://github.com/dev-sec/ansible-ssh-hardening/tree/4.1.1) (2017-05-18)
435
[Full Changelog](https://github.com/dev-sec/ansible-ssh-hardening/compare/4.1.0...4.1.1)
536

@@ -11,7 +42,6 @@
1142

1243
- fix validation error [\#113](https://github.com/dev-sec/ansible-ssh-hardening/pull/113) ([pwyliu](https://github.com/pwyliu))
1344

14-
1545
## [4.1.0](https://github.com/dev-sec/ansible-ssh-hardening/tree/4.1.0) (2017-05-09)
1646
[Full Changelog](https://github.com/dev-sec/ansible-ssh-hardening/compare/4.0.0...4.1.0)
1747

@@ -234,4 +264,4 @@
234264

235265

236266

237-
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
267+
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
## Description
88

9-
This role provides secure ssh-client and ssh-server configurations.
9+
This role provides secure ssh-client and ssh-server configurations. It is intended to be compliant with the [DevSec SSH Baseline](https://github.com/dev-sec/ssh-baseline).
1010

1111
Warning: This role disables root-login on the target server! Please make sure you have another user with su or sudo permissions that can login into the server.
1212

@@ -27,7 +27,7 @@ Warning: This role disables root-login on the target server! Please make sure yo
2727
|`ssh_server_ports` | ['22'] |ports on which ssh-server should listen|
2828
|`ssh_client_port` | '22' |port to which ssh-client should connect|
2929
|`ssh_listen_to` | ['0.0.0.0'] |one or more ip addresses, to which ssh-server should listen to. Default is all adresseses, but should be configured to specific addresses for security reasons!|
30-
|`ssh_host_key_files` | ['/etc/ssh/ssh_host_rsa_key', '/etc/ssh/ssh_host_dsa_key', '/etc/ssh/ssh_host_ecdsa_key'] |Host keys to look for when starting sshd.|
30+
|`ssh_host_key_files` | [] |Host keys for sshd. If empty ['/etc/ssh/ssh_host_rsa_key', '/etc/ssh/ssh_host_ecdsa_key', '/etc/ssh/ssh_host_ed25519_key'] will be used, as far as supported by the installed sshd version|
3131
|`ssh_client_alive_interval` | 600 | specifies an interval for sending keepalive messages |
3232
|`ssh_client_alive_count` | 3 | defines how often keep-alive messages are sent |
3333
|`ssh_permit_tunnel` | false | true if SSH Port Tunneling is required |
@@ -61,7 +61,7 @@ Warning: This role disables root-login on the target server! Please make sure yo
6161
|`ssh_server_match_user` | '' | Introduces a conditional block. If all of the criteria on the Match line are satisfied, the keywords on the following lines override those set in the global section of the config file, until either another Match line or the end of the file. |
6262
|`ssh_server_permit_environment_vars` | `false` | `true` to specify that ~/.ssh/environment and environment= options in ~/.ssh/authorized_keys are processed by sshd |
6363
|`ssh_use_dns` | `false` | Specifies whether sshd should look up the remote host name, and to check that the resolved host name for the remote IP address maps back to the very same IP address. |
64-
64+
|`ssh_server_revoked_keys` | [] | a list of revoked public keys that the ssh server will always reject, useful to revoke known weak or compromised keys.|
6565

6666
## Example Playbook
6767

ansible.cfg

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
# finds first
99

1010
[defaults]
11-
ansible_managed = Ansible managed: {file} modified on %Y-%m-%d by {uid} on {host}
11+
ansible_managed = Ansible managed: {file} modified by {uid} on {host}
12+
roles_path = /vagrant
1213

13-
role_path = /vagrant
14+
[ssh_connection]
1415
scp_if_ssh = True

defaults/main.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ ssh_client_port: '22' # ssh
4040
ssh_listen_to: ['0.0.0.0'] # sshd
4141

4242
# Host keys to look for when starting sshd.
43-
ssh_host_key_files: ['/etc/ssh/ssh_host_rsa_key', '/etc/ssh/ssh_host_ecdsa_key', '/etc/ssh/ssh_host_ed25519_key'] # sshd
43+
ssh_host_key_files: [] # sshd
4444

4545
# Specifies the maximum number of authentication attempts permitted per connection. Once the number of failures reaches half this value, additional failures are logged.
4646
ssh_max_auth_retries: 2
@@ -174,3 +174,9 @@ sshd_moduli_minimum: 2048
174174

175175
# disable ChallengeResponseAuthentication
176176
ssh_challengeresponseauthentication: false
177+
178+
# look up the remote host name, defaults to false from 6.8, see: http://www.openssh.com/txt/release-6.8
179+
ssh_use_dns: false
180+
181+
# a list of public keys that are never accepted by the ssh server
182+
ssh_server_revoked_keys: []

tasks/main.yml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,27 @@
1111
shell: ssh -V 2>&1 | sed -r 's/.*_([0-9]*\.[0-9]).*/\1/g'
1212
changed_when: false
1313
register: sshd_version
14+
check_mode: no
1415

1516
- name: set hostkeys according to openssh-version
1617
set_fact:
17-
ssh_host_key_files: ['/etc/ssh/ssh_host_rsa_key']
18-
when: sshd_version.stdout >= '5.3'
18+
ssh_host_key_files: ['/etc/ssh/ssh_host_rsa_key', '/etc/ssh/ssh_host_ecdsa_key', '/etc/ssh/ssh_host_ed25519_key']
19+
when: sshd_version.stdout >= '6.3' and not ssh_host_key_files
1920

2021
- name: set hostkeys according to openssh-version
2122
set_fact:
2223
ssh_host_key_files: ['/etc/ssh/ssh_host_rsa_key', '/etc/ssh/ssh_host_ecdsa_key']
23-
when: sshd_version.stdout >= '6.0'
24+
when: sshd_version.stdout >= '6.0' and not ssh_host_key_files
2425

2526
- name: set hostkeys according to openssh-version
2627
set_fact:
27-
ssh_host_key_files: ['/etc/ssh/ssh_host_rsa_key', '/etc/ssh/ssh_host_ecdsa_key', '/etc/ssh/ssh_host_ed25519_key']
28-
when: sshd_version.stdout >= '6.3'
28+
ssh_host_key_files: ['/etc/ssh/ssh_host_rsa_key']
29+
when: sshd_version.stdout >= '5.3' and not ssh_host_key_files
30+
31+
- name: create revoked_keys and set permissions to root/600
32+
template: src='revoked_keys.j2' dest='/etc/ssh/revoked_keys' mode=0600 owner="{{ ssh_owner }}" group="{{ ssh_group }}"
33+
notify: restart sshd
34+
when: ssh_server_hardening
2935

3036
- name: create sshd_config and set permissions to root/600
3137
template: src='opensshd.conf.j2' dest='/etc/ssh/sshd_config' mode=0600 owner="{{ ssh_owner }}" group="{{ ssh_group }}" validate="/usr/sbin/sshd -T -f %s"
@@ -57,7 +63,7 @@
5763

5864
- block: # only runs when selinux is running
5965
- name: install selinux dependencies when selinux is installed on RHEL or Oracle Linux
60-
yum: name="{{item}}" state=installed
66+
package: name="{{item}}" state=installed
6167
with_items:
6268
- policycoreutils-python
6369
- checkpolicy
@@ -71,7 +77,7 @@
7177
when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'
7278

7379
- name: check if ssh_password module is already installed
74-
shell: "semodule -l| grep ssh_password"
80+
shell: "semodule -l | grep ssh_password"
7581
register: ssh_password_module
7682
failed_when: false
7783
changed_when: false
@@ -99,7 +105,7 @@
99105

100106
# The following tasks only get executed when selinux is in state enforcing, UsePam is "yes" and the ssh_password module is installed.
101107
- name: remove selinux-policy when Pam is used, because Allowing sshd to read the shadow file directly is considered a potential security risk (http://danwalsh.livejournal.com/12333.html)
102-
shell: semodule -r ssh_password
108+
command: semodule -r ssh_password
103109
when: ssh_use_pam and ssh_password_module.stdout.find('ssh_password') == 0
104110

105111
when: sestatus.rc == 0

templates/openssh.conf.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# {{ansible_managed}}
1+
# {{ansible_managed|comment}}
22

33
# This is the ssh client system-wide configuration file.
44
# See ssh_config(5) for more information on any settings used. Comments will be added only to clarify why a configuration was chosen.

templates/opensshd.conf.j2

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# {{ansible_managed}}
1+
# {{ansible_managed|comment}}
22

33
# This is the ssh client system-wide configuration file.
44
# See sshd_config(5) for more information on any settings used. Comments will be added only to clarify why a configuration was chosen.
@@ -221,6 +221,9 @@ Banner {{ '/etc/ssh/banner.txt' if ssh_banner else 'none' }}
221221
DebianBanner {{ 'yes' if ssh_print_debian_banner else 'no' }}
222222
{% endif %}
223223

224+
# Reject keys that are explicitly blacklisted
225+
RevokedKeys /etc/ssh/revoked_keys
226+
224227
{% if sftp_enabled %}
225228
# SFTP matching configuration
226229
# ===========================

templates/revoked_keys.j2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# {{ansible_managed|comment}}
2+
{% for key in ssh_server_revoked_keys %}
3+
{{key}}
4+
{% endfor %}

0 commit comments

Comments
 (0)