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

Commit 9a3af69

Browse files
committed
Merge pull request #35 from hardening-io/pam_selinux
Support for selinux and pam. fix #23
2 parents 1046ede + adc8462 commit 9a3af69

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-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: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
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+
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+
517
- name: create sshd_config and set permissions to root/600
618
template: src='opensshd.conf.j2' dest='/etc/ssh/sshd_config' mode=0600 owner=root group=root validate="/usr/sbin/sshd -T -f %s"
719
notify: restart sshd
@@ -10,3 +22,31 @@
1022
- name: create ssh_config and set permissions to root/644
1123
template: src='openssh.conf.j2' dest='/etc/ssh/ssh_config' mode=0644 owner=root group=root
1224
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

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)