0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

FreeRADIUS + LDAPの構成でLDAPサーバーを認証サーバーにするべきではない?

0
Last updated at Posted at 2026-06-27

というのは、以下のFreeRADIUSのドキュメントに書かれている内容です。

Our recommendation is to use LDAP as a database. FreeRADIUS reads the "known good" password from LDAP, and then use that information to authenticate the user. It’s not recommended to use the LDAP "bind as user" method for authenticating users.

LDAPサーバーをユーザーデータベースとしてのみ使う方法では、PAP、CHAP、MS-CHAPを認証プロトコルとして使用できますが、LDAPサーバーで認証もする場合ではPAPのみの対応になるため非推奨、ということだと思われます。

(ただし、CHAP、MS-CHAPはLDAPサーバー側に平文でパスワードが保存される必要があり、FreeRADIUSではこれを非推奨としていることから、結局使えるプロトコルはどちらにせよPAPのみになるので結局同じでは? と思わなくもないです……)

正しい? 構築例

AlmaLinux 10.2
FreeRADIUS 3.2.8

LDAPサーバー側の準備

以下で構築したLDAPサーバーを使用します。

LDAPサーバー内のエントリを探索するユーザーを追加します。

dn: cn=radiusReadUser,ou=administrationUsers,dc=sayakek,dc=internal
changetype: add
cn: radiusReadUser
sn: radiusReadUser
userPassword: <パスワード>
objectclass: top
objectclass: Person

必要な属性・エントリに対する読み取り権限を与えます。

ldap1.sayakek.internal用
dn: olcDatabase={2}mdb,cn=config
changetype: modify
delete: olcAccess
olcAccess: {0}to attrs=userPassword 
 by self write 
 by dn="cn=editUser,ou=providerUsers,ou=administrationUsers,dc=sayakek,dc=internal" write 
 by dn="cn=replicateUser,ou=providerUsers,ou=administrationUsers,dc=sayakek,dc=internal" read 
 by anonymous auth by * none
olcAccess: {1}to dn.subtree="ou=users,ou=sayakekOU,dc=sayakek,dc=internal" 
 by dn="cn=editUser,ou=providerUsers,ou=administrationUsers,dc=sayakek,dc=internal" write 
 by dn="cn=replicateUser,ou=providerUsers,ou=administrationUsers,dc=sayakek,dc=internal" read 
 by dn="cn=sssdReadUser,ou=administrationUsers,dc=sayakek,dc=internal" read 
 by self read 
 by * none
-
add: olcAccess
olcAccess: {0}to attrs=userPassword 
 by self write 
 by dn="cn=editUser,ou=providerUsers,ou=administrationUsers,dc=sayakek,dc=internal" write 
 by dn="cn=replicateUser,ou=providerUsers,ou=administrationUsers,dc=sayakek,dc=internal" read 
 by dn="cn=radiusReadUser,ou=administrationUsers,dc=sayakek,dc=internal" read 
 by anonymous auth by * none
olcAccess: {2}to dn.subtree="ou=users,ou=sayakekOU,dc=sayakek,dc=internal" 
 by dn="cn=editUser,ou=providerUsers,ou=administrationUsers,dc=sayakek,dc=internal" write 
 by dn="cn=replicateUser,ou=providerUsers,ou=administrationUsers,dc=sayakek,dc=internal" read 
 by dn="cn=sssdReadUser,ou=administrationUsers,dc=sayakek,dc=internal" read 
 by dn="cn=radiusReadUser,ou=administrationUsers,dc=sayakek,dc=internal" read 
 by self read 
 by * none
ldap2.sayakek.internal用
dn: olcDatabase={2}mdb,cn=config
changetype: modify
delete: olcAccess
olcAccess: {0}to attrs=userPassword 
 by anonymous auth 
 by * none
olcAccess: to dn.subtree="ou=users,ou=sayakekOU,dc=sayakek,dc=internal" 
 by dn="cn=sssdReadUser,ou=administrationUsers,dc=sayakek,dc=internal" read 
 by * none
-
add: olcAccess
olcAccess: {0}to attrs=userPassword 
 by dn="cn=radiusReadUser,ou=administrationUsers,dc=sayakek,dc=internal" read 
 by anonymous auth 
 by * none
olcAccess: {1}to dn.subtree="ou=users,ou=sayakekOU,dc=sayakek,dc=internal" 
 by dn="cn=sssdReadUser,ou=administrationUsers,dc=sayakek,dc=internal" read 
 by dn="cn=radiusReadUser,ou=administrationUsers,dc=sayakek,dc=internal" read 
 by * none

FreeRADIUSの構築

