简体   繁体   English

在 Git HTTP Smart 上读取身份验证不发出登录挑战

[英]Read Authentication on Git HTTP Smart not issuing signon challange

I have implemented a Centos8 based Git Smart HTTP Server.我已经实现了一个基于 Centos8 的 Git 智能 HTTP 服务器。 All of the "push" ops are working correctly and are requiring sign on authentication.所有“推送”操作都正常工作,并且需要登录身份验证。 Read ops work properly but are not requiring authentication.读取操作正常工作但不需要身份验证。 SSL is also working. SSL 也在工作。

While anonymous "reads" are standard for a public central repo, in a "private" environment it is quite likely there will be a requirement to prevent unauthenticated reads.虽然匿名“读取”是公共中央存储库的标准,但在“私有”环境中,很可能需要防止未经身份验证的读取。 For example, the following request should require a user and password.例如,以下请求应该需要用户和密码。 At the moment, it doesn't and is open to the public.目前,它没有并向公众开放。 this is the git-srv.include file.这是 git-srv.include 文件。 I have omitted the git-srv.conf file as it is trivial.我省略了 git-srv.conf 文件,因为它很简单。 This is a examples of an undesirable un-authenticated access这是不受欢迎的未经身份验证访问的示例
$ git ls-remote https://git.xxxxxx.systems/git/jtest 6c3652164e4694d76b41eb87662b997b813d8b51 HEAD 6c3652164e4694d76b41eb87662b997b813d8b51 refs/heads/master $ git ls-remote https://git.xxxxxx.systems/git/jtest 6c3652164e4694d76b41eb87662b997b813d8b51 HEAD 6c3652164e4694d76b41eb87662b3drefshead/1

I have added the following "Location" block in Apache .include but It is not forcing a signon for read operations.我在 Apache .include 中添加了以下“位置”块,但它不会强制登录进行读取操作。 Write signons are required.需要写签名。 The LocationsMatch Block is from the original I copied. LocationsMatch 块来自我复制的原件。

RewriteEngine On重写引擎开启
RewriteCond %{QUERY_STRING} service=git-receive-pack [OR] RewriteCond %{QUERY_STRING} service=git-receive-pack [OR]
RewriteCond %{REQUEST_URI} /git-receive-pack$ RewriteCond %{REQUEST_URI} /git-receive-pack$
RewriteRule ^/git/ - [E=AUTHREQUIRED:yes]重写规则 ^/git/ - [E=AUTHREQUIRED:yes]
SetEnv GIT_HTTP_EXPORT_ALL SetEnv GIT_HTTP_EXPORT_ALL
ScriptAlias /git/jtest /usr/libexec/git-core/git-http-backend/脚本别名 /git/jtest /usr/libexec/git-core/git-http-backend/

<Location "/srv/git/jtest"> <位置 "/srv/git/jtest">

    SetEnv GIT_PROJECT_ROOT /srv/git/<br/>
    AuthType Basic<br/>
    AuthName "Git Read Access to jtest"<br/>
    AuthUserFile /etc/httpd/.authusers-<br/>
    Require valid-user<br/>
    Order deny,allow<br/>
    Deny from env=AUTHREQUIRED<br/>
    Satisfy any<br/>

</Location> </位置>

<LocationMatch "^/git/jtest"> <LocationMatch "^/git/jtest">

    SetEnv GIT_PROJECT_ROOT /srv/git/<br/>
    AuthType Basic<br/>
    AuthName "Git Write Access to jtest"<br/>
    AuthUserFile /etc/httpd/.authusers-<br/>
    Require valid-user<br/>
    Order deny,allow<br/>
    Deny from env=AUTHREQUIRED<br/>
    Satisfy any<br/>

</LocationMatch> </位置匹配>

Any suggestions would be appreciated.任何建议,将不胜感激。

The problem is with this block:问题在于这个块:

RewriteCond %{QUERY_STRING} service=git-receive-pack [OR]
RewriteCond %{REQUEST_URI} /git-receive-pack$
RewriteRule ^/git/ - [E=AUTHREQUIRED:yes]

This block sets AUTHREQUIRED if your operation is git-receive-pack (an upload) but not if your operation is git-upload-pack (a clone or fetch).如果您的操作是git-receive-pack (上传),但如果您的操作是git-upload-pack (克隆或获取),则此块设置AUTHREQUIRED

You probably want to just remove that block since you always want to require authentication, and then change this:您可能只想删除该块,因为您总是希望进行身份验证,然后更改以下内容:

Require valid-user
Order deny,allow
Deny from env=AUTHREQUIRED
Satisfy any

to this:对此:

Require valid-user
Order deny,allow
Deny from all
Satisfy any

Then the default behavior is to deny, and you can satisfy your request by providing a valid user.然后默认行为是拒绝,您可以通过提供有效用户来满足您的请求。

If you need fancier access control, you can consider something like gitolite, which can control access to different repositories based on the user accessing it.如果你需要更高级的访问控制,你可以考虑像 gitolite 这样的东西,它可以根据访问它的用户控制对不同存储库的访问。

The response by bk220k answered the issue. bk220k 的回应回答了这个问题。 With that response.有了那个回应。 I was then able to reduce the git-srv.include file to solely the following code.然后我能够将git-srv.include文件简化为以下代码。 Now both reads and writes require authentication as I sought,现在读取和写入都需要我寻求的身份验证,

    SetEnv GIT_HTTP_EXPORT_ALL

    ScriptAlias /git/jtest /usr/libexec/git- 
      core/git-http-backend/
    <LocationMatch "^/git/jtest">
      SetEnv GIT_PROJECT_ROOT /srv/git/jtest    
      AuthType Basic
      AuthName "Git Write Access to jtest"
      AuthUserFile /etc/httpd/.authusers-jtest
      Require valid-user
      Order deny,allow
      Deny from all
      Satisfy any
    </LocationMatch>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM