Skip to content

fix(base): give safe.directory to every user - #152

Merged
TomGrozev merged 1 commit into
masterfrom
fix/base-git-safe-directory-system
Oct 24, 2026
Merged

TomGrozev merged 1 commit into
masterfrom
fix/base-git-safe-directory-system

Conversation

@agent-007-hq

Copy link
Copy Markdown
Collaborator

Summary

The base image wrote git's ownership escape hatch as root, into a file only root reads. Switch the scope one level up, so it reaches every user:

 # images/base/Dockerfile (build runs as USER root here)
-# Git safe directory
-RUN git config --global --add safe.directory '*'
+# Git safe directory, written to /etc/gitconfig so every user gets it
+RUN git config --system --add safe.directory '*'
Write Lands in Who reads it
--global as root /root/.gitconfig root only
--system /etc/gitconfig every user

Effect on a workspace mount:

dev runs git in ~/workspace (files owned by another UID)
  old image: fatal: detected dubious ownership
  new image: command runs

The Coder template keeps its GIT_CONFIG_* env vars, because the template can run an older published image. Comments in coder-template/main.tf and coder-template/README.md now name both sources.

Evidence

  • Before: docker run --rm ghcr.io/tomgrozev/devcontainer-base:latest git config --get-all safe.directory printed nothing, because the value sat in /root/.gitconfig.
    After: the PR Smoke Tests job asserts test "$(git config --get-all safe.directory)" = "*" as the image's default user dev.

No local run: this host has no container runtime.

Merge Danger

Door: two-way. Reverting restores the old scope.

Blast Radius: base image, and every image built on it (elixir, rust, agent layers).

* disables git's ownership check for all repositories in every derived image. The image already intended that with --global; the change only makes the intent take effect. Users who want the check keep it by unsetting the entry or mounting their own /etc/gitconfig.

`git config --global` ran as root during the build, so the entry landed in
/root/.gitconfig and the dev user never read it. A workspace whose files carry
another UID then failed git's ownership check with "dubious ownership".

Write the entry with `--system` to /etc/gitconfig, and assert in the PR smoke
test that dev can read it. Update the Coder template comments and its README to
name both sources of git safety: the image's system config and the deployment's
GIT_CONFIG_* env vars.
Co-authored-by: Tom Grozev <1491414+TomGrozev@users.noreply.github.com>
@TomGrozev
TomGrozev merged commit 228793b into master Oct 24, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants