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

Commit 8e6ff59

Browse files
authored
Merge pull request #177 from BedrockSolutions/master
Dependency flag
2 parents 6b2e45c + b4014e6 commit 8e6ff59

File tree

4 files changed

+90
-81
lines changed

4 files changed

+90
-81
lines changed

defaults/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,3 +241,7 @@ ssh_challengeresponseauthentication: false
241241

242242
# a list of public keys that are never accepted by the ssh server
243243
ssh_server_revoked_keys: []
244+
245+
# Set to false to turn the role into a no-op. Useful when using
246+
# the Ansible role dependency mechanism.
247+
ssh_hardening_enabled: true

handlers/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
- name: restart sshd
22
service: name={{ sshd_service_name }} state=restarted
33
when: "(ssh_server_enabled|bool)"
4+
become: yes

tasks/hardening.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
- name: Set OS dependent variables
3+
include_vars: '{{ item }}'
4+
with_first_found:
5+
- '{{ ansible_distribution }}_{{ ansible_distribution_major_version }}.yml'
6+
- '{{ ansible_distribution }}.yml'
7+
- '{{ ansible_os_family }}_{{ ansible_distribution_major_version }}.yml'
8+
- '{{ ansible_os_family }}.yml'
9+
10+
- name: get openssh-version
11+
shell: ssh -V 2>&1 | sed -r 's/.*_([0-9]*\.[0-9]).*/\1/g'
12+
args:
13+
executable: /bin/sh
14+
changed_when: false
15+
register: sshd_version
16+
check_mode: no
17+
18+
- name: include tasks to create crypo-vars
19+
include_tasks: crypto.yml
20+
21+
- name: create revoked_keys and set permissions to root/600
22+
template:
23+
src: 'revoked_keys.j2'
24+
dest: '/etc/ssh/revoked_keys'
25+
mode: '0600'
26+
owner: '{{ ssh_owner }}'
27+
group: '{{ ssh_group }}'
28+
notify: restart sshd
29+
when: ssh_server_hardening
30+
31+
- name: create sshd_config and set permissions to root/600
32+
template:
33+
src: 'opensshd.conf.j2'
34+
dest: '/etc/ssh/sshd_config'
35+
mode: '0600'
36+
owner: '{{ ssh_owner }}'
37+
group: '{{ ssh_group }}'
38+
validate: '/usr/sbin/sshd -T -f %s'
39+
notify: restart sshd
40+
when: ssh_server_hardening
41+
42+
- name: create ssh_config and set permissions to root/644
43+
template:
44+
src: 'openssh.conf.j2'
45+
dest: '/etc/ssh/ssh_config'
46+
mode: '0644'
47+
owner: '{{ ssh_owner }}'
48+
group: '{{ ssh_group }}'
49+
when: ssh_client_hardening
50+
51+
- name: Check if {{ sshd_moduli_file }} contains weak DH parameters
52+
shell: awk '$5 < {{ sshd_moduli_minimum }}' {{ sshd_moduli_file }}
53+
register: sshd_register_moduli
54+
changed_when: false
55+
check_mode: no
56+
57+
- name: remove all small primes
58+
shell: awk '$5 >= {{ sshd_moduli_minimum }}' {{ sshd_moduli_file }} > {{ sshd_moduli_file }}.new ;
59+
[ -r {{ sshd_moduli_file }}.new -a -s {{ sshd_moduli_file }}.new ] && mv {{ sshd_moduli_file }}.new {{ sshd_moduli_file }} || true
60+
notify: restart sshd
61+
when: sshd_register_moduli.stdout
62+
63+
- name: include tasks to setup ca keys and principals
64+
include_tasks: ca_keys_and_principals.yml
65+
when: ssh_trusted_user_ca_keys_file != ''
66+
67+
- name: include tasks to setup 2FA
68+
include_tasks: 2fa.yml
69+
when:
70+
- ssh_use_pam
71+
- ssh_challengeresponseauthentication
72+
- ssh_google_auth
73+
74+
- name: test to see if selinux is installed and running
75+
command: getenforce
76+
register: sestatus
77+
failed_when: false
78+
changed_when: false
79+
check_mode: no
80+
81+
- name: include selinux specific tasks
82+
include_tasks: selinux.yml
83+
when: sestatus.rc == 0

