2021年7月28日 星期三

建罝 FreeRadius + Google Authenticator

目的是希望可以使用 sslvpn client作雙因子認證,經建議採用此方案後開始建立一個 VM環境測試 

參考文章

建置環境 CentOS 8

前置準備
yum update (要最新)
要先調整 chrony 設定檔加入 ad校時,參考如下:
執行 dnf install langpacks-en glibc-all-langpacks -y
防火牆要設定 (有的文章會全部關掉,有的調整設定檔,可等 freeradius安裝完再執行)
firewall-cmd --permanent --zone=public --add-service=radius
firewall-cmd --reload



步驟
1.安裝 freeradius server  ->  yum install freeradius freeradius-utils

2.設定 /etc/raddb/radiusd.conf  , user, group的值都改為 root  (原本是radius)

3.設定 /etc/raddb/sites-enabled/default  取消注解# pam

4.執行 link 指令 ln -s /etc/raddb/mods-available/pam /etc/raddb/mods-enabled/pam

5.設定 /etc/raddb/clients.conf 新增 NAS - Network Access Server連線設定,允許 Server可以使用 Radius Server,這邊要注意 secret不要太短,要長一點,在這設定檔可以看到本機的設定,其預設 secret為 testing123 (最好也改長)

6.設定  /etc/raddb/user
取消注解
DEFAULT Group == "disabled", Auth-Type := Reject
Reply-Message = "Your account has been disabled."
加上
DEFAULT Auth-Type := PAM

以上設定後就可以用本機測試,但還沒有 google authenticator one-time password
 debug模式看到執行 log可以執行 radiusd -X ,如果測試沒有問題可以用 systemctl enable  radiusd  長駐 service和  restart  重啟 (有設定更改時)
可以用 useradd , passwd 指令建立本機(centos) user如 raduser 測試
執行 radtest  raduser pwd localhost 0 testing123    (secret 用/etc/raddb/clients.conf 的 localhost)

7.安裝 SSSD ,目的 freeradius 與 windows 網域整合
yum install sssd realmd adcli

8. 加入 windows ad doman和給 ad 群組授權
realm join -U administrator [ad domain name]   (需輸入 AD管理者帳號)
realm permit -g [AD group]  (一定要執行, AD 使用者需加入群組)
成功後,代表可以用 AD帳號登入 CentOS哦 (radtest也可測 AD帳號),/home下會產生對應目錄


9.安裝 google-authenticator
有的是比較複雜,可以用下列方式安裝
sudo yum -y install google-authenticator  或是 sudo dnf -y install google-authenticator qrencode

10.手機安裝 google authenticator app

11.使用 AD帳號建立 google authenticator  file
先用 AD 帳號登入,執行 google-authenticator
a.time-base  -> yes
b.手机 google authenticator app新增一組並輸入 centos畫面出現的 secret key 成功後  centos可以看到下個提示
c.update file  -> yes
d.disallow multiple use -> yes
e.by dafault  -> no
f.enable rate-limiting -> yes
執行完成之後,會在 home/${user}/目錄產生一個 .google-authenticator ,可以把這個檔案 copy  到新的使用者目錄

表示要改用 sssd + google authenticator方式去認證使用者 
只留下方,其它註解
auth       requisite    pam_google_authenticator.so forward_pass
auth       required     pam_sss.so use_first_pass
account    required     pam_nologin.so
account    include      password-auth
session    include      password-auth

13.更改 /etc/selinux/config  目的是為了 fradius service 和 user radiusd可存取 /home/${user}下的 .google_authenticator
SELINUX=permissive  (原本為 enforce ,最差就改成 disabled)
改完要 reboot
以上設定完成之後可以再使用 radtest測試,密碼的部份需要加上 one time password
radtest <username> <active directory pasword><google-authenticator emergency code> localhost 0 testing123

14 .其它
log 啟用
/etc/raddb/sites-enabled/default auth_log, reply_log取消註解

複製原有的 .google_authenticator檔至其它 ad user
a.在 /home底下建立 ${aduser@domain} 目錄
b.copy 原本 user 目錄下 .google_authenticator 新目錄
c.變更目錄和檔案權限 給新的 AD帳號 (帳號存在 AD且有效即可,不用先在 centos 作登入)


沒有留言:

張貼留言