agent containers: push fails with 'permission denied' reading .git/objects, distinct from #468 #980

Closed
opened 2026-10-27 13:38:32 +00:00 by sam · 0 comments
Owner

Problem

Task #445 (daemon: label dispatch trigger) parked at the commit-push stage with:

push fix/445-daemon-label-dispatch-trigger-with-empty-label-matches-every:
getting wanted object 295b030cc6face20f8a377e94076922c460576c1:
openat objects/29/5b030cc6face20f8a377e94076922c460576c1: permission denied

This is a different failure mode than #468 (git's "dubious ownership" ownership check, resolved by safe.directory). Here git gets past whatever ownership check applies and fails on an actual filesystem permission bit when reading a loose object from the bind-mounted worktree's .git/objects/.

Why this is probably not fixed by #468

safe.directory only tells git to trust a repo it doesn't own — it does not change the actual read/write permission bits on the files. If the object file was written by a process running as a different UID than the archie-agent container's process (e.g. daemon-side worktree package operations running as the host user, vs. the container process), a straightforward openat ... permission denied on a specific loose object is consistent with a UID mismatch on the bind mount that safe.directory does nothing for.

Neither Dockerfile nor docker-compose.yml sets a USER/user: for the agent image, so the container should be running as root by default — worth confirming whether the deployment actually runs it as root (Docker userns-remap would explain root-inside behaving as an unprivileged UID on the host, which would produce exactly this symptom).

Ask

Confirm the UID the archie-agent process actually runs as versus the UID that owns files under the worktree's .git/objects/ on the host, and fix the mismatch (consistent UID, or chown/chmod the bind mount appropriately before handing it to the container).

Close reason

Confirmed root cause: agent containers run as root (no USER in Dockerfile, no userns-remap anywhere in docker-compose.yml/internal/container/pool.go), so a commit the agent writes to the bind-mounted worktree lands owned by UID 0 on the host. The daemon later reads those same loose objects to push, running as its own non-root host user -- 'openat objects/../..: permission denied'. Fixed: containerEnv() now passes the daemon's own os.Getuid()/os.Getgid() as WORKTREE_UID/WORKTREE_GID; hybridTrees.Push (the single choke point before the push RPC) chowns the worktree back to that owner first. Adversarial review (fresh subagent) found one real bug in the first pass -- chownTree used os.Chown, which follows symlinks and fails on a legitimately-tracked-but-dangling symlink, which would have aborted a push that would otherwise have succeeded (worse than the original bug). Fixed with os.Lchown plus a regression test proving it against a dangling symlink. Full task check clean; all other review findings (full-tree walk cost, minor test-hygiene notes) were judged non-blocking by the reviewer.


Imported from beads archie-core-1786749700606-6-bf6aa32d · GitHub #520 · type bug · priority P1 · created 2026-08-14 · closed 2026-08-17

## Problem Task `#445` (daemon: label dispatch trigger) parked at the `commit-push` stage with: ``` push fix/445-daemon-label-dispatch-trigger-with-empty-label-matches-every: getting wanted object 295b030cc6face20f8a377e94076922c460576c1: openat objects/29/5b030cc6face20f8a377e94076922c460576c1: permission denied ``` This is a different failure mode than #468 (git's "dubious ownership" ownership *check*, resolved by `safe.directory`). Here git gets *past* whatever ownership check applies and fails on an actual filesystem permission bit when reading a loose object from the bind-mounted worktree's `.git/objects/`. ## Why this is probably not fixed by #468 `safe.directory` only tells git to trust a repo it doesn't own — it does not change the actual read/write permission bits on the files. If the object file was written by a process running as a different UID than the archie-agent container's process (e.g. daemon-side `worktree` package operations running as the host user, vs. the container process), a straightforward `openat ... permission denied` on a specific loose object is consistent with a UID mismatch on the bind mount that `safe.directory` does nothing for. Neither `Dockerfile` nor `docker-compose.yml` sets a `USER`/`user:` for the agent image, so the container should be running as root by default — worth confirming whether the deployment actually runs it as root (Docker `userns-remap` would explain root-inside behaving as an unprivileged UID on the host, which would produce exactly this symptom). ## Ask Confirm the UID the archie-agent process actually runs as versus the UID that owns files under the worktree's `.git/objects/` on the host, and fix the mismatch (consistent UID, or `chown`/`chmod` the bind mount appropriately before handing it to the container). ### Close reason Confirmed root cause: agent containers run as root (no USER in Dockerfile, no userns-remap anywhere in docker-compose.yml/internal/container/pool.go), so a commit the agent writes to the bind-mounted worktree lands owned by UID 0 on the host. The daemon later reads those same loose objects to push, running as its own non-root host user -- 'openat objects/../..: permission denied'. Fixed: containerEnv() now passes the daemon's own os.Getuid()/os.Getgid() as WORKTREE_UID/WORKTREE_GID; hybridTrees.Push (the single choke point before the push RPC) chowns the worktree back to that owner first. Adversarial review (fresh subagent) found one real bug in the first pass -- chownTree used os.Chown, which follows symlinks and fails on a legitimately-tracked-but-dangling symlink, which would have aborted a push that would otherwise have succeeded (worse than the original bug). Fixed with os.Lchown plus a regression test proving it against a dangling symlink. Full task check clean; all other review findings (full-tree walk cost, minor test-hygiene notes) were judged non-blocking by the reviewer. --- _Imported from beads `archie-core-1786749700606-6-bf6aa32d` · GitHub #520 · type bug · priority P1 · created 2026-08-14 · closed 2026-08-17_
sam added the highbug labels 2026-10-27 13:38:32 +00:00
sam self-assigned this 2026-10-27 13:38:32 +00:00
sam closed this issue 2026-10-27 13:38:32 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sam/archie#980