17
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

FreeRADIUS

Posted at

#何がやりたいか

Vagrant上のCentOSFreeRADISをインストールして、ルータのログイン認証にRADIUSを利用してみたいだけです。

#セットアップ

##CentOSの準備

まず最初に、vagrantがインストールされているディレクトリに移動してから、下記のコマンドを実行します。

log
mkdir centos
cd centos
vagrant init centos/7
vi Vagrantfile

下記のコメントを外して保存します。

Vagrantfile_編集前
  # Create a public network, which generally matched to bridged network.
  # Bridged networks make the machine appear as another physical device on
  # your network.
  # config.vm.network "public_network"
Vagrantfile_編集後
  # Create a public network, which generally matched to bridged network.
  # Bridged networks make the machine appear as another physical device on
  # your network.
  config.vm.network "public_network"

下記のコマンドを実行して、CentOSを起動します。

log
vagrant up

OSの起動中に下記の様にネットワークインタフェースを聞かれたら、使っている環境に合わせて番号を指定します。
※ このテスト環境では、8) vmnet8を選択しています。

sample
==> default: Available bridged network interfaces:
1) en0: Wi-Fi (AirPort)
2) en1: Thunderbolt 1
3) en2: Thunderbolt 2
4) bridge0
5) p2p0
6) awdl0
7) vmnet1
8) vmnet8
==> default: When choosing an interface, it is usually the one that is
==> default: being used to connect to the internet.
    default: Which interface should the network bridge to? 

下記のコマンドを実行して、CentOSにログインします。

log
vagrant ssh

CentOSを終了する場合は、下記のコマンドを実行します。

log
vagrant halt

##FreeRADIUSのインストール

下記のコマンドを実行して、FreeRADIUSをインストールします。

log
sudo yum -y update
sudo yum -y install freeradius freeradius-utils freerad

#FreeRADIUSの動作確認

##Versionの確認

version
[vagrant@localhost ~]$ radiusd -v
radiusd: FreeRADIUS Version 3.0.13, for host x86_64-redhat-linux-gnu, built on Aug 23 2017 at 15:18:22
FreeRADIUS Version 3.0.13
Copyright (C) 1999-2017 The FreeRADIUS server project and contributors
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE
You may redistribute copies of FreeRADIUS under the terms of the
GNU General Public License
For more information about these matters, see the file named COPYRIGHT

##設定ファイルの確認

まず最初に、各設定ファイルの初期状態を確認します。
※ コメント行は省いています

###radiusd.conf

radiusd.conf
[vagrant@localhost ~]$ sudo cat /etc/raddb/radiusd.conf | grep -v -e '^\s*#' -e '^\s*$'
prefix = /usr
exec_prefix = /usr
sysconfdir = /etc
localstatedir = /var
sbindir = /usr/sbin
logdir = ${localstatedir}/log/radius
raddbdir = ${sysconfdir}/raddb
radacctdir = ${logdir}/radacct
name = radiusd
confdir = ${raddbdir}
modconfdir = ${confdir}/mods-config
certdir = ${confdir}/certs
cadir   = ${confdir}/certs
run_dir = ${localstatedir}/run/${name}
db_dir = ${localstatedir}/lib/radiusd
libdir = /usr/lib64/freeradius
pidfile = ${run_dir}/${name}.pid
correct_escapes = true
max_request_time = 30
cleanup_delay = 5
max_requests = 16384
hostname_lookups = no
log {
	destination = files
	colourise = yes
	file = ${logdir}/radius.log
	syslog_facility = daemon
	stripped_names = no
	auth = no
	auth_badpass = no
	auth_goodpass = no
	msg_denied = "You are already logged in - access denied"
}
checkrad = ${sbindir}/checkrad
security {
	user = radiusd
	group = radiusd
	allow_core_dumps = no
	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
	auto_limit_acct = no
}
modules {
	$INCLUDE mods-enabled/
}
instantiate {
}
policy {
	$INCLUDE policy.d/
}
$INCLUDE sites-enabled/

