svn基于mysql认证_让基于apache httpd的subversion实现通过mysql进行认证

关于“subversion + httpd + mysql”这个话题在网上的文章很多,貌似没有自己再写的必要,但通过研读多篇中外相关的blog和网页后,我还是决定自己记录一下,确保下次再做时能有清晰准确的思路。

由于这篇文章的主要目的在于"通过mysql进行身份验证",所以关于subversion(svn)架设在apache httpd上就不多说了,本文基于以下前提:

1.debian lenny 发行版

2.svn on apache httpd 已经配置好

3.mysql-server数据库服务器已经安装好

3.通过apt-get install libapache2-mod-auth-mysql安装mod_auth_mysql

这东东版本很多文档也零碎(http://freelamp.com/58349 中有提到)

我也搜到好两个:

http://modauthmysql.sourceforge.net/

http://www.heuer.org/mod_auth_mysql/

debian是基于sf那个修改的而来的,指令作了一些修改和扩充,网上很多资料都是"编译生成mod_auth_mysql.so ... ...",基本上用的是sf.net上那个3.0版了,虽然大同小异,但并不完全适用本文。

先说说原理:

*由httpd判断是否需要对location进行认证(require指令)

*然后通过配置文件中指定的认证模块完成这个认证过程,在这里,认证的模块是auth_mysql。

*auth_mysql模块通过访问指定的表及字段,检查用户提交的用户名及密码是否匹配用户表.

*如果有需要,auth_mysql模块还会验证组(group)

*接下来通过dav_svn模块检查AuthzSVNAccessFile文件进行存取控制。

步骤如下:

一、建单独的认证数据库

二、建httpd使用的数据库用户

三、建表

四、确认已经安装apache的mysql认证模块

五、修改httpd配置文件

一、认证数据库

这一步很简单,起个好名字就行.

mysql>CREATE DATABASE authz_db;

二、建数据库用户

mysql>mysql> GRANT SELECT,INSERT,UPDATE,DELETE ON authz_db.* TO 'mysqlauthuser'@'localhost' IDENTIFIED BY 'some_pass';

三、创建表

create table users

(

uid                  int unsigned not null auto_increment,

login                varchar(20) not null,

password             varchar(50) not null,

user_name            varchar(50) character set utf8 not null,

enabled              bool not null default true,

primary key (uid),

unique key uidx_users_login (login)

)

type = MYISAM;

四、确认安装apache的mysql认证模块

apt-get install libapache2-mod-auth-mysql

a2enmod auth_mysql

五、修改httpd配置文件

我把相关的apache配置指令在标签内,全局认证就没必要,下面我就是以虚拟主机中局部认证为例了

ServerAdmin webmaster@localhost

ServerName hostname

DocumentRoot /var/www-sites/root-path

DAV svn

SVNParentPath /svn-repos/parent/path

SVNListParentPath On

SVNAutoversioning On

SVNReposName "input as you like~~"

AuthzSVNAccessFile /path/svn-repos.acl #备注1

AuthBasicAuthoritative off  #备注2

AuthMYSQL on

AuthMySQL_Authoritative on

AuthMySQL_Socket /path/to/mysqld.sock  #备注3

#                AuthMySQL_Host localhost

AuthMySQL_User mysqlauthuser    #见第二步

AuthMySQL_Password some_pass    #见第二步

AuthMySQL_DB authz_db        #见第一步

AuthMySQL_Password_Table users        #

AuthMySQL_Username_Field login        #第三步创建表

AuthMySQL_Password_Field password    #

AuthMySQL_Empty_Passwords on

AuthMySQL_Encryption_Types Crypt_MD5    #备注4

AuthName "认证框提示内容~~"

Require valid-user

AuthType Basic

备注:

备注1:

AuthzSVNAccessFile 指向的是 authz 的策略文件,详细的权限控制可以在这个策略文件中指定。

如果这里暂时没用,就在前面+上#号注释掉

备注2

这东东折腾了好一会儿,直到在

http://www.pitr.net/index.php/2007/08/08/internal-error-pcfg_openfile-called-with-null-filename/

找到答案

While upgrading Apache to version 2.2.4-2 for a subversion upgrade (version 1.4.4dfsg1-1) I ran into errors with my auth_pgsql (or any other auth_mysql, auth_ldap or auth_* module) setup:

“Internal error: pcfg_openfile() called with NULL filename”

This is caused by auth_basic and stops the authentication and authorisation process. Adding the following directive to your auth_pgsql or auth_ldap config file solves the problem:

“AuthBasicAuthoritative Off”

It disables basic authorisation being authoritive for the authorisation process. The errors will still be visible in your logfiles, but the authorisation scheme works as normal.

大意貌似是auth_basic模块的问题。

备注3

本机上连接mysql可以不使用tcp,而是通过unix socket,性能更好一些。

在/etc/mysql/my.cnf中有定义,我本机上是/var/run/mysqld/mysqld.sock

如果不会弄这个,把AuthMySQL_Socket参数注释,改为用AuthMySQL_Host localhost也行

备注4

密码加密方式, 与php中的crypt()加密方法一致, 参看:

http://salomi.blog.51cto.com/389282/160326

至此,全部配置完毕,重启apache httpd即可生效

增加用户:

insert into users

(login, password, user_name, reg_date, enabled)

values

('mylogin','??????????????????', 'username', NOW(), 1);

????????????串用php的crypt()方法生成

参考资料:(除了上面提到的url之外)

http://www.arune.se/tech:svnwithmysqlauth

这里还提到了如何与dokuwiki集成帐号的方法

http://www.uml.org.cn/pzgl/200902136.asp

这里是svn的其它一些高级应用

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值