LoginSignup
10
12

More than 5 years have passed since last update.

OpenLDAPでActive Directoryに対してPass-Through 認証する

Posted at

OpenLDAPを認証に使っているが一部のユーザーはActive Directory(以降、AD)に問い合わせて認証を行いたいケースが出てきたので、OpenLDAPのPass-Through認証について調べてみた。

前提となる環境

  • CentOS 6.7 (64bit)
  • OpenLDAP 2.4.40 ※yumでインストール

方式

OpenLDAPでは認証処理をSASLに委譲できるとのこと。SASLはSimple Authentication and Security Layeの略で、認証のフレームワークの1つ。CentOSだとsaslauthdというデーモンサービスを起動し、こいつに認証を任せることができる。
さらに、このSASLの中で外部のADなどのLDAPサーバーに対して認証をさらに委譲することができるようになっている。
つまり、OpenLDAP --> SASL --> AD という経路でPass-Through認証が実現できる。

設定方法

saslauthdの設定

yumでサクッとインストール。

yum install cyrus-sasl cyrus-sasl-ldap

/etc/sysconfig/saslauthdを開きsaslauthdの起動オプションを設定する。SASLでLDAP認証を使うように設定する。

/etc/sysconfig/saslauthd
MECH=ldap
FLAGS="-r"

/etc/saslauthd.confを新規に作成し、ADへの接続設定を行う。ldap_filterの内容はAD側ではどの属性を認証IDとするかによって変わってくる。

/etc/saslauthd.conf
ldap_servers: ldap://yourad.org
ldap_search_base: dc=yourad,dc=org
ldap_filter: (cn=%u)
ldap_bind_dn: cn=Manager,ou=users,dc=yourad,dc=org
ldap_password: secret

設定後、saslauthdの自動起動を有効にしつつ起動。

chkconfig saslauthd on
service saslauthd start

saslauthdのテスト

saslauthd経由でADに認証できるかtestsaslauthdコマンドを使って試すことができる。設定が正しければADのアカウントで処理成功となるので確認しておく。

testsaslauthd -u foo -p mypass
0: OK "Success."

SASLの設定

/etc/sasl2/slapd.confを新規に作成し、OpenLDAPの認証をsaslauthdに任せるようにする。

/etc/sasl2/slapd.conf
mech_list: plain
pwcheck_method: saslauthd
saslauthd_path: /var/run/saslauthd/mux

設定後、OpenLDAPを再起動する。

service slapd restart

Pass-Through を行うユーザーの登録

OpenLDAPに下記のようなLDIFを作成してユーザーを登録する。
ポイントは userpassword: {SASL}foo の部分。こうすると、このユーザーでbindしようとするとSASLを利用してsaslauthd経由でADにfooで検索され、AD側でbindされるようになる。この時使われる検索フィルタが先のldap_filter: (cn=%u)の設定になる。この例だと、cn=fooでADを検索して存在すればAD側でbindが行われることになる。

user.ldif
dn: cn=foo,ou=users,dc=example,dc=com
objectclass: inetorgperson
cn: foo
userpassword: {SASL}foo
givenname: foo
sn: somebodyson
mail: foo@example.com

実行

ldapwhoamiコマンドで試す。-w mypassのパスワードはADに格納されているパスワードだが、Pass-Through認証が行われてAD側で処理され結果が返ってきている。

ldapwhoami -x -D cn=foo,ou=users,dc=example,dc=com -w mypass
dn:cn=foo,ou=users,dc=example,dc=com

参考サイト

10
12
1

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
10
12