- 追加された行はこの色です。
- 削除された行はこの色です。
*Radius [#k84dd7cd]
[[FreeRADIUS:+http://freeradius.org/]]
OSSのRadiusServerとしては、多分一番シェアが高い物。
~
*インストール [#o28b4508]
&size(16){&font(b){1. 前書き};};
ソースから入れるなら、3.0.xを入れるべきなのだろうが、CentOS6.5+FreeRADIUS3.0.3で構築を試みた結果、
libtallocとの連結やOpenSSLの組み込みとかで転けて大変だったので2.2.xで構築。
#author("2018-12-13T22:48:09+09:00","default:nowsky","nowsky")
*daloRADIUS [#w1cfb5cf]
-[[daloRADIUS:+http://www.daloradius.com/]]
-[[GitHub daloradius:+https://github.com/lirantal/daloradius]]
という事で、今回は以下の構成を前提にメモ。
OS : CentOS 6.5 x86_64
FreeRADIUS : 2.2.5
認証方式 : EAP-TTLS & PEAP
FreeRADIUSの認証データをMySQLに蓄えつつ、
ユーザ、パスワード、アトリビュート等をWebブラウザ経由で管理出来るフロントエンド。
メインラインの開発は0.9-9で終了しているが、GitHub版で稀に更新されている事がある。
SourceForge版はSQL構文エラーが出たり日本語対応していなかったりするが、
GitHub版は諸々のDB不具合解消と日本語対応が行われている。
~
&size(16){&font(b){2. FreeRADIUSのコンパイル};};
[[OpenSSL:http://www.ns-lab.org/wiki/?cmd=read&page=Linux%2FSource%2FOpenSSL]]もmakeでインストールしている事を前提。
yumなりapt-getなりでOpenSSLを入れた場合は、./configureのオプションを削ればOK
# mkdir /usr/local/src/radius
# cd /usr/local/src/radius
# wget "ftp://ftp.freeradius.org/pub/freeradius/freeradius-server-2.2.5.tar.gz"
# tar zxvf freeradius-server-2.2.5.tar.gz
# cd freeradius-server-2.2.5
# ./configure --prefix=/usr/local/radius-2.2.5 \
--with-openssl-lib-dir=/usr/local/openssl/lib \
--with-openssl-include-dir=/usr/local/openssl/include
# make && make install
後は事後処理として、FreeRADIUSへPATHを通したり、ldconfigを打ったりする。
~
&size(16){&font(b){3. インストール後処理};};
ログディレクトリを作成したり、FreeRADIUS用にユーザ・グループの作成。
"/etc/radius/raddb/*"内のファイルには生パスワードを書き込む為、パーミッションとグループは特に注意する。
# mkdir /var/run/radiusd
# mkdir -p /var/log/radius/radacct
# groupadd radiusd
# useradd -g radiusd -d /var/log/radius -s /sbin/nologin radiusd
# cd /usr/local
# ln -s /usr/local/radius-2.2.5 ./radius
# ln -s /uar/local/radius /etc/radius
# chown -R radiusd.radiusd /var/log/radius
# chmod -R 755 /var/log/radius
# chgrp -R radius /etc/radius/raddb/*
# chmod -R o-rwx /etc/radius/raddb/*
~
&size(16){&font(b){4. コンフィグ};};
大規模システムならradiusのデータをMySQLへ流すのだろうが、
今回は小規模な仕組みかつ平常時のメンテナンス性を重視する為、プレーンテキストで情報を保存する。
下記メモでは変更した部分のみ記載。他はメモ注釈を参照。
~
&font(b){# vi radiusd.conf};
prefix = /usr/local/radius #インストールディレクトリ
localstatedir = /var #PIDやログ保存ディレクトリの親
user = radiusd #FreeRADIUSの実行ユーザ
group = radiusd #FreeRADIUSの実行グループ
*FreeRADIUSのMySQL管理化 [#y4180e1e]
daloRADIUSを利用するには、[[FreeRADIUS>Linux/Source/Radius]]環境が動いている事が前提となる。
通常のFreeRADIUSはテキストベースで認証データを管理している。
その為、daloRADIUSで読み込める様に、テキスト管理からDB管理にする必要がある。
&font(b){※一度FreeRADIUSを構築した状態からMySQLへ組み替える際に、バックアップはとる事};
$ mysql -u root -p
mysql> create database radius;
mysql> grant all on radius.* to radius identified by 'FreeRadiusPass';
mysql> flush privileges;
mysql> quit;
###Radius認証用の待ち受け設定
listen {
type = auth #認証設定
ipaddr = * #認証の許可IPアドレス
port = 1812 #認証待ち受けポート
}
$ mysql -u radius -p radius < /etc/radius/raddb/sql/mysql/nas.sql
Enter Password: *****
$ mysql -u radius -p radius < /etc/radius/raddb/sql/mysql/schema.sql
Enter Password: *****
###アカウンティングの待ち受け設定
listen {
type = acct #アカウンティング設定
ipaddr = * #アカウンティング許可IPアドレス
port = 1813 #アカウンティング待ち受けポート
}
###ログ設定
log {
auth = yes #認証時のログを保存する
auth_badpass = no #認証失敗時のパスワードを記録しない
auth_goodpass = no #認証成功時のパスワードを記録しない
}
###RadiusServerセキュリティ
security {
allow_valnerable_openssl = yes #OpenSSLのHeartBeatチェックを行わない
#上記オプションを入れないと、yumで入れた修正済みOpenSSL"1.0.1e+hoge"に対しても反応してしまう。
}
$ vi /etc/radius/raddb/sql/mysql/dialup.conf
=========
289 :: # Uncomment simul_count_query to enable simultaneous use checking
290 :: simul_count_query = "SELECT COUNT(*) \
291 :: FROM ${acct_table1} \
292 :: WHERE username = '%{SQL-User-Name}' \
293 :: AND acctstoptime IS NULL"
~
&font(b){# vi clients.conf};
###localhostのクライアント設定を全部コメントアウト
#client localhost {
# ipaddr = 127.0.0.1
# netmask = 32
# secret = PASSWORD
# require_message_authenticator = no
# nastype = other
#}
FreeRADIUSのMySQL-DBを作成したら、コンフィグの変更を行う。
以下に書いてある箇所以外は全部コメントにする。
$ vi /etc/radius/raddb/sql.conf
※実際に書き換えた箇所は"server"と"password"の二箇所のみ
=========
sql {
database = "mysql"
driver = "rlm_sql_${database}"
server = "RadiusServerAddress"
login = "radius"
password = "FreeRadiusPass"
radius_db = "radius"
###RadiusServerへの接続を許可するクライアント情報
client 192.168.1.0/24 { #認証を許可するネットワーク
secret = RadiusServerPassword #クライアント用RadiusServer認証パスワード
shortname = RadiusServerName #クライアント用RadiusServer識別名
}
~
&font(b){# vi eap.conf};
###EAP認証の設定
eap {
default_eap_type = ttls #デフォルトでEAP-TTLSを使用する
acct_table1 = "radacct"
acct_table2 = "radacct"
postauth_table = "radpostauth"
authcheck_table = "radcheck"
authreply_table = "radreply"
groupcheck_table = "radgroupcheck"
groupreply_table = "radgroupreply"
usergroup_table = "radusergroup"
###EAP-MD5を無効化する
#md5 {
#}
deletestalesessions = yes
sqltrace = no
sqltracefile = ${logdir}/sqltrace.sql
num_sql_socks = ${thread[pool].max_servers}
connect_failure_retry_delay = 60
lifetime = 0
max_queries = 0
nas_table = "nas"
###EAP-LEAPを無効化する
#leap {
#}
###EAP-TLS認証の設定
tls {
private_key_password = "KeyPASSWORD" #private.keyのパスワード
# cipher_list = "DEFAULT" #TLS認証局のサイトリストを参照しない
$INCLUDE sql/${database}/dialup.conf
}
###EAP-TTLS認証の設定
ttls {
default_eap_type = mschapv2 #EAPトンネリング方式にMS-CHAPv2を使用する
# copy_request_to_tunnel = no #EAPトンネル内への属性コピーを無効化
# use_tunneled_reply = no #EAPトンネル内ユーザ名による属性値返答を無効化
# virtual_server = no #トンネル内の認証要求はVirtualServerを経由させる
}
~
&font(b){# vi users};
###Radius認証用のユーザ名とパスワード
#"ユーザ名" Cleartext-Password := "ログインパスワード"
# Reply-Message = "Hello, %{User-Name}"
###『ユーザ名=hoge / パスワード=bar』だとこんな感じ
"hoge" Cleartext-Password := "bar"
Reply-Message = "Hello, %{User-Name}"
~
&font(b){# vi proxy.conf};
###下記RadiusProxyの設定以外は全てコメントアウトする
###RadiusProxyの設定
proxy server {
default_fallback = yes #Radiusフォールバック機能を使う
}
~
&font(b){# vi certs/ca.cnf};
###RadiusServerの証明書を作成するMakefileを変更
DH_KEY_SIZE = 2048 #Diffie-Hellmanの鍵長を"2048"bitに変更
~
&font(b){# vi certs/bootstrap};
###DHパラメータの鍵長を"2048"bitに変更
if [ ! -f dh ]; then
openssl dhparam -out dh 2048 || exit 1
if [ -e /dev/urandom ] ; then
dd if=/dev/urandom of=./random count=10 >/dev/null 2>&1;
else
date > ./random;
fi
fi
~
&font(b){# vi certs/ca.cnf};
###認証鍵のパスワードを変更
[ req ]
input_password = "" #"eap.conf"内の[private_key_password]と同じ値にする
output_password = "" #"eap.conf"内の[private_key_password]と同じ値にする
###作成するCA証明書のパラメータを設定(ここでは説明省略)
[certificate_authority]
countryName = ""
stateOrProvinceName = ""
localityName = ""
orgnaizationName = ""
emailAddress = ""
commonName = ""
~
&font(b){# vi certs/client.cnf};
###認証鍵パスワードを変更
[ req ]
input_password = "" #"eap.conf"内の[private_key_password]と同じ値にする
output_password = "" #"eap.conf"内の[private_key_password]と同じ値にする
###作成するCA証明書のパラメータを設定(ここでは説明省略)
[client]
countryName = ""
stateOrProvinceName = ""
localityName = ""
organizationName = ""
emailAddress = ""
commonName = ""
~
&font(b){# vi certs/server.cnf};
###認証鍵パスワードを変更
[ req ]
input_password = "" #"eap.conf"内の[private_key_password]と同じ値にする
output_password = "" #"eap.conf"内の[private_key_password]と同じ値にする
###作成するCA証明書のパラメータを設定(ここでは説明省略)
countryName = ""
stateOrProvinceName = ""
localityName = ""
organizationName = ""
emailAddress = ""
commonName = ""
~
&font(b){# vi sites-enabled/default};
###コンフィグが下記の状態になる様にコメントアウト&アンコメントする
###(-> 下記以外は全てコメントアウトする)
$ vi /etc/radius/raddb/radiusd.conf
※sql.confをINCLUDEする箇所のアンコメントと、instantiateステートのコメントアウト
=========
743 :: $INCLUDE sql.conf
779 :: instantiate {
785 :: #exec
802 :: #expr
808 :: #daily
809 :: #expiration
810 :: #logintime
825 :: }
$ vi /etc/radius/raddb/sites-enabled/default
※SQL認証をONにして、File認証をコメントアウト
=========
###EAPトンネル内で許可する認証方式
authorize {
preprocess
mschap
suffix
eap {
ok = return
}
files
expiration
logintime
}
069 :: authorize {
088 :: preprocess
107 :: mschap
136 :: suffix
156 :: eap {
157 :: ok = return
158 :: }
177 :: sql
198 :: expiration
199 :: logintime
223 :: }
###接続を許可する認証タイプ
authenticate {
Auth-Type MS-CHAP {
mschap
}
eap
}
###アカウンティングの接続ログ書式
accounting {
detail
exec
}
###認証が通った時の設定
post-auth {
Post-Auth-Type REJECT {
attr_filter.access_reject
}
}
378 :: accounting {
406 :: sql
432 :: exec
443 :: }
~
&size(16){&font(b){5. 起動準備};};
最初にinitスクリプトの編集
# cp /usr/local/src/radius/freeradius-server-2.2.5/redhat/freeradius-radiusd-init /etc/init.d/radiusd
# chown root.root /etc/init.d/radiusd
# chmod 755 /etc/init.d/radiusd
# chkconfig --add radiusd
# chkconfig radiusd on
# vi /etc/init.d/radiusd
exec=${exec:=/usr/local/radius/sbin/$prog}
config_dir=${config_dir:=/etc/radius/raddb}
config=${config:=$config_dir/radiusd.conf}
pidfile=${pidfile:=/var/run/$prog/$prog.pid}
lockfile=${lockfile:=/var/lock/subsys/radiusd}
*テストデータの挿入 [#nd40dc5a]
初期状態ではDBにユーザ情報が入っていないので、テストユーザを作成して登録しておく。
下記では、Passwordアトリビュートのみを設定している。
-RadiusTestUser : テストユーザ名
-RadiusTestPass : テストユーザパスワード
※テストが終わったら、SQLコマンドかdaloRADIUS経由でテストユーザを削除する事
$ mysql -u radius -p
Enter Password: *****
mysql> use radius;
mysql> INSERT INTO radcheck (UserName, Attribute, Value) VALUES ('RadiusTestUser', 'Password', 'RadiusTestPass');
Query OK, 1 row affected (0.06 sec)
mysql> quit;
~
次にlogrotateスクリプトの編集
# cp /usr/local/src/radius/freeradius-server-2.2.5/redhat/freeradius-logrotate /etc/logrotate.d/radiusd
# chown root.root /etc/logrotate.d/radiusd
# chmod 644 /etc/logrotate.d/radiusd
*起動 [#i4daa174]
&size(16){&font(b){1. 初回起動(テスト起動)};};
初回起動時はRadiusServerで使用する証明書やDHパラメータの作成処理が実行される。
その為、1回目の起動は失敗するのでテストモードで起動をしてから、initスクリプトで通常起動する。
また、初回起動前にいらないファイルの全消しもしておく
# cd /etc/radius/raddb/certs
# rm -f *.pem *.der *.csr *.crt *.key *.p12 serial* index.txt*
*daloRADIUSコンフィグ [#vc094905]
apacheの設定に合わせて、daloRADIUSディレクトリのオーナーとユーザを変更したり、
ディレクトリ先に対してapacheのAliasを書く必要がある。
また、daroRADIUSには"PEAR::DB"が必要なので、合わせてインストールも行う。
・SourceForge版
$ wget "http://downloads.sourceforge.net/project/daloradius/daloradius/daloradius0.9-9/daloradius-0.9-9.tar.gz" daloradius-0.9-9.tar.gz
$ tar zxvf daloradius-0.9.9.tar.gz
###1回目の起動(必ず失敗する)
# radiusd -X
・GitHub版
$ git clone https://github.com/lirantal/daloradius daloradius
$ rm -rf daloradius/.git*
$ rm -rf daloradius/.ht*
###2回目の起動(テストモードで実行)
# radiusd -X
# [Ctrl]+[C]
###initスクリプトでRadiusServerを起動
# /etc/init.d/radiusd start
$ pear install DB
$ cd /usr/local/src
$ mv daloradius-0.9-9 {$ApacheDocumentRoot}/daloradius
$ cd {$ApacheDocumentRoot}/daloradius
$ mysql -u radius -p radius < ./contrib/db/fr2-mysql-daloradius-and-freeradius.sql
Enter Password: *****
$ vi library/daloradius.conf.php
=========
26 :: $configValues['DALORADIUS_VERSION'] = '0.9-9';
27 :: $configValues['FREERADIUS_VERSION'] = '2';
28 :: $configValues['CONFIG_DB_ENGINE'] = 'mysql';
29 :: $configValues['CONFIG_DB_HOST'] = 'localhost';
30 :: $configValues['CONFIG_DB_PORT'] = '3306';
31 :: $configValues['CONFIG_DB_USER'] = 'radius';
32 :: $configValues['CONFIG_DB_PASS'] = 'FreeRadiusPass';
33 :: $configValues['CONFIG_DB_NAME'] = 'radius';
~
&size(16){&font(b){2. テスト認証};};
今回の設定で認証が通るのかテストする。テストにはradtestコマンドを使用する。
RadiusServerをテストモード[radiusd -X]で起動するか、
RadiusServerのログを[tail -f]した状態でradtestを実行するとログが見れる。
radtestコマンドの書式は以下の通り(詳細はman見る事)。
# radtest "ユーザ名" "ユーザパスワード" "RadiusServerのIPアドレス":"認証待ち受けポート番号" "NAS番号(0)" "RadiusServer自体のアクセスパスワード"
*アクセス方法 [#cf0855d7]
Webブラウザから「http://"サーバIPアドレス"/daloradius/」に移動すれば、
daloRADIUSのログイン画面になる。
daloRADIUSの初期管理ユーザは、[ユーザ:administrator | パスワード:radius]になっている。
管理ユーザのパスワードを変更するには、以下の順番に移動して管理ユーザを編集する。
[Config] -> [Operators] -> [List Operators] -> [administrator] -> [Operator Info]
~
RadiusServerのIPアドレスが[192.168.200.1]と仮定すると、以下の様になる
# radtest hoge bar 192.168.200.1:1812 0 RadiusServerPassword
~
RadiusServer側はログを見ればOK。radtest側は認証結果が標準出力へ流れてくる
###radtestに成功した場合は以下の様なreplyが来る
rad_recv: Access-Accept packet from host 192.168.200.1 port 1812, id=001, length=20
Reply-Message = "Hello, hoge"
###radtestに失敗した場合はこちら
rad_recv: Access-Reject packet from host 192.168.200.1 port 1812, id=002, length=19
*PHP7.0対応 [#g5074134]
-[[daloRADIUS PHP-7 Support:+https://github.com/lirantal/daloradius/issues/5]]
-[[Database error:+https://github.com/lirantal/daloradius/issues/14]]
SourceForgeで配布しているdaloRADIUSは、PHP7.0以上に対応していない。
PHP7.0環境で動かすには、MySQLモジュールの参照部分と、DBエンジン選択箇所のソースを書き換える。
# diff /daloradius/library/daloradius.conf.php /daloradius/library/daloradius.conf.php.org
---
28c28
< $configValues['CONFIG_DB_ENGINE'] = 'mysqli';
---
> $configValues['CONFIG_DB_ENGINE'] = 'mysql';
# diff /daloradius/library/opendb.php /daloradius/library/opendb.php.org
97d96
< $dbSocket->query("SET SESSION sql_mode = '';");