3 月 012014
 

 



git的权限设置

参考url : http://fallenlord.blogbus.com/logs/71511589.html

4. 权限配置

到此为止我们还只是构建了一个需要认证的,且可以用于push的Git私服,还没有涉及到授权这块。那么下面我们将通过WebDAV为私服增加授权配置

由于权限是基于WebDAV配置的,因此我们主要是修改Apache的httpd-dav.conf文件:

<Directory “/home/work/local/apache-httpd-2.2.11/gitrepo/”>
Dav On
Options +Indexes +FollowSymLinks    # 拒绝所有请求
Deny from all

AuthType Basic
AuthName “Git”
AuthUserFile “/home/work/local/apache-httpd-2.2.11/user.git”
AuthGroupFile “/home/work/local/apache-httpd-2.2.11/group.git”
</Directory>

<Directory “/home/work/local/apache-httpd-2.2.11/gitrepo/testproject.git/“>
Allow from all
Order Allow,Deny
# 可读组
<Limit GET>
Require group testproject-read
</Limit>
# 可写组
<Limit GET PUT POST DELETE PROPPATCH MKCOL COPY MOVE LOCK UNLOCK>
Require group testproject-write
</Limit>
</Directory>

以上高亮的地方是需要注意的,首先我们添加了AuthGroupFile用于根据组来授权的功能;然后为我们的testproject项目进行了独立配置,使用Limit限制了testproject-read组和testproject-write组的不同权限

接下来我们编辑group.git文件,将用户加入到组中(假设user.git中现在有guolin,wujinliang,liuou三个用户):

testproject-read: guolin
testproject-write: wujinliang liuou

这样配置表示guolin有读取testproject的权限,却没有写入权限,而wujinliang和liuou却拥有读写权限。至此权限配置完成

可以使用guolin用户测试下效果:

$ git push origin master
Password:
error: The requested URL returned error: 401 while accessing http://guolin@bb-iit-dev05.bb01.baidu.com:8080/git/testproject.git/info/refs
fatal: HTTP request failed

这样一个带有权限配置的Git HTTP私服就大功告成了

 

关于客户端

按照以上配置,每次Git客户端进行读写操作都需要重新输入密码,如果觉得太麻烦,那么可以编辑~/.netrc文件(因为git是基于curl来进行http传输的)

machine bb-iit-dev05.bb01.baidu.com
login guolin
password mypass

 

 Posted by at 下午 3:50

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理

This website stores cookies on your computer. These cookies are used to provide a more personalized experience and to track your whereabouts around our website in compliance with the European General Data Protection Regulation. If you decide to to opt-out of any future tracking, a cookie will be setup in your browser to remember this choice for one year.

Accept or Deny