よりどエライ昔から個人的に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で統合してまえばええ思うで。
きょうびのコメント
I would li
続きを読む
えーじはん> どーも
続きを読む
どうもご無沙汰してま
続きを読む
Make Stamp
続きを読む
Tomo> あり?目
続きを読む