OpenLDAP - yusukew62/docs GitHub Wiki

OpenLDAP

インストール

ソースからインストール

ソースからインストールする場合2.4系はBDBのバージョンアップが必要
Oracle社のサイトからBDBのソースをダウンロードしておく

BDBのインストール

# mv /var/tmp/db-5.0.32.tar.gz /usr/local/src/
# cd /usr/local/src
# tar zxvf db-5.0.32.tar.gz
# cd db-5.0.32/build_unix/
# ../dist/configure
# make
# make install
# export LD_LIBRARY_PATH=/usr/local/BerkeleyDB.5.0/lib

OpenLDAPのインストール
make instal前に make testでテストを実施できるが時間がかかるため割愛

# mv /var/tmp/openldap-2.4.44.tgz /usr/local/src/
# cd /usr/local/src/
# tar zxvf openldap-2.4.44.tgz
# cd openldap-2.4.44
# CPPFLAGS=-I/usr/local/BerkeleyDB.5.0/include LDFLAGS=-L/usr/local/BerkeleyDB.5.0/lib ./configure --prefix=/usr/local/src/openldap-2.4.44/
# make depend
# make
# make install

インストールしたBDBが参照されているか確認
ldapユーザとldapグループを追加

# ldd /usr/local/src/openldap-2.4.44/libexec/slapd
        linux-vdso.so.1 =>  (0x00007ffdb1b49000)
        libdb-5.0.so => /usr/local/BerkeleyDB.5.0/lib/libdb-5.0.so (0x00007f2cfd9e4000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f2cfd7bf000)
        libresolv.so.2 => /lib64/libresolv.so.2 (0x00007f2cfd5a5000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f2cfd211000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f2cfdd6d000)
# id ldap
# groupadd ldap
# useradd -g ldap -s /bin/false ldap

パッケージからインストール

必要なモジュールのインストール

# yum install openldap openldap-servers openldap-clients

インストール後から起動まで

パッケージからインストールの続き

不要な定義ファイルを削除する

# rm -rf /etc/openldap/slapd.d/*
# rm -rf /var/lib/ldap/*
# mkdir -p /etc/openldap/tmp
# chmod 600 /etc/openldap/tmp

管理用パスワードの設定

# slappasswd
New password:
Re-enter new password:
{SSHA}7PDtKYQG2ARPPFp7VXgdiBRYb5aGhI1m

DB_CONFIG と slapd.conf のサンプルをコピーする

# cp -p  /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG
# cp -p /usr/share/openldap-servers/slapd.conf.obsolete /etc/openldap/slapd.conf

パーミッションを ldap:ldapとする

# chown -R ldap:ldap /var/lib/ldap/
# chown -R ldap:ldap /etc/openldap/

slapd.confを修正する

# diff /etc/openldap/slapd.conf.org /etc/openldap/slapd.conf
--- slapd.conf.org      2016-05-11 08:32:50.000000000 +0900
+++ slapd.conf  2017-03-02 11:00:24.034991683 +0900
@@ -63,9 +63,12 @@
 # dummy test certificate which you can generate by running
 # /usr/libexec/openldap/generate-server-cert.sh. Your client software may balk
 # at self-signed certificates, however.
-TLSCACertificatePath /etc/openldap/certs
-TLSCertificateFile "\"OpenLDAP Server\""
-TLSCertificateKeyFile /etc/openldap/certs/password
+# TLSCACertificatePath /etc/openldap/certs
+# TLSCertificateFile "\"OpenLDAP Server\""
+# TLSCertificateKeyFile /etc/openldap/certs/password
+TLSCACertificatePath /etc/openldap/cacerts/cacert.pem
+TLSCertificateFile /etc/openldap/certs/server.csr
+TLSCertificateKeyFile /etc/openldap/certs/server.key

 # Sample security restrictions
 #      Require integrity protection (prevent hijacking)
@@ -95,31 +98,43 @@
 # rootdn can always read and write EVERYTHING!

 # enable on-the-fly configuration (cn=config)
-database config
-access to *
-       by dn.exact="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" manage
+#database config
+#access to *
+#      by dn.exact="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" manage
+#      by * none
+access to attrs=userPassword
+       by self write
+       by dn="cn=Manager,dc=yusukew62,dc=net" write
+       by anonymous auth
        by * none

