LoginSignup
10
9

More than 5 years have passed since last update.

sAMAccountNameをキーとして、OpenLDAPとActiveDirectoryを検索する

Last updated at Posted at 2016-11-08

参考URL:http://www.linuxtopia.org/online_books/network_administration_guides/ldap_administration/overlays_Chaining.html

sAMAccountNameをキーとして、OpenLDAPで管理しているアカウント、ActiveDirectoryで管理しているアカウントを一元で検索するようにしました。

前提とするOS/MWのバージョン
CentOS 7.2.1511
cyrus-sasl:2.1.26
openldap-*:2.4.40

RPMまで導入済みの状態とする。

ドメイン定義
 AD:dc=ZZZ,dc=local
 LDAP:dc=YYY,dc=ZZZ,dc=local
ADのサブドメインとしてLDAPを定義

ユーザDN
 AD:cn=[フルネーム],OU=OU_Users,dc=ZZZ,dc=local
 LDAP:sAMAccountName=[アカウント名],ou=[会社名],ou=partner,dc=YYY,dc=ZZZ,dc=local
となるようにします。

1.パスワード生成

slappasswd
New password:
Re-enter new password:
{SSHA}hth5u4U3WU9lWWvWT2zS2vePRxVUhBrg

2.DB_CONFIGファイルの配置

サンプルを使用します。

cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG
chown ldap:ldap /var/lib/ldap/DB_CONFIG 

3.ActiveDirectory用のスキーマファイル取得

wget http://lism.sourceforge.jp/docs/ad.schema -O /etc/openldap/schema/ad.schema

4.カスタムスキーマの定義

inetOrgPersonを継承して、ADと共通の検索キーとする"sAMAccountName"を必須属性として定義。
sAMAccountNameにはuidと同じ値を設定します。

/etc/openldap/schema/custom.schema
# OpenLDAP User schema
objectclass ( 1.1.2.2.1
        NAME 'customObject'
        DESC 'Custom Object'
        SUP 'inetOrgPerson'
        STRUCTURAL
        MUST ( sAMAccountName ) )

5.slapd.conf

/etc/openldap/slapd.conf
include         /etc/openldap/schema/core.schema
include         /etc/openldap/schema/cosine.schema
include         /etc/openldap/schema/inetorgperson.schema
include         /etc/openldap/schema/nis.schema

pidfile         /var/run/openldap/slapd.pid
argsfile        /var/run/openldap/slapd.args

modulepath      /usr/lib64/openldap
moduleload      back_ldap.la

# For Additional Schema
include         /etc/openldap/schema/ad.schema
include         /etc/openldap/schema/custom.schema
sizelimit unlimited

# チェイン先のADを検索する設定
overlay chain
chain-max-depth 2
chain-return-error TRUE

chain-uri "ldap://[ADのIP]/"
chain-rebind-as-user true
chain-idassert-bind bindmethod="simple"
  binddn="[検索ユーザのDN]"
  credentials="[パスワード]" mode="legacy" flags="non-prescriptive"
chain-acl-bind bindmethod="simple"
  binddn="[検索ユーザのDN]"
  credentials="[パスワード]"


# Access Control
### ACLは省略 ###

password-hash   {SSHA}

# For Local LDAP
database        bdb
suffix          "dc=YYY,dc=ZZZ,dc=local"
rootdn          "cn=Manager,dc=YYY,dc=ZZZ,dc=local"
rootpw          {SSHA}hth5u4U3WU9lWWvWT2zS2vePRxVUhBrg
directory       /var/lib/ldap
loglevel        256

# For Local Index
index objectClass                       eq,pres
index ou,cn,mail,surname,givenname      eq,pres,sub
index uidNumber,gidNumber,loginShell    eq,pres
index uid,memberUid                     eq,pres,sub
index nisMapName,nisMapEntry            eq,pres,sub
index sAMAccountName                    eq,pres
index distinguishedName                 eq,pres

# ADのみを検索するための設定
database        ldap
chase-referrals no
suffix          "dc=ZZZ,dc=local"
uri             ldap://[ADのIP]/
acl-bind        bindmethod="simple"
  binddn="[検索ユーザのDN]"
  credentials="[パスワード]"
idassert-bind   bindmethod="simple"
  binddn="[検索ユーザのDN]"
  credentials="[パスワード]" mode="legacy" flags="non-prescriptive"

# For monitoring
database monitor

6.設定反映

まずはシンタックスチェック。

slaptest -u -f /etc/openldap/slapd.conf -v
config file testing succeeded

実際に反映させる。

chown root:ldap /etc/openldap/slapd.conf
chown -R ldap:ldap /var/lib/ldap
mkdir -p /etc/openldap/slapd.d/
slaptest -f /etc/openldap/slapd.conf -F /etc/openldap/slapd.d
config file testing succeeded

7.ADへの参照エントリ作成

ref.ldif
dn: ou=XXX,dc=YYY,dc=ZZZ,dc=local
changetype: add
objectClass: top
objectClass: organizationalUnit
ou: XXX

dn: cn=proxy,ou=XXX,dc=YYY,dc=ZZZ,dc=local
objectClass: referral
objectClass: extensibleObject
dc: AAATree
cn: proxy
ref: ldap://[ADのIP]/ou=OU_Users,dc=YYY,dc=local

参照エントリを登録。

ldapadd -x -D "cn=Manager,dc=YYY,dc=ZZZ,dc=local" -W -f ref.ldif

8.動作確認

LDAPのドメインをサーチベースとした時にLDAP/ADとも検索されることを確認。

LDAPのサブドメインからADのアカウントを検索
ldapsearch -x -h [LDAPのIP] -D "[LDAP検索ユーザーのDN]" -w'[パスワード]' \
 -b "dc=YYY,dc=ZZZ,dc=local"                                             \
 "(sAMAccountName=[ADに存在するアカウント])"                             \
 "sAMAccountName"
dn:: Y2496JiH55Sw5LquLG91PU9VX1VzZXJzLGRjPXRhZHMsZGM9bG9jYWw=
sAMAccountName: [ADに存在するアカウント]
LDAPのサブドメインからLDAPのアカウントを検索
ldapsearch -x -h [LDAPのIP] -D "[LDAP検索ユーザーのDN]" -w'[パスワード]' \
 -b "dc=YYY,dc=ZZZ,dc=local"                                             \
 "(sAMAccountName=[LDAPに存在するアカウント])"                           \
 "sAMAccountName"
dn: sAMAccountName=[LDAPに存在するアカウント],ou=[会社名],ou=partner,dc=YYY,dc=ZZZ,dc=local
sAMAccountName: [LDAPに存在するアカウント]

ADのドメインをサーチベースとした時にADのみ検索されることを確認。

ADのドメイン指定でADのアカウントを検索
ldapsearch -x -h [LDAPのIP] -D "[LDAP検索ユーザーのDN]" -w'[パスワード]' \
 -b "dc=ZZZ,dc=local"                                                    \
 "(sAMAccountName=[ADに存在するアカウント])"                             \
  "sAMAccountName"
dn:: Y2496JiH55Sw5LquLG91PU9VX1VzZXJzLGRjPXRhZHMsZGM9bG9jYWw=
sAMAccountName: [ADに存在するアカウント]
ADのドメイン指定でLDAPのアカウントを検索
ldapsearch -x -h [LDAPのIP] -D "[LDAP検索ユーザーのDN]" -w'[パスワード]' \
 -b "dc=ZZZ,dc=local"                                                    \
 "(sAMAccountName=[LDAPに存在するアカウント])"                           \
  "sAMAccountName"
(検索結果なし)

9.SASLの設定

/etc/sysconfig/saslauthd
MECH=ldap
FLAGS="-O /etc/saslauthd.conf"
/etc/saslauthd.conf
ldap_servers: ldap://127.0.0.1
ldap_use_sasl: no
ldap_bind_dn: [LDAP検索ユーザのDN]
ldap_password: [パスワード]
ldap_mech: PLAIN
ldap_auth_method: bind
ldap_filter: (sAMAccountName=%U)
ldap_scope: sub
ldap_search_base: dc=YYY,dc=ZZZ,dc=local
ldap_deref: always
chmod 600 /etc/saslauthd.conf

10.Subversionの認証をSASL経由に

svnserve.conf
[sasl]
use-sasl = true
/usr/lib64/sasl2/svn.conf
pwcheck_method: saslauthd
auxprop_plugin: ldap
mech_list: PLAIN
ldapdb_mech: PLAIN
10
9
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
10
9