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

Commit 3f962b5

Browse files
authored
Merge pull request #290 from aisbergg/harmonize-style
Harmonize style
2 parents 508c666 + ce41b9f commit 3f962b5

21 files changed

+199
-157
lines changed

defaults/main.yml

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
# true if IPv6 is needed
2-
network_ipv6_enable: false # sshd + ssh
2+
network_ipv6_enable: false # sshd + ssh
33

44
# true if sshd should be started and enabled
5-
ssh_server_enabled: true # sshd
5+
ssh_server_enabled: true # sshd
66

77
# true if DNS resolutions are needed, look up the remote host name, defaults to false from 6.8, see: http://www.openssh.com/txt/release-6.8
8-
ssh_use_dns: false # sshd
8+
ssh_use_dns: false # sshd
99

1010
# true or value if compression is needed
11-
ssh_client_compression: false # ssh
12-
ssh_compression: false # sshd
11+
ssh_client_compression: false # ssh
12+
ssh_compression: false # sshd
1313

1414
# For which components (client and server) to generate the configuration for. Can be useful when running against a client without an SSH server.
1515
ssh_client_hardening: true # ssh
1616
ssh_server_hardening: true # sshd
1717

1818
# If true, password login is allowed
19-
ssh_client_password_login: false # ssh
20-
ssh_server_password_login: false # sshd
19+
ssh_client_password_login: false # ssh
20+
ssh_server_password_login: false # sshd
2121

2222
# ports on which ssh-server should listen
23-
ssh_server_ports: ['22'] # sshd
23+
ssh_server_ports: ['22'] # sshd
2424

2525
# port to which ssh-client should connect
26-
ssh_client_port: '22' # ssh
26+
ssh_client_port: '22' # ssh
2727

2828
# one or more ip addresses, to which ssh-server should listen to. Default is empty, but should be configured for security reasons!
29-
ssh_listen_to: ['0.0.0.0'] # sshd
29+
ssh_listen_to: ['0.0.0.0'] # sshd
3030

3131
# Host keys to look for when starting sshd.
32-
ssh_host_key_files: [] # sshd
32+
ssh_host_key_files: [] # sshd
3333

3434
# Specifies the host key algorithms that the server offers
35-
ssh_host_key_algorithms: [] # sshd
35+
ssh_host_key_algorithms: [] # sshd
3636

3737
# specifies the time allowed for successful authentication to the SSH server
3838
ssh_login_grace_time: 30s
@@ -43,13 +43,13 @@ ssh_max_auth_retries: 2
4343
# Specifies the maximum number of open sessions permitted from a given connection
4444
ssh_max_sessions: 10
4545

46-
ssh_client_alive_interval: 300 # sshd
47-
ssh_client_alive_count: 3 # sshd
46+
ssh_client_alive_interval: 300 # sshd
47+
ssh_client_alive_count: 3 # sshd
4848

4949
# Allow SSH Tunnels
5050
ssh_permit_tunnel: false
5151

52-
# Hosts with custom options. # ssh
52+
# Hosts with custom options. # ssh
5353
# Example:
5454
# ssh_remote_hosts:
5555
# - names: ['example.com', 'example2.com']
@@ -59,23 +59,23 @@ ssh_permit_tunnel: false
5959
ssh_remote_hosts: []
6060

6161
# Set this to "without-password" or "yes" to allow root to login
62-
ssh_permit_root_login: 'no' # sshd
62+
ssh_permit_root_login: 'no' # sshd
6363

6464
# false to disable TCP Forwarding. Set to true to allow TCP Forwarding.
65-
ssh_allow_tcp_forwarding: 'no' # sshd
65+
ssh_allow_tcp_forwarding: 'no' # sshd
6666

6767
# false to disable binding forwarded ports to non-loopback addresses. Set to true to force binding on wildcard address.
6868
# Set to 'clientspecified' to allow the client to specify which address to bind to.
69-
ssh_gateway_ports: false # sshd
69+
ssh_gateway_ports: false # sshd
7070

7171
# false to disable Agent Forwarding. Set to true to allow Agent Forwarding.
72-
ssh_allow_agent_forwarding: false # sshd
72+
ssh_allow_agent_forwarding: false # sshd
7373

7474
# true if SSH has PAM support
7575
ssh_pam_support: true
7676

7777
# false to disable pam authentication.
78-
ssh_use_pam: true # sshd
78+
ssh_use_pam: true # sshd
7979

