使用gitosispipe理对git存储库的http访问

[2010年9月16日更新]

昨天晚上看了这个之后,我意识到我原来的问题确实在问两个不同的东西:

1)是否有可能为gitosis创build的所有远程存储库设置更新后的挂钩(即在gitosis中创build存储库之后,不必手动执行mv hooks/post-update.sample hooks/post-update )。 这是通过HTTP进行克隆工作所必需的(愚蠢的HTTP客户端依赖于git update-server-info从post-update钩子中调用的事实)。

2)一旦通过HTTP访问版本库,是否可以使用gitosis.conf中的选项打开和closures访问(类似于daemon = nogitweb = yes

—解决问题1 —

事实certificate,Git使用模板来使用git init命令创build新的存储库。 通过在模板目录内执行mv hooks/post-update.sample hooks/post-update ,以后所有在我的服务器上git init调用都会正确configurationpost-update钩子。 (在OSX上,模板目录是/opt/local/share/git-core/templates/

这个工作的另一个要求是打开Apache重写规则,以便存储库的HTTP克隆URL看起来像http//git.example.com/repo.git

我在/etc/apache2/extra/httpd-vhosts.conf重写规则如下所示:

 # turning on mod rewrite RewriteEngine on # make the front page an internal rewrite to the gitweb script RewriteRule ^/$ /cgi-bin/gitweb.cgi [L,PT] # make access for "dumb clients" work RewriteRule ^/(.*\.git/(?!/?(HEAD|info|objects|refs)).*)?$ /cgi-bin/gitweb.cgi%{REQUEST_URI} [L,PT] 

—仍然在寻找问题2的解决scheme…帮助! 🙂 —

现在,HTTP克隆适用于我所有的存储库,我想知道是否有一种方法来pipe理使用gitosis的HTTP访问控制。 设置daemon = nogitweb = no会closures仓库的git-daemon和gitweb访问权限,但是由于Apache重写规则仍然存在, 所以repohttp://git.example.com/repo.git 仍然是可复制的 http://git.example.com/repo.git 。 任何想法如何使用gitosis来pipe理?

[我最初发布的问题]

是否有可能使用gitosis来pipe理对git存储库的http访问? 例如,在gitosis.conf中,我可以使用以下命令pipe理gitweb和git-demon的访问权限:

 # Allow gitweb to show this repository. gitweb = yes # Allow git-daemon to publish this repository. daemon = no 

我目前能够通过发出以下命令克隆我的存储库:

 $ git clone git://git.example.com/repo.git 

但是,当我发出以下命令:

 $ git clone http://git.example.com/repo.git 

我收到以下错误信息:

 fatal: http://git.example.com/repo.git/info/refs not found: did you run git update-server-info on the server? 

但是,如果我login到我的服务器并从repo.git中运行以下内容:

 # From http://progit.org/book/ch4-5.html $ cd project.git $ mv hooks/post-update.sample hooks/post-update $ chmod a+x hooks/post-update $ git update-server-info 

然后通过HTTP克隆工作正常。

有什么办法来pipe理从gitosis内的存储库的http访问?

Gitosis使用gitweb进行存储库的http发布。

你需要运行gitweb。

请确保已安装gitweb。 你的gitweb.conf应该如下所示:

 # Location of the git binary $GIT = "/usr/bin/git"; # Project root for gitweb $projectroot = "/srv/git/repositories"; $stylesheet = "/gitweb.css"; $logo = "/git-logo.png"; $favicon = "/git-favicon.png"; # Site name $site_name = "My site"; # URL formatting #$my_uri = "http://git.somewhere.net/"; #$home_link = $my_uri; # Base URL for project trees @git_base_url_list = ("ssh://git\@somewhere.net"); # Length of the project description column in the webpage. $projects_list_description_width = 50; # Which repos are allowed to export $export_ok = "git-daemon-export-ok"; # Enable PATH_INFO so the server can produce URLs of the # form: http://git.hokietux.net/project.git/xxx/xxx $feature{'pathinfo'}{'default'} = [1]; # Enable blame, pickaxe search, snapshop, search, and grep $feature{'blame'}{'default'} = [1]; $feature{'blame'}{'override'} = [1]; $feature{'pickaxe'}{'default'} = [1]; $feature{'pickaxe'}{'override'} = [1]; $feature{'snapshot'}{'default'} = [1]; $feature{'snapshot'}{'override'} = [1]; $feature{'search'}{'default'} = [1]; $feature{'grep'}{'default'} = [1]; $feature{'grep'}{'override'} = [1]; 

在Apache中的示例gitwebconfiguration:

 Alias /gitweb/gitweb.css /usr/share/gitweb/gitweb.css Alias /gitweb/git-logo.png /usr/share/gitweb/git-logo.png Alias /gitweb/git-favicon.png /usr/share/gitweb/git-favicon.png ScriptAlias /gitweb /usr/lib/cgi-bin/gitweb.cgi <Directory /usr/share/gitweb> Options FollowSymLinks +ExecCGI AddHandler cgi-script .cgi </Directory> <Location /gitweb> Order allow,deny Allow from all #AuthType Basic #AuthName "GITOLITE" #AuthUserFile /etc/apache2/gitweb.htpasswd #Require valid-user </Location> # Securing with users example <Location /gitweb/SomethingToHide.git> Require user myusername </Location> 

我已经切换到gitolite,因为…

  • 它更容易使用
  • 它有更多的select(安全,分组等)

问题是你不能限制从http://克隆的访问,因为Apache直接处理这些请求。 我已经开发了一个使用git钩子和文件权限的解决scheme。

我有一个Redmine / Gitosis / Gitweb服务器设置在一个共享主机环境中,Apache用户不是 gitosis用户。 默认情况下,Apache无法访问我的存储库,因为gitosis创build了750个权限。 我有gitosis在/ home / xdgit / gitosis / projects.list中成功地填充了gitweb的projects.list,其中包含应该公开访问的所有存储库的名称。 我已经修改了我的gitosis-admin.git / hooks / post-update钩子以包含以下内容:

 #!/bin/sh set -e gitosis-run-hook post-update git-update-server-info # Find repo root from ENV or current dir GIT_DIR=$(git rev-parse --git-dir 2>/dev/null) if [ -z "$GIT_DIR" ]; then echo >&2 "fatal: post-receive: GIT_DIR not set" exit 1 fi # Process permissions for each repo for f in $GIT_DIR/../*.git do # Look for the repo name in projects.list if grep -q `basename $f` /home/xdgit/gitosis/projects.list then chmod o+rx $f else chmod o-rx $f fi done 

现在,无论何时将任何内容推送到gitosis-admin.git(例如更改gitosis.conf以允许公共访问存储库),更新后的挂钩将自动更改存储库的权限以允许或拒绝公共访问,具体取决于是否回购的名字出现在projects.list中。 由于虚拟客户端需要直接由Apache访问实际的存储库,所以这种基于权限的访问控制是理想的解决scheme – 即使Apache不能访问非公开的存储库。

我还开发了一个mod_rewrite / mod_setenvif解决scheme,检测存储库中是否存在git-daemon-export-ok文件,允许在适当的情况下进行访问。 它起作用了,但是如果Apache可以读取(他们必须),则需要额外的预防措施来显式地禁止访问非公开回购。 事实certificate,这是一个巨大的令人头疼的事情,对我来说(因为文件权限将不得不改变),这是极端的矫枉过正。 希望这可以帮助。