LDAPサーバーの構築で使用したCA証明書がインストールされている必要があります。
ca_cert.crtを/usr/share/pki/ca-trust-source/anchors/以下にコピーし、次のコマンドを実行します。

$ sudo chown root:root /usr/share/pki/ca-trust-source/anchors/ca_cert.crt
$ sudo restorecon /usr/share/pki/ca-trust-source/anchors/ca_cert.crt
$ sudo update-ca-trust extract

パッケージをインストールします。

$ sudo dnf install freeradius freeradius-utils freeradius-ldap

ldapモジュールが読み込まれるようにシンボリックリンクを作成します。
eapとinner-tunnelモジュールは今回使用しない上有効になっていると「証明書を作れ」というエラーが出るのでunlinkします。

$ sudo ln -s /etc/raddb/mods-available/ldap /etc/raddb/mods-enabled/ldap
$ sudo unlink /etc/raddb/mods-enabled/eap
$ sudo unlink /etc/raddb/sites-enabled/inner-tunnel

Radiusクライアントを定義します。

/etc/raddb/clients.conf
client cl1 {
    ipaddr = <クライアントのIPアドレス>/<サブネットマスク>
    secret = <任意のシークレット>
}

以下の定義ファイルを作成します。
gidNumberが4000番であるユーザーを対象に検索する設定です。

/etc/raddb/mods-available/ldap
ldap {
        server = 'ldaps://ldap1.sayakek.internal'
        server = 'ldaps://ldap2.sayakek.internal'
        port = 636
        identity = 'cn=radiusReadUser,ou=administrationUsers,dc=sayakek,dc=internal'
        password = <radiusReadUserのパスワード>
        base_dn = 'ou=users,ou=sayakekOU,dc=sayakek,dc=internal'
        update {
                control:Password-With-Header    += 'userPassword'
        }
        user {
                base_dn = "${..base_dn}"
                filter = "(&(gidNumber=4000)(cn=%{%{Stripped-User-Name}:-%{User-Name}}))"
        }
        options {
                chase_referrals = yes
                rebind = yes
                res_timeout = 10
                srv_timelimit = 3
                net_timeout = 1
                idle = 60
                probes = 3
                interval = 3
                ldap_debug = 0x0028
        }
        tls {
                start_tls = no
                require_cert = 'hard'
                tls_min_version = "1.2"
        }
        pool {
                start = ${thread[pool].start_servers}
                min = ${thread[pool].min_spare_servers}
                max = ${thread[pool].max_servers}
                spare = ${thread[pool].max_spare_servers}
                uses = 0
                retry_delay = 30
                lifetime = 0
                idle_timeout = 60
                max_retries = 5
        }
}

以下の定義ファイルを作成します。
PAPモジュールとLDAPモジュールによる認証以外を使用しないので、定義ファイルから削っています。
authenticateセクションにAuth-Type LDAP { ldap }を追加する必要があるという記述が見られる記事がありますが、それはLDAPサーバーで認証する場合の設定のため今回は不要です。
authorizeセクションのldapにより先ほど設定したLDAPモジュールが呼び出されユーザー情報とパスワードの取得が行われます。
その後のauthenticateのPAPモジュールにより、取得したLDAPのuserPasswordとRadius認証要求のUser-Passwordの照合が行われるという流れになります。

/etc/raddb/sites-available/default
server default {
listen {
        type = auth
        ipaddr = 172.16.1.30/32
        port = 1812
        limit {
              max_connections = 16
              lifetime = 0
              idle_timeout = 900
        }
}
authorize {
        filter_username
        preprocess
        -ldap
        pap
}
authenticate {
        Auth-Type PAP {
                pap
        }
}
post-auth {
        if (session-state:User-Name && reply:User-Name && request:User-Name && (reply:User-Name == request:User-Name)) {
                update reply {
                        &User-Name !* ANY
                }
        }
        update {
                &reply: += &session-state:
        }    
        Post-Auth-Type REJECT {
                attr_filter.access_reject
        }
}
}

起動して、FWに穴あけします。

$ sudo systemctl enable radiusd --now
$ sudo firewall-cmd --add-service=radius
$ sudo firewall-cmd --reload

確認

radtestコマンドで確認します。
まずはgidNumberが4000のユーザーから。
image.png

$ radtest userA <userAのパスワード> 172.16.1.30 1 <共通シークレット>
Sent Access-Request Id 47 from 0.0.0.0:60920 to 172.16.1.30:1812 length 75
        User-Name = "userA"
        User-Password = "<userAのパスワード>"
        NAS-IP-Address = 127.0.0.1
        NAS-Port = 1
        Message-Authenticator = 0x00
        Cleartext-Password = "<userAのパスワード>"