8080
# specify AuthenticationMethods
8181
sshd_authenticationmethods: 'publickey'
@@ -87,29 +87,29 @@ ssh_gssapi_support: false
8787
ssh_kerberos_support: true
8888

8989
# if specified, login is disallowed for user names that match one of the patterns.
90-
ssh_deny_users: '' # sshd
90+
ssh_deny_users: '' # sshd
9191

9292
# if specified, login is allowed only for user names that match one of the patterns.
93-
ssh_allow_users: '' # sshd
93+
ssh_allow_users: '' # sshd
9494

9595
# if specified, login is disallowed for users whose primary group or supplementary group list matches one of the patterns.
96-
ssh_deny_groups: '' # sshd
96+
ssh_deny_groups: '' # sshd
9797

9898
# if specified, login is allowed only for users whose primary group or supplementary group list matches one of the patterns.
99-
ssh_allow_groups: '' # sshd
99+
ssh_allow_groups: '' # sshd
100100

101101
# change default file that contains the public keys that can be used for user authentication.
102-
ssh_authorized_keys_file: '' # sshd
102+
ssh_authorized_keys_file: '' # sshd
103103

104104
# specifies the file containing trusted certificate authorities public keys used to sign user certificates.
105-
ssh_trusted_user_ca_keys_file: '' # sshd
105+
ssh_trusted_user_ca_keys_file: '' # sshd
106106

107107
# set the trusted certificate authorities public keys used to sign user certificates.
108108
# Example:
109109
# ssh_trusted_user_ca_keys:
110110
# - 'ssh-rsa ... comment1'
111111
# - 'ssh-rsa ... comment2'
112-
ssh_trusted_user_ca_keys: [] # sshd
112+
ssh_trusted_user_ca_keys: [] # sshd
113113

114114
# specifies the file containing principals that are allowed. Only used if ssh_trusted_user_ca_keys_file is set.
115115
# Example:
@@ -119,26 +119,26 @@ ssh_trusted_user_ca_keys: [] # sshd
119119
# replaced by the username of that user. After expansion, the path is taken to be
120120
# an absolute path or one relative to the user's home directory.
121121
#
122-
ssh_authorized_principals_file: '' # sshd
122+
ssh_authorized_principals_file: '' # sshd
123123

124124
# list of hashes containing file paths and authorized principals. Only used if ssh_authorized_principals_file is set.
125125
# Example:
126126
# ssh_authorized_principals:
127127
# - { path: '/etc/ssh/auth_principals/root', principals: [ 'root' ], owner: "{{ ssh_owner }}", group: "{{ ssh_group }}", directoryowner: "{{ ssh_owner }}", directorygroup: "{{ ssh_group}}" }
128128
# - { path: '/etc/ssh/auth_principals/myuser', principals: [ 'masteradmin', 'webserver' ] }
129-
ssh_authorized_principals: [] # sshd
129+
ssh_authorized_principals: [] # sshd
130130

131131
# false to disable printing of the MOTD
132-
ssh_print_motd: false # sshd
132+
ssh_print_motd: false # sshd
133133

134134
# false to disable display of last login information
135-
ssh_print_last_log: false # sshd
135+
ssh_print_last_log: false # sshd
136136

137137
# false to disable serving /etc/ssh/banner.txt before authentication is allowed
138-
ssh_banner: false # sshd
138+
ssh_banner: false # sshd
139139

140140
# false to disable distribution version leakage during initial protocol handshake
141-
ssh_print_debian_banner: false # sshd (Debian OS family only)
141+
ssh_print_debian_banner: false # sshd (Debian OS family only)
142142

143143
# true to enable sftp configuration
144144
sftp_enabled: false
@@ -156,19 +156,19 @@ sftp_chroot_dir: /home/%u
156156
ssh_client_roaming: false
157157

158158
# list of hashes (containing user and rules) to generate Match User blocks for.
159-
ssh_server_match_user: false # sshd
159+
ssh_server_match_user: false # sshd
160160

161161
# list of hashes (containing group and rules) to generate Match Group blocks for.
162-
ssh_server_match_group: false # sshd
162+
ssh_server_match_group: false # sshd
163163

164164
# list of hashes (containing addresses/subnets and rules) to generate Match Address blocks for.
165-
ssh_server_match_address: false # sshd
165+
ssh_server_match_address: false # sshd
166166

