Skip recursive home chown when ownership is correct#62
Merged
Conversation
With user-namespace-backed virtiofs (the default on Linux since the CAP_SETGID fix), the rootfs already has correct uid/gid ownership via xattr.SetOverrideStat. The previous code walked the entire home directory tree (~120K files, ~5GB for claude-code images) doing Lchown on every entry, adding ~14 seconds to guest boot. Now check whether the home dir is already owned by the sandbox user and, if so, only walk the .ssh/ subtree to enforce strict SSH permissions. The full recursive chown is preserved as a fallback for platforms without user namespaces (e.g. macOS). Co-Authored-By: Claude Opus 4.6 (1M context) <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.
Summary
chownof/home/sandboxwhen the directory is already owned by the correct uid/gid (the common case on Linux with user-namespace-backed virtiofs).ssh/to enforce strict SSH permissions (0700 dirs, 0600 files)Problem
fixHomeOwnershipwas doing afilepath.WalkDir+Lchownon every file under/home/sandbox. For the claude-code guest image this is ~120K files / ~5GB, taking ~14 seconds of guest boot time. This was the single largest contributor to slow VM startup.Since we now use user namespaces (
WithUserNamespaceUID), libkrun's virtiofs passthrough hasCAP_SETGIDwithin the namespace, andxattr.SetOverrideStaton the rootfs already gives the guest correct ownership. The recursive chown was redundant on Linux.Result
Measured with OTel tracing (
--trace) on the brood-box CLI:microvm.SSHWaitReadyTest plan
go test ./...— all tests passbrood-boxend-to-end:bbox claude-code --trace --timingsshows 7.4s Sandbox ready🤖 Generated with Claude Code