這陣子校園的無線網路漫遊出了一些問題,他校來咱們學校使用無線網路都無法認證通過 ~
出錯的環節應該是在 Roaming Server 上,此外咱們學校也沒有一台「正式」的 Radius Server
因此這幾天花了一點時間研究跨校漫遊的架構,也決定在 FreeBSD 上重弄一台 FreeRadius 並且整合 OpenLDAP 的帳號,以達單一帳號之整合
下方是簡略的系統架構圖,目前我們學校是用 Aruba 的產品,AP 是 AP-61,Controller 則是用 6000
以上圖為例,當使用者連上 AP 後則會自動導向 AP Controller 並找 Radius Server 做驗證,若是本校學生則向 LDAP 做帳號密碼驗證,若是他校人員則會再透過 VPN Roaming 回該校做帳號密碼之驗證。
接下來說明實作的部份,此篇文章僅說明如何將 FreeRadius 整合 OpenLDAP,前提是在這之前假設已經有一台 LDAP Server 了,LDAP 的 Schema 可以參考這篇酷學園 - [筆記]FreeRadius with LDAP ! 的文章。另外我的機器是將 FreeRadius 和 OpenLDAP Server 裝在一起,所以沒另外去設定 OpenLDAP Client 的東西,若您的機器是分開安裝,請記得設定 OpenLDAP Client 端的部份,確保連線正常!
1.首先安裝 FreeRadius
# cd /usr/ports/net/freeradius
# make config ( 請勾選 LDAP 的部份 )
# make install clean
2.設定 FreeRadius 與 LDAP Server
# cd /usr/local/etc/raddb
# cp /usr/local/share/examples/freeradius/raddb/ldap.attrmap .
3.設定 user 這檔案
# vi user
找到下面這段文字後,新增 LDAP 認證的設定
#
# First setup all accounts to be checked against the UNIX /etc/passwd.
# (Unless a password was already given earlier in this file).
#
DEFAULT Auth-Type = System
Fall-Through = 1
DEFAULT Auth-Type := LDAP
Fall-Through = 1
4.設定 radius.conf
先找到 ldap { 這一行,再開始設定參數,下面是我的例子
server = "127.0.0.1"
identity = "cn=root,dc=xxx,dc=xxx,dc=xxx,dc=xxx"
password = xxxxxxx
basedn = "dc=xxx,dc=xxx,dc=xxx,dc=xxx"
filter = "(uid=%{Stripped-User-Name:-%{User-Name}})"
access_attr = "uid"
dictionary_mapping = ${raddbdir}/ldap.attrmap
ldap_connections_number = 5
password_attribute = userPassword
password_header = "{crypt}"
edir_account_policy_check=no
timeout = 4
timelimit = 3
net_timeout = 1
再找到 下面的字串把 ldap 前的的 # 拿掉
#
# The ldap module will set Auth-Type to LDAP if it has not
# already been set
ldap
最後再找到下面這字串把 Auth-Type LDAP { 前面幾行的 # 都拿掉
# Uncomment it if you want to use ldap for authentication
#
# Note that this means "check plain-text password against
# the ldap database", which means that EAP won't work,
# as it does not supply a plain-text password.
Auth-Type LDAP {
ldap
}
5.設定 client.conf
首先先把下面區塊裡的密碼更改一下
client 127.0.0.1 {
secret = 校園內部密碼
}
再新增其它 Client 端的設定
# Roaming Center <- 跨校漫游用
client 172.16.16.0/24 {
secret = 跨校漫遊密碼
shortname = RoamingCenter
}
# 本校的 radius Server
client 192.168.1.0/24 {
secret = 校園內部密碼
shortname = school
}
6.修改 proxy.conf
新增
#現有的職員和學生
realm xxx.edu.tw {
type = radius
authhost = LOCAL
accthost = LOCAL
secret = 校園內部密碼
}
#其它學校跨校漫遊使用
realm DEFAULT {
type = radius
authhost = 跨校漫遊驗證主機:1812
accthost = 跨校漫遊驗證主機:1813
secret = 跨校漫遊密碼
nostrip
}
#一般若沒有跨校漫遊的話,可用下面的來替代 DEFAULT
#realm DEFAULT {
# type = radius
# authhost = LOCAL
# accthost = LOCAL
# secret = 校園內部密碼
#}
7.啟動 FreeRadius
# /usr/local/etc/rc.d/radiusd start
看一下 Port 1812、1813 是否有開始 listen 了,有的話就表示 OK 了
若起不來可以參考 /var/log/radius.log 的錯誤訊息
另外在 /etc/rc.conf 加入一行設定讓它開機時自己啟動
radiusd_enable="YES"
8.測試 Radius 是否有去找 LDAP 驗證
# radtest 帳號 密碼 localhost 0 校園內部密碼
這是成功的範例
# radtest bojack xxxxxx localhost 0 校園內部密碼
Sending Access-Request of id 252 to 127.0.0.1 port 1812
User-Name = "bojack"
User-Password = "xxxxxx"
NAS-IP-Address = 255.255.255.255
NAS-Port = 0
rad_recv: Access-Accept packet from host 127.0.0.1:1812, id=252, length=20
這是失敗的範例,通常都是後面的密碼打錯了
# radtest bojack xxxxxx localhost 0 錯的密碼
Sending Access-Request of id 1 to 127.0.0.1 port 1812
User-Name = "bojack"
User-Password = "xxxxxx"
NAS-IP-Address = 255.255.255.255
NAS-Port = 0
Re-sending Access-Request of id 1 to 127.0.0.1 port 1812
User-Name = "bojack"
User-Password = "xxxxxx"
NAS-IP-Address = 255.255.255.255
NAS-Port = 0
rad_recv: Access-Reject packet from host 127.0.0.1:1812, id=1, length=20
rad_verify: Received Access-Reject packet from client 127.0.0.1 port 1812 with invalid signature (err=2)! (Shared secret is incorrect.)
ps. 另外提到的 VPN 連線部份,我是用 /usr/ports/security/vpnd 來做連線,使用的方式可以參考[ 安裝心得 ] 如何設定 VPN ﹖
安裝方式一樣進 ports 安裝即可
設定檔在 /usr/local/etc 下
# cd /usr/local/etc
# cp vpnd.conf.sample vpnd.conf
# cp vpnd.chat.sample chat.conf
接下來產生一個 KEY,我名命為 1234.key
# vpnd -m 1234.key
把這個 KEY 留著,分別給 VPN Server & Client 端待會兒建立連線用
附上我的 client 設定
mode client
server VPN_Server_IP VPN_Port
client VPN_Client_IP VPN_Port
local 172.16.1.2
remote 172.16.1.1
keyfile /usr/local/etc/1234.key
route1 172.16.0.0 255.255.0.0 172.16.1.1
keepalive 60
noanswer 3
autoroute
此篇教學花費了我4天的時間才搞定,說實在的一開始連 Radius 到底是什麼都搞不清楚,現在架好了也只是略懂設定而已,功能應該更強大才是。
[1] [筆記]FreeRadius with LDAP !
[2] FreeRADIUS on FreeBSD and OpenLDAP
[3] Ch31 : Centralized Logins Using LDAP and RADIUS