OpenLDAP

更新日2008-02-27 (水) 11:54:22 Vine4.xでOpenLDAPでlogin認証を行う

インストールおよびチェック

$ rpm -qa | grep openldap
openldap-2.3.27-0vl2.4
# apt-get install openldap-clients
# apt-get install openldap-servers

LDAPサーバー設定

ドメイン名の各ゾーン名部分を"dc=○○"という形式で記述

今回はism.comというゾーン名にする

Openldapのパスワードを作成

# /usr/sbin/slappasswd -s ****** -h {MD5}
{MD5}**********************==
# cd /etc/openldap

slapd.conf

#######################################################################
# ldbm and/or bdb database definitions
#######################################################################

database        bdb
##suffix                "dc=my-domain,dc=com"
suffix          "dc=ism,dc=com"              <==ゾーン名を変更
##rootdn                "cn=Manager,dc=my-domain,dc=com"
rootdn          "cn=Manager,dc=ism,dc=com"   <==ゾーン名を変更
# 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                  {MD5}**********************==   <=先のパスワードを記述

以下を最終行へ追加

## Edit By JE2ISM

access to attrs=userPassword
        by self write
        by dn="cn=Manager,dc=ism,dc=com" write
        by anonymous auth
        by * none

access to *
        by dn="cn=Manager,dc=ism,dc=com" write
        by self write
        by * read

LDAPクライアント設定

ldap.conf

#BASE   dc=example, dc=com
BASE   dc=ism, dc=com

##BASE dc=example,dc=com
BASE   dc=ism, dc=com

NSS_LDAPクライアント設定

NSSについて
いったんユーザが認証されてからも、多くのアプリケーションはユーザ情報へのアクセスを必要とします。この情報は伝統的にはテキストファイル (/etc/passwd, /etc/shadow, /etc/group) に入れられていますが、他のネームサービスによって供給することもできます。

新しいネームサービス (たとえば LDAP) が導入されるにつれ、このような情報取得の実装は、 (NIS や DNS のように) C ライブラリ内、または その新しいネームサービスを使いたいアプリケーション内の、 どちらでも可能となってしまいました。

いずれにしても、こういったことは、共通の汎用的なネームサービス API を使って、各テクノロジに基づく動作でサービスから情報を得る ライブラリ群にそれを要求することにすれば避けられます。

GNU C Library は Name Service Switch を実装して上記を解決しました。これは Sun C library に起源を持ち、共通の API を通して種々のネームサービスから情報を得られるようにする方法です。

NSS は共通の API と設定ファイル (/etc/nsswitch.conf) を使用します。この設定ファイル内で、サポートするデータベース毎に、そのサービスを提供するライブラリを指定します。

現在 NSS によってサポートされている データベースは

nss_ldap 共有ライブラリを使えば、LDAP を用いて上記の割り当てを実装することができます。ほんとうは上記すべての割り当てが実装できるのですけれども、ここでは shadow, passwd, group データベースの LDAP 実装にのみ焦点を合わせることにします。

/etc/ldap.conf

# The distinguished name of the search base.
##base dc=example,dc=com
base dc=ism,dc=com

LDAPサーバー起動

# /etc/rc.d/init.d/ldap start

既存ユーザ情報をLDAPサーバーへ移行

LDAPサーバー初期情報登録

ユーザ情報移行ツール設定ファイル編集

# cd /usr/share/openldap/migration/

migrate_common.ph

# Default base
##$DEFAULT_BASE = "dc=padl,dc=com";
$DEFAULT_BASE = "dc=ism,dc=com";

LDAPサーバー初期情報登録用ファイル新規作成

# cd
# emacs base.ldif

base.ldifファイル

dn: dc=ism,dc=com
objectClass: dcObject
objectclass: organization
o: ism Organization
dc: ism

dn: cn=manager, dc=ism,dc=com
objectclass: organizationalRole
cn:manager

dn: ou=People,dc=ism,dc=com
objectClass: organizationalUnit
ou: People

dn: ou=Group,dc=ism,dc=com
objectClass: organizationalUnit
ou: Group

LDAPサーバー初期情報登録

# ldapadd -h localhost -x -D "cn=manager,dc=ism,dc=com" -W -f base.ldif
Enter LDAP Password:*****
adding new entry "dc=ism,dc=com"

adding new entry "cn=manager, dc=ism,dc=com"

adding new entry "ou=People,dc=ism,dc=com"

adding new entry "ou=Group,dc=ism,dc=com"

既存ユーザ情報をLDAPサーバーへ登録

ユーザパスワードの書き出し

grep ":5[0-9][0-9]" /etc/passwd > passwd.fil

passwd.fil

okada:x:500:501:Okada:/home/okada:/bin/bash

ユーザ情報LDAPサーバー登録用ファイル作成

# /usr/share/openldap/migration/migrate_passwd.pl passwd.fil
dn: uid=okada,ou=People,dc=ism,dc=com
uid: okada
cn: Okada
objectClass: account
objectClass: posixAccount
objectClass: top
objectClass: shadowAccount
userPassword: {crypt}$1$****************************  <=shadowファイルのパスワ ードが入る。
shadowLastChange: 13798
shadowMax: 99999
shadowWarning: 7
loginShell: /bin/bash
uidNumber: 500
gidNumber: 501
homeDirectory: /home/okada
gecos: Okada
# /usr/share/openldap/migration/migrate_passwd.pl passwd.fil >passwd.ldfi