+access to *
+       by self write
+       by dn="cn=Manager,dc=yusukew62,dc=net" write
+       by * read
+
 # enable server status monitoring (cn=monitor)
 database monitor
 access to *
-       by dn.exact="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" read
-        by dn.exact="cn=Manager,dc=my-domain,dc=com" read
+        by dn.exact="cn=Manager,dc=yusukew62,dc=net" read
         by * none
+#      by dn.exact="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" read
+#       by dn.exact="cn=Manager,dc=my-domain,dc=com" read

 #######################################################################
 # database definitions
 #######################################################################

 database       bdb
-suffix         "dc=my-domain,dc=com"
+suffix         "dc=yusukew62,dc=net"
 checkpoint     1024 15
-rootdn         "cn=Manager,dc=my-domain,dc=com"
+rootdn         "cn=Manager,dc=yusukew62,dc=net"
 # Cleartext passwords, especially for the rootdn, should
 # be avoided.  See slappasswd(8) and slapd.conf(5) for details.
 # Use of strong authentication encouraged.
 # rootpw               secret
 # rootpw               {crypt}ijFYNcSNctBYg
+rootpw         {SSHA}dOMN964TrPzuSootkzbTPE18MrIFUvIV

 # The database directory MUST exist prior to running slapd AND
 # should only be accessible by the slapd and slap tools.
@@ -138,3 +153,4 @@
 #replica host=ldap-1.example.com:389 starttls=critical
 #     bindmethod=sasl saslmech=GSSAPI
 #     authcId=host/[email protected]
+loglevel 192

slaptestでslapd.confの構文チェックを行う

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

slaptestで/etc/openldap/slapd.d/を更新する

# slaptest -f /etc/openldap/slapd.conf -F /etc/openldap/slapd.d/
# ls -l /etc/openldap/slapd.d/
合計 8
drwxr-x--- 3 ldap ldap 4096  5月  6 16:18 2017 cn=config
-rw------- 1 ldap ldap 1090  5月  6 16:18 2017 cn=config.ldif

slapdの起動確認をする

# service slapd start
# chkconfig slapd on

ログ設定

syslogを通じてlocal4に出力される
出力先ログファイルを指定する

# diff -wu rsyslog.conf.org rsyslog.conf
--- rsyslog.conf.org    2014-12-10 19:05:22.000000000 +0900
+++ rsyslog.conf        2017-03-02 11:01:12.160991417 +0900
@@ -60,6 +60,8 @@
 # Save boot messages also to boot.log
 local7.*                                                /var/log/boot.log

+# Save ldap messages also to ldap.log
+local4.*                                                -/var/log/ldap.log

 # ### begin forwarding rule ###
 # The statement between the begin ... end define a SINGLE forwarding

ベースLDIFの作成

ldif配置用ディレクトリの作成

# mkdir -p /etc/openldap/tmp
# chown ldap:ldap /etc/openldap/tmp

base.ldifの作成

# vi /etc/openldap/tmp/base.ldif

以下の通り作成した

# cat /etc/openldap/tmp/base.ldif
#-----------------------------------------------------------
# Domain
#-----------------------------------------------------------
dn: dc=yusukew62,dc=net
objectClass: dcObject
objectClass: organization
dc: yusukew62
o: Yusukew62 Net.

#-----------------------------------------------------------
# Manager
#-----------------------------------------------------------
dn: cn=Manager,dc=yusukew62,dc=net
objectClass: organizationalRole
cn: Manager
description: Directory Manager

#-----------------------------------------------------------
# People
#-----------------------------------------------------------
dn: ou=People,dc=yusukew62,dc=net
objectClass: organizationalUnit
ou: People

#-----------------------------------------------------------
# Group
#-----------------------------------------------------------
dn: ou=Group,dc=yusukew62,dc=net
objectClass: organizationalUnit
ou: Group

ベースLDIFファイルを登録する

# ldapadd -x -D "cn=Manager,dc=yusukew62,dc=net" -W -f /etc/openldap/tmp/base.ldif
Enter LDAP Password:
adding new entry "dc=yusukew62,dc=net"

adding new entry "cn=Manager,dc=yusukew62,dc=net"

