LDAP+SASL+SVN


前言

前面的文章里介紹了LDAP與一些公共平台的集成方法,今天看看與svn的集成方法,也是筆者花時間最多的一個環節了。

概述

在此之前,我想先跟大家分享下svn與ldap服務集成的大致思路,因為筆者當時在這方便走了不少彎路,也不想后續的同學繼續為此花費不必要的時間。

方法選擇

在集成的方法上,我這里嘗試過兩種方式,第一種是走apache,也就是說,需要先讓你的svn與apache綁定起來,讓你的svn版本庫能夠走http協議訪問,除此之外需要開啟apache的認證機制,並且這個認證的數據源,需要配置成ldap,如此一來,也就實現了svn+apache+ldap的集成套路;在嘗試的過程中,svn與apache的聯通比較好做,但apache與ldap的集成過程一直沒有從嘗試成功,在測試使用ldap中的用戶名和密碼登錄的時候,一直報錯認證失敗,花了很多時間也沒有解決;除此之外考慮到哪怕集成成功,后續公司所有同學本地的svn的checkout地址都需要從svn:// 改成http:// ,操作的代價比較大,因此轉而嘗試第二種方式:SASL

SASL

What Is SASL?

The Cyrus Simple Authentication and Security Layer is open source software written by Carnegie Mellon University. It adds generic authentication and encryption capabilities to any network protocol, and as of Subversion 1.5 and later, both the svnserve server and svn client know how to make use of this library. It may or may not be available to you: if you're building Subversion yourself, you'll need to have at least version 2.1 of SASL installed on your system, and you'll need to make sure that it's detected during Subversion's build process. If you're using a prebuilt Subversion binary package, you'll have to check with the package maintainer as to whether SASL support was compiled in. SASL comes with a number of pluggable modules that represent different authentication systems: Kerberos (GSSAPI), NTLM, One-Time-Passwords (OTP), DIGEST-MD5, LDAP, Secure-Remote-Password (SRP), and others. Certain mechanisms may or may not be available to you; be sure to check which modules are provided.You can download Cyrus SASL (both code and documentation) from http://asg.web.cmu.edu/sasl/s...

上面是svn官網上關於sasl的解釋,大致描述就是它能夠將通用的身份驗證和加密功能添加到任何網絡協議;
自svn從1.5版本之后,都能夠使用sasl功能,同時,我們發現svn的配置文件里有”# use-sasl = true“這條被注釋的參數;由此一來,我們就能夠通過配置svn的用戶驗證走sasl,並且sasl從ldap來獲1 取用戶和密碼信息,就能完整實現svn+sasl+ldap功能了,並且對於svn來說,后續需要變動的地方並不多,只需要修改配置即可。

SASL的驗證方式

這里需要着重介紹下sasl的幾種驗證方式以及每種驗證方式所適用的場景;

  • Password Verification Mechanisms  - 接收遠程的口令,傳遞給SASL膠合層,由口令驗證器驗證,這種機制的例子有 PLAIN ;
  • Shared Secret Mechanisms - 不是直接傳遞口令明文,而是服務方發起一個認證,客戶證明自己知道這個口令,這需要服務方和客戶方都保存有口令.這種機制的例子有 CRAM-MD5,DIGEST-MD5以及SRP ;
  • Kerberos Mechanisms - 使用信任的第三方來驗證客戶。
  • saslauthd - 呼叫saslauthd服務進程,驗證用戶。saslauthd支持很多識別方式,比如PAM,LDAP,Kerberos數據庫等 。
    如上,最后一種驗證方式,就是那個被選中的方式!!!

安裝sasl

root@saier-zj-online-game-192:/etc# apt-get -y install sasl*

配置sasl+ldap

vim /etc/default/saslauthd

修改參數

START=yes
MECHANISMS="ldap"

重啟服務:

root@saier-zj-online-game-192:~# /etc/init.d/saslauthd restart
[ ok ] Restarting saslauthd (via systemctl): saslauthd.service.

查看saslauthd進程

root@saier-zj-online-game-192:~# ps -ef | grep ldap
openldap  3282     1  0 Sep23 ?        00:00:09 /usr/sbin/slapd -h ldap:/// ldapi:/// -g openldap -u openldap -F /etc/ldap/slapd.d
root     27914     1  0 20:52 ?        00:00:00 /usr/sbin/saslauthd -a ldap -c -m /var/run/saslauthd -n 5
root     27915 27914  0 20:52 ?        00:00:00 /usr/sbin/saslauthd -a ldap -c -m /var/run/saslauthd -n 5
root     27916 27914  0 20:52 ?        00:00:00 /usr/sbin/saslauthd -a ldap -c -m /var/run/saslauthd -n 5
root     27919 27914  0 20:52 ?        00:00:00 /usr/sbin/saslauthd -a ldap -c -m /var/run/saslauthd -n 5
root     27921 27914  0 20:52 ?        00:00:00 /usr/sbin/saslauthd -a ldap -c -m /var/run/saslauthd -n 5
root     27937  1304  0 20:52 pts/0    00:00:00 grep --color=auto ldap

這里看到saslauthd進程已經啟動了,但是此時sasl並沒有正確關聯ldap,下面看看如何配置sasl與ldap的關聯~
我們需要在/etc/下創建一個文件,命名為:saslauthd.conf,內容如下:

root@saier-zj-online-game-192:~# cat /etc/saslauthd.conf 
ldap_servers: ldap://192.168.0.83:389

ldap_bind_dn: cn=admin,dc=ldap,dc=com

ldap_bind_pw: admin

ldap_auth_method: bind

ldap_search_base: dc=ldap,dc=com

ldap_filter: uid=%U

重啟saslauthd:

root@saier-zj-online-game-192:~# /etc/init.d/saslauthd restart
[ ok ] Restarting saslauthd (via systemctl): saslauthd.service.

測試saslauthd與ldap的認證鏈路是否正確,這里saslauthd提供了一個測試指令:testsaslauthd,在此之前需要現先在ldap中創建用戶並設置密碼,測試指令如下:

root@saier-zj-online-game-192:~# testsaslauthd -u zhangjian -p zhangjian123 
0: OK "Success."

當出現上面這樣的輸出,說明你的ldap+saslauthd配置正確。

安裝svn

指令

apt-get -y install subversion

創建版本庫:

svnadmin create /data/svntest

修改svn服務配置文件:

vim /data/svntest/conf/svnserve.conf

調整配置

anon-access = none
auth-access = write
authz-db = authz
use-sasl = true

修改權限認證文件:

需要調整的配置如下,因為我在ldap里創建的用戶名是‘zhangjian’,因此需要在這里給該用戶分組並且分配權限;

root@saier-zj-online-game-192:/data/svntest/conf# cat authz 
[aliases]
# joe = /C=XZ/ST=Dessert/L=Snake City/O=Snake Oil, Ltd./OU=Research Institute/CN=Joe Average
[groups]
admin = zhangjian

[svntest:/]
@admin = rw
* = r

配置sasl+svn

在上面的配置中,我們打開了svn的sasl認證方式,此外,我們還需要配置sasl的svn配置文件,用來告訴sasl,svn的這個服務的認證方式是怎樣的,上面的簡介中可以看到,我們需要使用saslauthd這個認證方式,而且,這個文件一般是需要新建的,並且以服務的名字來命名,因為這里是svn服務,所以名字就叫做“svn.conf”。
注意
不同系統中,這個配置文件的位置也是不一樣的,在Centos系列中,配置文件的絕對路徑為“/etc/sasl2/svn.conf”,在Ubuntu系列中,配置文件的絕對路徑為“/usr/lib/sasl2/svn.conf”。

root@saier-zj-online-game-192:/usr/lib/sasl2# cat svn.conf 
pwcheck_method: saslauthd
mech_list: PLAIN LOGIN

重啟saslauthd

root@saier-zj-online-game-192:/usr/lib/sasl2# /etc/init.d/saslauthd restart
[ ok ] Restarting saslauthd (via systemctl): saslauthd.service.

啟動svn

svnserve -d --listen-port 3690 -r /data

測試

ok,svn開啟之后,我們就來本地測試下,使用ldap里的用戶名和密碼,能不能拉取到我們的svn版本庫~
咱們新建一個目錄,在里面嘗試拉取我們的版本庫,截圖如下:
image
注意
因為我們的svn進程啟動的時候,指定的’-r‘是’/data‘,因此,這里CO的時候,路徑里需要把svntest加上;
輸入ldap中的用戶名和密碼,點擊OK:
image
可以看到,這里是能夠通過ldap里的用戶名和密碼來順利拉取到版本庫的~
image
同時,svn相關的提交和周邊操作都是可以正確執行的,至此,就實現了svn+sasl+ldap三個組件的集成;

典型報錯

筆者這里在部署初期遇到一個比較隱晦的問題,在參考很多其他文檔的時候,發現大家把如下兩條參數打開並配置了特定值

min-encryption = 125
max-encryption = 256

進而導致了如下的錯誤:
image

首先解釋下這兩條參數的含義,變量 min-encryption 和 max-encryption 控制服務器所需要的加密強度。要完全禁用加密,就將這 2 個變量的值都設為 0。要啟用簡單的數據校驗(例如,為了防止篡改和保證數據的完整,不加密),就將這 2 個值都設為 1。如果你想允許(但不強制)加密,將最小值設為 0,最大值設為任意位數。要強制加密,將這 2 個值設為大於 1 的數字。在前面的例子中,我們要求客戶端至少進行 128 位加密,但是不大於 256 位加密。
這里的加密是用在當svn需要使用sasl自帶的數據文件進行存儲並加密用戶數據的時候,舉個例子,當我們的svn.conf配置的內容如下的時候:

pwcheck_method: auxprop
auxprop_plugin: sasldb
sasldb_path: /home/svn/svnjiami/sasldb
mech_list: DIGEST-MD5

此時,我們需要通過saslpasswd2指令來創建用戶和密碼的,上面兩條參數,就是指定這里的加密策略,那么再回到當前的場景中,我們使用的用戶數據,都是來自ldap,並且ldap自身在存儲用戶信息的時候是有加密的,默認SHA1,因此,在筆者的部署場景中,並不需要打開這兩條參數,或者把這兩條參數都設置為0,截圖中的報錯就能解決了~

總結

以上是一些在集成svn和ldap服務的時候,一些個人的發現和感想,不能確保百分百准確,關於ldap,還有很多功能需要發掘和探索,僅僅是給大家一個參考,有理解偏差或沒有闡明的地方,還望指正 ^ ^.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM