我想通过“智能”HTTP 获得 git 存储库,只有我可以推送到它,但任何人(或任何拥有帐户的人)都可以从中克隆/获取。
在 git-http-backend(1) 联机帮助页中,可以找到 Apache Web 服务器的以下示例配置:
Ensure mod_cgi, mod_alias, and mod_env are enabled, set GIT_PROJECT_ROOT (or DocumentRoot) appropriately, and create a ScriptAlias to the CGI:
SetEnv GIT_PROJECT_ROOT /var/www/git SetEnv GIT_HTTP_EXPORT_ALL ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/
To enable anonymous read access but authenticated write access, require authorization with a LocationMatch directive:
<LocationMatch "^/git/.*/git-receive-pack$"> AuthType Basic AuthName "Git Access" Require group committers #... </LocationMatch>
不幸的是,这个配置不起作用。我可以毫无问题地获取/克隆存储库,无需身份验证,但推送失败:
$ git push origin master
error: Cannot access URL http://localhost/git/test.git/, return code 22
fatal: git-http-push failed
检查 Apache Web 服务器的 error.log
没有帮助:
[...] Service not enabled: 'receive-pack' [...] Request not supported: '/var/www/git/test.git/'
access.log
告诉我们 git push
首先在 /git/test.git/info/refs?service=git-receive 上使用 GET 方法-pack
基于查询的 URL,不在 LocationMatch 指令中:
[...] "GET /git/test.git/info/refs?service=git-receive-pack HTTP/1.1" 403 304 "-" "git/1.7.10.4" [...] "GET /git/test.git/info/refs HTTP/1.1" 200 267 "-" "git/1.7.10.4" [...] "GET /git/test.git/HEAD HTTP/1.1" 200 337 "-" "git/1.7.10.4" [...] "PROPFIND /git/test.git/ HTTP/1.1" 404 250 "-" "git/1.7.10.4"
(以下几行是关于回退到“愚蠢的”基于 WebDAV 的 HTTP 推送 - 是否可以禁用此回退?)。
现在我使用以下解决方法:我需要有效的用户来获取和推送(使用 git-http-backend(1) 联机帮助页中“读取和写入的身份验证”示例的修改配置),并通过 pre 将推送限制为单个用户-通过检查
hook。REMOTE_USER
环境变量接收
最佳答案
一个不太复杂的替代方法是使用 gitolite除了你的 Apache-git 设置。
您可以轻松地将 gitolite 插入 Apache(无需 ssh 配置)。
参见示例:httpd.conf , 结合这个本地 gitolite installation script .
然后您可以轻松地声明 Apache 登录名用于写访问,并声明 @all
用于读访问。
关于git - 如何通过 http 启用对 git 存储库的匿名读取访问( pull )但经过身份验证的写入访问(推送)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13792391/