阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

基于SSL和LDAP的SVN工具安装指南

178次阅读
没有评论

共计 13075 个字符,预计需要花费 33 分钟才能阅读完成。

为了提升账户管理的便捷和安全性,公司在本人的建议下决定从 NIS 升级到 LDAP。研究了 2 个星期,终于完成了 LDAP 服务器的搭建,并和 SVN 整合了起来。期间查找了很多资料,但多半无用,居然没有一个文档是可以完整搭建成功的。一时感慨,资料泛滥的年代,能找出几个像样的还真不容易。因此,贴出最近搭建的完整步骤,期望能给需要的人士一些帮助。有问题的地方,还请大家多多指教。

1安装准备

lneon-0.29.6.tar.tar

下载地址:http://www.webdav.org/neon/

lapr-1.4.6.tar.gz

下载地址:http://apr.apache.org/download.cgi

lapr-util-1.4.1.tar.gz

下载地址:http://apr.apache.org/download.cgi

lopenssl-1.0.0g.tar

下载地址:http://openssl.org.com

lserf-0.3.0.tar.bz2

下载地址:http://serf.googlecode.com/

lhttpd-2.2.22.tar

下载地址:http://httpd.apache.org/download.cgi

lsubversion-1.6.18.tar.gz、subversion-deps-1.6.18.tar.gz

下载地址:www.subversion.org.cn

Subversion英文版安装说明:http://svn.collab.net/repos/svn/trunk/INSTALL

l 配置环境

操作系统版本:RHEL x86_64 AS 4.6(5.8 也测试通过)

LDAP 服务器版本:Red_Hat_Diretory_Server-8.0

l 说明

neon、serf、apr、apr-util 具体功能就不阐述了,全部是 subversion 需要的,其实 subversion 本身的源码包里面有,不过在某些情况下使用自己下载的会更好一些,这是我使用别的工具和 SVN 集成后发现的,使用自带的包无法编译,因此,建议使用上面的版本。换而言之,这些版本是经过测试能够完美整合的。

2安装步骤

2.1卸载系统自带的httpd,apr,apr-util

非常重要,如果不卸载,apache 将无法编译安装。

# yum remove httpd apr apr-util

或者

# rpm -e –allmatches apr-{version}

# rpm -e apr-util-{version}

# rpm -e httpd

 

以下安装步骤都不做累述,源码包的安装是基本常识,查看安装包的 INSTALL 文件,按部就班即可。

2.2安装 APRAPR-util

# tar xzvf APR-1.4.6.tar.gz

# cd apr-1.4.6

# ./configure –prefix=/usr/local/apr

# make

# make install

 

# tar xzvf APR-util-1.4.1.tar.gz

# cd apr-util-1.4.1

#./configure –prefix=/usr/local/apr-util –with-apr=/usr/local/apr

# make

# make install

2.3安装openssl

 

# tar zxvfopenssl-1.0.0g.tar.gz

# cd openssl-1.0.0g

#./config –shared

# make

# make test

# make install

# echo /usr/local/ssl/lib >> /etc/ld.so.conf

# ldconfig

2.4安装apache

# tar xzvf httpd-2.2.22.tar.gz

# cd httpd-2.2.22

#./configure \

–prefix=/usr/local/apache2 \

–enable-so \

–enable-rewrite=share \

–enable-proxy=share \

–enable-proxy-ajp=share \

–enable-dav=share \

–enable-dav-fs \

–enable-mods-shared=all \

–enable-ssl=static \

–enable-ldap \

–enable-authnz-ldap \

–with-ldap \

–with-included-apr \

–with-apr=/usr/local/apr \

–with-apr-util=/usr/local/apr-util/ \

–with-ssl=/usr/local/ssl/

# make

# make install

2.5安装subversion

 

# tar xzvf subversion-1.6.18.tar.gz

# tar xzvf subversion-deps-1.6.18.tar.gz

# tar xzvf neon-0.29.6.tar.gz

# tar xjvf serf-0.3.0.tar.bz2

# cd subversion-1.6.18

# rm -rf apr apr-util neon serf

# cp -ar ../neon-0.29.6 neon

# cp -ar ../serf-0.3.0 serf

# chown -R 1000:users neon serf

# ./configure \

–prefix=/usr/local/subversion \

–with-apxs=/usr/local/apache2/bin/apxs \

–with-ssl \

–with-apr=/usr/local/apr \

–with-apr-util=/usr/local/apr-util \

–with-zlib=/usr/lib64

# make && make install

 

 

装完之后执行 /usr/local/subversion/bin/svn –version 检查是否出现以下信息:

svn, version1.6.18 (r1303927)

compiled Aug 22 2012, 10:32:42

 

Copyright (C)2000-2009 CollabNet.

Subversion is opensource software, see http://subversion.apache.org/

This productincludes software developed by CollabNet (http://www.Collab.Net/).

 

The followingrepository access (RA) modules are available:

 

* ra_neon : Modulefor accessing a repository via WebDAV protocol using Neon.

– handles ‘http’scheme 支持http

– handles ‘https’scheme 支持https

* ra_svn : Modulefor accessing a repository using the svn network protocol.

– with Cyrus SASL authentication

– handles ‘svn’ scheme

* ra_local :Module for accessing a repository on local disk.

– handles ‘file’ scheme

推荐阅读

Linux 中 Subversion 配置实例 http://www.linuxidc.com/Linux/2012-02/53109.htm

CentOS 6.2 SVN 搭建 (YUM 安装) http://www.linuxidc.com/Linux/2013-10/91903.htm

Apache+SVN 搭建 SVN 服务器 http://www.linuxidc.com/Linux/2013-03/81379.htm

Windows 下 SVN 服务器搭建和使用 + 客户端重新设置密码 http://www.linuxidc.com/Linux/2013-05/85189p5.htm

Ubuntu Server 12.04 安装 SVN 并迁移 Virtual SVN 数据 http://www.linuxidc.com/Linux/2013-05/84695.htm

Ubuntu Server 搭建 svn 服务以及迁移方法 http://www.linuxidc.com/Linux/2013-05/84693.htm

借助网盘搭建 SVN 服务器 http://www.linuxidc.com/Linux/2013-10/91271.htm

3制作证书

# mkdir /usr/local/apache2/conf/crt; cd /usr/local/apache2/conf/crt

# openssl genrsa -out server-dsa.key 1024

# openssl req -new -x509 -days3650 -key server-dsa.key -out server-dsa.crt

//httpd-ssl-conf 中需指定这两个文件的存放位置

 

4配置apache for svn

4.1修改 apache 配置文件(本地认证)

# vi /usr/local/apache2/conf/httpd.conf //取消如下内容的注释

Include conf/extra/httpd-ssl.conf

 

在配置文件末尾添加如下内容

<Location /svn>

DAV svn

SVNParentPath /home/subversion/project

AuthType Basic

AuthName “Subversion repository”

AuthUserFile /home/subversion/passwd

AuthzSVNAccessFile /home/subversion/auth

Require valid-user

</Location>

其中:

SVNParentPath后面跟的是 ( 此处配置你的版本库根目录 ). 在这里 , 版本库根目录假设为/home/subversion/project

AuthName 后面跟的(是提示对话框标题)

AuthUserFile 跟的是(访问版本库用户的文件,须用 apache htpasswd命令生成)

AuthzSVNAccessFile后面跟的是(访问版本库权限的文件)

4.2修改 httpd-ssl.conf 文件

# vi /usr/local/apache2/conf/extra/httpd-ssl.conf

改三个地方

1SSLCertificateFile”/usr/local/apache2/conf/crt/server-dsa.crt” //指定到生成的证书

2SSLCertificateKeyFile”/usr/local/apache2/conf/crt/server-dsa.key” //指定到生成的证书

3SSLCACertificatePath”/usr/local/apache2/conf/crt

 

5建库

重启 web 服务

/usr/local/apache2/bin/apachectl restart

 

5.1建立版本仓库

假设版本仓库的根目录为/home/subversion/projecrt

所以,先创建这个目录 mkdir -p /home/subversion/project

根目录创建完毕,下面我们创建一个叫 data 的仓库。 /usr/local/subversion/bin/svnadmincreate /home/subversion/project/data

注意命令的全路径。如果仅仅敲 svnadmin 将会用到系统自带的svn,会有报错信息。

查看 data 文件夹会发现多了一些像 conf,dav 等这类的文件 , 说明建库成功(注意:创建仓库的路径中,路径目录必须为所有人可读,否则采用 svn 客户端访问仓库时会失败。

# mkdir -p /home/subversion/project/data/dav/activities.d

# chown -R o+w /home/subversion/project/data/

5.2建立可以访问 Subversion 的用户

#/usr/local/apache2/bin/htpasswd -cm /home/subversion/passwd test1

这时系统会提示你要求你输入密码,以及确认密码,输入即可,创建的用户就是 Subversion 的用户。但是,仅仅是创建了用户还是不行的,必须得给他授权才可以。

先在根目录创建授权文件。(注意:htpasswd -cm命令生成用户密码时会将 passwd 文件中原有的密码给覆盖掉,因此,如果创建多个用户,需要将 -cm 参数后边的文件指定到一个临时文件,然后将临时文件中的内容 cppasswd文件

#vi /home/subversion/auth

输入如下内容:

[data:/] 指的是访问 data 仓库(可以具体到下面的子目录)

test1=rw test1有读和写权限

test2=r test2有只读的权限,只读权限的设置不能为ro

还可以细化用户的详细目录路径:

[data:/trunk/FrontEnd/code]

test2=rw

结合上面对 user1 权限的设置,综合权限的结果是:test2/data 仓库有读取权限,没有写权限,但是对 /data 仓库下的 /data/trunk/FrontEnd/code 目录有读取和写的权限。

# su – test1

$ mkdir -p test/a/b/c

$ /usr/local/subversion/bin/svn import test https://192.168.1.198/svn/data/test -m “add test dir”

5.3LDAP认证配置

# vi /usr/local/apache2/conf/httpd.conf

将之前的配置注释掉。添加如下信息:

<Location /svn>

DAV svn

SVNParentPath /home/subversion/project

AuthzSVNAccessFile /home/subversion/auth

 

# Authentication

AuthType Basic

AuthName “SVN_repository”

AuthBasicProvider ldap

Require valid-user

AuthzLDAPAuthoritative off

AuthLDAPURL “ldap://192.168.1.226:389/DC=example,DC=com,DC=cn?uid?sub?(objectClass=*)”

</Location>

5.4测试并访问svn

#/usr/local/apache2/bin/apachectl restart

在浏览器中输入https://localhost/svn/data

回车会出现 svn 登录的验证窗口,提示输入帐号和密码,帐号就是上面创建的 subversion 用户,输入帐号和密码之后,如果出现下面窗口,则说明 subversion 的安装成功了。

 

在服务器端可以使用终端:

svn checkout https://localhost/svn/datadata 仓库 checkout 出来。

 

 

Svn客户端:

Svn客户端需要安装 apr-1.2.12apr-util-1.2.12,否则 svn 客户端不能 checkout 仓库。

CollabNetSubversion-client-1.5.6-1.i386.rpm

CollabNetSubversion-extras-1.5.6-1.i386.rpm

CollabNetSubversion-server-1.5.6-1.i386.rpm

为了提升账户管理的便捷和安全性,公司在本人的建议下决定从 NIS 升级到 LDAP。研究了 2 个星期,终于完成了 LDAP 服务器的搭建,并和 SVN 整合了起来。期间查找了很多资料,但多半无用,居然没有一个文档是可以完整搭建成功的。一时感慨,资料泛滥的年代,能找出几个像样的还真不容易。因此,贴出最近搭建的完整步骤,期望能给需要的人士一些帮助。有问题的地方,还请大家多多指教。

1安装准备

lneon-0.29.6.tar.tar

下载地址:http://www.webdav.org/neon/

lapr-1.4.6.tar.gz

下载地址:http://apr.apache.org/download.cgi

lapr-util-1.4.1.tar.gz

下载地址:http://apr.apache.org/download.cgi

lopenssl-1.0.0g.tar

下载地址:http://openssl.org.com

lserf-0.3.0.tar.bz2

下载地址:http://serf.googlecode.com/

lhttpd-2.2.22.tar

下载地址:http://httpd.apache.org/download.cgi

lsubversion-1.6.18.tar.gz、subversion-deps-1.6.18.tar.gz

下载地址:www.subversion.org.cn

Subversion英文版安装说明:http://svn.collab.net/repos/svn/trunk/INSTALL

l 配置环境

操作系统版本:RHEL x86_64 AS 4.6(5.8 也测试通过)

LDAP 服务器版本:Red_Hat_Diretory_Server-8.0

l 说明

neon、serf、apr、apr-util 具体功能就不阐述了,全部是 subversion 需要的,其实 subversion 本身的源码包里面有,不过在某些情况下使用自己下载的会更好一些,这是我使用别的工具和 SVN 集成后发现的,使用自带的包无法编译,因此,建议使用上面的版本。换而言之,这些版本是经过测试能够完美整合的。

2安装步骤

2.1卸载系统自带的httpd,apr,apr-util

非常重要,如果不卸载,apache 将无法编译安装。

# yum remove httpd apr apr-util

或者

# rpm -e –allmatches apr-{version}

# rpm -e apr-util-{version}

# rpm -e httpd

 

以下安装步骤都不做累述,源码包的安装是基本常识,查看安装包的 INSTALL 文件,按部就班即可。

2.2安装 APRAPR-util

# tar xzvf APR-1.4.6.tar.gz

# cd apr-1.4.6

# ./configure –prefix=/usr/local/apr

# make

# make install

 

# tar xzvf APR-util-1.4.1.tar.gz

# cd apr-util-1.4.1

#./configure –prefix=/usr/local/apr-util –with-apr=/usr/local/apr

# make

# make install

2.3安装openssl

 

# tar zxvfopenssl-1.0.0g.tar.gz

# cd openssl-1.0.0g

#./config –shared

# make

# make test

# make install

# echo /usr/local/ssl/lib >> /etc/ld.so.conf

# ldconfig

2.4安装apache

# tar xzvf httpd-2.2.22.tar.gz

# cd httpd-2.2.22

#./configure \

–prefix=/usr/local/apache2 \

–enable-so \

–enable-rewrite=share \

–enable-proxy=share \

–enable-proxy-ajp=share \

–enable-dav=share \

–enable-dav-fs \

–enable-mods-shared=all \

–enable-ssl=static \

–enable-ldap \

–enable-authnz-ldap \

–with-ldap \

–with-included-apr \

–with-apr=/usr/local/apr \

–with-apr-util=/usr/local/apr-util/ \

–with-ssl=/usr/local/ssl/

# make

# make install

2.5安装subversion

 

# tar xzvf subversion-1.6.18.tar.gz

# tar xzvf subversion-deps-1.6.18.tar.gz

# tar xzvf neon-0.29.6.tar.gz

# tar xjvf serf-0.3.0.tar.bz2

# cd subversion-1.6.18

# rm -rf apr apr-util neon serf

# cp -ar ../neon-0.29.6 neon

# cp -ar ../serf-0.3.0 serf

# chown -R 1000:users neon serf

# ./configure \

–prefix=/usr/local/subversion \

–with-apxs=/usr/local/apache2/bin/apxs \

–with-ssl \

–with-apr=/usr/local/apr \

–with-apr-util=/usr/local/apr-util \

–with-zlib=/usr/lib64

# make && make install

 

 

装完之后执行 /usr/local/subversion/bin/svn –version 检查是否出现以下信息:

svn, version1.6.18 (r1303927)

compiled Aug 22 2012, 10:32:42

 

Copyright (C)2000-2009 CollabNet.

Subversion is opensource software, see http://subversion.apache.org/

This productincludes software developed by CollabNet (http://www.Collab.Net/).

 

The followingrepository access (RA) modules are available:

 

* ra_neon : Modulefor accessing a repository via WebDAV protocol using Neon.

– handles ‘http’scheme 支持http

– handles ‘https’scheme 支持https

* ra_svn : Modulefor accessing a repository using the svn network protocol.

– with Cyrus SASL authentication

– handles ‘svn’ scheme

* ra_local :Module for accessing a repository on local disk.

– handles ‘file’ scheme

推荐阅读

Linux 中 Subversion 配置实例 http://www.linuxidc.com/Linux/2012-02/53109.htm

CentOS 6.2 SVN 搭建 (YUM 安装) http://www.linuxidc.com/Linux/2013-10/91903.htm

Apache+SVN 搭建 SVN 服务器 http://www.linuxidc.com/Linux/2013-03/81379.htm

Windows 下 SVN 服务器搭建和使用 + 客户端重新设置密码 http://www.linuxidc.com/Linux/2013-05/85189p5.htm

Ubuntu Server 12.04 安装 SVN 并迁移 Virtual SVN 数据 http://www.linuxidc.com/Linux/2013-05/84695.htm

Ubuntu Server 搭建 svn 服务以及迁移方法 http://www.linuxidc.com/Linux/2013-05/84693.htm

借助网盘搭建 SVN 服务器 http://www.linuxidc.com/Linux/2013-10/91271.htm

6ldap 配置详细说明

ldap认证配置如下:

<Location/svn>

# 开启 Subversion

DAV svn

 

# 包含所有版本库的路径

SVNParentPath /home/subversion/project

 

#Access file for Subversion Repository

AuthzSVNAccessFile /home/subersion/project/auth

 

# 使用基本的密码认证

AuthType Basic

 

# 弹出的对话框的库名

AuthName “Subversion repository”

 

# Authentication Provider is LDAP

AuthBasic Providerldap

 

# 绑定 ldap 认证用户(可以不要,则采用匿名用户,ldap 默认是匿名查询)

AuthLDAPBindDN “CN=ldapadmin,OU=systemadmin,DC=example,DC=com,DC=cn”

 

# 绑定 ldap 认证用户的密码(上面用户如果没有设置,这一条则取消)

AuthLDAPBindPassword ins.key.ok00

 

# TheLDAP query URL

#Format: scheme://host:port/basedn?attribute?scope?filter

# TheURL below will search for all objects recursively below the basedn

# andvalidate against the sAMAccountName attribute

AuthLDAPURL “ldap://192.168.1.226:389/DC=example,DC=com,DC=cn?uid?sub?(objectClass=*)”

 

#Require authentication for this Location ,Requires that mod_authz_user beloaded and that # theAuthzLDAPAuthoritative off

Requirevalid-user

 

# LDAPAuthentication & Authorization is final; do not check other databases

#Prevent other authentication modules from authenticating the user if this onefails

AuthzLDAPAuthoritative off

</Location>

 

6.1注解

在认证的过程中,httpd 首先在 LDAP 目录中搜索客户端提供的用户名(通过 AuthLDAPURL 配置如何搜索),假如未找到,则认证失败;如果搜索到,则尝试使用客户端提供的用户名和密码来 bind LDAP,如果 bind 成功则认证通过。

在我们的 httpd.conf 文件中,AuthLDAPBindDN 和 AuthLDAPBindPassword 也是用来 bind 到 LDAP 服务的。考拉一开始对此迷惑了好久,不是说用 httpd 客户端提供的用户名和密码来 bind LDAP 的么,怎么这里又有个 bind?httpd 的官方文档对 AuthLDAPBindDN 是如此描述的:

An optional DN used to bind to the server whensearching for entries. If not provided, mod_authnz_ldapwill use an anonymous bind.

原来,刚才说到认证的第一步是对 LDAP 目录进行搜索。其实 AuthLDAPBindDN 和 AuthLDAPBindPassword 所对应的就是搜索这个操作的 bind。如果没有配置这两兄弟的话,httpd 会使用匿名 bind 来搜索目录。为了不让 LDAP 的密码以明文的形式出现在配置文件中,考拉强烈建议在 httpd.conf 中不要使用这两个配置项。考拉的 LDAP 服务可是允许匿名绑定的哦~(当然匿名 bind 只有读取的权限,不过对于 search 操作而言,足够了呀)。

#ldap://是 LDAP 通讯的方式;ldapserver:389 是 LDAP 的服务器名或 IP 地址,389 为 LDAP 协议的端口;ou 是组织单元 (如果下面还有 ou 的话, 应该在此后面再加上 ou=xxx, 用逗号隔开);dc= 后面跟域名, 有多少点就有多少 dc=xxx, 也要用逗号隔开, 再举个例子 LDAP 服务器名为 shanghai.domain.com.cn, 那 shanghai 应该是 主机 的实际名字,domain.com.cn 才是真正的域名, 参数应该是这样 ”ldap://shanghai.domain.com.cn:389/ou=developer,dc=domain,dc=com,dc=cn?sAMAccountName?sub?(objectClass=*)”;sAMAccountName?sub?(objectClass=*)参数是指明所有验证的是 windows 域中独特的帐户形式 sam

当 basedn 不写 OU,仅仅写后面的 DC 时,需要将 389 端口修改成 3268。

 

TheAuthzLDAPAuthoritative offdirective will letauthentication fall through to the next module only if the user cannot bematched to a DN in the query. Currently even though the user is expired, itseems that their account will still be returned as a result when the LDAP queryis performed.

I don’t knowenough about the ActiveDirectory LDAP schema to give a definite answer here,but if you could add a filter to your AuthLDAPURL directivethat filters out expired accounts it should result in the username not matchingany DN in the query. This should result in the authentication falling throughto the next module.

 

或许需要:

# AuthLDAPGroupAttributeIsDN on

# Require ldap-group CN=ldapadmin,OU=systemadmin,DC=example,DC=com,DC=cn

# AuthLDAPGroupAttribute memberUid

– Require ldap-groupcn=SVNUsers,ou=Group,dc=xliu-home,dc=org:这条配置告诉 httpd,客户端提供的用户,必须隶属于 SVNUsers 这个组,注意这里一定要使用 DN。

– AuthLDAPGroupAttribute memberUid:它告诉 httpd 去读取 LDAP 中 SVNUsers 这个组记录的 memberUid 属性来和客户端提供的用户 DN 来比较。

– AuthLDAPGroupAttributeIsDN on:它告诉 httpd,memberUid 这个属性里保存的是隶属于该组的用户的 DN,httpd 就会根据客户端提供的用户名和密码来寻找匹配的用户记录 DN,再用这条 DN 来匹配 SVNUsers 组的 memberUid 属性的值。考拉在这个配置项上吃了点苦头,因为它默认值是 on,所以简单注解掉该条配置项是没有用的,必须显式地把它设置为 off。如果我们设置成 off,那么就可以将 LDAP 中 SVNUsers 的 memberUid 设置成 yyd 了,不过考拉认为还是用 memberUid 来存储 DN 比较和谐。

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计13075字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中