tasks/main.yml

Lines changed: 2 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,4 @@
11
---
2-
- name: Set OS dependent variables
3-
include_vars: '{{ item }}'
4-
with_first_found:
5-
- '{{ ansible_distribution }}_{{ ansible_distribution_major_version }}.yml'
6-
- '{{ ansible_distribution }}.yml'
7-
- '{{ ansible_os_family }}_{{ ansible_distribution_major_version }}.yml'
8-
- '{{ ansible_os_family }}.yml'
92

10-
- name: get openssh-version
11-
shell: ssh -V 2>&1 | sed -r 's/.*_([0-9]*\.[0-9]).*/\1/g'
12-
args:
13-
executable: /bin/sh
14-
changed_when: false
15-
register: sshd_version
16-
check_mode: no
17-
18-
- name: include tasks to create crypo-vars
19-
include_tasks: crypto.yml
20-
21-
- name: create revoked_keys and set permissions to root/600
22-
template:
23-
src: 'revoked_keys.j2'
24-
dest: '/etc/ssh/revoked_keys'
25-
mode: '0600'
26-
owner: '{{ ssh_owner }}'
27-
group: '{{ ssh_group }}'
28-
notify: restart sshd
29-
when: ssh_server_hardening
30-
31-
- name: create sshd_config and set permissions to root/600
32-
template:
33-
src: 'opensshd.conf.j2'
34-
dest: '/etc/ssh/sshd_config'
35-
mode: '0600'
36-
owner: '{{ ssh_owner }}'
37-
group: '{{ ssh_group }}'
38-
validate: '/usr/sbin/sshd -T -f %s'
39-
notify: restart sshd
40-
when: ssh_server_hardening
41-
42-
- name: create ssh_config and set permissions to root/644
43-
template:
44-
src: 'openssh.conf.j2'
45-
dest: '/etc/ssh/ssh_config'
46-
mode: '0644'
47-
owner: '{{ ssh_owner }}'
48-
group: '{{ ssh_group }}'
49-
when: ssh_client_hardening
50-
51-
- name: Check if {{ sshd_moduli_file }} contains weak DH parameters
52-
shell: awk '$5 < {{ sshd_moduli_minimum }}' {{ sshd_moduli_file }}
53-
register: sshd_register_moduli
54-
changed_when: false
55-
check_mode: no
56-
57-
- name: remove all small primes
58-
shell: awk '$5 >= {{ sshd_moduli_minimum }}' {{ sshd_moduli_file }} > {{ sshd_moduli_file }}.new ;
59-
[ -r {{ sshd_moduli_file }}.new -a -s {{ sshd_moduli_file }}.new ] && mv {{ sshd_moduli_file }}.new {{ sshd_moduli_file }} || true
60-
notify: restart sshd
61-
when: sshd_register_moduli.stdout
62-
63-
- name: include tasks to setup ca keys and principals
64-
include_tasks: ca_keys_and_principals.yml
65-
when: ssh_trusted_user_ca_keys_file != ''
66-
67-
- name: include tasks to setup 2FA
68-
include_tasks: 2fa.yml
69-
when:
70-
- ssh_use_pam
71-
- ssh_challengeresponseauthentication
72-
- ssh_google_auth
73-
74-
- name: test to see if selinux is installed and running
75-
command: getenforce
76-
register: sestatus
77-
failed_when: false
78-
changed_when: false
79-
check_mode: no
80-
81-
- name: include selinux specific tasks
82-
include_tasks: selinux.yml
83-
when: sestatus.rc == 0
3+
- include_tasks: hardening.yml
4+
when: ssh_hardening_enabled

0 commit comments

Comments
 (0)