167167
ssh_server_permit_environment_vars: 'no'
168168
ssh_server_accept_env_vars : ''
169169

170170
# maximum number of concurrent unauthenticated connections to the SSH daemon
171-
ssh_max_startups: '10:30:100' # sshd
171+
ssh_max_startups: '10:30:100' # sshd
172172

173173
ssh_ps53: 'yes'
174174
ssh_ps59: 'sandbox'

handlers/main.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
- name: restart sshd
2-
service: name={{ sshd_service_name }} state=restarted
3-
when: "(ssh_server_enabled|bool)"
2+
service:
3+
name: '{{ sshd_service_name }}'
4+
state: restarted
5+
when: ssh_server_enabled | bool
46
become: yes

tasks/ca_keys_and_principals.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
- name: Set ssh CA pub keys
2+
- name: set ssh CA pub keys
33
template:
44
src: 'trusted_user_ca_keys.j2'
55
dest: '{{ ssh_trusted_user_ca_keys_file }}'
@@ -8,20 +8,20 @@
88
group: '{{ ssh_group }}'
99
notify: restart sshd
1010

11-
- name: Create ssh authorized principals directories
11+
- name: create ssh authorized principals directories
1212
file:
1313
path: '{{ item.path | dirname }}'
1414
mode: '{{ item.directorymode | default(0700) }}'
1515
owner: '{{ item.directoryowner | default(ssh_owner) }}'
1616
group: '{{ item.directorygroup | default(ssh_group) }}'
1717
state: directory
18-
with_items: '{{ ssh_authorized_principals }}'
18+
loop: '{{ ssh_authorized_principals }}'
1919

20-
- name: Set ssh authorized principals
20+
- name: set ssh authorized principals
2121
template:
2222
src: 'authorized_principals.j2'
2323
dest: '{{ item.path }}'
2424
mode: '{{ item.filemode | default(0600) }}'
2525
owner: '{{ item.owner| default(ssh_owner) }}'
2626
group: '{{ item.group | default(ssh_group) }}'
27-
with_items: '{{ ssh_authorized_principals }}'
27+
loop: '{{ ssh_authorized_principals }}'

tasks/crypto.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
---
2-
32
- name: set hostkeys according to openssh-version
43
set_fact:
54
ssh_host_key_files: ['/etc/ssh/ssh_host_rsa_key', '/etc/ssh/ssh_host_ecdsa_key', '/etc/ssh/ssh_host_ed25519_key']

tasks/hardening.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
2-
- name: Set OS dependent variables
2+
- name: set OS dependent variables
33
include_vars: '{{ item }}'
44
with_first_found:
5-
- '{{ ansible_facts.distribution }}_{{ ansible_facts.distribution_major_version }}.yml'
6-
- '{{ ansible_facts.distribution }}.yml'
7-
- '{{ ansible_facts.os_family }}_{{ ansible_facts.distribution_major_version }}.yml'
8-
- '{{ ansible_facts.os_family }}.yml'
5+
- '{{ ansible_facts.distribution }}_{{ ansible_facts.distribution_major_version }}.yml'
6+
- '{{ ansible_facts.distribution }}.yml'
7+
- '{{ ansible_facts.os_family }}_{{ ansible_facts.distribution_major_version }}.yml'
8+
- '{{ ansible_facts.os_family }}.yml'
99

1010
- name: get openssh-version
1111
command: ssh -V
@@ -37,7 +37,7 @@
3737
mode: '0600'
3838
owner: '{{ ssh_owner }}'
3939
group: '{{ ssh_group }}'
40-
validate: '/usr/sbin/sshd -T -C user=root -C host=localhost -C addr=localhost -f %s'
40+
validate: '/usr/sbin/sshd -T -C user=root -C host=localhost -C addr=localhost -C lport=22 -f %s'
4141
notify: restart sshd
4242
when: ssh_server_hardening | bool
4343

@@ -62,7 +62,7 @@
6262
group: '{{ ssh_group }}'
6363
when: ssh_client_hardening | bool
6464

65-
- name: Check if {{ sshd_moduli_file }} contains weak DH parameters
65+
- name: check if {{ sshd_moduli_file }} contains weak DH parameters
6666
shell: awk '$5 < {{ sshd_moduli_minimum }}' {{ sshd_moduli_file }}
6767
register: sshd_register_moduli
6868
changed_when: false

tasks/main.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
---
2-
32
- include_tasks: hardening.yml
43
when: ssh_hardening_enabled | bool

