一般來說,RADIUS 較常見的應用於無線網路的使用者認證,以控制無線網路資源的使用,但其實 RADIUS 可以跟很多應用程式相互搭配使用,Apache 就有提供模組可以與 RADIUS 搭配使用來對用戶進行存取控制(access control)。
Apache 本身就有不少模組來對用戶進行認證與授權等,譬如 mod_authz_host 可以針對個別用戶端的 IP 位址或 Domain name 來進行處理;mod_rewrite可以設定某些特別規則來對使用者進行控制。
而較常用的方法為利用 mod_auth_basic 與 mod_auth_digest,其可根據AuthBasicProvider 中所列的認證授權模組來對用戶端進行控制,Apache 預設的認證模組有mod_authn_dbm(使用者帳號密碼存於dbm password file)、mod_authn_file(使用者帳號密碼存與純文字檔)、mod_authn_dbd、mod_authz_ldap(使用者帳號密碼存於ldap目錄)。
因此,你若要用 RADIUS 來對使用者進行認證,需要去安裝 Apache 上的 RADIUS 認證模組。較常看到的模組為 mod_auth_radius 以及mod_auth_xradius(後段說明之),首先去 FreeRADIUS 的官方網站下載此套件(最新版為1.5.7),並解開它:
[root@localhost aaron]#wget ftp://ftp.freeradius.org/pub/radius/mod_auth_radius-1.5.7.tar
[root@localhost aaron]#tar xvf mod_auth_radius
目錄中的 mod_auth_radius-2.0.c 是給 Apache 2.0 以後的版本使用;而mod_auth_radius.c 是給 Apache 1.3.x 使用。
接著輸入下列指令將此模組編譯至Apache中:
[root@localhost aaron]#apxs -i -a -c mod_auth_radius-2.0.c
(需安裝httpd_devel套件才可以使用apxs指令)
安裝完畢之後,會在 httpd.conf 自動加入 LoadModule radius_auth_module /usr/lib/httpd/modules/mod_auth_radius-2.0.so。如此,你即可使用此模組。
接著在 httpd.conf 中加入下列規則:
#設定認證伺服器的 IP 位址與 secret key
AddRadiusAuth server IP[:port] <shared-secret>
#mod_auth_radius 使用cookie session,0為永遠有效
AddRadiusCookieValid <minutes-for-which-cookie-is-valid>
#指定要使用其他模組來進行認證
AuthAuthoritative off
AuthType Basic
AuthName "Raius Authentication"
#指明只使用 RADIUS 來對用戶端認證
AuthRadiusAuthoritative on
#使用 RADIUS 來對用戶進行認證
AuthRadiusActive on
require
valid-user
如此,則完成了mod_auth_radius的基礎設定。
不過因為這個模組需要重新編譯整個 Apache 伺服器且使用 cookies 來儲存
session,但由於現在各個 distro 的套件管理做的都很不錯,因此,不一定是抓 RPM
回來重新編譯,這樣就沒辦法將此套件重新編譯,因此我選擇 mod_auth_xradius。
mod_auth_xradius
首先,至官方網站(http://www.outoforder.cc/projects/apache/mod_auth_xradius/)下載目前最新版本的mod_auth_xradius模組,並解壓縮:
[root@localhost aaron]#wget
http://www.outoforder.cc/downloads/mod_auth_xradius/mod_auth_xradius-0.4.6.tar.bz2
[root@localhost aaron]#bunzip2
mod_auth_xradius-0.4.6.tar.bz2
[root@localhost aaron]#tar -xvf
mod_auth_xradius-0.4.6.tar
接著開始將模組編譯(需事先安裝httpd_devel套件):
[root@localhost aaron]#cd cd
mod_auth_xradius-0.4.6
[root@localhost aaron]#./configure
--with-apxs=/sbin/apxs
[root@localhost aaron]#make
[root@localhost aaron]#make install
如此則完成 mod_auth_xradius
的安裝。接下來在httpd.conf中加入下列設定啟動mod_auth_xradius模組:
LoadModule auth_xradius_module
modules/mod_auth_xradius.so
接著加入下列規則來設定讓Apache設定使用RADIUS認證:
AuthType Basic
#使用RADIUS對用戶進行認證
AuthBasicProvider xradius
AuthName "Private Area"
#設定 RADIUS 伺服器的 IP 位址與secret key
AuthXRadiusAddServer "localhost" "testing123"
#等待認證伺服器回應的時間(秒)
AuthXRadiusTimeout 7
#若認證伺服器無回應,重試的次數
AuthXRadiusRetries
2
require valid-user
可將這段規則至於整個網頁伺服器的設定,或是至於 virtual
host中,則所有連接至站台的用戶都需要輸入正確的帳號/密碼才能夠瀏覽。