|
2 | 2 | - name: add the OS specific variables |
3 | 3 | include_vars: "{{ ansible_os_family }}.yml" |
4 | 4 |
|
| 5 | +- name: test to see if selinux is running |
| 6 | + command: getenforce |
| 7 | + register: sestatus |
| 8 | + changed_when: false |
| 9 | + ignore_errors: true |
| 10 | + |
| 11 | +- name: check the ssh_password policy state |
| 12 | + shell: semodule -l | grep "ssh_password" | awk '{print $3}' |
| 13 | + register: selinux_policy_state |
| 14 | + when: sestatus.rc == 0 and sestatus.stdout != 'Disabled' |
| 15 | + changed_when: false |
| 16 | + |
5 | 17 | - name: create sshd_config and set permissions to root/600 |
6 | 18 | template: src='opensshd.conf.j2' dest='/etc/ssh/sshd_config' mode=0600 owner=root group=root validate="/usr/sbin/sshd -T -f %s" |
7 | 19 | notify: restart sshd |
|
10 | 22 | - name: create ssh_config and set permissions to root/644 |
11 | 23 | template: src='openssh.conf.j2' dest='/etc/ssh/ssh_config' mode=0644 owner=root group=root |
12 | 24 | when: ssh_client_hardening |
| 25 | + |
| 26 | +- name: Create selinux custom policy drop folder |
| 27 | + file: path={{ custom_selinux_dir }} state=directory owner=root group=root mode=0750 |
| 28 | + when: not ssh_use_pam and sestatus.rc == 0 and sestatus.stdout != 'Disabled' |
| 29 | + |
| 30 | +# The following tasks only get executed when selinux is in state enforcing and UsePam is "no". |
| 31 | +# See this issue for more info: https://github.com/hardening-io/ansible-ssh-hardening/issues/23 |
| 32 | + |
| 33 | +- name: Distributing custom selinux policies |
| 34 | + copy: src='ssh_password' dest='{{ custom_selinux_dir }}' |
| 35 | + register: custom_policies_output |
| 36 | + when: not ssh_use_pam and sestatus.rc == 0 and sestatus.stdout != 'Disabled' |
| 37 | + |
| 38 | +- name: check and compile policy |
| 39 | + shell: checkmodule -M -m -o {{ custom_selinux_dir }}/ssh_password.mod {{ custom_selinux_dir }}/ssh_password |
| 40 | + when: not ssh_use_pam and sestatus.rc == 0 and sestatus.stdout != 'Disabled' |
| 41 | + |
| 42 | +- name: create selinux policy module package |
| 43 | + shell: semodule_package -o {{ custom_selinux_dir }}/ssh_password.pp -m {{ custom_selinux_dir }}/ssh_password.mod |
| 44 | + when: not ssh_use_pam and sestatus.rc == 0 and sestatus.stdout != 'Disabled' |
| 45 | + |
| 46 | +- name: install selinux policy |
| 47 | + shell: semodule -i {{ custom_selinux_dir }}/ssh_password.pp |
| 48 | + when: not ssh_use_pam and sestatus.rc == 0 and sestatus.stdout != 'Disabled' |
| 49 | + |
| 50 | +- 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) |
| 51 | + shell: semodule -r ssh_password |
| 52 | + when: sestatus.rc == 0 and ssh_use_pam |
0 commit comments