tasks/selinux.yml

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
name: '{{ ssh_selinux_packages }}'
55
state: present
66

7-
- name: "authorize {{ ssh_server_ports }} ports for selinux"
7+
- name: authorize {{ ssh_server_ports }} ports for selinux
88
seport:
99
ports: '{{ item }}'
1010
proto: tcp
1111
setype: ssh_port_t
1212
state: present
13-
with_items:
14-
- "{{ ssh_server_ports }}"
13+
loop: '{{ ssh_server_ports }}'
1514

1615
- name: check if ssh_password module is already installed
1716
shell: 'set -o pipefail && semodule -l | grep ssh_password'
@@ -22,35 +21,41 @@
2221
changed_when: false
2322
check_mode: no
2423

25-
# The following tasks only get executed when selinux is in state enforcing, UsePam is 'no' and the ssh_password module is installed.
26-
# See this issue for more info: https://github.com/hardening-io/ansible-ssh-hardening/issues/23
27-
- block:
28-
- name: Create selinux custom policy drop folder
29-
file:
30-
path: '{{ ssh_custom_selinux_dir }}'
31-
state: 'directory'
32-
owner: 'root'
33-
group: 'root'
34-
mode: '0750'
35-
36-
- name: Distributing custom selinux policies
37-
copy:
38-
src: 'ssh_password'
39-
dest: '{{ ssh_custom_selinux_dir }}'
40-
41-
- name: check and compile policy
42-
command: checkmodule -M -m -o {{ ssh_custom_selinux_dir }}/ssh_password.mod {{ ssh_custom_selinux_dir }}/ssh_password
43-
44-
- name: create selinux policy module package
45-
command: semodule_package -o {{ ssh_custom_selinux_dir }}/ssh_password.pp -m {{ ssh_custom_selinux_dir }}/ssh_password.mod
46-
47-
- name: install selinux policy
48-
command: semodule -i {{ ssh_custom_selinux_dir }}/ssh_password.pp
49-
50-
when: not ssh_use_pam | bool and ssh_password_module.stdout.find('ssh_password') != 0
51-
52-
# The following tasks only get executed when selinux is installed, UsePam is 'yes' and the ssh_password module is installed.
53-
# See http://danwalsh.livejournal.com/12333.html for more info
24+
# The following tasks only get executed when selinux is in state enforcing,
25+
# UsePam is 'no' and the ssh_password module is not installed. See this issue for
26+
# more info: https://github.com/hardening-io/ansible-ssh-hardening/issues/23
27+
- when:
28+
- not (ssh_use_pam | bool)
29+
- ('ssh_password' not in ssh_password_module.stdout)
30+
block:
31+
- name: create selinux custom policy drop folder
32+
file:
33+
path: '{{ ssh_custom_selinux_dir }}'
34+
state: 'directory'
35+
owner: 'root'
36+
group: 'root'
37+
mode: '0750'
38+
39+
- name: distributing custom selinux policies
40+
copy:
41+
src: 'ssh_password'
42+
dest: '{{ ssh_custom_selinux_dir }}'
43+
44+
- name: check and compile policy
45+
command: checkmodule -M -m -o {{ ssh_custom_selinux_dir }}/ssh_password.mod {{ ssh_custom_selinux_dir }}/ssh_password
46+
47+
- name: create selinux policy module package
48+
command: semodule_package -o {{ ssh_custom_selinux_dir }}/ssh_password.pp -m {{ ssh_custom_selinux_dir }}/ssh_password.mod
49+
50+
- name: install selinux policy
51+
command: semodule -i {{ ssh_custom_selinux_dir }}/ssh_password.pp
52+
53+
54+
# The following tasks only get executed when selinux is installed, UsePam is
55+
# 'yes' and the ssh_password module is installed. See
56+
# http://danwalsh.livejournal.com/12333.html for more info
5457
- name: remove selinux-policy when Pam is used, because Allowing sshd to read the shadow file directly is considered a potential security risk
5558
command: semodule -r ssh_password
56-
when: ssh_use_pam | bool and ssh_password_module.stdout.find('ssh_password') == 0
59+
when:
60+
- ssh_use_pam | bool
61+
- ('ssh_password' in ssh_password_module.stdout)

templates/authorized_principals.j2

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

33
{% for principal in item.principals %}
44
{{ principal }}

0 commit comments

Comments
 (0)