基於ssl和ldap的SVN工具安裝指南

基於sslldapSVN工具安裝指南

   爲了提升賬戶管理的便捷和安全性,公司在本人的建議下決定從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


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



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比較和諧。



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章