Received Access-Accept Id 47 from 172.16.1.30:1812 to 172.16.1.30:60920 length 38
        Message-Authenticator = 0x914476a25be5e60b8381d6618b7bc385

正常に認証できたので、次はgidNumberを4001番にして実行します。
image.png
きちんと弾かれました。

$ radtest userA <userAのパスワード> 172.16.1.30 1 <共通シークレット>
Sent Access-Request Id 138 from 0.0.0.0:58733 to 172.16.1.30:1812 length 75
        User-Name = "userA"
        User-Password = "<userAのパスワード>"
        NAS-IP-Address = 127.0.0.1
        NAS-Port = 1
        Message-Authenticator = 0x00
        Cleartext-Password = "<userAのパスワード>"
Received Access-Reject Id 138 from 172.16.1.30:1812 to 172.16.1.30:58733 length 38
        Message-Authenticator = 0x7d56dbf446bdf2934641a1cd6dada7f2
(0) -: Expected Access-Accept got Access-Reject

おまけ LDAPサーバーで認証してみる

ADとFreeRADIUSを統合する場合、この方法で設定するか廃止予定のNTLMv2を必要とする設定をするかの択のようなので、研究のためにこの方法もやってみたいと思います。
userPasswordを読み取れる必要はありませんが、最初にauthZの段階でBINDするユーザー(LDAPモジュールのidentityで指定するユーザー。無指定の場合はanonymous)がユーザーの存在を読み取れる必要があります。

ldap1.sayakek.internal用
dn: olcDatabase={2}mdb,cn=config
changetype: modify
delete: olcAccess
olcAccess: {2}to dn.subtree="ou=users,ou=sayakekOU,dc=sayakek,dc=internal" 
 by dn="cn=editUser,ou=providerUsers,ou=administrationUsers,dc=sayakek,dc=internal" write 
 by dn="cn=replicateUser,ou=providerUsers,ou=administrationUsers,dc=sayakek,dc=internal" read 
 by dn="cn=sssdReadUser,ou=administrationUsers,dc=sayakek,dc=internal" read 
 by self read 
 by * none
-
add: olcAccess
olcAccess: {2}to dn.subtree="ou=users,ou=sayakekOU,dc=sayakek,dc=internal" 
 by dn="cn=editUser,ou=providerUsers,ou=administrationUsers,dc=sayakek,dc=internal" write 
 by dn="cn=replicateUser,ou=providerUsers,ou=administrationUsers,dc=sayakek,dc=internal" read 
 by dn="cn=sssdReadUser,ou=administrationUsers,dc=sayakek,dc=internal" read 
 by dn="cn=radiusReadUser,ou=administrationUsers,dc=sayakek,dc=internal" read 
 by self read 
 by * none
ldap2.sayakek.internal用
dn: olcDatabase={2}mdb,cn=config
changetype: modify
delete: olcAccess
olcAccess: {1}to dn.subtree="ou=users,ou=sayakekOU,dc=sayakek,dc=internal" 
 by dn="cn=sssdReadUser,ou=administrationUsers,dc=sayakek,dc=internal" read 
 by * none
-
add: olcAccess
olcAccess: {1}to dn.subtree="ou=users,ou=sayakekOU,dc=sayakek,dc=internal" 
 by dn="cn=sssdReadUser,ou=administrationUsers,dc=sayakek,dc=internal" read 
 by dn="cn=radiusReadUser,ou=administrationUsers,dc=sayakek,dc=internal" read 
 by * none
$ sudo chown root:root /usr/share/pki/ca-trust-source/anchors/ca_cert.crt
$ sudo restorecon /usr/share/pki/ca-trust-source/anchors/ca_cert.crt
$ sudo update-ca-trust extract
$ sudo dnf install freeradius freeradius-utils freeradius-ldap
$ sudo ln -s /etc/raddb/mods-available/ldap /etc/raddb/mods-enabled/ldap
$ sudo unlink /etc/raddb/mods-enabled/eap
$ sudo unlink /etc/raddb/sites-enabled/inner-tunnel
/etc/raddb/clients.conf
client cl1 {
    ipaddr = <クライアントのIPアドレス>/<サブネットマスク>
    secret = <任意のシークレット>
}

以下の定義ファイルを作成します。

