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

Commit c4482cb

Browse files
author
Sebastian Gumprich
committed
Support for selinux and pam. fix #23
This change add the following: - it checks wether selinux is in "Enforcing" mode - when selinux is enforcing, it copies a new selinux-policy to the host - this policy allows sshd to read the shadow-file directly, which is forbidden by selinux otherwise - the policy is then compiled, a package is created and the policy is installed - when selinux is enforcing, pam is used and the policy is not disabled, it gets removed, because its considered a security risk. see here: http://danwalsh.livejournal.com/12333.html
1 parent ef8c4ad commit c4482cb

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module ssh_password 1.0;
2+
3+
require {
4+
type sshd_t;
5+
type shadow_t;
6+
class file { read open };
7+
}
8+
9+
#============= sshd_t ==============
10+
allow sshd_t shadow_t:file { read open };

roles/ansible-ssh-hardening/tasks/main.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
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+
changed_when: false
9+
10+
- name: check the ssh_password policy state
11+
shell: semodule -l | grep "ssh_password" | awk '{print $3}'
12+
register: selinux_policy_state
13+
when: sestatus.stdout == 'Enforcing'
14+
changed_when: false
15+
516
- name: create sshd_config and set permissions to root/600
617
template: src='opensshd.conf.j2' dest='/etc/ssh/sshd_config' mode=0600 owner=root group=root validate="/usr/sbin/sshd -T -f %s"
718
notify: restart sshd
@@ -10,3 +21,31 @@
1021
- name: create ssh_config and set permissions to root/644
1122
template: src='openssh.conf.j2' dest='/etc/ssh/ssh_config' mode=0644 owner=root group=root
1223
when: ssh_client_hardening
24+
25+
- name: Create selinux custom policy drop folder
26+
file: path={{ custom_selinux_dir }} state=directory owner=root group=root mode=0750
27+
when: not ssh_use_pam and sestatus.stdout == 'Enforcing'
28+
29+
# The following tasks only get executed when selinux is in state enforcing and UsePam is "no".
30+
# See this issue for more info: https://github.com/hardening-io/ansible-ssh-hardening/issues/23
31+
32+
- name: Distributing custom selinux policies
33+
copy: src='ssh_password' dest='{{ custom_selinux_dir }}'
34+
register: custom_policies_output
35+
when: not ssh_use_pam and sestatus.stdout == 'Enforcing'
36+
37+
- name: check and compile policy
38+
shell: checkmodule -M -m -o {{ custom_selinux_dir }}/ssh_password.mod {{ custom_selinux_dir }}/ssh_password
39+
when: not ssh_use_pam and sestatus.stdout == 'Enforcing'
40+
41+
- name: create selinux policy module package
42+
shell: semodule_package -o {{ custom_selinux_dir }}/ssh_password.pp -m {{ custom_selinux_dir }}/ssh_password.mod
43+
when: not ssh_use_pam and sestatus.stdout == 'Enforcing'
44+
45+
- name: install selinux policy
46+
shell: semodule -i {{ custom_selinux_dir }}/ssh_password.pp
47+
when: not ssh_use_pam and sestatus.stdout == 'Enforcing'
48+
49+
- 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)
50+
shell: semodule -r ssh_password
51+
when: selinux_policy_state.stdout != 'Disabled' and ssh_use_pam

roles/ansible-ssh-hardening/vars/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ kex_59_weak: '{{kex_59_default + ",diffie-hellman-group14-sha1,diffie-hellman-gr
1818
kex_66_default: 'curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256'
1919
kex_66_weak: '{{kex_66_default + ",diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1"}}'
2020

21+
# directory where to store ssh_password policy
22+
custom_selinux_dir: '/etc/selinux/local-policies'

0 commit comments

Comments
 (0)