###clients.conf

clients.conf
[vagrant@localhost ~]$ sudo cat /etc/raddb/clients.conf | grep -v -e '^\s*#' -e '^\s*$'
client localhost {
	ipaddr = 127.0.0.1
	proto = *
	secret = testing123
	require_message_authenticator = no
	nas_type	 = other	# localhost isn't usually a NAS...
	limit {
		max_connections = 16
		lifetime = 0
		idle_timeout = 30
	}
}
client localhost_ipv6 {
	ipv6addr	= ::1
	secret		= testing123
}

###users

users
[vagrant@localhost ~]$ sudo cat /etc/raddb/users | grep -v -e '^\s*#' -e '^\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

##radtestコマンド

radtestコマンドを使って、FreeRADIUSで認証ができることを確認します。

###ユーザーの追加

先ほど確認したuserファイルを編集して、認証したいユーザーを追加します。
ここでは、/etc/raddb/usersファイルの内容を全て削除して、下記の内容に置き換えます。

viエディタで:%dを入力すると、全行を削除します。

log
sudo vi /etc/raddb/users
:%d
users
user01 Cleartext-Password := "pass"
hoge01 Cleartext-Password := "hogehoge"

###raduisdの起動

下記のコマンドでradiusdを起動します。
※ パスワードを聞かれますので、vagrantと入力します。

log
[vagrant@localhost ~]$ systemctl start radiusd
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to manage system services or units.
Authenticating as: root
Password: 
==== AUTHENTICATION COMPLETE ===
[vagrant@localhost ~]$ 

###radtestで確認

ここでのlocalhostは、clients.confファイルのipaddr = 127.0.0.1部部に紐付くようです。送信元のアドレスになります。

ここでのtesting123は、clients.confファイルのsecret = testing123部部に紐付くようです。

log
[vagrant@localhost ~]$ radtest user01 pass localhost 0 testing123
Sent Access-Request Id 109 from 0.0.0.0:36267 to 127.0.0.1:1812 length 76
	User-Name = "user01"
	User-Password = "pass"
	NAS-IP-Address = 127.0.0.1
	NAS-Port = 0
	Message-Authenticator = 0x00
	Cleartext-Password = "pass"
Received Access-Accept Id 109 from 127.0.0.1:1812 to 0.0.0.0:0 length 20
[vagrant@localhost ~]$ 
[vagrant@localhost ~]$ radtest hoge01 hogehoge localhost 0 testing123
Sent Access-Request Id 136 from 0.0.0.0:46104 to 127.0.0.1:1812 length 76
	User-Name = "hoge01"
	User-Password = "hogehoge"
	NAS-IP-Address = 127.0.0.1
	NAS-Port = 0
	Message-Authenticator = 0x00
	Cleartext-Password = "hogehoge"
Received Access-Accept Id 136 from 127.0.0.1:1812 to 0.0.0.0:0 length 20
[vagrant@localhost ~]$ 

###新しいユーザーを追加

新しいユーザーとしてhoge02を追加します。

log
sudo vi /etc/raddb/users
users
user01 Cleartext-Password := "pass"
hoge01 Cleartext-Password := "hogehoge"
hoge02 Cleartext-Password := "hogehoge"

###もう一度、radtestで確認

ここでは、Access-Rejectが返ってきますので、認証が失敗しているようです。

log
[vagrant@localhost ~]$ radtest hoge02 hogehoge localhost 0 testing123
Sent Access-Request Id 49 from 0.0.0.0:43054 to 127.0.0.1:1812 length 76
	User-Name = "hoge02"
	User-Password = "hogehoge"
	NAS-IP-Address = 127.0.0.1
	NAS-Port = 0
	Message-Authenticator = 0x00
	Cleartext-Password = "hogehoge"
