【问题标题】:nginx with git-http-backend: insufficent access permission for `git push` with www-data user带有 git-http-backend 的 nginx:带有 www-data 用户的 `git push` 的访问权限不足
【发布时间】:2018-08-11 15:17:28
【问题描述】:

我正在尝试使用 fcgiwrap 设置 nginx 以将 https://<host>/git/<repo>.git 下的请求转发到 git-http-backend。

服务器是新装的debian linux,所以后台应该不会有什么尴尬的事情。

错误场景

fcgiwrap 套接字以www-data 用户身份运行,并且应该可以访问 git 存储库(见下文)。但是,当尝试推送时,我得到以下 git 消息(与访问权限问题有关,我想):

$ git push origin master
Counting objects: 6, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (6/6), 385 bytes | 0 bytes/s, done.
Total 6 (delta 0), reused 0 (delta 0)
remote: error: insufficient permission for adding an object to repository database objects
remote: fatal: failed to write object
error: unpack failed: unpack-objects abnormal exit
To https://xxx:xxx@127.0.0.1/git/test.git
 ! [remote rejected] master -> master (unpacker error)
error: failed to push some refs to 'https://xxx:xxx@127.0.0.1/git/test.git'

设置

nginx 配置:

server {                                                                                                                                                                          
        server_name  xxxxxxx.com;                                                                                                                                        

        location ~ /git(/.*) {                                                                                                                                                    
                auth_basic      "Private Git Repository";                                                                                                                         
                auth_basic_user_file /etc/nginx/.htpasswd;                                                                                                                        

                # fcgiwrap is set up to listen on this host:port                                                                                                                  
                fastcgi_pass unix:/var/run/fcgiwrap.socket;                                                                                                                       
                include       fastcgi_params;
                fastcgi_param SCRIPT_FILENAME     /usr/lib/git-core/git-http-backend;
                # export all repositories under GIT_PROJECT_ROOT
                fastcgi_param GIT_HTTP_EXPORT_ALL "";
                fastcgi_param GIT_PROJECT_ROOT    /opt/git;
                fastcgi_param PATH_INFO           $1;
                fastcgi_param REMOTE_USER $remote_user;
        }
}

FastCGIWrap:

$ apt-get install fcgiwrap
$ cat /etc/init.d/fcgiwrap
...
FCGI_USER="www-data"
FCGI_GROUP="www-data"
# Socket owner/group (will default to FCGI_USER/FCGI_GROUP if not defined)
FCGI_SOCKET_OWNER="www-data"
FCGI_SOCKET_GROUP="www-data"
...

/opt/git 中的权限:

$ chown -R git:git /opt/git/
$ chmod -R 775 /opt/git/
$ chmod -R a+s /opt/git/
$ ls -la /opt/git                                                                                                                         0 !193 0jobs
drwsrwsr-x 6 git  git  4096 Aug 11 15:21 .
drwxr-xr-x 3 root root 4096 Jul 15 12:01 ..
drwsrwsr-x 7 git  git  4096 Aug 12 11:47 test.git

git repo 配置:

$ cat /opt/git/test.git/config
[core]
        repositoryformatversion = 0
        filemode = true
        bare = true
        sharedrepository = 1
        sharedRepository = 1
[receive]
        denyNonFastforwards = true
[http]
    receivepack = true

nginx 用户是www-data,它是git 组的成员:

$ groups www-data
www-data : www-data git
$ cat /etc/group | grep www-data
www-data:x:33:
git:x:1001:www-data

解决方法

  1. 奇怪的是,如果我 chgrp -R www-data /opt/git/ 它可以工作。不过,我想将其设为git:git

  2. chmod a+s /usr/lib/git-core/git-http-* 有效。现在我也可以做chmod -R 705 /opt/git/ 并且它有效。我想是因为现在 root 用户执行命令。我怀疑这是安全的。所以不应该用...

  3. 使用 ssh。使用 ssh 有效,甚至以用户 www-data 的身份登录并直接推送到 repo 有效(因为组权限设置正确!)。但是,这不是选项,因为需要https 访问权限!

我错过了什么?

我的想法已经不多了。 推送每个 ssh 有效。 如果我这样做chown -R 770 /opt/git/,那么我什至无法再通过 https 进行克隆或获取。因此,www-data 用户似乎无法通过git-http-backend cgi 脚本进行访问。但为什么???用户是git 组的成员,应该具有组访问权限!!!

相关

【问题讨论】:

    标签: git nginx permissions git-http-backend


    【解决方案1】:

    重启!!

    不敢相信... 一个简单的服务器reboot 解决了它。

    我只是来尝试这个,因为在向我的用户添加组权限时,我必须实际注销并重新登录。似乎许可的东西有时不能即时应用?哇...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-05
      • 2016-05-21
      • 2018-09-30
      • 1970-01-01
      • 2014-08-01
      • 1970-01-01
      • 2017-10-21
      • 1970-01-01
      相关资源
      最近更新 更多