最近は殆どの製品が ActiveDirectory / LDAP に対応していますが、古いバージョンの Cisco Catalyst は「対話側ログイン時には LDAP を利用出来ない (Radius は利用出来る)」といった具合に、「一部の機能では ActiveDirectory / LDAP が利用出来ない」というケースが存在します。 かと言って ActiveDirectory / Radius を別々に構築してしまうとデータを二重管理することになり、面倒です。 こういった場合は以下のような構成を取ることも可能です。
- Samba を ActiveDirectory のドメインコントローラーとして動作させ、LDAP の処理をさせる
- FreeRADIUS を動作させ、Radius 要求が受信した場合は Samba へ問い合わせし、結果をクライアントへ応答する
- ユーザは全て Samba 上で管理する
今回はこういった構成を取る場合の FreeRADIUS 構築例をメモしておきます。
環境
今回は最終的に以下の環境を構築しました。 サーバのインスタンス数を節約する為、Samba と FreeRADIUS は同じサーバ上に同居させています。
- AmazonLinux2
- Samba 4.10.5
- FreeRADIUS 3.0.13
FreeRADIUS をインストールする
現時点で AmazonLinux の標準リポジトリからインストール出来る FreeRADIUS のバージョンは 3.0.13 でした。
# yum info freeradius Loaded plugins: extras_suggestions, langpacks, priorities, update-motd 190 packages excluded due to repository priority protections Available Packages Name : freeradius Arch : x86_64 Version : 3.0.13 Release : 10.amzn2 Size : 1.1 M Repo : amzn2-core/2/x86_64 Summary : High-performance and highly configurable free RADIUS server URL : http://www.freeradius.org/ License : GPLv2+ and LGPLv2+ Description : The FreeRADIUS Server Project is a high performance and highly configurable : GPL'd free RADIUS server. The server is similar in some respects to : Livingston's 2.0 server. While FreeRADIUS started as a variant of the : Cistron RADIUS server, they don't share a lot in common any more. It now has : many more features than Cistron or Livingston, and is much more configurable. : : FreeRADIUS is an Internet authentication daemon, which implements the RADIUS : protocol, as defined in RFC 2865 (and others). It allows Network Access : Servers (NAS boxes) to perform authentication for dial-up users. There are : also RADIUS clients available for Web servers, firewalls, Unix logins, and : more. Using RADIUS allows authentication and authorization for a network to : be centralized, and minimizes the amount of re-configuration which has to be : done when adding or deleting new users.
FreeRADIUS をインストールします。
yum -y install freeradius freeradius-utils
Radius クライアントの定義
FreeRADIUS へのアクセスを許可するクライアントの定義を行います。 ここでは「192.168.0.0/16 範囲内から "SECRET" という Radius Secret Key でアクセスしてくるクライント」を定義しています。 テスト用に localhost の設定も残しています。
cat << EOF > /etc/raddb/clients.conf 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 = 10 } } client 192.168.0.0/16 { secret = SECRET } EOF
NTLM 認証の設定
FreeRADIUS で受信した認証要求を NTLM 認証で問い合わせ出来るように設定します。 /etc/raddb/mods-available/ntlm_auth
は初期状態で以下のようになっています。
# # For testing ntlm_auth authentication with PAP. # # If you have problems with authentication failing, even when the # password is good, it may be a bug in Samba: # # https://bugzilla.samba.org/show_bug.cgi?id=6563 # exec ntlm_auth { wait = yes program = "/path/to/ntlm_auth --request-nt-key --domain=MYDOMAIN --username=%{mschap:User-Name} --password=%{User-Password}" }
/path/to/ntlm_auth
と MYDOMAIN
を環境に応じて修正します。 今回の環境では ntlm_auth
は /usr/local/samba/bin/html_auth
にありました。 ドメイン名も自身の環境にあわせて修正します。
sed -i -e "s/\/path\/to\/ntlm_auth/\/usr\/local\/samba\/bin\/ntlm_auth/" /etc/raddb/mods-available/ntlm_auth sed -i -e "s/MYDOMAIN/EXAMPLE.COM/" /etc/raddb/mods-available/ntlm_auth
NTLM 認証ポリシーを設定する
ntlm_auth 用の認証ポリシーを定義します。 以下の内容で /etc/raddb/policy.d/ntlm_auth
を新規作成します。
cat << EOF > /etc/raddb/policy.d/ntlm_auth # Give the ntlm_auth exec module an "authorize" method that sets Auth-Type # to itself but only if it's a valid PAP request, and Auth-Type is not # already set to something ntlm_auth.authorize { if (!control:Auth-Type && User-Password) { update control { Auth-Type := ntlm_auth } } } EOF
認証タイプの設定を修正する
認証タイプは /etc/raddb/sites-enabled/default
で定義されています。 これを修正してきます。
authorize セクション
変更前
authorize セクションは要約すると以下のようになっていました。
authorize { filter_username # filter_password preprocess # operator-name # cui # auth_log chap mschap digest # wimax # IPASS suffix # ntdomain eap { ok = return # updated = return } # unix files -sql # smbpasswd -ldap # daily expiration logintime pap }
変更後
最後にある pap
をコメントアウトして無効化し、更に ntlm_auth
の定義を追加します。
# pap
ntlm_auth
authenticate セクション
変更前
authenticate セクションは要約すると以下のようになっていました。
authenticate { Auth-Type PAP { pap } Auth-Type CHAP { chap } Auth-Type MS-CHAP { mschap } mschap digest # pam # Auth-Type LDAP { # ldap # } eap # Auth-Type eap { # eap { # handled = 1 # } # if (handled && (Response-Packet-Type == Access-Challenge)) { # attr_filter.access_challenge.post-auth # handled # override the "updated" code from attr_filter # } # } }
変更後
以下のように Auth-Type ntlm_auth
を追加します。
# authenticate { Auth-Type ntlm_auth { ntlm_auth } # # PAP authentication, when a back-end database listed # in the 'authorize' section supplies a password. The # password can be clear-text, or encrypted. Auth-Type PAP { pap }
起動&自動起動の設定
これで FreeRADIUS の設定は完了です。 デーモンを起動&自動起動設定します。
systemctl start radiusd systemctl enable radiusd
認証テストを実施する
radtest
を使うと RADIUS の認証テストを行うことが出来ます。 まず、サーバ自身 (localhost) から接続テストを実施してみます。 USERNAME
と PASSWORD
には、認証したいユーザの名前とパスワードを指定します。 サーバ自身へ接続テストを行いますのでアドレスには 127.0.0.1 を、Radius Secret Key にはクライアントファイル中で定義している testing123
を指定します。 Received Access-Accept
の応答があれば認証は成功です。
radtest [USERNAME] [PASSWORD] 127.0.0.1 0 testing123
次はリモートクライアント (Linux) から接続テストを実施してみます。 ADDRESS
には FreeRADIUS サーバのアドレスを、Radius Secret Key にはクライアントファイル中で定義している SECRET
を指定しました。 こちらも同様に、認証されることを確認します。
radtest [USERNAME] [PASSWORD] [ADDRESS] 0 SECRET