File tree Expand file tree Collapse file tree 4 files changed +66
-1
lines changed Expand file tree Collapse file tree 4 files changed +66
-1
lines changed Original file line number Diff line number Diff line change 2020 - verify_tasks/pw_ageing.yml
2121 - verify_tasks/netrc.yml
2222 - verify_tasks/ignore_home_folders.yml
23+ - verify_tasks/ssh_auth_locked.yml
2324
2425 # temp. disabled - https://github.com/dev-sec/ansible-collection-hardening/issues/690
2526 # - name: Include PAM tests
Original file line number Diff line number Diff line change 1+ ---
2+ - name : Install sshpass
3+ package :
4+ name :
5+ - sshpass
6+ state : present
7+
8+ - name : Set password for test
9+ ansible.builtin.set_fact :
10+ test_pw : myTest!pw
11+
12+ - name : Create locked_user
13+ user :
14+ name : locked_user
15+ password : " {{ test_pw | password_hash('sha512') }}"
16+
17+ - name : Create ssh-client-keypair
18+ community.crypto.openssh_keypair :
19+ path : /root/.ssh/locked_user_id
20+ type : ed25519
21+ state : present
22+ register : generated_key
23+
24+ - name : Add ssh-public-key to locked_user
25+ ansible.posix.authorized_key :
26+ user : locked_user
27+ key : " {{ generated_key.public_key }}"
28+ state : present
29+
30+ - name : Check successful login with password
31+ ansible.builtin.shell :
32+ cmd : sshpass -p {{ test_pw }} ssh locked_user@localhost echo "success"
33+
34+ - name : Check successful login with ssh key
35+ ansible.builtin.shell :
36+ cmd : ssh -i /root/.ssh/locked_user_id locked_user@localhost echo "success"
37+
38+ - name : Set password change date for locked_user
39+ ansible.builtin.shell :
40+ cmd : chage -d 2020-01-01 locked_user
41+
42+ - name : Check unsuccessful login with password
43+ ansible.builtin.shell :
44+ cmd : sshpass -p {{ test_pw }} ssh locked_user@localhost echo "success"
45+ register : output
46+ ignore_errors : true
47+
48+ - name : Assert check unsuccessful login
49+ ansible.builtin.assert :
50+ that :
51+ - output.rc | int == 1
52+ - " 'WARNING: Your password has expired.' in output.stderr"
53+ - " 'success' not in output.stdout"
54+
55+ - name : Check successful login with ssh key
56+ ansible.builtin.shell :
57+ cmd : ssh -i /root/.ssh/locked_user_id locked_user@localhost echo "success"
Original file line number Diff line number Diff line change 118118 state : absent
119119 when :
120120 - not os_auth_pam_passwdqc_enable
121+
122+ - name : Allow Login with SSH Keys, when user password is expired
123+ lineinfile :
124+ path : /etc/pam.d/common-account
125+ backrefs : yes
126+ regexp : " ^(account.*pam_unix.so(?!.*no_pass_expiry).*)$"
127+ line : ' \1 no_pass_expiry'
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ auth required pam_deny.so
2424{% if os_auth_retries |int > 0 %}
2525account required pam_faillock.so
2626{% endif %}
27- account required pam_unix.so
27+ account required pam_unix.so no_pass_expiry
2828account sufficient pam_localuser.so
2929account sufficient pam_succeed_if.so uid < 1000 quiet
3030{% if (os_auth_pam_sssd_enable | bool ) %}
You can’t perform that action at this time.
0 commit comments