Skip to content

Commit e8cf61b

Browse files
committed
Make changes portable
Signed-off-by: Martin Schurz <[email protected]> Make changes portable Signed-off-by: Martin Schurz <[email protected]> Make changes portable Signed-off-by: Martin Schurz <[email protected]> Make changes portable Signed-off-by: Martin Schurz <[email protected]> Make changes portable Signed-off-by: Martin Schurz <[email protected]> Make changes portable Signed-off-by: Martin Schurz <[email protected]> Make changes portable Signed-off-by: Martin Schurz <[email protected]> Make changes portable Signed-off-by: Martin Schurz <[email protected]>
1 parent 767293e commit e8cf61b

File tree

2 files changed

+58
-7
lines changed

2 files changed

+58
-7
lines changed

molecule/os_hardening/verify_tasks/ssh_auth_locked.yml

+40-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,31 @@
11
---
22
- name: Install tools
33
package:
4-
name:
5-
- sshpass
4+
name: "{{ item }}"
65
state: present
6+
ignore_errors: true
7+
loop:
8+
- sshpass
9+
- openssh
10+
- openssh-clients
11+
- openssh-server
12+
13+
- name: Allow password Login for sshd
14+
ansible.builtin.lineinfile:
15+
path: /etc/ssh/sshd_config
16+
search_string: PasswordAuthentication no
17+
line: PasswordAuthentication yes
18+
when:
19+
- ansible_facts.distribution == "Amazon"
20+
21+
- name: Start sshd service
22+
ansible.builtin.service:
23+
name: "{{ item }}"
24+
state: started
25+
ignore_errors: true
26+
loop:
27+
- sshd
28+
- ssh
729

830
- name: Set password for test
931
ansible.builtin.set_fact:
@@ -16,7 +38,7 @@
1638

1739
- name: Create ssh-client-keypair
1840
community.crypto.openssh_keypair:
19-
path: /root/.ssh/locked_user_id
41+
path: /root/locked_user_id
2042
type: ed25519
2143
state: present
2244
register: generated_key
@@ -29,19 +51,19 @@
2951

3052
- name: Check successful login with password
3153
ansible.builtin.shell:
32-
cmd: sshpass -p {{ test_pw }} ssh locked_user@localhost echo "success"
54+
cmd: sshpass -p {{ test_pw }} ssh -o StrictHostKeyChecking=no locked_user@localhost echo "success"
3355

3456
- name: Check successful login with ssh key
3557
ansible.builtin.shell:
36-
cmd: ssh -i /root/.ssh/locked_user_id locked_user@localhost echo "success"
58+
cmd: ssh -i /root/locked_user_id -o StrictHostKeyChecking=no locked_user@localhost echo "success"
3759

3860
- name: Set password change date for locked_user
3961
ansible.builtin.shell:
4062
cmd: chage -d 2020-01-01 locked_user
4163

4264
- name: Check unsuccessful login with password
4365
ansible.builtin.shell:
44-
cmd: sshpass -p {{ test_pw }} ssh locked_user@localhost echo "success"
66+
cmd: sshpass -p {{ test_pw }} ssh -o StrictHostKeyChecking=no locked_user@localhost echo "success"
4567
register: output
4668
ignore_errors: true
4769

@@ -51,7 +73,18 @@
5173
- output.rc | int == 1
5274
- "'WARNING: Your password has expired.' in output.stderr"
5375
- "'success' not in output.stdout"
76+
when:
77+
- ansible_facts.os_family != "OpenSuse"
78+
79+
- name: Assert check unsuccessful login
80+
ansible.builtin.assert:
81+
that:
82+
- output.rc | int == 5
83+
- output.stderr | length == 0
84+
- output.stdout | length == 0
85+
when:
86+
- ansible_facts.os_family == "OpenSuse"
5487

5588
- name: Check successful login with ssh key
5689
ansible.builtin.shell:
57-
cmd: ssh -i /root/.ssh/locked_user_id locked_user@localhost echo "success"
90+
cmd: ssh -i /root/locked_user_id -o StrictHostKeyChecking=no locked_user@localhost echo "success"

roles/os_hardening/tasks/pam.yml

+18
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,24 @@
2727
when:
2828
- ansible_facts.os_family == 'RedHat'
2929

30+
- name: Allow Login with SSH Keys, when user password is expired
31+
ansible.builtin.lineinfile:
32+
path: /etc/pam.d/system-auth
33+
backrefs: true
34+
regexp: "^(account.*pam_unix.so(?!.*no_pass_expiry).*)$"
35+
line: '\1 no_pass_expiry'
36+
when:
37+
- ansible_facts.os_family == 'Archlinux'
38+
39+
- name: Allow Login with SSH Keys, when user password is expired
40+
ansible.builtin.lineinfile:
41+
path: /etc/pam.d/common-account
42+
backrefs: true
43+
regexp: "^(account.*pam_unix.so(?!.*no_pass_expiry).*)$"
44+
line: '\1 no_pass_expiry'
45+
when:
46+
- ansible_facts.os_family == 'OpenSuse'
47+
3048
- name: NSA 2.3.3.5 Upgrade Password Hashing Algorithm to SHA-512
3149
ansible.builtin.template:
3250
src: etc/libuser.conf.j2

0 commit comments

Comments
 (0)