Skip to content

mount: add --uid/--gid to set file ownership in the mount - #25

Merged
rowantrollope merged 1 commit into
mainfrom
feat/mount-uid-gid-flags
Aug 4, 2026
Merged

rowantrollope merged 1 commit into
mainfrom
feat/mount-uid-gid-flags

Conversation

@jeremyplichta

Copy link
Copy Markdown
Contributor

Problem

agent-filesystem-mount can only present files as the uid/gid of its own process. main.go takes ownership solely from afsfs.GetOwnership(), which returns os.Getuid()/os.Getgid().

The plumbing to do better already exists — afsfs.Options carries UID/GID and Mount() passes them to go-fuse — only the command line couldn't reach it. GetOwnership's doc comment even claimed "Defaults come from opts" while taking no opts; corrected here.

Why it matters beyond the CLI

To hand a mount to a non-root workload today, the mount process itself must run as that user. In a container that pulls in two non-obvious requirements, because fusermount3 needs both:

  • /etc/mtab — absent from slim images (failed to open /etc/mtab)
  • a passwd entry for the uid, or it aborts with could not determine username

With --uid/--gid the mount stays root while presenting files as the workload user, and that whole class of setup disappears.

I hit this writing a CSI driver that mounts AFS volumes into Kubernetes pods. It currently runs each mount process under the target uid and synthesizes an /etc/passwd entry to compensate; this change lets that go away.

Change

Two flags defaulting to -1 (unset), so behaviour is unchanged unless a caller opts in. 15 insertions.

Verification

Real FUSE mount on linux/arm64, mount process running as root, against Redis 8.8.1:

Mount process Flags Resulting file owner
uid 0 --uid 1000 --gid 1000 1000:1000, writes succeed
uid 0 none 0:0 — unchanged default

Both files and directories report the requested owner, and content reads back correctly. go vet ./... and the mount module test suite pass.

Possible follow-up

If useful, the same two flags would apply to agent-filesystem-nfs. Left out here to keep the change focused — happy to add them if you'd like.

🤖 Generated with Claude Code

agent-filesystem-mount can only present files as the uid/gid of its own
process, because main.go takes ownership solely from afsfs.GetOwnership(),
which returns os.Getuid()/os.Getgid(). afsfs.Options already carries UID and
GID and Mount() passes them through to go-fuse, so the plumbing exists and only
the command line could not reach it. GetOwnership's doc comment even claimed
"Defaults come from opts" while taking no opts; that comment is corrected here.

The flags default to -1, meaning unset, so behaviour is unchanged unless a
caller opts in.

Why this matters outside the CLI: to hand a mount to a non-root workload today,
the mount process itself has to run as that user. In a container that pulls in
two non-obvious requirements, because fusermount3 needs both:

  - /etc/mtab, absent from slim images, or it fails to open it
  - a passwd entry for the uid, or it fails with "could not determine username"

With --uid/--gid the mount can stay root while presenting files as the workload
user, and that whole class of setup disappears. I hit this writing a CSI driver
that mounts AFS volumes into Kubernetes pods; it currently runs each mount
process under the target uid and synthesizes a passwd entry to compensate.

Verified with a real FUSE mount on linux/arm64, mount process running as root:

  --uid 1000 --gid 1000  ->  files and dirs owned by 1000:1000, writes succeed
  no flags               ->  files owned by 0:0, i.e. unchanged default

go vet and the mount module test suite pass.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@rowantrollope
rowantrollope merged commit 7da1215 into main Aug 4, 2026
5 checks 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