3 Commits

Author SHA1 Message Date
MohammadHasan Akbari
8086fae369 gitutil: preserve SUDO_UID for git subprocesses
When git runs as root under sudo it consults SUDO_UID to decide whether a
repository's ownership can be trusted, additionally granting access to
repositories owned by the user who invoked sudo. GitCLI builds a
restricted environment for the git subprocess and did not forward
SUDO_UID, so commands such as `sudo docker build` tripped git's "detected
dubious ownership" check and silently lost commit provenance: the build
still succeeds but prints "current commit information was not captured by
the build".

Forward SUDO_UID (only when present) on the host git config path enabled
via WithHostGitConfig, i.e. client-side local git inspection. The default
isolated path used by daemon-side callers is left untouched so it does not
pick up host environment. This matches git's own default behavior under
sudo: it does not disable safe.directory checks and is not equivalent to
safe.directory=*; it merely lets git trust repositories owned by the
invoking user. Only SUDO_UID is forwarded (git's ownership check is
uid-based and never consults SUDO_GID).

Fixes the root cause for docker/buildx#3855. buildx inspects the build
context through this GitCLI with WithHostGitConfig enabled, so buildx
picks the fix up via a moby/buildkit dependency bump with no buildx-side
code change.

Signed-off-by: MohammadHasan Akbari <jarqvi.jarqvi@gmail.com>
2026-06-18 10:28:08 +04:00
CrazyMax
5bc2459bf2 gitutil: add opt-in support for host git config
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2026-04-02 23:25:40 +02:00
Tonis Tiigi
e6e602641d gitutil: avoid global git config lookup on Windows
Avoid global conf lookup via HOME that fails on Windows.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-04-01 17:38:15 -07:00