具有 git-http-backend 的 nginx:对 www-data 用户的 `git push` 的访问权限不足

nginx with git-http-backend: insufficent access permission for `git push` with www-data user

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

服务器是新装的debianlinux,所以后台应该没有什么别扭的东西。

错误场景

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           ;
                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 回购配置:

$ 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 组的成员,应该具有组访问权限!!!

相关

重启!!

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

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