Make rootfs hook chown best-effort for macOS support#7
Merged
Conversation
On macOS, non-root users cannot os.Chown to a different UID, causing InjectAuthorizedKeys to fail with EPERM. This makes VM startup impossible on macOS without root. Two-layer fix: - Host side: InjectAuthorizedKeys now uses an injected ChownFunc (defaulting to BestEffortLchown) that swallows EPERM. Uses Lchown instead of Chown to avoid following symlinks in the rootfs. - Guest side: New fixHomeOwnership step in boot.Run recursively chowns /home/sandbox and enforces SSH strict permissions (0700 for .ssh/, 0600 for files). Runs as PID 1 before cap drop, so chown always succeeds. Symlinks are skipped for safety. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
JAORMX
added a commit
to stacklok/brood-box
that referenced
this pull request
Mar 3, 2026
Replace os.Chown with bestEffortLchown in InjectGitConfig and InjectMCPConfig hooks. On macOS, non-root users cannot chown files to a different UID, causing VM startup to fail with EPERM. bestEffortLchown uses os.Lchown (symlink-safe) and swallows permission errors. The guest init in propolis now handles authoritative ownership fixup at boot time as PID 1. Depends on stacklok/go-microvm#7. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
3 tasks
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.
Summary
InjectAuthorizedKeysnow uses an injectedChownFunc(defaulting toBestEffortLchown) instead of hardos.Chown, so it no longer fails with EPERM on macOS for non-root usersBestEffortLchownusesos.Lchown(symlink-safe) and swallows permission errors — the guest init handles authoritative ownershipfixHomeOwnershipstep inboot.Runrecursively chowns/home/sandboxand enforces SSH strict permissions (0700 for.ssh/, 0600 for files) as PID 1 before cap dropTest plan
task fmt && task lint && task testpassesrecordingChownDI mock — run on any platform regardless of UIDfixhome_test.gocovers permission enforcement, nested SSH files, missing home dir, symlink path detection/home/sandboxowned by sandbox user🤖 Generated with Claude Code