You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a process is run with "Run as Administrator" or some similar non-UAC mode, then libgit2 is unable to open repositories it creates. This is because the files are owned by Administrator, but the current user is still the local user. The check here will then fail.
I think this ownership validation is a little too strict simply for opening a repository. The git-for-windows CLI will also allow opening repositories owned by Administrator if the user account is also a member of Administrators (see is_path_owned_by_current_sid).
This comes up on GitHub Actions when running something with the default Powershell. It seems to be run without UAC and will create files owned by BUILTIN\Administrators but the user SID is runneradmin.
Steps:
Run a process as Administrator
Run a process that uses libgit2 to initialize a new repository, and then open the repository.
Expected behavior
Allow to open a repository owned by Administrators group when the current user is in the Administrators group.
I don't know that this issue is actually limited to Windows. I'm seeing the same thing with Linux.
I have a directory that's group-writable and the current user is in that group. I get the same "is not owned by current user" message as the OP.
I don't know the libgit2 codebase at all, really, but I'm at least a little bit wondering why this ownership validation is even a thing. Won't the underlying OS naturally prevent writes to locations on the file system that the user cannot write to? What's the benefit of the library overzealously attempting to enforce this itself?
fwiw, this is the behavior in v1.3+. v1.2 and previous seem to be ok.
@ethomson thanks for the info. I just read that post, but I'm having a little trouble connecting the dots between that and not being able to write to a directory I otherwise have permission to write to. In fact, I can git clone into said dir. (fwiw, I'm doing this as a non-root user inside a container running in Kubernetes. Kubernetes allows you to set the group ownership of a mounted volume, but not the user owner.)
@ethomson following up on this discussion could this check be made configurable/optional? I'm in a similar situation to @krancour where openshift (kubernetes) pods use random user IDs that don't match the filesystem user. I'm trying to perform read-only operations on a repo but am still running into the above error. What's interesting is that I'm able to use the git cli without any issues so this seems specific to libgit. Please let me know if this has been discussed elsewhere. Also I'm happy to work on implementing any changes that might be needed
The behavior should already be configurable via the safe.directory config. That setting was introduced in git 2.36.0 and should be understood by libgit2. In fact, the commit referenced by @ehuss introduces the check, (initial) support for safe.directory and the GIT_OPT_SET_OWNER_VALIDATION option which also lets you disable the check.
If git doesn't complain in your pod then I'd guess that there's some config introducing safe.directorys (which could missed by your version of libgit2 for some reason) or the pod comes with an old version (pre 2.36) of git. The outputs of git config --get-all safe.directory and git version would be helpful, as would be the specific version of libgit2 you are using.
EDIT: if you do find discrepancies between newer versions of git and libgit2, you may want to open another issue for that.
Hey @HonakerM - what @neithernut is on point. You can disable validation entirely if you want, but I'd love to understand why libgit2 is behaving differently here than git. I'd love to know what version of git you're using. 🙏
@ethomson@neithernut thank you both for your quick responses! I'll look into that config value, I had no idea about it. Also @ethomson you are spot on, the version of git I was using was old, git version 2.31.1 which explains the discrepancy! Thanks again to you both
Activity
krancour commentedon Apr 28, 2022
I don't know that this issue is actually limited to Windows. I'm seeing the same thing with Linux.
I have a directory that's group-writable and the current user is in that group. I get the same "is not owned by current user" message as the OP.
I don't know the libgit2 codebase at all, really, but I'm at least a little bit wondering why this ownership validation is even a thing. Won't the underlying OS naturally prevent writes to locations on the file system that the user cannot write to? What's the benefit of the library overzealously attempting to enforce this itself?
fwiw, this is the behavior in v1.3+. v1.2 and previous seem to be ok.
ethomson commentedon Apr 28, 2022
Thanks @ehuss! We'll match git's behavior since we aim to be bug-for-bug compatible. I misread the patch on the mailing list.
That's by design, @krancour. You can find out more in the security post.
krancour commentedon Apr 28, 2022
@ethomson thanks for the info. I just read that post, but I'm having a little trouble connecting the dots between that and not being able to write to a directory I otherwise have permission to write to. In fact, I can
git cloneinto said dir. (fwiw, I'm doing this as a non-root user inside a container running in Kubernetes. Kubernetes allows you to set the group ownership of a mounted volume, but not the user owner.)HonakerM commentedon Apr 22, 2023
@ethomson following up on this discussion could this check be made configurable/optional? I'm in a similar situation to @krancour where openshift (kubernetes) pods use random user IDs that don't match the filesystem user. I'm trying to perform read-only operations on a repo but am still running into the above error. What's interesting is that I'm able to use the
gitcli without any issues so this seems specific to libgit. Please let me know if this has been discussed elsewhere. Also I'm happy to work on implementing any changes that might be neededneithernut commentedon Apr 22, 2023
The behavior should already be configurable via the
safe.directoryconfig. That setting was introduced in git 2.36.0 and should be understood by libgit2. In fact, the commit referenced by @ehuss introduces the check, (initial) support forsafe.directoryand theGIT_OPT_SET_OWNER_VALIDATIONoption which also lets you disable the check.If
gitdoesn't complain in your pod then I'd guess that there's some config introducingsafe.directorys (which could missed by your version oflibgit2for some reason) or the pod comes with an old version (pre 2.36) ofgit. The outputs ofgit config --get-all safe.directoryandgit versionwould be helpful, as would be the specific version oflibgit2you are using.EDIT: if you do find discrepancies between newer versions of git and libgit2, you may want to open another issue for that.
ethomson commentedon Apr 22, 2023
Hey @HonakerM - what @neithernut is on point. You can disable validation entirely if you want, but I'd love to understand why libgit2 is behaving differently here than git. I'd love to know what version of
gityou're using. 🙏HonakerM commentedon Apr 22, 2023
@ethomson @neithernut thank you both for your quick responses! I'll look into that config value, I had no idea about it. Also @ethomson you are spot on, the version of git I was using was old,
git version 2.31.1which explains the discrepancy! Thanks again to you both