仕事でopenLDAPを使うことになり、構築手順が謎だったので備忘録として書きます。
openLDAP2.3からConfiguration Backend方式になったらしく、不便だったのでconfでスキーマ情報を読み込みました。
#導入
以下CentOS7でやってます。
参考 http://qiita.com/kazukikudo/items/703d6e6664e13882fa0b
# yum -y install openldap openldap-clients openldap-servers
# cp -p /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG
# systemctl start slapd
# firewall-cmd --add-service=ldap --zone=public --permanent
# firewall-cmd --reload
ここまででLDAP起動完了です。
#slapd.conf作成
confファイルで管理するようにします。
参考http://takuti.hatenablog.com/entry/20110219/1298114658
まずはパスワードをハッシュ化する。
# slappasswd -s Hoge1234
{SSHA}HDattK3TiRAGNFiokxg7KYQD4OJbVGcv
confファイル作成
パスワードやdc等適宜変えてください。
# vi /etc/openldap/slapd.conf
include /etc/openldap/schema/corba.schema
include /etc/openldap/schema/core.schema
include /etc/openldap/schema/cosine.schema
include /etc/openldap/schema/duaconf.schema
include /etc/openldap/schema/dyngroup.schema
include /etc/openldap/schema/inetorgperson.schema
include /etc/openldap/schema/java.schema
include /etc/openldap/schema/misc.schema
include /etc/openldap/schema/nis.schema
include /etc/openldap/schema/openldap.schema
include /etc/openldap/schema/ppolicy.schema
include /etc/openldap/schema/collective.schema
allow bind_v2
pidfile /var/run/openldap/slapd.pid
argsfile /var/run/openldap/slapd.args
#######################################################################
# ldbm and/or bdb database definitions
#######################################################################
database bdb
suffix "dc=example,dc=com"
checkpoint 1024 15
rootdn "cn=Manager,dc=example,dc=com"
rootpw {SSHA}HDattK3TiRAGNFiokxg7KYQD4OJbVGcv
directory /var/lib/ldap
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
database monitor
access to *
by dn.exact="cn=Manager,dc=example,dc=com" read
by * none
access to attrs=userPassword
by self write
by dn="cn=Manager,dc=example,dc=com" write
by anonymous auth
by * none
access to *
by dn="cn=Manager,dc=example,dc=com" write
by self write
by * read
起動時に読み込むよう設定します。
# /usr/sbin/slapd -f /etc/openldap/slapd.conf
#設定を読み込んで起動
slapd.dの下を消して配置し直します。
参考http://qiita.com/gigatune/items/969b6b0015e09de930a8
まずはconfが動くかテストします。
# slaptest -f /etc/openldap/slapd.conf
そして、消して再配置します。
# rm -rf /etc/openldap/slapd.d/*
# slaptest -f /etc/openldap/slapd.conf -F /etc/openldap/slapd.d
# chown -R ldap. /etc/openldap/slapd.d
再起動
# systemctl restart slapd
これでLDAP自体は完了です。
includeで独自スキーマを読ませるなり好きに出来ます。
#エントリ追加
このままだと中身が無いので、とりあえず適当に入れてみます。
参考http://www.atmarkit.co.jp/flinux/rensai/linuxtips/907ldapentrie.html
# mkdir /home/.ldap_work
# vi /home/.ldap_work/entries.ldif
dn: dc=example,dc=com
objectClass: dcObject
objectClass: organization
dc: example
o: Example Corporation
description: The Example Corporation
dn: cn=Manager,dc=example,dc=com
objectClass: organizationalRole
cn: Manager
description: Directory Manager
そしてエントリ追加します。
-w 以下のパスワードは設定した値に変えます。
ldapadd -f /home/.ldap_work/entries.ldif -x -D "cn=Manager,dc=example,dc=com" -w Hoge1234
#GUIで中身を見る
今回はphpldapadminで中身を見ます。
クライアントツールでも中身は見ることが出来ます。
ログイン DNやパスワードは同様です。
まずは入れます。
remi-release-7.rpmがリポジトリ登録されているものとして進めます。
http://qiita.com/minechan1234/items/07f8055155c58b77220d
# yum -y install --enablerepo=remi,remi-php70 phpldapadmin
続いてconfを修正します。
# vi /etc/phpldapadmin/config.php
「:397」と入力すれば397行目に飛べます。
// $servers->setValue('login','attr','dn');
$servers->setValue('login','attr','uid');
を
$servers->setValue('login','attr','dn');
// $servers->setValue('login','attr','uid');
に変更(コメントアウトの入れ替え)
以下のconfも変更
# vi /etc/httpd/conf.d/phpldapadmin.conf
Require ipとAllowを追加します。
Require ipは許可するIPを指定してください。
許可されていないとForbiddenになります。
#
# Web-based tool for managing LDAP servers
#
Alias /phpldapadmin /usr/share/phpldapadmin/htdocs
Alias /ldapadmin /usr/share/phpldapadmin/htdocs
<Directory /usr/share/phpldapadmin/htdocs>
<IfModule mod_authz_core.c>
# Apache 2.4
Require local
Require ip 192.168.0.0/16
</IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
Allow from ::1
Allow from all
</IfModule>
</Directory>
httpd再起動
# systemctl restart httpd
ブラウザから http://localhost/phpldapadmin にアクセス出来れば成功です。
ログインDN : cn=Manager,dc=example,dc=com
パスワード : Hoge1234
以上です。