以前から個人的にLDAPを導入しているのですが、意外と忘れがちなので備忘をかねてメモります。

昔のメモなので今と挙動が違うかもしれませんがご了承ください。OSはCentOS 5です。

まずはOpen LDAPのインストールと設定をします。

関連パッケージのインストール

$ yum -y install openldap openldap-servers openldap-clients openldap-devel


ディレクトリマネージャのパスワードを生成する

$ /usr/sbin/slappasswd -h {SSHA}
New password:
Re-enter new password:

slapd.confの設定

/etc/openldap/slapd.conf
...snip...

access to attrs=userPassword
 by self write
 by anonymous auth
 by * none
access to *
 by self write
 by * read

...snip...

suffix      "dc=example,dc=com"
rootdn      "cn=Manager,dc=example,dc=com"

...snip...

rootpw さっき作ったパスワード

...snip...

ldapd.confの設定

/etc/openldap/ldap.conf
...snip...

URI ldap://127.0.0.1/

...snip...

slapdの起動と自動起動設定

$ /etc/init.d/ldap start
$ /sbin/chkconfig ldap on

既存アカウントの移行をします

移行ツールの設定

/usr/share/openldap/migration/migrate_common.ph
-- snip --
# Default base
$DEFAULT_BASE = "dc=example,dc=com";
-- snip --

base, passwd, groupをエクスポート

$ /usr/share/openldap/migration/migrate_base.pl > base.ldif
$ /usr/share/openldap/migration/migrate_group.pl /etc/group > group.ldif
$ /usr/share/openldap/migration/migrate_passwd.pl /etc/passwd > passwd.ldif

適当に整形してLDAPサーバに挿入

$ ldapadd -h localhost -x -D "cn=Manager,dc=example,dc=com" -W -f base.ldif
$ ldapadd -h localhost -x -D "cn=Manager,dc=example,dc=com" -W -f passwd.ldif
$ ldapadd -h localhost -x -D "cn=Manager,dc=example,dc=com" -W -f group.ldif

確認

$ ldapsearch -x -D "cn=Manager,dc=example,dc=com" -W -b "dc=example,dc=com" "uid=hide"
Enter LDAP Password:
# extended LDIF
#
# LDAPv3
# base <dc=example,dc=com> with scope subtree
# filter: uid=hide
# requesting: ALL
#

# hide, People, example.com
dn: uid=hide,ou=People,dc=example,dc=com
uid: hide
cn: hide
objectClass: account
objectClass: posixAccount
objectClass: top
objectClass: shadowAccount
--snip--

PAM認証先をLDAPに向けます

関連パッケージのインストール

$ yum -y install nss_ldap nscd

nscd(ネームサービス)の起動と自動起動の設定

$ /etc/init.d/nscd start
$ /sbin/chkconfig nscd on

認証をLDAPに向ける

$ /usr/sbin/authconfig-tui

            │  ユーザー情報         認証                          │
            │  [*] キャッシュ情報   [*] MD5 パスワードを使用      │
            │  [ ] Hesiod を使用    [*] シャドウパスワードを使用  │
            │  [*] LDAP を使用      [*] LDAP 認証を使用           │
            │  [ ] NIS を使用       [ ] Kerberos 5 を使用         │
            │  [ ] Winbind を使用   [ ] SMB 認証を使用            │
            │                       [ ] Winbind 認証を使用        │
            │                       [ ] ローカル認証は十分です    │
            │                                                     │

...次へ...

            │                                                     │
            │            [ ] TLS を使用                           │
            │  サーバー: ldap://127.0.0.1/_______________________ │
            │ ベース DN: dc=example,dc=com______________________ │
            │                                                     │

...OK...

LDAPサーバが落ちていてもローカルで認証できるようにする

/etc/ldap.conf
--snip--
#bind_policy hard
bind_policy soft
--snip--

最初のログインで自動的にホームディレクトリをスケルトンから作るようにする

/etc/pam.d/system-auth-ac
--snip--
session     required      pam_mkhomedir.so skel=/etc/skel umask=0022

ちなみに、システム認証をLDAPに依存する以上、slapdが落ちたら一般アカウントでのログインが出来なくなります。また、通常rootアカウントでのsshのアクセスは認められていないので、コンソールからログインしてslapdを立ち上げる必要があります。

次にWebDAV経由でのSubversionの認証をLDAPに向けます

mod_authz_ldapのインストール

$ yum install mod_authz_ldap

mod_dav_svnの設定

認証はLDAPでdevグループにのみ閲覧・変更権限を与える

/etc/httpd/conf.d/subversion.conf
LoadModule dav_svn_module     modules/mod_dav_svn.so
LoadModule authz_svn_module   modules/mod_authz_svn.so

