LDAPとFreeRadiusの連携
とある製品はRadius認証はできるんだけどLDAPのインタフェイスがない。そこでFreeRadiusを入れてLDAPのフロントエンドとして動作させることにしました。
手動での試験まではうまく通ったのでメモ。LDAPでposixAccountでエントリがあり、正常に動作していることが前提です。
FreeRadiusをインストール
ここからソースをダウンロードできます。最新版は1.1.7。インストールは、展開してconfigure,makeでOK。
$ tar -zxvf freeradius-1.1.7.tar.gz $ cd freeradius-1.1.7/ $ ./configure $ make # make install
/etc/passwdで認証させる
まずはファイル認証が通るかどうかをチェックLDAPと連携が取れているかどうかを試す前にradiusdが正常に動作しているかどうかを確認するために、ローカルのファイルで認証が通るかどうかを試験します。
デフォルトでインストールすると、FreeRadiusの設定ファイルは/usr/local/etc/raddb/radiusd.conにあります。これを適当に編集して/etc/passwdとか/etc/shadowなんかを見るようにします。こんな感じ。
prefix = /usr/local exec_prefix = ${prefix} sysconfdir = ${prefix}/etc localstatedir = ${prefix}/var sbindir = ${exec_prefix}/sbin logdir = ${localstatedir}/log/radius raddbdir = ${sysconfdir}/raddb radacctdir = ${logdir}/radacct confdir = ${raddbdir} run_dir = ${localstatedir}/run/radiusd log_file = ${logdir}/radius.log libdir = ${exec_prefix}/lib pidfile = ${run_dir}/radiusd.pid #接続クライアントの設定 $INCLUDE ${confdir}/clients.conf modules { unix { cache = no cache_reload = 600 passwd = /etc/passwd shadow = /etc/shadow group = /etc/group radwtmp = ${logdir}/radwtmp } files { usersfile = ${confdir}/users acctusersfile =${confdir}/acct_users compact = no } authorize { files } authenticate{ unix }
radiusd.confと同じディレクトリにusersっていうファイルがあって、このファイル中のデフォルト認証になにを使うかの設定がありますので、これを確認。
DEFAULT Auth-Type = System Fall-Through = 1
これだけ編集したらradiusdをデバッグモードで起動。
# radiusd -X -A (なんかいっぱい) Module: Instantiated files (files) Listening on authentication *:1812 Listening on accounting *:1813 Ready to process requests.
別のターミナルからradtestを使って認証が通るかどうかを試験します。
hogehogeがユーザ名、hogepassがパスワード、最後のtesting123ってのは、clients.confファイルに書いてある"secret"の値です。デフォルトインストールだとこの値になっているはず。
$ radtest hogehoge hogepass localhost 0 testing123 Sending Access-Request of id 136 to 127.0.0.1 port 1812 User-Name = "hogehoge" User-Password = "hogepass" NAS-IP-Address = 255.255.255.255 NAS-Port = 0 Framed-Protocol = PPP rad_recv: Access-Accept packet from host 127.0.0.1:1812, id=140, length=20
Access-Acceptで認証OKってことですね。
LDAPと連携させる
まずradiusd.confにのmodules{}内に以下の行を追加。
ldap { server = "localhost" port = "389" basedn = "dc=hoge,dc=com" filter ="(&(objectclass=posixAccount)(uid=%{Stripped-User-Name:-%{User-Name}}))" start_tls = yes }
もう一箇所 authenticate{}のところをこんな風に変更。
authenticate{ authtype LDAP { ldap } unix }
さらにusersファイルのデフォルト認証のところをLDAPに変更します。
DEFAULT Auth-Type := LDAP Fall-Through = 1
これでradiusdを再起動。
今度はLDAPにしかエントリがないユーザでradtestを試してみます。
$ radtest hogeldap hogepass localhost 0 testing123 Sending Access-Request of id 136 to 127.0.0.1 port 1812 User-Name = "hogeldap" User-Password = "hogepass" NAS-IP-Address = 255.255.255.255 NAS-Port = 0 Framed-Protocol = PPP rad_recv: Access-Accept packet from host 127.0.0.1:1812, id=140, length=20
やぁ、うまくいきました。radiusdの方のデバッグメッセージにはLDAPと連携してくれるrlm_ldapモジュールからの出力が沢山でています。
modcall: leaving group authorize (returns ok) for request 0 rad_check_password: Found Auth-Type LDAP auth: type "LDAP" Processing the authenticate section of radiusd.conf modcall: entering group LDAP for request 0 rlm_ldap: - authenticate rlm_ldap: login attempt by "hogeldap" with password "hogepass" radius_xlat: '(&(objectclass=posixAccount)(uid=hogeldap))' radius_xlat: 'dc=hoge,dc=com' rlm_ldap: ldap_get_conn: Checking Id: 0 rlm_ldap: ldap_get_conn: Got Id: 0 rlm_ldap: attempting LDAP reconnection rlm_ldap: (re)connect to localhost:389, authentication 0 rlm_ldap: starting TLS rlm_ldap: bind as / to localhost:389 rlm_ldap: waiting for bind result ... rlm_ldap: Bind was successful rlm_ldap: performing search in dc=hoge,dc=com, with filter (&(objectclass=posixAccount)(uid=hogeldap)) rlm_ldap: ldap_release_conn: Release Id: 0 rlm_ldap: user DN: uid=hogeldap,ou=personal,dc=hoge,dc=com rlm_ldap: (re)connect to localhost:389, authentication 1 rlm_ldap: starting TLS rlm_ldap: bind as uid=hogeldap,ou=personal,dc=goge,dc=com/password to localhost:389 rlm_ldap: waiting for bind result ... rlm_ldap: Bind was successful rlm_ldap: user hogeldap authenticated succesfully modcall[authenticate]: module "ldap" returns ok for request 0 modcall: leaving group LDAP (returns ok) for request 0 Sending Access-Accept of id 80 to 127.0.0.1 port 36925
でも「とある製品」からの認証はまだできていないのだ。鋭意調査中です。