JG7*_*707 8 nginx basic-authentication gitlab
我已经成功安装了GitLab来管理私有存储库(它非常棒!).
我遇到的问题是默认情况下,当有人点击我的子域时会出现Gitlab登录.在用户获取GitLab登录屏幕之前,我想用basic_auth层保护整个区域.不幸的是,当它启用时,这会破坏我从GitLab推/拉的能力.
我的nginx配置启用basic_auth:
  auth_basic            "Restricted";
  auth_basic_user_file  htpasswd;
关于如何在不破坏git/gitlab功能的情况下启用basic_auth的任何想法?
将此添加到/etc/gitlab/gitlab.rb:
nginx['custom_gitlab_server_config'] = "auth_basic 'Restricted';\n  auth_basic_user_file htpasswd;\n"
并运行 gitlab-ctl reconfigure
目前有点黑客攻击,但可以尝试一下。
编辑您的 nginx 站点配置以添加/修改以下位置
location ^~ /api/v3/internal/allowed {
    proxy_read_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
    proxy_connect_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
    proxy_redirect     off;
    proxy_set_header   X-Forwarded-Proto $scheme;
    proxy_set_header   Host              $http_host;
    proxy_set_header   X-Real-IP         $remote_addr;
    proxy_pass http://gitlab;}
location / {
    auth_basic "Gitlab Restricted Access";
    auth_basic_user_file  /home/git/gitlab/htpasswd.users;
    # serve static files from defined root folder;.
    # @gitlab is a named location for the upstream fallback, see below
    try_files $uri $uri/index.html $uri.html @gitlab;
}
保留您的 @gitlab 位置块不变。
诀窍是让 /api/v3/internal/allowd 绕过身份验证。如果您在执行 git pull/push 时查看日志,则会向服务器发出是否允许的请求。在带有 htpasswd 的标准 nginx 配置上,该请求将被阻止,因为服务器不知道所需的身份验证。
无论如何,不确定是否有更好的选择(找不到任何),但这似乎对我有用。
| 归档时间: | 
 | 
| 查看次数: | 4885 次 | 
| 最近记录: |