SVN 部署以及对接Ldap

安装环境

  • 系统版本:Centos7.9
  • 安装方式: yum 安装

部署SVN

  • 安装svn
yum -y install subversion
  • 检查版本
svnserve --version

配置SVN

  • 创建SVN库
mkdir -p /opt/svn
  • 创建repo代码库
svnadmin create /opt/svn/repo
  • 创建完成后,生成以下文件
cd /opt/svn/repo

  • svn 配置文件修改,修改以下参数
vim /opt/svn/repo/conf/svnserve.conf
[general]
anon-access = none #匿名访问的权限,可以是read,write,none,默认为read
auth-access = write #使授权用户有写权限
password-db = passwd #密码数据库的路径
authz-db = authz #访问控制文件
realm = repo #认证命名空间,subversion会在认证提示里显示,并且作为凭证缓存的关键字

截图如下:

  • 启动svn
svnserve -d -r /opt/svn/ --listen-port=3690 --log-file /tmp/svn.log &
  • 查看svn 进程

至此,svn 部署完成,开始对接ldap!

svn对接ldap

配置sasl

  • sasl 说明
SASL全称Simple Authentication and Security Layer,是一种用来扩充C/S模式验证能力的机制。
SASL是一个胶合库,通过这个库把应用层与形式多样的认证系统整合在一起。这有点类似于PAM,但是后者是认证方式,决定什么人可以访问什么服务,而SASL是认证过程,侧重于信任建立过程,这个过程可以调用PAM来建立信任关系。在这里Memcached就是上面提到的应用层,具体的认证交给SASL库,SASL会根据相应的认证机制来完成验证功能。
  • 安装sasl
yum -y install *sasl*
  • 修改认证方式
vim /etc/sysconfig/saslauthd
将MECH=pam 修改成MECH=ldap
  • 创建/etc/saslauthd.conf 文件,写入以下内容
    vim /etc/saslauthd.conf
ldap_servers: ldap://xxx.xxx.cn:389/
ldap_bind_dn: cn=admin,dc=xxx,dc=cn
ldap_bind_pw: xxxxx
ldap_search_base: dc=xxx,dc=cn
ldap_filter: uid=%U
ldap_password_attr: userPassword
  • 创建/etc/sasl2/svn.conf文件,写入以下内容
    vim /etc/sasl2/svn.conf
pwcheck_method: saslauthd
mech_list: PLAIN LOGIN
  • 重启saslauthd服务
systemctl restart saslauthd 
注: 如果是docker 启动,需要另一种方式启动
/usr/sbin/saslauthd -m /run/saslauthd -a ldap 
测试ldap认证是否配置成功,xioali是ldap用户名,123是密码。可以看到ldap配置没有问题
testsaslauthd -uxiaoli -p123
0: OK "Success."
  • 修改SVN svnserve.conf 配置文件
我的SVN仓库地址为/opt/svn/repo,所以服务器配置文件路径为/opt/svn/repo/conf/svnserve.conf 

启用如下配置
vim /opt/svn/repo/conf/svnserve.conf
use-sasl = true  

注意:使用LDAP认证后,passwd就不再生效了。但是账户权限还是需要在authz中设置。LDAP Server只是验证用户在ldap server上是否存在,但不进行权限限制
  • 修改完svn 配置后需要重启svn
1. 杀死svn 进程号
2.启动svn 
svnserve -d -r /opt/svn/ --listen-port=3690 --log-file /tmp/svn.log &
  • 在authz 中增加用户权限
cat /opt/svn/repo/conf/authz 

[groups]
repo = li.xinliang,zhao.bb
rrepo = li.aa

[repo:/]
@repo = rw
@rrepo = r

上述权限表面 li.xinliang,zhao.bb 拥有 rw 读写权限;li.aa 用户拥有只读 r 权限
  • 验证
下载svn 客户端,打开客户端并输入 svn://10.65.0.11:3690/repo  
输入ldap 账号: li.xinliang
输入ldap 密码:xxxx 

结论:li.xinliang,zhao.bb 拥有 rw 读写权限,可以checkout、update、提交代码
      li.aa 只能update,查看内容,不能提交代码

至此,SVN 对接Ldap 完成!

原文地址:https://www.cnblogs.com/lixinliang/p/15532858.html