libgit2 / libgit2/pygit2

pygit2 does not respect a global setting of safe.directory='*'

Open
#1,156 7 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.7k
Forks
408
Avg merge
2d 57m
Merged PRs (30d)
7

Description

We are currently working with dvc for multiple projects and the dvc exp run leads to a pygit2 exception on a azure machine learning instance. This leads to problems since folders on mounted drives in azure belong to user root whilst the working user is azureuser The exception looks like following:

_pygit2.GitError: /mnt/batch/tasks/shared/LS_root/mounts/clusters/<XXX>/.git/: repository path '/mnt/batch/tasks/shared/LS_root/mounts/clusters/<XXX>' is not owned by current user

A workaround for this problem should be setting the git safe.directory to ='*'.
But unfortunately this does not work with dvc resp. pygit2.

I narrowed the problem down and was able to reproduce it with pure pygit2.
Since it seems to be a pygit2 problem, I am opening the issue directly here.
FYI @efiop, @skshetry, @dmpetrov

My git config looks as follows:

user.email=<XXX>
user.name=<XXX>
safe.directory=*

With my normal git (git version 2.36.1) everything works great with the wildcard *. But pygit2 seems to ignore this config.

import pygit2
repo = pygit2.Repository(pygit2.discover_repository('.'))
GitError: /mnt/batch/tasks/shared/LS_root/mounts/clusters/<XXX>/.git: repository path '/mnt/batch/tasks/shared/LS_root/mounts/clusters/<XXX>/' is not owned by current user

But the config seems to be loaded:

import pygit2
config = pygit2.Config()
for x in config.get_global_config():
    print(x.name + ":" + x.value)
user.email:<XXX>
user.name:<XXX>
safe.directory:*

Used Versions: pygit2 1.10.0

Any help would be really appreciated, since we can't run experiments anymore.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the pure pygit2 reproduction using pygit2.Repository and compare it with the global Config output shown for safe.directory=*. Investigate the repository ownership check in pygit2 1.10.0 and verify behavior against Git 2.36.1. Done means a global wildcard safe.directory setting permits the reproduced repository to open without the ownership error.

Written by the indexing model from the issue text.

Assessment

Tech stack
git, python
Domain
security, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.