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

Commit c6f6f98

Browse files
authored
Merge pull request #87 from dev-sec/new_docker_images
remove support for ansible 1.9
2 parents 997bba6 + 4059eba commit c6f6f98

File tree

7 files changed

+53
-62
lines changed

7 files changed

+53
-62
lines changed

.kitchen.vagrant.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,4 @@ verifier:
5959
- https://github.com/dev-sec/tests-ssh-hardening
6060

6161
suites:
62-
- name: ssh-ansible_1.9
63-
provisioner:
64-
ansible_version: 1.9.4
6562
- name: ssh-ansible_latest

.kitchen.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,4 @@ verifier:
5454
- https://github.com/dev-sec/tests-ssh-hardening
5555

5656
suites:
57-
- name: ssh-ansible_1.9
58-
provisioner:
59-
ansible_version: 1.9.4
6057
- name: ssh-ansible_latest

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ python: "2.7"
66

77
env:
88
- ANSIBLE_VERSION=latest
9-
- ANSIBLE_VERSION=1.9.4
109

1110
before_install:
1211
- sudo apt-get update -qq

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Warning: This role disables root-login on the target server! Please make sure yo
1212

1313
## Requirements
1414

15-
* Ansible
15+
* Ansible > 2.2.1
1616

1717
## Role Variables
1818
| Name | Default Value | Description |

default.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
2+
23
- name: wrapper playbook for kitchen testing "ansible-ssh-hardening" with custom settings
34
hosts: localhost
45
roles:

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)