検証業務を行っている際、Radius 認証をテストしたい場合があります。Radius サーバの実装には以下のような選択肢があるかと思います。
- Windows の NPS
- Linux / UNIX の FreeRADIUS
今回は FreeRADIUS を使って Radius サーバと Proxy を構築します。
環境 & 構成
以下を用いました。
- Radius クライアント
- Radius Proxy
- Ubuntu 14.04.2 LTS
- FreeRADIUS 2.1.12+dfsg-1.2ubuntu8
- Radius サーバ
- Ubuntu 14.04.2 LTS
- FreeRADIUS 2.1.12+dfsg-1.2ubuntu8
構成は以下の通りです。Radius サーバと Proxy を同じネットワークに配置しています。実用的では無いかも知れませんが、今回はあくまで検証ですので、この構成としました。
修正対象の設定ファイル
Radius Proxy では以下のファイルを修正していきます。
- /etc/freeradius/clients.conf
- /etc/freeradius/proxy.conf
Radius Proxy では以下のファイルを修正していきます。
- /etc/freeradius/clients.conf
- /etc/freeradius/radiusd.conf
- /etc/freeradius/users
FreeRADIUS のインストール
Radius Proxy とサーバの両方で FreeRADIUS をインストールします。apt-get install でインストールします。
sudo apt-get -y install freeradius freeradius-mysql freeradius-utils mysql-client mysql-server
インストール中、MySQL の root 用パスワードが聞かれますので、入力した値を控えておきます。Ubuntu の場合、設定ファイルは /etc/freeradius 以下に保存されました。
Radius Proxy の設定
clients.conf の修正
clients.conf ファイルにはアクセスを許可するホストやネットワークを記載します。デフォルトで以下のようになっていました。「grep -v "^\s*$" | grep -v "^\s*#"」にパイプすることで空行やコメント行を除外しています。
# cat /etc/freeradius/clients.conf | grep -v "^\s*$" | grep -v "^\s*#" client localhost { ipaddr = 127.0.0.1 secret = testing123 require_message_authenticator = no nastype = other # localhost isn't usually a NAS... }
このファイルに以下を追記します。
client 10.0.0.0/24 { secret = PROXY shortname = MY-NETWORK }
これは以下のような意味合いになります。
proxy.conf の修正
proxy.conf は Radiux Proxy 動作に関連する設定を行います。デフォルトで以下のようになっていました。
# cat /etc/freeradius/proxy.conf | grep -v "^\s*$" | grep -v "^\s*#" proxy server { default_fallback = no } home_server localhost { type = auth ipaddr = 127.0.0.1 port = 1812 secret = testing123 require_message_authenticator = yes response_window = 20 zombie_period = 40 revive_interval = 120 status_check = status-server check_interval = 30 num_answers_to_alive = 3 max_outstanding = 65536 coa { irt = 2 mrt = 16 mrc = 5 mrd = 30 } } home_server_pool my_auth_failover { type = fail-over home_server = localhost } realm example.com { auth_pool = my_auth_failover } realm LOCAL { }
このファイルへ以下のように「DEFAULT」という realm を追記します。
realm DEFAULT { type = radius authhost = 10.0.0.202:1812 accthost = 10.0.0.202:1813 secret = SECRET nostrip }
これは以下のような意味合いになります。
FreeRADIUS の再起動
ここまで設定が完了したら FreeRADIUS を再起動しておきます。
sudo service freeradius restart
Radius サーバの設定
clients.conf の修正
Radius Proxy の設定と同じです。/etc/freeradius/clients.conf に以下を追記します。
client 10.0.0.201 { secret = SECRET shortname = MY-NETWORK }
Radius サーバでは Proxy からのアクセスのみを受け付けるよう、Proxy のホストアドレスを記載しました。
radiusd.conf の修正
radiusd.conf は Radius デーモン全体に関連する設定を行います。デフォルトで以下のようになっていました。
# cat /etc/freeradius/radiusd.conf | grep -v "^\s*$" | grep -v "^\s*#" prefix = /usr exec_prefix = /usr sysconfdir = /etc localstatedir = /var sbindir = ${exec_prefix}/sbin logdir = /var/log/freeradius raddbdir = /etc/freeradius radacctdir = ${logdir}/radacct name = freeradius confdir = ${raddbdir} run_dir = ${localstatedir}/run/${name} db_dir = ${raddbdir} libdir = /usr/lib/freeradius pidfile = ${run_dir}/${name}.pid user = freerad group = freerad max_request_time = 30 cleanup_delay = 5 max_requests = 1024 listen { type = auth ipaddr = * port = 0 } listen { ipaddr = * port = 0 type = acct } hostname_lookups = no allow_core_dumps = no regular_expressions = yes extended_expressions = yes log { destination = files file = ${logdir}/radius.log syslog_facility = daemon stripped_names = no auth = no auth_badpass = no auth_goodpass = no } checkrad = ${sbindir}/checkrad security { max_attributes = 200 reject_delay = 1 status_server = yes } proxy_requests = yes $INCLUDE proxy.conf $INCLUDE clients.conf thread pool { start_servers = 5 max_servers = 32 min_spare_servers = 3 max_spare_servers = 10 max_requests_per_server = 0 } modules { $INCLUDE ${confdir}/modules/ $INCLUDE eap.conf } instantiate { exec expr expiration logintime } $INCLUDE policy.conf $INCLUDE sites-enabled/
認証時の結果をログに出力する為、log セクションの auth = no 部分を以下のように auth = yes へ修正します。
log { destination = files file = ${logdir}/radius.log syslog_facility = daemon stripped_names = no auth = yes auth_badpass = no auth_goodpass = no }
users の修正
users は Radius で認証するユーザ名とパスワードの組み合わせを記載します。デフォルトで以下のようになっていました。
# cat /etc/freeradius/users | grep -v "^\s*$" | grep -v "^\s*#" DEFAULT Framed-Protocol == PPP Framed-Protocol = PPP, Framed-Compression = Van-Jacobson-TCP-IP DEFAULT Hint == "CSLIP" Framed-Protocol = SLIP, Framed-Compression = Van-Jacobson-TCP-IP DEFAULT Hint == "SLIP" Framed-Protocol = SLIP
ユーザ名「USER」、パスワード「PASSWORD」を平文で設定するには、最下行に以下を追記します。
USER Cleartext-Password := "PASSWORD"
セキュリティ上の問題から平文を避け、MD5 値でパスワードを記載することも可能です。まず、パスワードを openssl コマンドで MD5 化します。
# echo -n PASSWORD | openssl md5 (stdin)= 319f4d26e3c536b5dd871bb2c52e3178
users.conf ファイルへ以下のように追記します。
USER MD5-Password := "319f4d26e3c536b5dd871bb2c52e3178"
FreeRADIUS の再起動
ここまで設定が完了したら FreeRADIUS を再起動しておきます。
sudo service freeradius restart
Radius クライアントの設定
Cisco ルータから Radius のテストを実施する場合、大前提として Radius サーバと IP レベルで疎通性が取れるよう、インターフェイスアドレスやルーティング設定を事前に行っておきます。この他、Radius 認証のテストを実施する為に最低限、以下の設定しておきます。この設定だけでは TELNET や SSH でのログイン時に Radius への認証は「行われない」のですが、専用コマンドを用いることでテストだけは実施することが可能です。
aaa new-model ! radius server RADIUS-PROXY address ipv4 10.0.0.201 auth-port 1812 acct-port 1813 key PROXY ! end
設定後は show radius server-group all コマンドで Radius サーバが定義されていることを確認出来ます。
Router# show radius server-group all Server group radius Sharecount = 1 sg_unconfigured = FALSE Type = standard Memlocks = 1 Server(10.0.0.201:1812,1813) Transactions: Authen: 0 Author: 0 Acct: 0 Server_auto_test_enabled: FALSE Keywrap enabled: FALSE
より実戦的なシナリオとして、実際の TELNET や SSH でのログイン時に Radius 認証させるには以下のように aaa authentication login default group radius コマンドを追加で設定します。
aaa new-model ! aaa authentication login default group radius ! radius server RADIUS-PROXY address ipv4 10.0.0.201 auth-port 1812 acct-port 1813 key PROXY ! end
Radius 認証のテスト
Cisco IOS からの Radius 認証テスト
Cisco IOS からのテストは以下のように test aaa コマンドで実行出来ます。
test aaa group radius USER PASSWORD port 1812 new-code
認証に成功した場合は以下のように表示されます("User successfully authenticated" 表示になりました)。
# test aaa group radius USER PASSWORD port 1812 new-code User successfully authenticated USER ATTRIBUTES
パスワードを間違えた場合は場合は以下のように表示されます("User rejected" されました)。
# test aaa group radius USER BAD-PASSWORD port 1812 new-code User rejected
Linux からの Radius 認証テスト
Linux からのテストは以下のように radtest コマンドで実行出来ます。
radtest USER PASSWORD 10.0.0.201 1812 PROXY
認証に成功した場合は以下のように表示されます。今回は Radius Proxy 上から認証テストを実行しました("Access-Accept" 表示になりました)。
# radtest USER PASSWORD 10.0.0.201 1812 PROXY Sending Access-Request of id 167 to 10.0.0.201 port 1812 User-Name = "USER" User-Password = "PASSWORD" NAS-IP-Address = 127.0.0.1 NAS-Port = 1812 Message-Authenticator = 0x00000000000000000000000000000000 rad_recv: Access-Accept packet from host 10.0.0.201 port 1812, id=167, length=20
パスワードを間違えた場合は場合は以下のように表示されます("Access-Reject" されました)。
# radtest USER BADPASSWORD 10.0.0.201 1812 TEST Sending Access-Request of id 243 to 10.0.0.201 port 1812 User-Name = "USER" User-Password = "BADPASSWORD" NAS-IP-Address = 127.0.0.1 NAS-Port = 1812 Message-Authenticator = 0x00000000000000000000000000000000 rad_recv: Access-Reject packet from host 10.0.0.201 port 1812, id=243, length=20