mount: add --uid/--gid to set file ownership in the mount - #25
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
agent-filesystem-mountcan only present files as the uid/gid of its own process.main.gotakes ownership solely fromafsfs.GetOwnership(), which returnsos.Getuid()/os.Getgid().The plumbing to do better already exists —
afsfs.OptionscarriesUID/GIDandMount()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
fusermount3needs both:/etc/mtab— absent from slim images (failed to open /etc/mtab)could not determine usernameWith
--uid/--gidthe 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/passwdentry 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:--uid 1000 --gid 1000Both files and directories report the requested owner, and content reads back correctly.
go vet ./...and themountmodule 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