SVN对接LDAP实现域用户统一认证有两种核心模式:一是svnserve+SASL,适用于svn://协议,需配置saslauthd和svnserve.conf启用use-sasl;二是Apache+mod_ldap,适用于HTTP/HTTPS访问,通过AuthLDAPURL等指令集成LDAP认证,两者均弃用本地passwd文件,权限仍由authz文件控制。

SVN服务端要对接LDAP实现域用户统一认证,核心是让SVN跳过本地密码文件(passwd),转而调用LDAP服务器验证用户身份。实际部署中主要分两种模式:一种是基于svnserve + SASL(适用于纯svn协议访问),另一种是基于Apache + mod_ldap(适用于HTTP/HTTPS访问)。两者都依赖LDAP服务可用、网络连通、权限账号配置正确。
确认LDAP服务与基础环境
确保LDAP服务器(如OpenLDAP或Windows AD)已正常运行,且能从SVN服务器通过ldapsearch或testsaslauthd连通。关键信息需提前明确:
- LDAP服务器地址与端口(如
ldap://192.168.10.5:389或ldaps://...) - 绑定DN和密码(建议使用只读专用账号,如
cn=svnbind,dc=example,dc=com) - 用户搜索基准(
baseDN,如ou=People,dc=example,dc=com) - 用户唯一标识属性(通常为
uid或sAMAccountName) - 用户密码对应属性(如
userPassword或unicodePwd,AD需注意TLS/SSL要求)
方式一:svnserve + SASL(推荐用于内网svn://协议)
该方式不依赖Apache,轻量直接,适合传统SVN客户端(TortoiseSVN、命令行等)通过svn://访问。
- 安装SASL组件:
yum install -y cyrus-sasl cyrus-sasl-lib cyrus-sasl-plain cyrus-sasl-ldap - 修改
/etc/sysconfig/saslauthd,设MECH=ldap - 创建
/etc/saslauthd.conf,填入LDAP连接参数(务必注意缩进和换行):ldap_servers: ldap://192.168.10.5<br> ldap_bind_dn: cn=svnbind,dc=example,dc=com<br> ldap_bind_pw: your_secure_password<br> ldap_search_base: ou=People,dc=example,dc=com<br> ldap_filter: (uid=%U)<br> ldap_password_attr: userPassword
- 创建
/etc/sasl2/svn.conf,指定校验方式:pwcheck_method: saslauthd<br> mech_list: plain login
- 重启
saslauthd并测试:systemctl restart saslauthd && testsaslauthd -u testuser -p 'xxx' - 编辑SVN库的
conf/svnserve.conf,启用SASL:[sasl]<br> use-sasl = true
同时注释或删除password-db = passwd,避免干扰
方式二:Apache + mod_ldap(推荐用于https://访问及Web集成)
该方式更灵活,支持HTTPS、单点登录扩展、细粒度组策略,适合企业级Web前端访问场景。
- 启用必要模块:
a2enmod ldap authnz_ldap(Debian/Ubuntu)或确认mod_ldap.so和mod_authnz_ldap.so已加载(RHEL/CentOS) - 在VirtualHost或Location块中配置LDAP认证段,例如:
AuthType Basic<br> AuthName "SVN Repository"<br> AuthBasicProvider ldap<br> AuthLDAPURL "ldap://192.168.10.5/ou=People,dc=example,dc=com?uid?sub?(objectClass=posixAccount)"<br> AuthLDAPBindDN "cn=svnbind,dc=example,dc=com"<br> AuthLDAPBindPassword "your_secure_password"<br> Require ldap-user
- 可选增强权限控制:
Require ldap-group cn=svn-devs,ou=Groups,dc=example,dc=com - 禁用本地密码文件:
#AuthUserFile /path/to/passwd注释掉即可 - 重启Apache:
systemctl restart httpd或apache2
权限控制仍由authz管理
无论哪种LDAP接入方式,SVN自身的权限分配(读/写/路径级控制)依然通过authz文件完成。LDAP只负责“你是谁”,不决定“你能做什么”。所以需在authz中用LDAP用户名(如testuser)或组名(如@dev-team)显式授权:
[groups]<br> dev-team = testuser, alice, bob
[repo:/trunk]<br> @dev-team = rw<br> * = r
注意:若使用Apache方式且启用了AuthLDAPGroupAttributeIsDN off,则authz中的组名需与LDAP中cn值严格一致;若为on,则需填写完整DN。

















