-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrhel9-mfa.yaml
69 lines (59 loc) · 2.24 KB
/
rhel9-mfa.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
---
- hosts: "{{ target }}"
gather_facts: no
become: yes
become_user: root
become_method: sudo
tasks:
- name: Install yum-utils
ansible.builtin.dnf:
name: yum-utils
state: present
- name: Enable CRB (coreready builder)
ansible.builtin.shell: dnf config-manager --set-enabled crb
- name: Enable EPEL repo
ansible.builtin.dnf:
name: epel-release
state: present
- name: Install google-authenticator and other dependencies
ansible.builtin.dnf:
name: "{{ item }}"
state: present
loop:
- google-authenticator
- qrencode
- qrencode-libs
- name: Set ChallengeResponseAuthentication to yes
ansible.builtin.lineinfile:
path: /etc/ssh/sshd_config.d/50-redhat.conf
regexp: '^ChallengeResponseAuthentication'
line: ChallengeResponseAuthentication yes
- name: Set pam configs.
ansible.builtin.lineinfile:
path: /etc/pam.d/sshd
insertafter: 'auth\s+\w+\s+postlogin$'
line: 'auth required pam_google_authenticator.so secret=${HOME}/.google_authenticator nullok no_increment_hotp'
- name: Restart sshd.
ansible.builtin.systemd:
state: restarted
daemon_reload: true
name: sshd
- name: Modify the default .bashrc.
ansible.builtin.blockinfile:
path: /etc/skel/.bashrc
marker: "##### {mark} ANSIBLE MANAGED BLOCK #####"
insertbefore: "unset rc"
block: |
## If .google_authenticator file is not found (eg. newly created user account), then generate one.
## The QR code will be shown to the user upon initial login.
if [ ! -f $HOME/.google_authenticator ];
then
echo "Enabling MFA for $USER"
echo ""
/usr/bin/google-authenticator -t -f -d -w 3 -e 5 -r 3 -R 30
fi
## Issue with SELinux, fix it with the steps below. Not adding it to the playbook as I can't reproduce the issue. - Jay O.
# grep google_authenticator /var/log/audit/audit.log | audit2allow -m google_auth_2 > google_auth_2.te
# grep google_authenticator /var/log/audit/audit.log | audit2allow -M google_auth_2
# semodule -i google_auth_2.pp
# semodule --reload