一般ユーザ情報をLDAPサーバーへ登録

# ldapadd -h localhost -x -D "cn=manager,dc=ism,dc=com" -W -f passwd.ldif
Enter LDAP Password:
adding new entry "uid=okada,ou=People,dc=ism,dc=com"

既存グループ情報をLDAPサーバーへ登録

ユーザグループ情報抽出

grep ":5[0-9][0-9]" /etc/group > group.fil

group.fil

okada:x:501:

ユーザグループ情報LDAPサーバー登録用ファイル作成

# /usr/share/openldap/migration/migrate_group.pl group.fil
dn: cn=okada,ou=Group,dc=ism,dc=com
objectClass: posixGroup
objectClass: top
cn: okada
userPassword: {crypt}x
gidNumber: 501
# /usr/share/openldap/migration/migrate_group.pl group.fil > group.ldfi

般ユーザグループ情報をLDAPサーバーへ登録

# ldapadd -h localhost -x -D "cn=manager,dc=ism,dc=com" -W -f group.ldfi
Enter LDAP Password:
adding new entry "cn=okada,ou=Group,dc=ism,dc=com"

ユーザ認証方式にLDAP認証を追加

LDAP を使用とLDAP 認証を使用にチェックを入れる

# authconfig 
authconfig 4.6.1 - (c) 1999-2003 Red Hat, Inc., (c) 2002-2004 Project Vine.


 --------------------- 認証の設定 ----------------------
 |                                                     |
 |  ユーザー情報         認証                          |
 |  [ ] キャッシュ情報   [*] MD5 パスワードを使用      |
 |  [ ] Hesiod を使用    [*] シャドウパスワードを使用  |
 |  [*] LDAP を使用      [*] LDAP 認証を使用           |
 |  [ ] NIS を使用       [ ] Kerberos 5 を使用         |
 |  [ ] Winbind の使用   [ ] SMB 認証を使用            |
 |                       [ ] Winbind 認証を使用        |
 |                                                     |
 |         ------------                ------          |
 |         | 取り消し |                | 次 |          |
 |         ------------                ------          |
 |                                                     |
 |                                                     |
 -------------------------------------------------------

次の画面でOK

authconfig 4.6.1 - (c) 1999-2003 Red Hat, Inc., (c) 2002-2004 Project Vine.


 ---------------------- LDAP設定 -----------------------
 |                                                     |
 |            [ ] TLSを使用                            |
 |    サーバ: 127.0.0.1_______________________________ |
 | ベース DN: dc=ism,dc=com___________________________ |
 |                                                     |
 |          --------                  ------           |
 |          | 戻る |                  | OK |           |
 |          --------                  ------           |
 |                                                     |
 |                                                     |
 -------------------------------------------------------

これで、/etc/passwdまたはopenldapのどちらかに登録されたユーザはログインできるようになる。

authconfigでLDAPが指定しているとldapが起動しない。ldapを起動してからauthconfigでLDAPを指定する必要があるようだ。またldapが起動されていない状況ではpasswdファイルにあるユーザもリモートからloginできない。
また、boot時openldapが起動しないことにより起動時system message busで起動が停止する

LDAPサーバー確認

LDAPサーバーでユーザ認証できることを確認するため、LDAPサーバー上のみに存在するユーザで、Linuxにログインできることを確認するために新しいユーザを登録し、それをopenldapに登録しuserdelコマンドで/etc/passwdファイルからそのユーザを削除し、loginできるか確認する

# /usr/sbin/adduser je2ism
# passwd je2ism
Changing password for user je2ism.
New password:******
Retype new password:*******
passwd: all authentication tokens updated successfully.
# grep je2ism /etc/passwd > passwd.fil
# /usr/share/openldap/migration/migrate_passwd.pl passwd.fil > passwd

.ldif

# ldapadd -h localhost -x -D "cn=manager,dc=ism,dc=com" -W -f passwd.ldif

Enter LDAP Password: adding new entry "uid=je2ism,ou=People,dc=ism,dc=com"

# grep je2ism /etc/group > group.fil
# /usr/share/openldap/migration/migrate_group.pl group.fil > group.ldif
# ldapadd -h localhost -x -D "cn=manager,dc=ism,dc=com" -W -f group.ldif
Enter LDAP Password:
adding new entry "cn=je2ism,ou=Group,dc=ism,dc=com"

/etc/passwdのje2ismを削除

# /usr/sbin/userdel je2ism

これで、je2ismでloginできたらOK

ldapユーザ・グループの削除

# ldapdelete -h localhost -x -D 'cn=manager,dc=ism,dc=com' - W "uid=je2ism,ou=people,dc=ism,dc=com"
Enter LDAP Password:
# ldapdelete -h localhost -x -D 'cn=manager,dc=ism,dc=com' -W "cn=je2ism,ou=group,dc=ism,dc=com"
Enter LDAP Password:

ユーザの検索

uid=*もOK

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

# je2ism, People, ism.com
dn: uid=je2ism,ou=People,dc=ism,dc=com
uid: je2ism
cn: je2ism
objectClass: account
objectClass: posixAccount
objectClass: top
objectClass: shadowAccount
shadowLastChange: 13901
shadowMax: 99999
shadowWarning: 7
loginShell: /bin/bash
uidNumber: 501
gidNumber: 502
homeDirectory: /home/je2ism

# search result
search: 2
result: 0 Success

# numResponses: 2
# numEntries: 1

トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS