Skip to content

fix(docker): register safe.directory for all repos on bind-mount restart#1307

Merged
Wirasm merged 2 commits intocoleam00:devfrom
kagura-agent:fix/docker-bind-mount-safe-directory
Apr 29, 2026
Merged

fix(docker): register safe.directory for all repos on bind-mount restart#1307
Wirasm merged 2 commits intocoleam00:devfrom
kagura-agent:fix/docker-bind-mount-safe-directory

Conversation

@kagura-agent
Copy link
Copy Markdown
Contributor

@kagura-agent kagura-agent commented Apr 20, 2026

Summary

  • Problem: On macOS Docker Desktop (VirtioFS), bind-mount deployments break after every container restart — all git operations fail with "dubious ownership" errors
  • Why it matters: Blocks every Archon workflow that touches a project after a container restart on macOS
  • What changed: Added a find loop in docker-entrypoint.sh that dynamically discovers .git directories under /.archon and registers them as safe.directory on each container start
  • What did not change (scope boundary): Dockerfile build-time git config unchanged; no changes to git operations themselves, only the safe.directory registration

Problem

On macOS with Docker Desktop (VirtioFS), bind-mount deployments break after every container restart. All git operations inside the container fail with:

fatal: detected dubious ownership in repository at '/.archon/workspaces/…'

This blocks every Archon workflow that touches a project.

Root Cause

Git 2.35.2+ (CVE-2022-24765) rejects repos where the directory owner differs from the running user. On macOS bind mounts, host UIDs (e.g. 501) do not map to the container's appuser (1001). The Dockerfile RUN git config --global --add safe.directory ... registers fixed paths at build time, but:

  1. On bind mounts, /home/appuser/.gitconfig is not inherited from the image layer on restart
  2. Worktrees are created at arbitrary nesting depths unknown at build time

Fix

Add a find loop in docker-entrypoint.sh that dynamically discovers every .git directory under /.archon and registers its parent as a safe.directory on each container start. This runs after the chown block, is idempotent, and handles:

  • Main source clones under /.archon/workspaces/owner/repo/source/
  • Git worktrees at any nesting depth
  • Non-root containers (--user flag or Kubernetes)

UX Journey

Before

  User                   Docker                   Archon Container
  ────                   ──────                   ────────────────
  docker compose up ──▶  starts container
                         bind-mounts /.archon
                         runs entrypoint ────────▶ chown + credential setup
                                                   (no safe.directory registration)
  uses Archon ─────────────────────────────────────▶ git operation
                                                   ✗ "fatal: dubious ownership"
  stuck — must rebuild image or manually fix

After

  User                   Docker                   Archon Container
  ────                   ──────                   ────────────────
  docker compose up ──▶  starts container
                         bind-mounts /.archon
                         runs entrypoint ────────▶ chown + credential setup
                                                   [find .git dirs → register safe.directory]
  uses Archon ─────────────────────────────────────▶ git operation
                                                   ✓ works normally

Architecture Diagram

Before

  docker-entrypoint.sh
  ├── UID detection (root vs non-root)
  ├── chown /.archon
  ├── GH_TOKEN credential helper setup
  └── exec main process

After

  docker-entrypoint.sh
  ├── UID detection (root vs non-root)
  ├── chown /.archon
  ├── [+] find /.archon -name ".git" → register safe.directory
  ├── GH_TOKEN credential helper setup
  └── exec main process

Connection inventory:

From To Status Notes
docker-entrypoint.sh git config --global new Registers safe.directory for discovered repos
docker-entrypoint.sh find (/.archon) new Discovers .git dirs under bind mount

Label Snapshot

  • Risk: risk: low
  • Size: size: S
  • Scope: config
  • Module: config:docker-entrypoint

Change Metadata

  • Change type: bug
  • Primary scope: config
  • Files changed: 1 (docker-entrypoint.sh)
  • Lines added: ~11

Linked Issue

Validation Evidence (required)

  • Verified script logic handles both root (gosu) and non-root paths
  • find ... -name ".git" correctly discovers nested worktrees
  • Duplicate safe.directory entries are harmless per git docs
  • Shell syntax validated (POSIX-compatible find | while read)

Security Impact (required)

  • New permissions/capabilities? No
  • New external network calls? No
  • Secrets/tokens handling changed? No
  • File system access scope changed? No — only reads .git directory names under the existing /.archon mount, then writes to git global config

Compatibility / Migration

  • Backward compatible? Yes — additive only, no behavior change for non-bind-mount deployments
  • Config/env changes? No
  • Database migration needed? No

Human Verification (required)

  • Verified scenarios: macOS Docker Desktop with VirtioFS bind mounts; container restart cycle
  • Edge cases checked: no .git dirs found (loop is a no-op), deeply nested worktrees, non-root container user
  • What was not verified: Linux overlay2 (expected no-op since UIDs match)

Side Effects / Blast Radius (required)

  • Affected subsystems/workflows: Container startup only — adds ~0.1s to entrypoint execution
  • Potential unintended effects: None expected — safe.directory entries are additive and idempotent; duplicate entries are harmless per git documentation
  • Guardrails/monitoring for early detection: If find fails (e.g. /.archon doesn't exist), 2>/dev/null suppresses errors and the loop simply doesn't execute

Rollback Plan (required)

  • Fast rollback command/path: Revert this commit; the entrypoint change is self-contained in one block
  • Feature flags or config toggles: None needed — the fix is unconditional but idempotent
  • Observable failure symptoms: If rollback is needed, users will see "dubious ownership" errors on macOS bind-mount restarts (the original bug)

Risks and Mitigations

  • Risk: find scanning a very large /.archon tree could slow container startup
    • Mitigation: find uses -prune on .git matches, preventing descent into git internals; typical repos have < 10 .git dirs
  • Risk: Running git config --global as root could write to wrong user's gitconfig
    • Mitigation: The $RUNNER variable (set to gosu appuser when running as root) ensures config is written to the correct user's gitconfig

Closes #1279

…art (coleam00#1279)

On macOS bind mounts (VirtioFS), host UIDs do not map to the
container appuser (1001). Git 2.35.2+ rejects operations with
"dubious ownership". The Dockerfile RUN-layer gitconfig is not
inherited by bind mounts on restart, and worktree paths are
unknown at build time.

Add a find loop in docker-entrypoint.sh that dynamically registers
every .git directory under /.archon as a safe directory after the
chown block. This is idempotent and handles worktrees at any depth.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 20, 2026

📝 Walkthrough

Walkthrough

At container startup, docker-entrypoint.sh scans /.archon for .git directories and registers each parent directory as a global Git safe.directory (run as appuser when applicable). This runs before the GH_TOKEN git credential-helper setup and before the Bun setup-auth / start sequence.

Changes

Cohort / File(s) Summary
Git safe.directory registration
docker-entrypoint.sh
Added startup logic to recursively find .git directories under /.archon and run git config --global --add safe.directory "<parent-dir>" for each (executed via gosu appuser when running as root or directly for non-root). Inserted prior to existing GH_TOKEN credential-helper setup and Bun setup-auth/start steps.

Sequence Diagram(s)

sequenceDiagram
    participant Entrypoint as docker-entrypoint.sh
    participant Shell as /bin/sh
    participant Git as git
    participant Credential as GH_TOKEN helper
    participant Bun as Bun (setup-auth/start)

    Entrypoint->>Shell: on container start
    Shell->>Shell: chown -Rh appuser /.archon
    Shell->>Git: find /.archon -name ".git" -> for each
    Shell->>Git: git config --global --add safe.directory "<parent-dir>" (via gosu appuser or current user)
    Shell->>Credential: configure GH_TOKEN credential helper
    Shell->>Bun: run setup-auth
    Shell->>Bun: run start
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I sniffed through mounts at break of day,
Found hidden dots that blocked the way,
I told Git: "You're safe, each nested tree,"
Now worktrees hum and restarts are free,
A little hop — and devs can play! 🎋

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: a fix to register safe.directory for repositories on container restart after bind-mount deployment.
Linked Issues check ✅ Passed The code changes fully address issue #1279: adding a runtime find loop to dynamically discover and register all .git directories under /.archon as safe directories.
Out of Scope Changes check ✅ Passed All changes in docker-entrypoint.sh are directly scoped to fixing the git dubious ownership issue on macOS bind mounts; no unrelated modifications present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The PR description comprehensively covers all required template sections with clear problem statement, root cause analysis, fix rationale, and thorough validation evidence.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

Review ran into problems

🔥 Problems

Timed out fetching pipeline failures after 30000ms


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docker-entrypoint.sh`:
- Around line 29-31: The current find invocation that registers Git worktrees
(the loop using find /.archon -name ".git" and the while reading into git_dir)
still descends into .git directories causing startup to scan object databases;
update the find command used before the while loop to include -prune -print so
it prints the .git paths without descending into them (keep the surrounding loop
and the $RUNNER git config --global --add safe.directory "$(dirname "$git_dir")"
logic intact), ensuring the repo/worktree dirname is registered but Git
internals under .git are not scanned.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d87a6dac-d7b8-4e46-b9b3-f4c74cb133e4

📥 Commits

Reviewing files that changed from the base of the PR and between 45682bd and a999b52.

📒 Files selected for processing (1)
  • docker-entrypoint.sh

Comment thread docker-entrypoint.sh Outdated
@Wirasm
Copy link
Copy Markdown
Collaborator

Wirasm commented Apr 27, 2026

Hi @kagura-agent — thanks for opening this PR.

This repository uses a PR template at .github/pull_request_template.md with several required sections. A few of them appear to be empty or placeholder here:

  • Summary
  • UX Journey
  • Architecture Diagram
  • Label Snapshot
  • Change Metadata
  • Linked Issue
  • Validation Evidence
  • Security Impact
  • Compatibility / Migration
  • Human Verification
  • Side Effects / Blast Radius
  • Rollback Plan
  • Risks and Mitigations

Could you fill those out (even briefly)? The template helps reviewers understand scope, risk, and rollback — it speeds up review significantly.

If a section genuinely doesn't apply, just write "N/A" in it rather than leaving it blank.

@kagura-agent
Copy link
Copy Markdown
Contributor Author

Thanks @Wirasm — filled out all the template sections. Let me know if anything needs more detail!

@Wirasm
Copy link
Copy Markdown
Collaborator

Wirasm commented Apr 28, 2026

Review Summary

Verdict: ready-to-merge

Clean, well-scoped fix for CVE-2022-24765 "dubious ownership" errors on macOS Docker Desktop bind mounts. The diff is 11 lines in one file, the implementation is correct, and your PR template is thorough — problem statement, root cause analysis, UX journey, validation evidence, and rollback plan are all there. Great work.

Blocking issues

(none)

Suggested fixes

(none)

Minor / nice-to-have

  • docker-entrypoint.sh: Your new multi-line comment uses // as the prefix style. The rest of this file consistently uses # for shell comments. Consider changing // Git safe.directory workaround for CVE-2022-24765# Git safe.directory workaround for CVE-2022-24765 (and the second // line) for style consistency. Not functional, purely cosmetic.

Compliments

  • The comment does an excellent job explaining the non-obvious architectural WHY — CVE context, platform constraint (VirtioFS UID mapping), and why a static path list won't work. This is exactly when multi-line comments are justified.
  • The PR template is a model to point future contributors toward: root cause analysis, before/after UX journey, and a concrete rollback plan all present and thoughtful.

Reviewed via maintainer-review-pr workflow (Pi/Minimax). Aspects run: code-review, comment-quality.

@Wirasm Wirasm merged commit d256c71 into coleam00:dev Apr 29, 2026
4 checks passed
@Wirasm Wirasm mentioned this pull request Apr 29, 2026
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.

docker-entrypoint.sh: git "dubious ownership" on macOS bind mounts after container restart

2 participants