CentOS 5 で OpenLDAP によって LDAP ユーザーサービスを提供する

CentOS 5.3 で環境構築にあたってのメモ。

  • ベースDNは dc=tilfin,dc=local とする。
  • グループ tilfin とそれに属するユーザー tosshi を追加する。

openldap パッケージをインストール

# yum install openldap-clients
# yum install openldap-servers

/etc/openldap/slapd.conf の設定

suffix          "dc=tilfin,dc=local"
rootdn          "cn=Manager,dc=tilfin,dc=local"
rootpw          secret
パスワード属性に対する制限を追記
########################################################
#
# Set Permisson "userPassword"
#
access to attrs=userPassword
        by self write
        by anonymous auth
        by * none

#
# Set Permission except "userPassword"
#
access to *
        by self write
        by * read

DB パラメータの配置

# cd /var/lib/ldap
# cp /etc/openldap/DB_CONFIG.example DB_CONFIG
# chgrp ldap DB_CONFIG

認証方法の設定

# authconfig-tui

[LDAPを使用], [LDAP認証を使用] を選択し [Next]
Server URI ) ldap://127.0.0.1
Base DN ) dc=tilfin,dc=local

LDAP, NSCD サービスを自動起動するように設定する
# chkconfig ldap on
# chkconfig nscd on
LDAP, NSCD サービスを起動する
# service ldap start
# service nscd start

LDAP クライアントの設定

/etc/ldap.conf

base dc=tilfin,dc=local
uri ldap://127.0.0.1/

LDAP に情報を追加する

ドメイン, OU の People, Group を追加
dn: dc=tilfin,dc=local
dc: tilfin
objectClass: top
objectClass: domain

dn: ou=People,dc=tilfin,dc=local
objectClass: organizationalUnit
objectClass: top
ou: People

dn: ou=Group,dc=tilfin,dc=local
objectClass: organizationalUnit
objectClass: top
ou: Group

base.ldif として保存し、下記を実行する。

# ldapadd -x -w secret -D "cn=Manager,dc=tilfin,dc=local" -f base.ldif 
adding new entry "ou=People,dc=tilfin,dc=local"
adding new entry "ou=Group,dc=tilfin,dc=local"
グループ tilfin の追加
dn: cn=tilfin,ou=Group,dc=tilfin,dc=local
objectClass: posixGroup
objectClass: top
cn: tilfin
userPassword: {crypt}x
gidNumber: 1001

tilfin.ldif として保存し、下記を実行する。

# ldapadd -x -w secret -D "cn=Manager,dc=tilfin,dc=local" -f tilfin.ldif 
adding new entry "cn=tilfin,ou=Group,dc=tilfin,dc=local"
ユーザー tosshi の追加
dn: uid=tosshi,ou=People,dc=tilfin,dc=local
uid: tosshi
cn: Tosshi
objectClass: account
objectClass: posixAccount
objectClass: top
userPassword: {crypt}x
loginShell: /bin/bash
uidNumber: 1001
gidNumber: 1001
homeDirectory: /home/tosshi
gecos: Tosshi

user.ldif として保存し、下記を実行する。

# ldapadd -x -w secret -D "cn=Manager,dc=tilfin,dc=local" -f user.ldif 
adding new entry "uid=tosshi,ou=People,dc=tilfin,dc=local"

LDAP 情報の確認

$ ldapsearch -x
# extended LDIF
#
# LDAPv3
# base <> with scope subtree
# filter: (objectclass=*)
# requesting: ALL
#

# tilfin.local
dn: dc=tilfin,dc=local
dc: tilfin
objectClass: top
objectClass: domain

# People, tilfin.local
dn: ou=People,dc=tilfin,dc=local
objectClass: organizationalUnit
objectClass: top
ou: People

# Group, tilfin.local
dn: ou=Group,dc=tilfin,dc=local
objectClass: organizationalUnit
objectClass: top
ou: Group

# tilfin, Group, tilfin.local
dn: cn=tilfin,ou=Group,dc=tilfin,dc=local
objectClass: posixGroup
objectClass: top
cn: tilfin
gidNumber: 1001

# tosshi, People, tilfin.local
dn: uid=tosshi,ou=People,dc=tilfin,dc=local
uid: tosshi
cn: Tosshi
objectClass: account
objectClass: posixAccount
objectClass: top
loginShell: /bin/bash
uidNumber: 1001
gidNumber: 1001
homeDirectory: /home/tosshi
gecos: Tosshi

# search result
search: 2
result: 0 Success

# numResponses: 6
# numEntries: 5

root ユーザーのパスワードを暗号化する

ハッシュを生成する
# slappasswd -s rootpassword -h {SSHA}
{SSHA}xxxxxxxxxxxxxxxxxxxxxxxxxxxx
/etc/openldap/slapd.conf を修正する
rootpw  {SSHA}xxxxxxxxxxxxxxxxxxxxxxxxxxxx