/etc/raddb/mods-available/ldap
ldap {
        server = 'ldaps://ldap1.sayakek.internal'
        server = 'ldaps://ldap2.sayakek.internal'
        port = 636
        identity = 'cn=radiusReadUser,ou=administrationUsers,dc=sayakek,dc=internal'
        password = <radiusReadUserのパスワード>
        base_dn = 'ou=users,ou=sayakekOU,dc=sayakek,dc=internal'
        update {
                control:Password-With-Header    += 'userPassword'
        }
        user {
                base_dn = "${..base_dn}"
                filter = "(&(gidNumber=4000)(cn=%{%{Stripped-User-Name}:-%{User-Name}}))"
        }
        options {
                chase_referrals = yes
                rebind = yes
                res_timeout = 10
                srv_timelimit = 3
                net_timeout = 1
                idle = 60
                probes = 3
                interval = 3
                ldap_debug = 0x0028
        }
        tls {
                start_tls = no
                require_cert = 'hard'
                tls_min_version = "1.2"
        }
        pool {
                start = ${thread[pool].start_servers}
                min = ${thread[pool].min_spare_servers}
                max = ${thread[pool].max_servers}
                spare = ${thread[pool].max_spare_servers}
                uses = 0
                retry_delay = 30
                lifetime = 0
                idle_timeout = 60
                max_retries = 5
        }
}

以下の定義ファイルを作成します。
authorizeセクションに探索でユーザーが見つかった場合にLDAP Authに飛ばすような設定を投入します。
authenticateセクションにAuth-Type LDAP { ldap }を追加します。

/etc/raddb/sites-available/default
server default {
listen {
        type = auth
        ipaddr = 172.16.1.30/32
        port = 1812
        limit {
              max_connections = 16
              lifetime = 0
              idle_timeout = 900
        }
}
authorize {
        filter_username
        preprocess
        ldap
        if ((ok || updated) && User-Password && !control:Auth-Type) {
                update{
                        control:Auth-Type := ldap
                }
        }
}
authenticate {
        Auth-Type LDAP {
                ldap
        }
}
post-auth {
        if (session-state:User-Name && reply:User-Name && request:User-Name && (reply:User-Name == request:User-Name)) {
                update reply {
                        &User-Name !* ANY
                }
        }
        update {
                &reply: += &session-state:
        }    
        Post-Auth-Type REJECT {
                attr_filter.access_reject
        }
}
}
$ sudo systemctl enable radiusd --now
$ sudo firewall-cmd --add-service=radius
$ sudo firewall-cmd --reload

userAはgidNumberが4001、userBは4000のユーザーです。
それぞれ期待通り動作しています。

$ radtest userB <userBのパスワード> 172.16.1.30 1 <共通シークレット>
Sent Access-Request Id 248 from 0.0.0.0:57705 to 172.16.1.30:1812 length 75
        User-Name = "userB"
        User-Password = "<userBのパスワード>"
        NAS-IP-Address = 127.0.0.1
        NAS-Port = 1
        Message-Authenticator = 0x00
        Cleartext-Password = "<userBのパスワード>"
Received Access-Accept Id 248 from 172.16.1.30:1812 to 172.16.1.30:57705 length 38
        Message-Authenticator = 0x2265fde6a5e23c0ab66ab501b6f064e2
$ radtest userA <userAのパスワード> 172.16.1.30 1 <共通シークレット>
Sent Access-Request Id 5 from 0.0.0.0:49389 to 172.16.1.30:1812 length 75
        User-Name = "userA"
        User-Password = "<userAのパスワード>"
        NAS-IP-Address = 127.0.0.1
        NAS-Port = 1
        Message-Authenticator = 0x00
        Cleartext-Password = "<userAのパスワード>"
Received Access-Reject Id 5 from 172.16.1.30:1812 to 172.16.1.30:49389 length 38
        Message-Authenticator = 0x42c45acfc38797936f66221cf3202470
(0) -: Expected Access-Accept got Access-Reject

LDAPサーバー側にもuserBでのLDAP BIND要求が来て、認証成功した旨のログが残っています。

Jun 27 14:37:11 localhost slapd[4984]: conn=1020 op=1 BIND dn="cn=userB,ou=users,ou=sayakekOU,dc=sayakek,dc=internal" method=128
Jun 27 14:37:11 localhost slapd[4984]: conn=1020 op=1 BIND dn="cn=userB,ou=users,ou=sayakekOU,dc=sayakek,dc=internal" mech=SIMPLE bind_ssf=0 ssf=256
Jun 27 14:37:11 localhost slapd[4984]: conn=1020 op=1 RESULT tag=97 err=0 qtime=0.000038 etime=0.004373 text=

どちらの方法でも探索ユーザーを必要とする上、この方法では2回LDAP BINDする無駄があるので、ADのような探索ユーザーでuserPasswordが取得できないLDAPサーバーを使う場合以外はRadiusサーバー側で認証した方が良さそうです。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?