Git has started requiring write access to the root of bare repositories in order to create /HEAD.lock. This is a major security problem in shared environments as it also entails control over the /config link i.e. core.hooksPath. Permission to write objects and update refs should be entirely separate from permission to edit hook execution logic. Given that /HEAD is not dynamically modified in the normal lifetimes of bare repositories, /HEAD.lock creation failure should probably be, at worst, an ignorable soft failure. Alternatively, some form of stale lockfile handling (currently there is none) could be made to work with a writable HEAD.lock in a read-only bare repository. Obigatory HEAD.lock creation was introduced in the following commit: commit 92b1551b1d407065f961ffd1d972481063a0edcc Author: Michael Haggerty <mhagger@xxxxxxxxxxxx> Date: Mon Apr 25 15:56:07 2016 +0200 refs: resolve symbolic refs first Test case: root@richardiv:~# GIT_DIR=/tmp/test.git git init --bare --shared=group Initialized empty shared Git repository in /tmp/test.git/ root@richardiv:~# cd /tmp/test.git root@richardiv:/tmp/test.git# touch git-daemon-export-ok packed-refs root@richardiv:/tmp/test.git# mkdir -p info logs branches root@richardiv:/tmp/test.git# find refs info branches objects logs -type d -print0 | xargs -0 chmod 2775 root@richardiv:/tmp/test.git# find refs info branches logs HEAD packed-refs -type f -print0 | xargs -0 chmod 0664 root@richardiv:/tmp/test.git# find objects -type f -print0 | xargs -0 --no-run-if-empty chmod 0644 root@richardiv:/tmp/test.git# find refs info branches objects logs HEAD packed-refs -print0 | xargs -0 chgrp git-test root@richardiv:/tmp/test.git# chown root.root . config description git-daemon-export-ok hooks root@richardiv:/tmp/test.git# chmod 0644 config description git-daemon-export-ok root@richardiv:/tmp/test.git# chmod 00755 . hooks root@richardiv:/tmp/test.git# sudo -i -u user1 user1@richardiv:~$ git clone /tmp/test.git Cloning into 'test'... warning: You appear to have cloned an empty repository. done. user1@richardiv:~$ cd test user1@richardiv:~/test$ touch test user1@richardiv:~/test$ git add test user1@richardiv:~/test$ git commit -m test test [master (root-commit) ff21d72] test 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test user1@richardiv:~/test$ git push Counting objects: 3, done. Writing objects: 100% (3/3), 206 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) remote: error: cannot lock ref 'HEAD': Unable to create '/tmp/test.git/HEAD.lock': Permission denied To /tmp/test.git ! [remote rejected] master -> master (failed to update ref) error: failed to push some refs to '/tmp/test.git' user1@richardiv:~/test$ logout root@richardiv:/tmp/test.git# chgrp git-test . root@richardiv:/tmp/test.git# chmod 2775 . root@richardiv:/tmp/test.git# sudo -s -u user1 user1@richardiv:/tmp/test.git$ mv config config-old user1@richardiv:/tmp/test.git$ touch config # POWER ALMIGHTY user1@richardiv:/tmp/test.git$ Please CC me on this thread; I am not on the mailing list.
Attachment:
signature.asc
Description: signature