Skip to content

Fix guest VM git operations for worktrees and ownership mismatch#48

Open
jhrozek wants to merge 2 commits intomainfrom
worktree-proper
Open

Fix guest VM git operations for worktrees and ownership mismatch#48
jhrozek wants to merge 2 commits intomainfrom
worktree-proper

Conversation

@jhrozek
Copy link
Contributor

@jhrozek jhrozek commented Mar 16, 2026

Summary

  • Fix .git/config permissions (06000644) so guest UID can read the sanitized config
  • Add [safe] directory = /workspace to guest ~/.gitconfig unconditionally to prevent git 2.36+ "dubious ownership" errors
  • Create minimal git structure (HEAD, objects/, refs/) for worktree snapshots so git recognizes them as valid repos
  • Harden gitdir resolution against path traversal (validate HEAD exists, tighten ref prefix filter)

Known limitation

Worktree snapshots show "No commits yet" because the object database lives in the main repo's .git/objects/ which is outside the workspace mount.

Test plan

  • task fmt && task lint && task test — all pass
  • Manual: normal repo → git status works in VM
  • Manual: worktree → git status works (no errors), but shows no commits (known limitation)
  • Security red-team review — two findings addressed (gitdir validation, HEAD content filter)

🤖 Generated with Claude Code

Three fixes for git operations failing inside the guest VM:

1. Change sanitized .git/config permissions from 0600 to 0644.
   The config contains no credentials (stripped by SanitizeConfig)
   but was unreadable by the guest UID due to ownership mismatch.

2. Always write ~/.gitconfig with [safe] directory = /workspace.
   Git 2.36+ rejects repos owned by a different UID (host 501 vs
   guest 1000) without this setting. The gitconfig is now written
   unconditionally, even without identity or token configured.

3. Create minimal git structure (HEAD, objects/, refs/) for worktree
   snapshots so git recognizes them as valid repositories. Detached
   HEADs fall back to a symbolic ref to avoid errors with empty
   objects/. The resolved gitdir is validated (must contain HEAD)
   to prevent path traversal, and HEAD content is filtered to
   require "ref: refs/" prefix.

Known limitation: worktree snapshots show "No commits yet" because
the object database lives in the main repo's .git/objects/ which
is outside the workspace mount.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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