gitea: New git security policy `safe.directory` (eg: 1.16.6 docker image) makes pushing fails
Description
Since upgrading to 1.16.6, every push fails with the following error:
git -c diff.mnemonicprefix=false -c core.quotepath=false --no-optional-locks push -v origin master:master
fatal: credential-cache unavailable; no unix socket support
POST git-receive-pack (2733 bytes)
remote:
remote: Gitea: Internal Server Error
In docker console this is logged:
Failed to open repository: Git/Data Error: exit status 128 - fatal: unsafe repository ('/data/git/repositories/git/data.git' is owned by someone else)
Downgrading to 1.16.5 makes it work again. UI works in 1.16.6 and also allows me to browse the files in this repository (or any other, all have this push error).
Gitea Version
1.16.6
Can you reproduce the bug on the Gitea demo site?
No
How are you running Gitea?
Windows Server 2022 + Docker. Windows 10 + Docker has the same problem.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 94 (55 by maintainers)
Commits related to this issue
- git 2.36 is needed for safe.directory = '*' to work Refs: #19455 — committed to singuliere/gitea by singuliere 2 years ago
- gitconfig: set safe.directory = * Allow git push to work when networked file systems with mixed ownership are used with Gitea docker images >= 1.16.6 or Gitea binaries running alongside git versions ... — committed to singuliere/gitea by singuliere 2 years ago
- gitconfig: set safe.directory = * (#19870) Allow git push to work when networked file systems with mixed ownership are used with Gitea docker images >= 1.16.6 or Gitea binaries running alongside gi... — committed to go-gitea/gitea by singuliere 2 years ago
- gitconfig: set safe.directory = * (#19870) Allow git push to work when networked file systems with mixed ownership are used with Gitea docker images >= 1.16.6 or Gitea binaries running alongside gi... — committed to IntegraSDL/gitea by singuliere 2 years ago
- gitconfig: set safe.directory = * (#19870) Allow git push to work when networked file systems with mixed ownership are used with Gitea docker images >= 1.16.6 or Gitea binaries running alongside gi... — committed to kitspace/gitea by singuliere 2 years ago
- Downgrading to go version pre-v18, to workaround https://github.com/go-gitea/gitea/issues/19455 — committed to bcgov/nrm-feedback by garywong-bc 2 years ago
- Updates to build, deployment and development for OCP4 and Fider 0.21.1 (#42) * OCP4 updates * Trying w updated Node version * Updating reference to Artifactory (sub-folder) * Resolving 'Erro... — committed to bcgov/nrm-feedback by garywong-bc 2 years ago
WinServer 2019 + gitia 1.16.6 amd64 (with out gogit) + git 2.36.0.windows.1 = Error 500 in Web UI or error push 128 solution: add to
C:\Program Files\Git\etc\gitconfigIt does not appear to. I also tried
/data/git/*and that didn’t work either. After some research, the wildcard ability was added in 2.36 from what I can tell, the version of git running in my gitea container is 2.30.3. Maybe recursive is added as well.Just encountered this issue myself. Running docker on Ubuntu Linux.
So I am mounting
repositoriesandlfsfrom an NFS Share from TrueNAS:This same filesystem is also shared to a Windows machine via an SMB share. For some reason adding
directory = *under the[safe]section did not fix the issue, had to specify the exact path, so not ideal. I did notice a bunch of my repo dirs were owned byroot. I didchownthose togit(which is the user gitea was running under).However, once I added the
directoryto safe, the new repo was created withrootas the owner.There is a transparent solution: setting safe.directory=* in customized git global config, then no security risk for Gitea internal usage, users do not need to do anything, Gitea doesn’t blow up it’s app.ini/settings, no need to update document, and from then on Gitea never pollute user’s git config again and again.
Still same error. User ownership doesn’t matter to get this error either, I’ve tried repos with git and root user, the error is the same. And it indeed usualy changes on (failed, obviously) push from root to git.
On second thought, I think as soon as the repos directory is volume-mounted to the outside, the system could be seen as multi-user. So concluding, I would advice to either:
chownthe files so they are owned by eithergitin rootless orrootin rootful image/etc/gitconfigand volume-mount that file into the container. This is the wildcard version of the workaround, I think it could also be to just the repository directory.I see no “risk” in a docker environment when bypassing these fixes. The CVEs are only relevant in multi-user system, while our docker environment is strictly single-user.
No. I run a docker image in macOS.
But the equivalent exists in windows via : properties -> security -> advance -> change owner And ticking the [x] replace all child object permission entries with inheritable permission entries from this object
I run Windows as host, this is not possible.
Quick question, is this title really correct? From what I read its about git and not docker. So I suggest changing it.