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

Commit d12627a

Browse files
authored
Merge branch 'master' into docker
2 parents a1fc225 + ca24738 commit d12627a

File tree

7 files changed

+68
-59
lines changed

7 files changed

+68
-59
lines changed

.kitchen.vagrant.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ provisioner:
2323
transport:
2424
max_ssh_sessions: 5
2525

26+
transport:
27+
max_ssh_sessions: 5
28+
29+
2630
platforms:
2731
- name: ubuntu-12.04
2832
driver_config:
@@ -37,9 +41,10 @@ platforms:
3741
box: opscode-ubuntu-16.04
3842
box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_ubuntu-16.04_chef-provisionerless.box
3943
- name: centos-6.4
44+
- name: centos-7.2
4045
driver_config:
41-
box: opscode-centos-6.4
42-
box_url: https://opscode-vm.s3.amazonaws.com/vagrant/opscode_centos-6.4_provisionerless.box
46+
box: opscode-centos-7.2
47+
box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-7.2_chef-provisionerless.box
4348
- name: centos-6.5
4449
driver_config:
4550
box: opscode-centos-6.5

.kitchen.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ driver:
99
transport:
1010
max_ssh_sessions: 5
1111

12+
transport:
13+
max_ssh_sessions: 5
14+
15+
1216
provisioner:
1317
name: ansible_playbook
1418
hosts: all
@@ -74,4 +78,4 @@ verifier:
7478
- https://github.com/dev-sec/ssh-baseline
7579

7680
suites:
77-
- name: ssh
81+
- name: ssh

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ env:
4646
init: /lib/systemd/systemd
4747
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
4848

49+
4950
before_install:
5051
# Pull container
5152
- 'docker pull rndmh3ro/docker-${distro}-ansible:${version}'

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88

99
This role provides secure ssh-client and ssh-server configurations.
1010

11+
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.
12+
1113
## Requirements
1214

13-
* Ansible
15+
* Ansible > 2.2.1
1416

1517
## Role Variables
1618
| Name | Default Value | Description |

defaults/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ ssh_client_ports: ['22'] # ssh
3030
ssh_listen_to: ['0.0.0.0'] # sshd
3131

3232
# Host keys to look for when starting sshd.
33-
ssh_host_key_files: ['/etc/ssh/ssh_host_rsa_key', '/etc/ssh/ssh_host_dsa_key', '/etc/ssh/ssh_host_ecdsa_key'] # sshd
33+
ssh_host_key_files: ['/etc/ssh/ssh_host_rsa_key', '/etc/ssh/ssh_host_ecdsa_key', '/etc/ssh/ssh_host_ed25519_key'] # sshd
3434

3535
# Specifies the maximum number of authentication attempts permitted per connection. Once the number of failures reaches half this value, additional failures are logged.
3636
ssh_max_auth_retries: 2

meta/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ galaxy_info:
44
description: 'This Ansible role provides numerous security-related ssh configurations, providing all-round base protection.'
55
company: Hardening Framework Team
66
license: Apache License 2.0
7-
min_ansible_version: '1.9'
7+
min_ansible_version: '2.2.1'
88
platforms:
99
- name: EL
1010
versions:

tasks/main.yml

Lines changed: 50 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,6 @@
22
- name: add the OS specific variables
33
include_vars: "{{ ansible_os_family }}.yml"
44