LDAPTrustedGlobalCert CA_DER /etc/pki/tls/certs/ca-bundle.crt
LDAPVerifyServerCert Off

  DAV svn
  SVNParentPath /var/repos

  AuthType Basic
  AuthName "subversion authentication"
  AuthBasicProvider ldap
  AuthLDAPGroupAttributeIsDN off
  AuthLDAPGroupAttribute memberUid
  AuthLDAPURL ldaps://localhost/dc=example,dc=com?uid?sub?(ObjectClass=*)

  Require ldap-group cn=dev,ou=Group,dc=example,dc=com

Auth*の部分は普通のhtaccessとして使えます。

次にTracの設定です。

LdapPluginのインストール

 
$ svn export http://trac-hacks.org/svn/ldapplugin/0.10/ ldapplugin
$ cd ldapplugin
$ python setup.py install

trac.iniの設定

/var/trac/conf/trac.ini
... snip ...
[components]
trac.ticket.report.* = disable
ldapplugin.* = enabled

[ldap]
enable = true
host = 127.0.0.1
port = 389
basedn = dc=example,dc=com
user_rdn = ou=People
uidattr = uid
group_rdn = ou=Group
groupmemberisdn = false
groupname = posixGroup
groupmember = memberUid
manage_groups = true
store_bind = true
bind_user = cn=Manager,dc=example,dc=com
bind_passwd = リポジトリマネージャのパスワード
... snip ...

mod_pythonの設定

/etc/httpd/conf.d/trac.conf
###
### Sample Trac configuration taken from http://trac.edgewall.org/wiki/TracModPython
###

### The recommended Trac web interface requires mod_python


### Create your Trac environments as subdirectories of /var/trac
### They will appear in a listing on your website at /trac/, and be available
### at /trac/PROJECTNAME/

  SetHandler mod_python
  PythonInterpreter main_interpreter
  PythonHandler trac.web.modpython_frontend
  PythonOption TracEnvParentDir /var/trac
  PythonOption TracUriRoot /trac


### Use htpasswd to add Trac accounts to the AuthUserFile
LDAPTrustedGlobalCert CA_DER /etc/pki/tls/certs/ca-bundle.crt
LDAPVerifyServerCert Off

   AuthType Basic
   AuthName "trac"
   AuthBasicProvider ldap
   AuthLDAPURL ldaps://127.0.0.1/dc=example,dc=com?uid?sub?(ObjectClass=*)
   AuthLDAPGroupAttribute memberUid
   AuthLDAPGroupAttributeIsDN off
   Require ldap-filter objectCLass=posixAccount




再起動

/etc/init.d/httpd restart

LDAPスキーマの追加

/etc/openldap/schema/trac.schemaを追加

/etc/openldap/schema/trac.schema
# 1.3.6.1.4.1.15527 is reserved. Do not hijack it
# Please see http://www.iana.org/cgi-bin/enterprise.pl

# Attribute type definitions
attributetype ( 1.3.6.1.4.1.15527.143
                NAME 'tracperm'
                DESC 'Trac Permission'
                EQUALITY caseIgnoreMatch
                SUBSTR caseIgnoreSubstringsMatch
                SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32} )

# Class definitions
objectclass ( 1.3.6.1.4.1.15527.8
              NAME 'tracUser'
              DESC 'Regular user with Trac permission'
              SUP top
              AUXILIARY
              MUST ( uid $ cn $ userpassword )
              MAY  ( tracperm $ sn $ description ) )
objectclass ( 1.3.6.1.4.1.15527.9
              NAME 'tracGroup'
              DESC 'Trac permission for groupofnames'
              SUP top
              AUXILIARY
              MAY  ( tracperm ) )

/etc/openldap/slapd.confを編集

/etc/openldap/slapd.conf
...snip...
include     /etc/openldap/schema/trac.schema
...snip...

slapdの再起動

$ /etc/init.d/ldap restart

tracの権限を与えるGroupのObjectClassにtracGroupを追加する

権限を与える

tracのホストで
$ trac-admin /var/trac/dev permission add @dev TRAC_ADMIN

これでLDAPのdevグループに参加しているユーザーでTracにログインすると管理画面からLDAPのグループやユーザーに対して権限をマッピングすることができるようになります。

個人的にはアプリケーション間でさえOpenIDだーなんだーとSSO化されてるのだから社内ツールなんかは全てLDAPで統合してしまえばいいと思います。

              

              

トラックバック(0)

トラックバックURL: http://mt.hide-k.net/mt-tb.cgi/803

コメントする

プロフィール

このブログ記事について

このページは、hideが2009年9月28日 20:46に書いたブログ記事です。

ひとつ前のブログ記事は「ザ・テレビ欄 1975~1990」です。

次のブログ記事は「LIVE AT PACHA IBIZA mixed by sugiurumn&DJ EMMA」です。

最近のコンテンツはインデックスページで見られます。過去に書かれたものはアーカイブのページで見られます。