Closed as not planned
Description
i think that git.utils.get_user_id
should return the Effective user and not the. currently the function uses getpass.getuser()
which relies on environment variables and not getuid/geteuid functions, from the docs
checks the environment variables LOGNAME, USER, LNAME and USERNAME, in order, and returns the value of the first one which is set to a non-empty string. If none are set, the login name from the password database is returned on systems which support the pwd module, otherwise, an exception is raised.
with the following code
import git
import os
import pwd
import shutil
from git.util import get_user_id
from pathlib import Path
CHECKOUT = Path("/tmp/gist")
shutil.rmtree(CHECKOUT, ignore_errors=True)
ORIGIN_REPO = "https://gist.github.com/b4ldr/449d490b43fb3d2d01a74d28bc9a41e4"
os.seteuid(pwd.getpwnam('jbond').pw_uid)
euid = pwd.getpwuid(os.geteuid()).pw_name
print(f"git.utils.get_user_id: {get_user_id()}")
print(f"euid: {euid}")
repo = git.Repo.clone_from(ORIGIN_REPO, CHECKOUT)
print(f"directory owner: {CHECKOUT.owner()}")
When run as root we get the following output
$ sudo python -i git_test.py
git user id: root@storage
euid: jbond
directory owner: jbond
i think it would be more useful if gitpython returned the user matching the EUID e.g. pwd.getpwuid(os.geteuid()).pw_name)
Metadata
Metadata
Assignees
Labels
No labels