Skip to content

Ownership check on windows seems too strict #6279

Description

@ehuss

Reproduction steps

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:

  1. Run a process as Administrator
  2. 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.

Actual behavior

Fails with "is not owned by current user" error.

Version of libgit2 (release number or SHA1)

6397024

Operating system(s) tested

Windows 10 Version 2004
Windows 10.0.20348 (Windows Server 2022 Datacenter)

Activity

  1. krancour commented on Apr 28, 2022

    @krancour

    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.

  2. ethomson commented on Apr 28, 2022

    @ethomson
    Member

    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.

    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.

    That's by design, @krancour. You can find out more in the security post.

  3. krancour commented on Apr 28, 2022

    @krancour

    @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.)

  4. HonakerM commented on Apr 22, 2023

    @HonakerM

    @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

  5. neithernut commented on Apr 22, 2023

    @neithernut
    Contributor

    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.

  6. ethomson commented on Apr 22, 2023

    @ethomson
    Member

    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. 🙏

  7. HonakerM commented on Apr 22, 2023

    @HonakerM

    @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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions