RADIUS是遠端認證用的伺服器,而Freeradius則是一個Linux based的免費且開源的服務,很好用之外也符合安全需求,只是要架設它的過程需要做點功課,我在架設過程中遇到很多障礙,三種方式中這個最花時間。
1.建立一台Freeradius主機
其實硬體需求不用太高,但我是第一次架設,還是保守點給4 Core CPU、8 GB RAM、100GB硬碟、一張網卡。
2.基本設定
更新、安裝Freeradius、關閉防火牆、SElinux並重開電腦。
[root@freeradius ~]# yum update -y
[root@freeradius ~]# yum install vim net-tools -y
[root@freeradius ~]# yum install freeradius freeradius-utils -y
[root@freeradius ~]# systemctl status firewalld
[root@freeradius ~]# systemctl stop firewalld
[root@freeradius ~]# systemctl disable firewalld
[root@freeradius ~]# vi /etc/selinux/config
[root@freeradius ~]# shutdown -r -t 0
3.更改使用者和群組
要執行goole-authenticator 必須用到root權限。
[root@freeradius ~]# vi /etc/raddb/radiusd.conf
#group = radiusd
#user = radiusd
user = root
group = root
4.sites-enabled/default檔將pam取消註解
[root@freeradius ~]# vi /etc/raddb/sites-enabled/default
# Pluggable Authentication Modules.
pam
5.client端防火牆連線設定
這邊的設定很重要,如果錯誤了就無法跟Fortigate做連接。
[root@freeradius ~]# vi /etc/raddb/clients.conf
client 10.113.112.10/24 {
secret = testing123
require_message_authenticator = no
nas_type = other
}
\\有些文件上寫還要ipaddr的位置,但我花很多時間測試才發現這是多餘的。
6.變更認證類型
[root@freeradius ~]# vi /etc/raddb/users
# DEFAULT Group == "disabled", Auth-Type := Reject
# Reply-Message = "Your account has been disabled."
#
\\把上面的設定取消註解並改成下面的
DEFAULT Group == "disabled", Auth-Type := Reject
Reply-Message = "Your account has been disabled."
DEFAULT Auth-Type := PAM
7.建立本機帳號並測試認證
[root@freeradius ~]# useradd raduser
[root@freeradius ~]# passwd raduser
Changing password for user raduser.
New password: 1qaz@WSX
Retype new password: 1qaz@WSX
passwd: all authentication tokens updated successfully.
[root@freeradius ~]# radiusd -X \\這是debug模式,有錯誤的話會顯示在最下方結果
[root@freeradius ~]# radtest raduser 1qaz@WSX localhost 0 testing123
Sent Access-Request Id 71 from 0.0.0.0:41478 to 127.0.0.1:1812 length 77
User-Name = "raduser"
User-Password = "1qaz@WSX"
NAS-IP-Address = 10.113.112.10
NAS-Port = 0
Message-Authenticator = 0x00
Cleartext-Password = "1qaz@WSX"
Received Access-Accept Id 71 from 127.0.0.1:1812 to 0.0.0.0:0 length 20
\\Received Access-Accept就表示本機的單因認證測試通過了
8.安裝網域套件並加入網域
[root@freeradius ~]# yum install sssd realmd adcli
[root@freeradius ~]# yum install oddjob oddjob-mkhomedir sssd samba-commontools
[root@freeradius ~]# realm join interpay.com.tw \\網域就看公司用什麼
Password for Administrator: \\要輸入AD主機的管理者密碼
測試看看能不能連線到AD上面的帳號
[root@freeradius ~]# su - testuser@interpay.com.tw
上一次登入:五 5月 21 10:17:10 CST 2021在 pts/0
[testuser@interpay.com.tw@freeradius ~]$ \\這樣就表示網域已經在這台radius上串連成功
[testuser@interpay.com.tw@freeradius ~]$ radiusd -X \\再跑一次debug模式
[testuser@interpay.com.tw@freeradius ~]# radtest testuser@interpay.com.tw 1qaz@WSX localhost 0
testing123
Sent Access-Request Id 144 from 0.0.0.0:35469 to 127.0.0.1:1812 length 84
User-Name = "testuser@interpay.com.tw"
User-Password = "1qaz@WSX"
NAS-IP-Address = 10.113.112.10
NAS-Port = 0
Message-Authenticator = 0x00
Cleartext-Password = "1qaz@WSX"
Received Access-Accept Id 144 from 127.0.0.1:1812 to 0.0.0.0:0 length 20
\\這次的測試是以AD帳號且只有單因認證,下面要再做雙因認證
9.安裝Google Authenticator PAM
[root@freeradius ~]# yum install pam-devel make gcc-c++ git
[root@freeradius ~]# yum install automake autoconf libtool
[root@freeradius ~]# cd ~
[root@freeradius ~]# git clone https://github.com/google/google-authenticatorlibpam.git
Cloning into 'google-authenticator-libpam'...
remote: Enumerating objects: 796, done.
remote: Total 796 (delta 0), reused 0 (delta 0), pack-reused 796
Receiving objects: 100% (796/796), 538.35 KiB | 381.00 KiB/s, done.
Resolving deltas: 100% (508/508), done.
[root@freeradius ~]# cd ~/google-authenticator-libpam/
[root@freeradius google-authenticator-libpam]# ./bootstrap.sh
[root@freeradius google-authenticator-libpam]# ./configure
[root@freeradius google-authenticator-libpam]# make
[root@freeradius google-authenticator-libpam]# make install
10.測試Google Authenticator雙因認證
[root@freeradius ~]# su - testuser@interpay.com.tw
Creating home directory for adtom@eden.com.
[testuser@interpay.com.tw@freeradius ~]$ google-authenticator
Do you want authentication tokens to be time-based (y/n) y \\按y 會接著產生QR Code
Warning: pasting the following URL into your browser exposes the OTP secret to
Google:
https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl=otpauth://tot
p/adtom@eden.com@centos7radius%3Fsecret%3DWASLQBOJ7SC5CWN3CB
RT62AMOY%26issuer%3Dcentos7radius
\\手機要下載Google Authenticator APP,並掃描上述方法產生的QR CodeYour new secret key is: WASLQBOJ7SC5CWN3CBRT62AMOY
Enter code from app (-1 to skip):
-1633617
Code confirmed
Your emergency scratch codes are:
43322639
34705877
32173950
41646850
82907757
Do you want me to update your "/home/adtom@eden.com/.google_authenticator"
file? (y/n) y
Do you want to disallow multiple uses of the same authentication
token? This restricts you to one login about every 30s, but it increases
your chances to notice or even prevent man-in-the-middle attacks (y/n) y
By default, a new token is generated every 30 seconds by the mobile app.
In order to compensate for possible time-skew between the client and the server,
we allow an extra token before and after the current time. This allows for a
time skew of up to 30 seconds between authentication server and client. If you
experience problems with poor time synchronization, you can increase the
window
from its default size of 3 permitted codes (one previous code, the current
code, the next code) to 17 permitted codes (the 8 previous codes, the current
code, and the 8 next codes). This will permit for a time skew of up to 4 minutes
between client and server.
Do you want to do so? (y/n) y
If the computer that you are logging into isn't hardened against brute-force
login attempts, you can enable rate-limiting for the authentication module.
By default, this limits attackers to no more than 3 login attempts every 30s.
Do you want to enable rate-limiting? (y/n) y
\\接下來一路選y就好了
11.調整PAM設定檔
[testuser@interpay.com.tw@freeradius ~]$ su - root
Password:
[root@freeradius testuser@interpay.com.tw]# vi /etc/pam.d/radiusd
#%PAM-1.0
#auth include password-auth
#account required pam_nologin.so
#account include password-auth
#password include password-auth
#session include password-auth
\\把上面的設定取消註解並改成下面的
auth requisite /usr/local/lib/security/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
12.測試AD帳號搭配Google Authenticator雙因認證
[testuser@interpay.com.tw@freeradius ~]$ radtest testuser@interpay.com.tw 1qaz@WSX696193 localhost 0 testing123
Sent Access-Request Id 71 from 0.0.0.0:39594 to 127.0.0.1:1812 length 94
User-Name = "testuser@interpay.com.tw"
User-Password = "1qaz@WSX696193"
NAS-IP-Address = 10.113.112.10
NAS-Port = 0
Message-Authenticator = 0x00
Cleartext-Password = "1qaz@WSX696193"
Received Access-Accept Id 71 from 127.0.0.1:1812 to 0.0.0.0:0 length 20
\\這關得要過才能在接下來的Fortigate上設定下一步
13.帳號已簡易方式登入
為了避免登入帳號後面帶很長的domain,增加登入的麻煩和輸入錯誤機率,這邊要先設定sssd.conf,讓帳號只需要前綴。例如,我的ad帳號是testuser@interpay.com.tw,希望登入的時候只要輸入testuser,而不是落落長的testuser@interpay.com.tw。
[root@freeradius /]# vi /etc/sssd/sssd.conf
[sssd]
domains = interpay.com.tw
config_file_version = 2
services = nss, pam
default_domain_suffix = interpay.com.tw
[domain/interpay.com.tw]
ad_domain = interpay.com.tw
krb5_realm = INTERPAY.COM.TW
realmd_tags = manages-system joined-with-samba
cache_credentials = True
id_provider = ad
krb5_store_password_if_offline = True
default_shell = /bin/bash
ldap_id_mapping = True
use_fully_qualified_names = True
fallback_homedir = /home/%u@%d
access_provider = simple \\這邊要填上simple
simple_allow_group = MIS \\這段要自己加,可以指定AD群組,讓其成員登入不帶domain
simple_allow_users = testuser \\這段也要自己加,直接指定帳號登入不需要帶domain
14.Fortigate與Freeradius做連線
 |
連線設定的secret要對照前面client.conf裡面的的配置 |
 |
也可以測試一下AD+radius認證 |
沒有留言:
張貼留言