- 论坛徽章:
- 0
|
源地址:http://nocaprince.appspot.com/?p=135002
Ldap优势
ldap是一种标准的目录访问协议。通过统一的schema的规定,不同的应用程序可以共同使用同一份数据而不需要做任何修改。通过ldap集中管理用户信息,管理员就可以通过一个统一的接口来管理所有的用户信息而不是为每个应用程序生成一份用户信息的冗余拷贝;用户则只需要记录一个用户名和口令就可以访问所有被授权的资源和应用程序。
Subversion和ldap集成方案概述
subversion本身并没有实现ldap验证的接口,而是通过apache来和ldap交互的。subversion通过dav的方式可以通过apache以标准的HTTP协议访问版本库;而apache通过ldap的标准接口验证用户来授权subversion对应的dav资源的访问。
环境安装
下面指令中会出现$base参数,这个是我们指定安装的目录,可以自己指定,我写了个简单的shell脚本,要指定一个公共的安装目录。
安装openldap
openldap后台依赖berkeleyDB,所以需要先安装berkeleyDB,再安装openldap。
该死的Oracle做的下载很恶心,必须要验证才能下,所以这里就假设大家已经下载好了bdb并命名为bdb.tar.gz
# install BerkelyDB for openldap
# while BerkeleyDB can not be download directly from internet for fucking autherization
# we assume there already exist one source package named 'bdb.tar.gz'
mkdir bdb
tar xvzf bdb.tar.gz -C bdb/ || exit
cd bdb/db-5.1.19/build_unix
../dist/configure --prefix=$base/bdb/ || exit
make || exit
make install || exit;
安装openldap
# install openldap
mkdir openldap
wget -c ftp://ftp.dti.ad.jp/pub/net/Open ... stable-20100719.tgz || exit
tar xvzf openldap-stable-20100719.tgz -C openldap || exit
cd openldap/openldap-2.4.23
CPPFLAGS=-I$base/bdb/include LDFLAGS=-L$base/bdb/lib LIBS=-ldb ./configure --prefix=$base/openldap || exit
make || exit
make install || exit;
安装apache
apache安装时要指明支持ldap,为此必须使用apr和apr-util。可以独立编译apr和apr-util,也可以指定—with-included-apr来编译apache内部的apr和par-util。我们就偷懒用内置的了。
# install apache
mkdir httpd
wget -c http://labs.renren.com/apache-mirror//httpd/httpd-2.2.17.tar.gz
tar xvzf httpd-2.2.17.tar.gz -C httpd || exit
cd httpd/httpd-2.2.17/
# here, we encounter the "APR-util version must be 1.2.0 or later" problem, while certainly we have already installed apr-util
# while I can't solve the apr-util version problem, but with --with-included-apr, I come over it and for simply, the apr and apr-util
# do not need installed independently, perfect!
./configure --prefix=$base/httpd --enable-so --enable-dav=share --enable-dav-fs --enable-ldap --enable-authnz-ldap --with-included-apr --with-ldap --with-ldap-include=$base/openldap/include --with-ldap-lib=$base/openldap/lib #--with-apr-util=$base/apr-util/bin/apu-1-config --with-apr=$base/apr/bin/apr-1-config --with-ldap || exit
make
make install;
安装subversion
subversion以来berkelyDB和sqlite,所以需要先安装sqlite。
安装sqlite:
# install sqlite for subversion
mkdir sqlite
wget -c http://www.sqlite.org/sqlite-autoconf-3070400.tar.gz || exit
tar xvzf sqlite-autoconf-3070400.tar.gz -C sqlite || exit
cd sqlite/sqlite-autoconf-3070400/
./configure --prefix=$base/sqlite || exit
make
make install;
安装subversion:
# install subversion mkdir subversion wget -c http://subversion.tigris.org/downloads/subversion-1.6.15.tar.gz || exit tar xvzf subversion-1.6.15.tar.gz -C subversion || exit cd subversion/subversion-1.6.15/# the apr and apr-util should use the bundled one from apache ./configure --prefix=$base/subversion --with-apxs=$base/httpd/bin/apxs --with-sqlite=$base/sqlite --with-apr=$base/httpd/bin/apr-1-config --with-apr-util=$base/httpd/bin/apu-1-config || exit make make install;
脚本
ldapsvn.sh
BerkeleyDB必须验证后才能下载,所以脚本假设文件已经下载到build目录下。其他源代码默认是从网上下载的,但鉴于下载速度,建议提前把已下载好的文件放在标准目录下。
系统配置
openldap配置
openldap服务器端服务为slapd,其读取配置文件slapd.conf,配置文件基本配置如下:
database bdb #指定数据存储方式,貌似还有个hdb的方式,没研究
suffix "dc=netease,dc=com" #指定目录的根前缀,所有目录都以该路径为前缀
rootdn "cn=Manager,dc=netease,dc=com" #指定管理员目录
rootpw {SSHA}JNGiKOEcFoyrOpIVxN9K64vyhd8KX9mR #指定管理员密码,该密码可由slappasswd命令生成
directory /home/eagle/software/var/openldap-data #指定数据存储路径
为支持用户信息验证,需要指定network information service对应的schema,配置信息如下:
include /path/to/openldap/etc/openldap/schema/cosine.schema
include /path/to/openldap/software/etc/openldap/schema/nis.schema
添加用户信息,ldap信息的添加使用ldapadd命令指定标准的ldif文件
添加用户根目录:
userou.ldif:
dn: ou=users, dc=netease, dc=com
ou: users
objectClass: top
objectClass: organizationalUnit
执行:
ldapadd -x -D "cn=Manager,dc=netease,dc=com" -w testproftpd -f userou.ldif
添加用户信息:
user.ldif:
dn: uid=eagle, ou=users, dc=netease, dc=com
cn: xiao yunpeng
uid: eagle
uidNumber: 100
gidNumber: 99
homeDirectory: /home/eagle
userPassword: {SSHA}XUmPUPcy/wmWcbZ42e4s1uYP0ChbplGc
loginShell: /bin/nologin
objectClass: posixAccount
objectClass: account
执行:
ldapadd -x -D "cn=Manager,dc=netease,dc=com" -w testproftpd -f user.ldif
为了确认哪些用户可以访问svn服务,我们添加一个svn用户组,指定可访问用户svn服务的用户
添加应用服务组根目录:
appgroupou.ldif:
dn: ou=appgroups, dc=netease, dc=com
ou: appgroups
objectClass: top
objectClass: organizationalUnit
执行:
ldapadd -x -D "cn=Manager,dc=netease,dc=com" -w testproftpd -f appgroupou.ldif
添加svn应用服务组:
svngroup.ldif
dn: cn=svngroup, ou=appgroups, dc=netease, dc=com
objectclass: posixGroup
cn: nobody
gidNumber: 101
memberUid: eagle
执行:
ldapadd -x -D "cn=Manager,dc=netease,dc=com" -w testproftpd -f svngroup.ldif
subversion配置
由于使用httpd访问subversion,所以subversion服务器基本不需要配置,唯一要做的就是使用svnadmin命令创建一个版本库:
svnadmin create /svndata/svnrepos
httpd配置
http配置主要配置三部分,使用dav方式访问subversion版本库,使用ldap验证用户信息,和使用authz文件授权路径。
配置如下:
LoadModule dav_svn_module modules/mod_dav_svn.so #此模块支持使用http协议通过dav方式访问subversion版本库
LoadModule authz_svn_module modules/mod_authz_svn.so #此模块支持使用subversion标准路径授权文件authz授权
# ldap模块由于编译时已指定,此处不需再加载
<Location /repos>
DAV svn #指定此路径为使用DAV方式访问svn
SVNParentPath /svndata #指定svn库的父路径,dav_svn模块支持访问多个svn版本库
SVNListParentPath on #是否显示所有的版本库
#SVNPath /svndata/repos #若只有一个版本库,那就直接配置此参数
SVNReposName "Netease subversion"
# authentication
AuthType Basic
AuthName "netease.com"
AuthBasicProvider ldap #指定使用ldap验证用户
#AuthLDAPBindDN "CN=Manager,DC=netease,DC=com"
#AuthLDAPBindPassword testproftpd #如果查询资源也需要授权,则指定此两个参数
AuthLDAPURL "ldap://localhost:389/ou=users,dc=netease,dc=com?uid?sub?(objectClass=posixAccount)"
# authorization
Require ldap-group cn=svngroup,ou=appgroups,dc=netease,dc=com #此授权仅为判断该用户是否可以访问svn服务
AuthLDAPGroupAttribute memberUid
AuthLDAPGroupAttributeIsDN off #默认验证用户是否为组成员为使用DN,而通常做法是使用用户名,将该参数置成off,则使用用户名验证
AuthzSVNAccessFile /path/to/svn/authfile/authz #指定路径授权文件
</Location>
多种验证方式
apache支持多种验证方式并存,如果你之前部署了基于文件的验证方式,那么最好的迁移方式是同时使用LDAP和FILE两种方式验证,优先使用LDAP,等你什么时候把文件用户迁移完,或者文件用户都无用之后,直接去除文件验证就OK了。我靠,什么叫强大,这就叫!
AuthBasicProvider ldap file #指定使用ldap和file方式验证用户,优先使用ldap用户
AuthUserFile /path/to/authuserfile/trac.passwd #指定验证文件
疑难问题:
apr-utils编译时要指定--with-ldap,否则编译httpd时会出错
svnserve和httpd是平等关系,他们支持不同的协议访问svn库
如何让mod_authz_svn支持mod_auth_ldap的用户组: http://www.thoughtspark.org/node/26 |
|