0

Whenever I try to commit to a particular Git repo, I'm getting the error "Insufficient Permission For Adding An Object To Repository Database .git/objects." Initially, this seems like the same question that's already been asked & answered countless times (i.e. here, here, here, etc). However, the solution that's always given - which seems quite obvious from the error message itself - is that it's one of file permissions and/or ownership. Yet even when I recursively set the owner for the entire directory tree, and recursively set permissions to the most "permissive" 777...I still can't seem to resolve the error.

More details: the Git commits are actually taking place by a service running in a Docker container. The repo is on a filesystem on the host machine, that's mapped into the container. I know that the uid/gid used by the container when it invokes Git is 2999, so in order to test/debug the issue more easily from the host machine, I can use docker exec. First, just to confirm how to use docker exec to run commands as a specific user:

docker exec -u 2999:2999 containerName sh -c "id"

...Yup, as expected, this prints uid=2999 and gid=2999.

So first I'll set the recursive permissions & ownership, per all the solutions given elsewhere to this error:

docker exec containerName sh -c "chmod 777 /path/to/repo -R"
docker exec containerName sh -c "chown 2999:2999 /path/to/repo -R"

I can then confirm that they were set properly:

docker exec containerName sh -c "ls -la /path/to/repo"

Now, let's try to run some git commands:

docker exec -u 2999:2999 containerName sh -c "cd /path/to/repo && git add -A"
docker exec -u 2999:2999 containerName sh -c "cd /path/to/repo && git commit -m 'testcomit'"

The result:

error: insufficient permission for adding an object to repository database .git/objects
error: testfile: failed to insert into database
error: unable to index file testfile 
fatal: adding files failed

At this point, I'm at a total loss. If I've explicitly set the ownership/permissions and am explicitly running the commit as the same user...why would this error still arise? Note that I can definitely write to the repo itself as user 2999, so it only seems to be Git that's failing. For example, this works, & the file does appear as expected:

docker exec -u 2999:2999 containerName sh -c "echo sometext > /path/to/repo/testfile"
J23
  • 3,061
  • 6
  • 41
  • 52
  • Is this repository living on a file system within the container or is it living on a file system outside of the container that's been mapped in? – bk2204 Apr 07 '19 at 23:54
  • Filesystem outside the container that's been mapped in. – J23 Apr 07 '19 at 23:55
  • Are you using user namespaces with your containers? – bk2204 Apr 08 '19 at 00:00
  • When I run docker inspect, it shows "UsernsMode": "". I'm not really familiar with user namespaces - but the container came from DockerHub, & one thing I should probably add is that I've actually run this same container on a previous server, and there, Git did work as expected. Also, as I'm both setting the permissions and running git from within the container, wouldn't namespaces not have an effect? (i.e. I'm not setting the uid from outside then running from inside - I'm doing both by means of docker exec, aka "inside")? – J23 Apr 08 '19 at 00:06
  • If you're using user namespaces (which you are, since the value is "" and not "host"), the UID 2999 that you're using on the `docker exec` command line won't map to the 2999 that's inside the container. In general, it's highly unusual to use numeric user IDs for permissions, and I suspect that's what's getting you into trouble here. It's also possible that your container just won't have privileges to write to that directory at all. – bk2204 Apr 08 '19 at 00:53
  • Well, just out of curiosity, I also ran docker inspect on the old server, where Git works - it also shows UsernsMode = "". Why might it be working on one system and not the other? Also, if this is indeed the issue, does it seem odd that the final "echo sometext" example shown above would work (aka be able to write to that dir) while Git would not? Finally, and perhaps most importantly...could you suggest a possible solution? Thanks so much for your thoughts/insight :) – J23 Apr 08 '19 at 01:06

0 Answers0