5-
- name: test to see if selinux is running
6-
command: getenforce
7-
register: sestatus
8-
failed_when: false
9-
changed_when: false
10-
always_run: true
11-
12-
- name: install selinux dependencies when selinux is installed on RHEL or Oracle Linux
13-
yum: name="{{item}}" state=installed
14-
with_items:
15-
- policycoreutils-python
16-
- checkpolicy
17-
when: sestatus.rc == 0 and (ansible_os_family == 'RedHat' or ansible_os_family == 'Oracle Linux')
18-
19-
- name: install selinux dependencies when selinux is installed on Debian or Ubuntu
20-
apt: name="{{item}}" state=installed
21-
with_items:
22-
- policycoreutils
23-
- checkpolicy
24-
when: sestatus.rc == 0 and (ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu')
25-
26-
- name: check the ssh_password policy state
27-
shell: semodule -l | grep "ssh_password" | awk '{print $3}'
28-
register: selinux_policy_state
29-
when: sestatus.rc == 0 and sestatus.stdout != 'Disabled'
30-
failed_when: false
31-
changed_when: false
32-
335
- name: create sshd_config and set permissions to root/600
346
template: src='opensshd.conf.j2' dest='/etc/ssh/sshd_config' mode=0600 owner=root group=root validate="/usr/sbin/sshd -T -f %s"
357
notify: restart sshd
@@ -39,37 +11,62 @@
3911
template: src='openssh.conf.j2' dest='/etc/ssh/ssh_config' mode=0644 owner=root group=root
4012
when: ssh_client_hardening
4113

42-
- name: check if ssh_password module is already installed
43-
shell: "semodule -l| grep ssh_password"
44-
register: ssh_password_module
14+
- name: create ssh_config and set permissions to root/644
15+
template: src='openssh.conf.j2' dest='/etc/ssh/ssh_config' mode=0644 owner=root group=root
16+
when: ssh_client_hardening
17+
18+
- name: test to see if selinux is running
19+
command: getenforce
20+
register: sestatus
4521
failed_when: false
4622
changed_when: false
47-
always_run: true
23+
check_mode: no
24+
25+
- block: # only runs when selinux is running
26+
- name: install selinux dependencies when selinux is installed on RHEL or Oracle Linux
27+
yum: name="{{item}}" state=installed
28+
with_items:
29+
- policycoreutils-python
30+
- checkpolicy
31+
when: ansible_os_family == 'RedHat' or ansible_os_family == 'Oracle Linux'
32+
33+
- name: install selinux dependencies when selinux is installed on Debian or Ubuntu
34+
apt: name="{{item}}" state=installed
35+
with_items:
36+
- policycoreutils
37+
- checkpolicy
38+
when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'
39+
40+
- name: check if ssh_password module is already installed
41+
shell: "semodule -l| grep ssh_password"
42+
register: ssh_password_module
43+
failed_when: false
44+
changed_when: false
45+
check_mode: no
46+
47+
# The following tasks only get executed when selinux is in state enforcing, UsePam is "no" and the ssh_password module is installed.
48+
# See this issue for more info: https://github.com/hardening-io/ansible-ssh-hardening/issues/23
49+
- block:
50+
- name: Create selinux custom policy drop folder
51+
file: path='{{ ssh_custom_selinux_dir }}' state=directory owner=root group=root mode=0750
4852

49-
# The following tasks only get executed when selinux is in state enforcing, UsePam is "no" and the ssh_password module is installed.
50-
# See this issue for more info: https://github.com/hardening-io/ansible-ssh-hardening/issues/23
53+
- name: Distributing custom selinux policies
54+
copy: src='ssh_password' dest='{{ ssh_custom_selinux_dir }}'
5155

52-
- name: Create selinux custom policy drop folder
53-
file: path={{ ssh_custom_selinux_dir }} state=directory owner=root group=root mode=0750
54-
when: not ssh_use_pam and sestatus.rc == 0 and sestatus.stdout != 'Disabled' and ssh_password_module.stdout.find('ssh_password') != 0
56+
- name: check and compile policy
57+
shell: checkmodule -M -m -o {{ ssh_custom_selinux_dir }}/ssh_password.mod {{ ssh_custom_selinux_dir }}/ssh_password
5558

56-
- name: Distributing custom selinux policies
57-
copy: src='ssh_password' dest='{{ ssh_custom_selinux_dir }}'
58-
when: not ssh_use_pam and sestatus.rc == 0 and sestatus.stdout != 'Disabled' and ssh_password_module.stdout.find('ssh_password') != 0
59+
- name: create selinux policy module package
60+
shell: semodule_package -o {{ ssh_custom_selinux_dir }}/ssh_password.pp -m {{ ssh_custom_selinux_dir }}/ssh_password.mod
5961

60-
- name: check and compile policy
61-
shell: checkmodule -M -m -o {{ ssh_custom_selinux_dir }}/ssh_password.mod {{ ssh_custom_selinux_dir }}/ssh_password
62-
when: not ssh_use_pam and sestatus.rc == 0 and sestatus.stdout != 'Disabled' and ssh_password_module.stdout.find('ssh_password') != 0
62+
- name: install selinux policy
63+
shell: semodule -i {{ ssh_custom_selinux_dir }}/ssh_password.pp
6364

64-
- name: create selinux policy module package
65-
shell: semodule_package -o {{ ssh_custom_selinux_dir }}/ssh_password.pp -m {{ ssh_custom_selinux_dir }}/ssh_password.mod
66-
when: not ssh_use_pam and sestatus.rc == 0 and sestatus.stdout != 'Disabled' and ssh_password_module.stdout.find('ssh_password') != 0
65+
when: not ssh_use_pam and sestatus.stdout != 'Disabled' and ssh_password_module.stdout.find('ssh_password') != 0
6766

68-
- name: install selinux policy
69-
shell: semodule -i {{ ssh_custom_selinux_dir }}/ssh_password.pp
70-
when: not ssh_use_pam and sestatus.rc == 0 and sestatus.stdout != 'Disabled' and ssh_password_module.stdout.find('ssh_password') != 0
67+
# The following tasks only get executed when selinux is in state enforcing, UsePam is "yes" and the ssh_password module is installed.
68+
- 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)
69+
shell: semodule -r ssh_password
70+
when: ssh_use_pam and ssh_password_module.stdout.find('ssh_password') == 0
7171

72-
# The following tasks only get executed when selinux is in state enforcing, UsePam is "yes" and the ssh_password module is installed.
73-
- 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)
74-
shell: semodule -r ssh_password
75-
when: sestatus.rc == 0 and ssh_use_pam and ssh_password_module.stdout.find('ssh_password') == 0
72+
when: sestatus.rc == 0

0 commit comments

Comments
 (0)