CentOS 5.4でLDAPサーバーの構築
CentOS 5.4 に OpenLDAP を導入してLDAPサーバーとし、LDAPによる統合認証環境を構築する。
1. 要件と仮定
要件は以下の通り。
- 導入後のローカルユーザー認証をLDAPに対応させる。
- FTP、SSH、SambaをそれぞれLDAPに対応させる。それぞれの設定については別途。
- メール(Postfix)との連携は熟考の上、行わないことにした。
- Cyrus SASLを導入し、DIGEST-MD5認証に対応する。
便宜上、設定等について下記の通り仮定する。
- ベースDNは "dc=example,dc=jp" とする。
- 管理用DNは "cn=Manager,dc=example,dc=jp" とする。
- 管理用パスワードは "hogehoge" とする。
2. インストール
yumを使ってクライアントとサーバーをインストール。また、SASLを使う際に必要となる cyrus-sasl-md5 もあらかじめインストールしておく。
[root@localhost ~]# yum -y install openldap-clients openldap-servers [root@localhost ~]# yum -y install cyrus-sasl-md5
2009年12月15現在、yumでインストールした場合のバージョンは 2.3.43-3 だった。以降の手順の確認は本バージョンで行っており、以前・以降のバージョンでは異なる場合があるので注意してほしい。
3. 外部スキーマの入手
4. 設定
まず最初に /etc/openldap/slapd.conf の rootpw に設定するためのパスワードハッシュを生成する。パスワードハッシュの生成には slappasswd コマンドを使用する。
[root@localhost ~]# slappasswd
New password: (管理用パスワードを入力)
Re-enter new password: (管理用パスワードを入力)
{SSHA}dvh5ZlE+P+CgufnuQkBvTmM9yZaUZuit最後に出力された値をどこかにメモしておく。次に /etc/openldap/slapd.conf の編集に入る。rootpw は slappasswd コマンドから出力されたハッシュを指定すること。
[root@localhost ~]# vim /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
include /etc/openldap/schema/samba.schema
include /etc/openldap/schema/openssh-lpk_openldap.schema
allow bind_v2
pidfile /var/run/openldap/slapd.pid
argsfile /var/run/openldap/slapd.args
access to attrs=userPassword
by dn="cn=Manager,dc=example,dc=jp" write
by self write
by anonymous auth
by * none
access to attrs=SambaLMPassword
by dn="cn=Manager,dc=example,dc=jp" write
by self read
by anonymous auth
by * none
access to attrs=SambaNTPassword
by dn="cn=Manager,dc=example,dc=jp" write
by self read
by anonymous auth
by * none
access to *
by self write
by * read
database bdb
suffix "dc=example,dc=jp"
rootdn "cn=Manager,dc=example,dc=jp"
rootpw {SSHA}dvh5ZlE+P+CgufnuQkBvTmM9yZaUZuit
directory /var/lib/ldap
password-hash {CLEARTEXT}
sasl-host localhost
sasl-realm example.jp
authz-regexp
uid=([^,]+),(.+),cn=auth
uid=$1,ou=People,dc=example,dc=jp
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次に /etc/openldap/ldap.conf の編集を行う。このファイルにはLDAPクライアントが使用するパラメータを記述する。
[root@localhost ~]# vim /etc/openldap/ldap.conf BASE dc=example,dc=jp URI ladp://127.0.0.1/
最後にデータベース設定ファイルを設置する。/etc/openldap/DB_CONFIG.example に推奨設定ファイルがあるのでそれをそのままコピーすればよい。
[root@localhost ~]# cp /etc/openldap/DB_CONFIG.example /var/lib/ldap/DB_CONFIG [root@localhost ~]# chgrp ldap /var/lib/ldap/DB_CONFIG
5. サービスの起動
ここまで設定したらサービスを起動し、次回から起動時に実行されるように設定する。
[root@localhost ~]# service ldap start
slapd の設定ファイルをチェック中: config file testing succeeded
[ OK ]
slapd を起動中: [ OK ]
[root@localhost ~]# chkconfig ldap on"config file testing succeeded"と表示されない場合、設定ファイルに記述ミスがあるので確認して修正する。
6. エントリの登録
LDAPサーバーに基本的なエントリを登録する。まず、BASE.LDIFという名前のファイルを下記の通り作成する。
[root@localhost ~]# vim /etc/openldap/BASE.LDIF # domain dn: dc=example,dc=jp objectClass: dcObject objectClass: organization dc: example o: Example Inc. # Manager dn: cn=Manager,dc=example,dc=jp objectClass: organizationalRole cn: Manager description: Directory Manager # People dn: ou=People,dc=example,dc=jp objectClass: organizationalUnit ou: People # Group dn: ou=Group,dc=example,dc=jp objectClass: organizationalUnit ou: Group
作成した BASE.LDIF を使用して ldapadd を実行する。
[root@localhost ~]# ldapadd -x -W -D "cn=Manager,dc=example,dc=jp" -f /etc/openldap/BASE.LDIF Enter LDAP Password: (パスワードを入力) adding new entry "dc=example,dc=jp" adding new entry "cn=Manager,dc=example,dc=jp" adding new entry "ou=People,dc=example,dc=jp" adding new entry "ou=Group,dc=example,dc=jp"
7. クライアントの設定
ローカルユーザー認証をLDAPサーバーによって行う様に変更する。authconfig コマンドを下記の通り実行する。
[root@localhost ~]# authconfig --enableldap --enableldapauth --ldapserver=127.0.0.1 --ldapbasedn=dc=example,dc=jp --update
次に、初ログインの際に自動でホームディレクトリが作成されるようにする。/etc/pam.d/system-auth に下記の行を追加。
session required pam_mkhomedir.so skel=/etc/skel umask=0022
8. ユーザーアカウントの管理
今回はSambaとの連携を行うため、ユーザーアカウントの管理は smbldap-tools で行う。続けてSambaの構築を行う場合は以下の記事を参照。