Received Access-Reject Id 49 from 127.0.0.1:1812 to 0.0.0.0:0 length 20
(0) -: Expected Access-Accept got Access-Reject
[vagrant@localhost ~]$ 

###raduisdを再起動

下記のコマンドでradiusdを再起動します。
※ パスワードを聞かれますので、vagrantと入力します。

log
[vagrant@localhost ~]$ systemctl restart radiusd
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to manage system services or units.
Authenticating as: root
Password: 
==== AUTHENTICATION COMPLETE ===
[vagrant@localhost ~]$ 

restartではなく、stopしてstartでも良い

log
systemctl stop radiusd

###もう一度、radtestで確認

この結果からは、ユーザーを追加した際には、radiusdの再起動が必要となることが確認できました。

log
[vagrant@localhost ~]$ radtest hoge02 hogehoge localhost 0 testing123
Sent Access-Request Id 101 from 0.0.0.0:34803 to 127.0.0.1:1812 length 76
	User-Name = "hoge02"
	User-Password = "hogehoge"
	NAS-IP-Address = 127.0.0.1
	NAS-Port = 0
	Message-Authenticator = 0x00
	Cleartext-Password = "hogehoge"
Received Access-Accept Id 101 from 127.0.0.1:1812 to 0.0.0.0:0 length 20
[vagrant@localhost ~]$ 

#ルータとの認証

##Topology

###RADIUSサーバのアドレス確認

CentOSは、下記のコマンドでインタフェースに割り当てられたアドレスを確認します。

log
ip address

ここでは、RADISサーバのアドレスが、172.16.62.152/24であるとします。
また、ルータのアドレスは、172.16.62.154になります。

###clients.confにクライアントを追加

ルータが接続されているネットワークアドレスをclients.confに追加します。

log
sudo vi /etc/raddb/clients.conf
clients.conf
client localnet {
	ipaddr = 172.16.62.0/24
	proto = *
	secret = testing123
	require_message_authenticator = no
	nas_type	 = other	# localhost isn't usually a NAS...
	limit {
		max_connections = 16
		lifetime = 0
		idle_timeout = 30
	}
}

下記のコマンドでradiusdを再起動します。
※ パスワードを聞かれますので、vagrantと入力します。

log
[vagrant@localhost ~]$ systemctl restart radiusd
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to manage system services or units.
Authenticating as: root
Password: 
==== AUTHENTICATION COMPLETE ===
[vagrant@localhost ~]$ 

###ルータの設定

aaa new-modelを設定しますので、ログインできなくて困ってしまうのを防ぐために、cisco/ciscoでログインできるように設定しておきます。

config
radius server rad-srv
 address ipv4 172.16.62.152 auth-port 1812 acct-port 1813
 key testing123

username cisco password 0 cisco
aaa new-model
aaa authentication login default local group radius group rad-srv

###test aaaコマンド

実際にログインしなくても、下記のコマンドRADIUSの動作が確認できますので、debug radius authenticationを有効にした状態でログを確認します。

log
R1#test aaa group radius hoge01 hogehoge port 1812 new-code
User successfully authenticated

USER ATTRIBUTES

