■ OpenLDAP クライアント設定 (pam_ldapモジュール) 2010/03/11 更新
GUIツール 「system-config-authentication」 でLDAPの設定を行うと /etc/ldap.conf、/etc/openldap/ldap.con の2つのファイルが変更されます。 両者の違いは以下の通りです。 ややこしいですね。
/etc/ldap.conf pam_ldap、nss_ldap から利用されるファイルです。
nsswitch.conf で 「ldap」 を設定すると、このファイルの内容に従って処理が行われます。
/etc/openldap/ldap.conf OpenLDAPに付いている、LDAPコマンドを実行するときに参照されるファイルです。
 例えば、ldapsearch コマンドを実行する際に -x のみを指定すると、他に必要なパラメータはこのファイルから読みこまれます。 ldapsearch はLDAPサーバとの接続性を確認するものであって、正しくLDAPの情報が参照できても、PAM認証が正常に働くといったものではありません。
設定ポリシー
  1. PAM認証にLDAPを含める。
  2. LDAPサーバは2台を設定し冗長化を図る。 1秒以内にマスタサーバに接続できない場合、スレーブサーバに接続する。
  3. LDAPクライアントからのパスワード変更は許可しない。
設定手順
  1. ldap.conf の編集
    # vi /etc/ldap.conf

    # grep -v ^# /etc/proftpd.conf | grep -v ^$ (コメント行は削除して表示。説明のため一部加工)
    緑:デフォルト、オレンジ:変更箇所
     
    base o=****,dc=co,dc=jp ※1

    uri ldap://192.168.100.10/ ldap://192.168.100.20/ ※2
    host 192.168.100.10 192.168.100.20 ※2

    binddn cn=****,o=****,dc=co,dc=jp ※3
    bindpw ******** ※4

    #bind_timelimit 120
    bind_timelimit 1 ※5
    timelimit 120 ※6
    idle_timelimit 3600 ※7

    nss_initgroups_ignoreusers root,ldap,named,avahi,haldaemon,dbus,radvd
                               ,tomcat,radiusd,news,mailman,nscd,gdm ※8

    ssl no
    tls_cacertdir /etc/openldap/cacerts
    #pam_password md5
    pam_password clear ※9
    ※1 検索するディレクトリツリー
    ※2 LDAPサーバをスペース区切りで記載 ( uri でも host でもどちらで書いても良い)
    ※3 LDAPサーバに問い合わせをするためのユーザ
    ※4 そのパスワード
    ※5 LDAPサーバへの接続タイムアウト値 (この時間内に接続できない場合、次のサーバに接続を試みる。)
    ※6 情報検索のタイムアウト値
    ※7 LDAPサーバとの無通信タイムアウト値
    ※8 LDAPサーバに照会を行わないユーザを列挙する。
    ※9 このLDAPクライアントから、LDAPサーバ上のユーザパスワードを変更させたくない場合、「clear」 を記述する。
     
  2. PAMの設定ファイルの編集
    # vi /etc/pam.d/system-auth
    緑:デフォルト、オレンジ:変更箇所
     
    #%PAM-1.0
    # This file is auto-generated.
    # User changes will be destroyed the next time authconfig is run.
    auth required pam_env.so
    auth sufficient pam_unix.so nullok try_first_pass
    auth requisite pam_succeed_if.so uid >= 500 quiet
    auth sufficient pam_ldap.so use_first_pass
    auth required pam_deny.so

    account required pam_unix.so broken_shadow
    account sufficient pam_succeed_if.so uid < 500 quiet
    account [default=bad success=ok user_unknown=ignore] pam_ldap.so
    account required pam_permit.so

    password requisite pam_cracklib.so try_first_pass retry=3
    password sufficient pam_unix.so md5 shadow nullok try_first_pass use_authtok
    password sufficient pam_ldap.so use_authtok
    password required pam_deny.so

    session optional pam_keyinit.so revoke
    session required pam_limits.so
    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
     
  3. nsswitch.conf の編集
    # vi /etc/pam.d/system-auth
    緑:デフォルト、オレンジ:変更箇所
     
     :
    省略
     :
    passwd: files ldap
    shadow: files ldap
    group: files ldap
    ログイン認証であれば、passwd、shadow、groupに ldap を追加しておけば良いでしょう。
 

 ■ LDAP関連その他 2010/03/05 更新
LDAPに関するちょっとメモ
設定手順
  1. OpenLDAPデータベースの検索
    # ldapsearch -h 192.168.10.20 -x -D 'cn=aaa,dc=bbbb,dc=or,dc=jp' -w パスワード \
      -b 'cn=Users,dc=xxxx,dc=or,dc=jp' UserName

    # ldapsearch -x
    よく使うと思うオプション
    -h 192.168.10.20 LDAPサーバのアドレスorホスト名
    -x 簡易認証を行うことを明示
    -D 'cn=aaa,dc=bbbb,dc=or,dc=jp' バインドDNの指定
    -w パスワード バインドDNのパスワード
    -b 'cn=Users,dc=xxxx,dc=or,dc=jp' ベースDN(検索する場所)
    UserName 検索したいアトリビュート(属性)
    ldapsearch が参照する設定ファイルは、/etc/openldap/ldap.conf です。 なぜ、/etc/ldap.conf ではないのか?
    それは、ldapsearch が OpenLDAP のコマンドだからです。 記述されている内容は似ていますが、pam_ldap が参照する  /etc/ldap.conf はここでは使用されません。 ややこしいです。
     
  2. 認証情報の表示
    # getent passwd
    # getent group
    # getent shadow
    # id -a ユーザ名
    それぞれ実行すると、nsswitch.conf に設定した認証システム (files,ldap,nis,winbindなど) を参照し情報を表示します。
    id コマンドでも、認証システムに接続しユーザ名、グループ名を取得します。
     
  3. /etc/ldap.conf のパーミッションをデフォルトの "644" から "700" にすると・・・
    Last login: Wed Jan 6 10:52:10 2010 from 192.168.1.199
    id: cannot find name for user ID 1001
    $
    $ id
    id: ldap-nss.c:1319: do_init: Assertion `cfg->ldc_uris[__session.ls_current_uri] !=
    ((void *)0)' が失敗しました.
    uid=1001 gid=1001アボートしました
    $
    $ ls -l
    id: ldap-nss.c:1319: do_init: Assertion `cfg->ldc_uris[__session.ls_current_uri] !=
    ((void *)0)' が失敗しました.
    uid=1001 gid=1001アボートしました
    $
     こんな感じでエラーになります。 ログイン中のユーザ権限で ldap.conf の設定を参照して、LDAPサーバにアクセスしているようです。 ldap.conf にバインドDNのパスワードを書いているからといって、パーミッションを 600 にしてしまうとこんなことに・・・。
     正しくは、LDAPサーバ側でanonymous参照できるアトリビュートを制限して、ldap.conf にはパスワードを記載しないのがよろしいらしいです。