adding new entry "ou=People,dc=yusukew62,dc=net"

adding new entry "ou=Group,dc=yusukew62,dc=net"

グループLDIFの作成

グループ追加用LDIF作成スクリプトを用意する

# touch /etc/openldap/tmp/create_group_ldif.sh
# chmod 700 /etc/openldap/tmp/create_group_ldif.sh
# vi /etc/openldap/tmp/create_group_ldif.sh

作成したスクリプトは以下の内容

# cat /etc/openldap/tmp/create_group_ldif.sh
#!/bin/sh

read -p "ベースDN(例:dc=example,dc=com) : " BASE_DN_NAME
read -p "グループ名(例:testgroup)       : " GROUP_NAME
read -p "グループID(例:1001)            : " GROUP_ID

echo "
dn: cn=${GROUP_NAME},ou=Group,${BASE_DN_NAME}
objectClass: posixGroup
objectClass: top
cn: ${GROUP_NAME}
gidNumber: ${GROUP_ID}
"

グループ追加用LDIFファイル作成

# /etc/openldap/tmp/create_group_ldif.sh > /etc/openldap/tmp/group.ldif
ベースDN(例:dc=example,dc=com) : dc=yusukew62,dc=net
グループ名(例:testgroup)       : yusukew62group
グループID(例:1001)            : 1001

グループ追加用LDIFファイルを登録

# ldapadd -x -D "cn=Manager,dc=yusukew62,dc=net" -W -f /etc/openldap/tmp/group.ldif
Enter LDAP Password:
adding new entry "cn=yusukew62group,ou=Group,dc=yusukew62,dc=net"

登録情報を確認

# ldapsearch  -x -b 'dc=yusukew62,dc=net' 'cn=yusukew62group'
# extended LDIF
#
# LDAPv3
# base <dc=yusukew62,dc=net> with scope subtree
# filter: cn=yusukew62group
# requesting: ALL
#

# yusukew62group, Group, yusukew62.net
dn: cn=yusukew62group,ou=Group,dc=yusukew62,dc=net
objectClass: posixGroup
objectClass: top
cn: yusukew62group
gidNumber: 1001

# search result
search: 2
result: 0 Success

# numResponses: 2
# numEntries: 1

ユーザLDIFの作成

ユーザ追加用LDIFファイル作成スクリプトの作成

# touch /etc/openldap/tmp/create_user_ldif.sh
# chmod 700 /etc/openldap/tmp/create_user_ldif.sh
# vi /etc/openldap/tmp/create_user_ldif.sh

作成したスクリプトは以下の内容

# cat /etc/openldap/tmp/create_user_ldif.sh
#!/bin/sh

read -p "ベースDN(例:dc=example,dc=com) : " BASE_DN_NAME
read -p "ユーザー名(例:testuser)        : " USER_NAME
read -p "ユーザーID(例:1001)            : " USER_ID
read -p "グループID(例:1001)            : " GROUP_ID
read -p "ユーザーパスワード(例:pass)    : " USER_PASSWORD
read -p "Home Directory(/home/testuser) : " USER_DIRECTORY

PASSWORD=$(slappasswd -s "${USER_PASSWORD}")

echo "
dn: uid=${USER_NAME},ou=People,${BASE_DN_NAME}
uid: ${USER_NAME}
cn: ${USER_NAME}
objectClass: account
objectClass: posixAccount
objectClass: top
objectClass: shadowAccount
userPassword: ${PASSWORD}
shadowLastChange: 15862
shadowMin: 0
shadowMax: 99999
shadowWarning: 7
loginShell: /bin/bash
uidNumber: ${USER_ID}
gidNumber: ${GROUP_ID}
homeDirectory: ${USER_DIRECTORY}
"

ユーザ追加用LDIFファイル作成

# /etc/openldap/tmp/create_user_ldif.sh > /etc/openldap/tmp/user.ldif
ベースDN(例:dc=example,dc=com) : dc=yusukew62,dc=net
ユーザー名(例:testuser)        : yusukew62
ユーザーID(例:1001)            : 1001
グループID(例:1001)            : 1001
ユーザーパスワード(例:pass)    : password
Home Directory(/home/testuser) : /home/yusukew62 

ユーザ追加用LDIFファイルの登録

# ldapadd -x -D "cn=Manager,dc=yusukew62,dc=net" -W -f /etc/openldap/tmp/user.ldif
Enter LDAP Password:
adding new entry "uid=yusukew62,ou=People,dc=yusukew62,dc=net"

登録情報を確認

# ldapsearch  -x -b 'dc=yusukew62,dc=net' 'uid=yusukew62'
# extended LDIF
#
# LDAPv3
# base <dc=yusukew62,dc=net> with scope subtree
# filter: uid=yusukew62
# requesting: ALL
#

# yusukew62, People, yusukew62.net
dn: uid=yusukew62,ou=People,dc=yusukew62,dc=net
uid: yusukew62
cn: yusukew62
objectClass: account
objectClass: posixAccount
objectClass: top
objectClass: shadowAccount
shadowLastChange: 15862
shadowMin: 0
shadowMax: 99999
shadowWarning: 7
loginShell: /bin/bash
uidNumber: 1001
gidNumber: 1001
homeDirectory: /home/yusukew62

# search result
search: 2
result: 0 Success

# numResponses: 2
# numEntries: 1

LDAPクライアントの設定

# yum install nss-pam-ldapd

設定ファイルのバックアップ

# cp -p /etc/openldap/ldap.conf /etc/openldap/ldap.conf.org
# cp -p /etc/nslcd.conf /etc/nslcd.conf.org
# cp -p /etc/pam_ldap.conf /etc/pam_ldap.conf.org
# cp -p /etc/nsswitch.conf /etc/nsswitch.conf.org
# cp -p /etc/sysconfig/authconfig /etc/sysconfig/authconfig.org
# cp -p /etc/pam.d/system-auth /etc/pam.d/system-auth.org
# cp -p /etc/pam.d/password-auth /etc/pam.d/password-auth.org

authconfigでクライアント用のldap認証の設定を行う

# authconfig --enableldap --enableldapauth --ldapserver=192.168.1.22 --ldapbasedn="dc=yusukew62,dc=net" --update
nslcd を起動中:                                            [  OK  ]
# chkconfig nslcd on

system-authの設定