R1#
*May  2 02:24:13.646: RADIUS/ENCODE(00000000):Orig. component type = Invalid
*May  2 02:24:13.647: RADIUS/ENCODE(00000000): dropping service type, "radius-server attribute 6 on-for-login-auth" is off
*May  2 02:24:13.647: RADIUS(00000000): Config NAS IP: 0.0.0.0
*May  2 02:24:13.647: RADIUS(00000000): Config NAS IPv6: ::
*May  2 02:24:13.647: RADIUS(00000000): sending
*May  2 02:24:13.647: RADIUS/DECODE(00000000): There is no General DB. Want server details may not be specified
*May  2 02:24:13.647: RADIUS/ENCODE: Best Local IP-Address 172.16.62.154 for Radius-Server 172.16.62.152
*May  2 02:24:13.647: RADIUS(00000000): Send Access-Request to 172.16.62.152:1812 id 1645/55, len 52
RADIUS:  authenticator 96 74 A4 D3 61 C7 4A D9 - B3 78 60 D8 AE 37 3C 17
*May  2 02:24:13.648: RADIUS:  User-Password       [2]   18  *
*May  2 02:24:13.648: RADIUS:  User-Name           [1]   8   "hoge01"
*May  2 02:24:13.648: RADIUS:  NAS-IP-Address      [4]   6   172.16.62.154             
*May  2 02:24:13.648: RADIUS(00000000): Sending a IPv4 Radius Packet
*May  2 02:24:13.648: RADIUS(00000000): Started 5 sec timeout
*May  2 02:24:13.649: RADIUS: Received from id 1645/55 172.16.62.152:1812, Access-Accept, len 20
RADIUS:  authenticator 2A 61 AB B8 77 7B 62 5A - 7A 92 A6 57 1E 5A 77 F2
*May  2 02:24:13.649: RADIUS/DECODE(00000000): There is no General DB. Reply server details may not be recorded
*May  2 02:24:13.649: RADIUS(00000000): Received from id 1645/55
R1#

パスワードがpassword01と正しくない値を指定した場合

log
R1#undebug all
All possible debugging has been turned off
R1#
R1#test aaa group radius hoge01 password01 port 1812 new-code
User rejected

R1#
R1#debug radius authentication                               
R1#
R1#test aaa group radius hoge01 password01 port 1812 new-code

*May  2 02:26:41.469: RADIUS/ENCODE(00000000):Orig. component type = Invalid
*May  2 02:26:41.469: RADIUS/ENCODE(00000000): dropping service type, "radius-server attribute 6 on-for-login-auth" is off
*May  2 02:26:41.469: RADIUS(00000000): Config NAS IP: 0.0.0.0
*May  2 02:26:41.469: RADIUS(00000000): Config NAS IPv6: ::
*May  2 02:26:41.469: RADIUS(00000000): sending
*May  2 02:26:41.469: RADIUS/DECODE(00000000): There is no General DB. Want server details may not be specified
*May  2 02:26:41.469: RADIUS/ENCODE: Best Local IP-Address 172.16.62.154 for Radius-Server 172.16.62.152User rejected

R1#
*May  2 02:26:41.469: RADIUS(00000000): Send Access-Request to 172.16.62.152:1812 id 1645/60, len 52
RADIUS:  authenticator 51 68 D8 AE 54 0B 09 02 - 66 A8 A1 54 F8 16 05 48
*May  2 02:26:41.469: RADIUS:  User-Password       [2]   18  *
*May  2 02:26:41.469: RADIUS:  User-Name           [1]   8   "hoge01"
*May  2 02:26:41.470: RADIUS:  NAS-IP-Address      [4]   6   172.16.62.154             
*May  2 02:26:41.470: RADIUS(00000000): Sending a IPv4 Radius Packet
*May  2 02:26:41.470: RADIUS(00000000): Started 5 sec timeout
*May  2 02:26:42.472: RADIUS: Received from id 1645/60 172.16.62.152:1812, Access-Reject, len 20
RADIUS:  authenticator 16 DB F2 E6 C3 CF 23 11 - B1 0F AC AC 12 0B 47 B4
*May  2 02:26:42.472: RADIUS/DECODE(00000000): There is no General DB. Reply server details may not be recorded
*May  2 02:26:42.472: RADIUS(00000000): Received from id 1645/60
R1#

###Wireshark

ws.jpeg

上の画像ファイルをws.jpgというファイル名で保存して、下記の通り、unzipコマンドで解凍するとWiresharkのファイルが展開されます。

unzip_command
$ unzip ws.jpeg 
Archive:  ws.jpeg
warning [ws.jpeg]:  8450 extra bytes at beginning or within zipfile
  (attempting to process anyway)
  inflating: freeradius.pcapng
17
20
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?