我的目标是通过HTTP/HTTPS在git cloneweb服务器2.4.29上实现对git裸存储库的匿名读访问(git pull/ git pull)和身份验证的写访问(git push)。
我尝试文档化的配置(https://git-scm.com/docs/git-http-backend):
SetEnv GIT_PROJECT_ROOT /var/www/git
SetEnv GIT_HTTP_EXPORT_ALL
ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/..。在这两种变体中。
变式1)与模块mod_rewrite
RewriteCond %{QUERY_STRING} service=git-receive-pack [OR]
RewriteCond %{REQUEST_URI} /git-receive-pack$
RewriteRule ^/git/ - [E=AUTHREQUIRED:yes]
<LocationMatch "^/git/">
Order Deny,Allow
Deny from env=AUTHREQUIRED
AuthType Basic
AuthName "Git Access"
AuthBasicProvider ldap
AuthLDAPURL ldap://ldapserver:386
Require user test
Satisfy Any
</LocationMatch>变式2:没有模块mod_rewrite
<LocationMatch "^/git/.*/git-receive-pack$">
AuthType Basic
AuthName "Git Access"
AuthBasicProvider ldap
AuthLDAPURL ldap://ldapserver:386
Require user test
</LocationMatch>
<LocationMatch "^/git/">
Require all granted
Allow from all
</LocationMatch>我在服务器端使用debian包apache2 (2.4.29-1 ubuntu4.14),在客户端使用git2.29.2来测试配置。
两种变体都不起作用。
发布于 2020-12-27 14:08:02
这个问题是由不完整的文档https://git-scm.com/docs/git-http-backend引起的。
对于mod_rewrite**)**变体1(使用模块),需要启用重写引擎。添加RewriteEngine On解决了这个问题。使用正确的LogLevel语句(在下面的示例中注释掉),您可以在apache2日志文件中观察正确的行为。
RewriteEngine On
#LogLevel alert rewrite:trace6
SetEnv GIT_PROJECT_ROOT /var/www/git
SetEnv GIT_HTTP_EXPORT_ALL
ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/对于rewrite_mod**)**变体2(没有模块 LocationMatch ),在我的示例中LocationMatch将不匹配,因为git pull是使用查询字符串完成的:
GET /git/repo.git/info/refs?service=git-receive-pack描述的LocationMatch无法检查请求的查询字符串。
见http://httpd.apache.org/docs/2.0/en/mod/core.html#location ..。
不包括任何方案、主机名、端口或查询字符串。
一个解决方案是在<If>...</If><Else>...</Else>中添加LocationMatch (也请参阅2019594)。使用CustomLog语句,如果LocationMatch按需要工作,就可以签入日志文件(参见https://serverfault.com/questions/718234/how-to-check-if-locationmatch-regex-is-working)。
CustomLog ${APACHE_LOG_DIR}/location.log "%h %l %u %t \"%r\" %>s %b what:%{INDICATOR_VAR}e"
<LocationMatch "^/git/">
<If "%{QUERY_STRING} =~ /service=git-receive-pack/">
SetEnv INDICATOR_VAR "git push"
AuthType Basic
AuthName "Git Access"
AuthBasicProvider ldap
AuthLDAPURL ldap://ldapserver:386
Require user test
Allow from all
</If>
<Else>
SetEnv INDICATOR_VAR "git pull"
Require all granted
Allow from all
</Else>
</LocationMatch>https://stackoverflow.com/questions/65466618
复制相似问题