# diff -wu /etc/pam.d/system-auth.org /etc/pam.d/system-auth
--- /etc/pam.d/system-auth.org  2017-02-20 17:28:29.536331491 +0900
+++ /etc/pam.d/system-auth      2017-02-20 17:33:26.220331801 +0900
@@ -23,3 +23,4 @@
 session     [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid
 session     required      pam_unix.so
 session     optional      pam_ldap.so
+session     optional      pam_mkhomedir.so skel=/etc/skel umask=022

password-authの設定

# diff -wu /etc/pam.d/password-auth.org /etc/pam.d/password-auth
--- /etc/pam.d/password-auth.org        2017-02-20 17:28:29.543331491 +0900
+++ /etc/pam.d/password-auth    2017-02-20 17:31:31.989331604 +0900
@@ -23,3 +23,4 @@
 session     [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid
 session     required      pam_unix.so
 session     optional      pam_ldap.so
+session     optional      pam_mkhomedir.so skel=/etc/skel umask=022

authconfigのFORCELEGACYをyesに変更

# cp -p /etc/sysconfig/authconfig /etc/sysconfig/authconfig.20170220                                                                  
# vi /etc/sysconfig/authconfig

authconfigの設定

# diff -wu /etc/sysconfig/authconfig.20170220 /etc/sysconfig/authconfig
--- /etc/sysconfig/authconfig.20170220  2017-02-20 17:37:33.196851028 +0900
+++ /etc/sysconfig/authconfig   2017-02-20 17:38:05.709851633 +0900
@@ -7,7 +7,7 @@
 USEWINBIND=no
 USESSSD=no
 PASSWDALGORITHM=sha512
-FORCELEGACY=no
+FORCELEGACY=yes
 USEFPRINTD=no
 USEHESIOD=no
 FORCESMARTCARD=no

/var/lib/ldapと /etc/openldap のオーナー・グループを ldapにする

# chown -R ldap:ldap /var/lib/ldap/
# chown -R ldap:ldap /etc/openldap/

再起動して設定を反映

# shutdown -r now

SSH接続時のLDAP認証、ユーザ作成を確認

[wmba13@yusukew62 ~]$ ssh yusukew62@ldap2
yusukew62@ldap2's password:
Creating directory '/home/yusukew62'.
$ ls /home/yusukew62/
$ id yusukew62
uid=1001(yusukew62) gid=1001(yusukew62group) 所属グループ=1001(yusukew62group)

SASL認証

SASLの起動

# service saslauthd start

SASLの利用可能な認証方法を調べる

# saslauthd -v
saslauthd 2.1.23
authentication mechanisms: getpwent kerberos5 pam rimap shadow ldap  

自動起動を有効にする

# chkconfig saslauthd on

SASL認証ユーザを追加する
レルム(SASLのグループの役割)を yusukew62.net、ユーザ名を yusukew62 として作成

# saslpasswd2 -u yusukew62.net yusukew62

SASL認証ユーザを確認
ユーザ名@レルムの形式で誤りがないか確認

# sasldblistusers2
[email protected]: userPassword

SASLの変更を有効にする

# service saslauthd restart

phpldapadmin

epelリポジトリが有効の状態でyumからインストール

# yum install phpldapadmin

httpdのphpldapadmin.confのバックアップを行う

# cd /etc/httpd/conf.d
# cp -p phpldapadmin.conf phpldapadmin.conf.org

phpldapadminのアクセス許可を行う

# vi phpldapadmin.conf

設定を確認

# diff -wu phpldapadmin.conf.org phpldapadmin.conf
--- phpldapadmin.conf.org       2016-09-23 04:01:07.000000000 +0900
+++ phpldapadmin.conf   2017-02-20 20:08:07.134436253 +0900
@@ -8,7 +8,7 @@
 <Directory /usr/share/phpldapadmin/htdocs>
   Order Deny,Allow
   Deny from all
-  Allow from 127.0.0.1
+  Allow from 127.0.0.1 192.168.1.0/24
   Allow from ::1
 </Directory>

httpdを起動

# service httpd start

80ポートを開放

# cp -p /etc/sysconfig/iptables /etc/sysconfig/iptables.org
# vi /etc/sysconfig/iptables
# service iptables restart

Webブラウザから以下にアクセス

http://phpldapadminのIPアドレス/ldapadmin/index.php

phpldapadminの画面が表示されたら、ログインを押下し、ログインする

UserName: cn=Manager,dc=yusukew62,dc=net
Password: slapdの管理パスワード
Anonymous: checked

ログインできたことを確認

SSL対応

サーバの秘密鍵を作成

# openssl genrsa -rand /dev/urandom -des3 -out /etc/openldap/tmp/server.pem 2048
2048 semi-random bytes loaded
Generating RSA private key, 2048 bit long modulus
............+++
...................................+++
e is 65537 (0x10001)
Enter pass phrase for /etc/openldap/tmp/server.pem:
Verifying - Enter pass phrase for /etc/openldap/tmp/server.pem:

サーバの秘密鍵からパスフレーズを削除

# openssl rsa -in /etc/openldap/tmp/server.pem -out /etc/openldap/tmp/server.key
Enter pass phrase for /etc/openldap/tmp/server.pem:
writing RSA key
# chmod 400 /etc/openldap/tmp/server.key
# chown ldap:ldap /etc/openldap/tmp/server.key

サーバ証明書の作成

# openssl req -new -days 3650 -key /etc/openldap/tmp/server.key -out /etc/openldap/tmp/server.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:JP
State or Province Name (full name) []:Tokyo
Locality Name (eg, city) [Default City]:^C
[root@ldap2 ~]# openssl req -new -days 3650 -key /etc/openldap/tmp/server.key -out /etc/openldap/tmp/server.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:JP
State or Province Name (full name) []:Saitama
Locality Name (eg, city) [Default City]:Tokorozawa
Organization Name (eg, company) [Default Company Ltd]:Yusukew62
Organizational Unit Name (eg, section) []:Engineering
Common Name (eg, your name or your server's hostname) []:yusukew62
Email Address []:[email protected]

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:    
An optional company name []:
# chmod 444 /etc/openldap/tmp/server.csr
# chown ldap:ldap /etc/openldap/tmp/server.csr
# grep TLS /etc/openldap/slapd.conf
# The next three lines allow use of TLS for encrypting connections using a
# TLSCACertificatePath /etc/openldap/certs
# TLSCertificateFile "\"OpenLDAP Server\""
# TLSCertificateKeyFile /etc/openldap/certs/password
# TLSCACertificatePath /etc/openldap/cacerts/cacert.pem
TLSCertificateFile /etc/openldap/certs/server.csr
TLSCertificateKeyFile /etc/openldap/certs/server.key

鍵と証明書を設置パスへコピー

# cp -p /etc/openldap/tmp/server.csr /etc/openldap/certs/server.csr
# cp -p /etc/openldap/tmp/server.key /etc/openldap/certs/server.key

slapdの再起動

# service slapd restart
slapd を停止中:                                            [  OK  ]
slapd を起動中:                                            [  OK  ]

オレオレ証明書の妥当性を確認しないようldap.confに設定を追加

# diff -wu /etc/openldap/ldap.conf.20170220 /etc/openldap/ldap.conf
--- /etc/openldap/ldap.conf.20170220    2017-02-20 17:28:29.523331489 +0900
+++ /etc/openldap/ldap.conf     2017-02-20 18:00:27.729051955 +0900
@@ -15,3 +15,4 @@
 TLS_CACERTDIR /etc/openldap/cacerts
 URI ldap://192.168.1.22/
 BASE dc=yusukew62,dc=net
+TLS_REQCERT     never

slapdを再起動

# service slapd restart
slapd を停止中:                                            [  OK  ]
slapd を起動中:                                            [  OK  ]

バックアップを作成

# cp -p /etc/sysconfig/ldap /etc/sysconfig/ldap.org

/etc/sysconfig/ldap で起動時に ldapsで接続できるよう設定

# vi /etc/sysconfig/ldap

ldapの設定を確認

# diff -wu /etc/sysconfig/ldap.org /etc/sysconfig/ldap
--- /etc/sysconfig/ldap.org     2016-05-11 08:32:50.000000000 +0900
+++ /etc/sysconfig/ldap 2017-02-20 18:20:50.607050044 +0900
@@ -13,7 +13,7 @@

 # Run slapd with -h "... ldaps:/// ..."
 #   yes/no, default: no
-SLAPD_LDAPS=no
+SLAPD_LDAPS=yes

 # Run slapd with -h "... $SLAPD_URLS ..."
 # This option could be used instead of previous three ones, but:

slapdを再起動

# service slapd restart
slapd を停止中:                                            [  OK  ]
slapd を起動中:                                            [  OK  ]

ldapsで接続可能か確認

# ps -ef| grep -v grep | grep slapd
ldap       1977      1  0 18:21 ?        00:00:00 /usr/sbin/slapd -h  ldap:/// ldaps:/// ldapi:/// -u ldap

レプリケーション

syncrepl

マスターをプロバイダ、スレーブをコンシューマという

プロバイダ側の設定

cn=module,cn=configというエントリを作成し読み込むモジュールを定義する

# ldapadd -x -W -H 'ldap://ldap01.yusukew62.net' -D 'cn=Manager,dc=yusukew62,dc=net' -f syncprov-module.ldif
Enter LDAP Password:
adding new entry "cn=module,cn=config"
ldap_add: Insufficient access (50)

データベースの設定エントリの配下にプロバイダ設定用のエントリを追加

# ldapadd -x -W -H 'ldap://ldap01.yusukew62.net' -D 'cn=Manager,dc=yusukew62,dc=net' -f syncprov.ldif
Enter LDAP Password:
adding new entry "olcOverlay=syncprov,olcDatabase={2}bdb,cn=config"
ldap_add: Invalid syntax (21)
        additional info: objectClass: value #1 invalid per syntax

コンシューマ側の設定

プロバイダLDAPサーバと同様の設定をしておく(LDIFのインポートは不要)
以下は何も入れていないため空の状態

# ldapsearch -x -W -D 'cn=Manager,dc=yusukew62,dc=net' -b 'dc=yusukew62,dc=net'
Enter LDAP Password:
# extended LDIF
#
# LDAPv3
# base <dc=yusukew62,dc=net> with scope subtree
# filter: (objectclass=*)
# requesting: ALL
#

# search result
search: 2
result: 32 No such object

# numResponses: 1

プロバイダへの接続方法、同期方法、複製するデータに関する設定を行う
設定用のLDIFファイル

# cat syncrepl.ldif
dn: olcDatabase={2}bdb,cn=config
changetype: modify
add: olcSyncRepl
olcSyncRepl: rid=001
  provider=ldap://ldap01.yusukew62.net/
  bindmethod=simple
  binddn="cn=Manager,dc=yusukew62,dc=net"
  credentials=password
  type=refreshAndPersist
  interval=00:00:05:00
  searchbase="dc=yusukew62,dc=net"
  scope=sub
  retry="60 10 300 3"

ldapmodifyでエントリの更新

# ldapmodify -x -W -D 'cn=Manager,dc=yusukew62,dc=net' -f syncrepl.ldif
Enter LDAP Password:
modifying entry "olcDatabase={2}bdb,cn=config"
ldap_modify: Insufficient access (50)

デバッグ

ldapsで接続できない場合などは -d で詳細情報を表示する

# ldapsearch -x -d -1 -H "ldaps://localhost"
ldap_url_parse_ext(ldaps://localhost)
ldap_create
ldap_url_parse_ext(ldaps://localhost:636/??base)
ldap_sasl_bind
ldap_send_initial_request
ldap_new_connection 1 1 0
ldap_int_open_connection
ldap_connect_to_host: TCP localhost:636
ldap_new_socket: 3
ldap_prepare_socket: 3
ldap_connect_to_host: Trying ::1 636
ldap_pvt_connect: fd: 3 tm: -1 async: 0
attempting to connect:
connect success
TLS: certdb config: configDir='/etc/openldap/cacerts' tokenDescription='ldap(0)' certPrefix='' keyPrefix='' flags=readOnly
TLS: cannot open certdb '/etc/openldap/cacerts', error -8018:Unknown PKCS #11 error.
tls_write: want=137, written=137
  0000:  16 03 01 00 84 01 00 00  80 03 03 4e 4c 91 37 ec   ...........NL.7.
  0010:  bf 91 aa f1 5c b8 66 4c  ca 4c cd 84 17 60 89 f6   ....\.fL.L...`..
  0020:  ef 8a f0 9d 8f d0 38 57  f2 23 50 00 00 26 c0 0a   ......8W.#P..&..
  0030:  c0 14 00 39 00 6b 00 38  00 35 00 3d c0 09 c0 13   ...9.k.8.5.=....
  0040:  00 33 00 67 00 32 00 2f  00 3c 00 05 00 04 00 16   .3.g.2./.<......
  0050:  00 13 00 0a 01 00 00 31  ff 01 00 01 00 00 0a 00   .......1........
  0060:  08 00 06 00 17 00 18 00  19 00 0b 00 02 01 00 00   ................
  0070:  0d 00 16 00 14 04 01 05  01 06 01 02 01 04 03 05   ................
  0080:  03 06 03 02 03 04 02 02  02                        .........
tls_read: want=5, got=0

TLS: error: connect - force handshake failure: errno 0 - moznss error -5938
TLS: can't connect: TLS error -5938:Encountered end of file.
ldap_err2string
ldap_sasl_bind(SIMPLE): Can't contact LDAP server (-1)

参考

メモ

各設定ファイルの違いのメモ

用途 パス
/etc/openldap/slapd.conf LDAPサーバーとしての設定ファイル
/etc/openldap/ldap.conf ldapsearch を実行する際に -x のみを指定すると他に必要なパラメータはこのファイルから読みこまれる。
/etc/ldap.conf pam_ldap、nss_ldap から参照され、nsswitch.conf で 「ldap」 を設定すると、このファイルをみて処理される
/etc/nsswitch.conf 名前サービス(NSS)の解決順序を設定するファイル。NSSからLDAPを参照するように設定する。
/etc/pam_ldap.conf NSSが参照するLDAPサーバの設定を行う。接続先LDAPサーバなど。
/etc/pam.d/system-auth-ac pamがLDAPサーバを参照するように設定する。
/etc/nslcd.conf LDAPサーバーに問い合わせるデーモンの設定ファイル

リンク集

⚠️ **GitHub.com Fallback** ⚠️