Skip to content

Add ReadOnly support for VirtioFS mounts#55

Merged
JAORMX merged 1 commit intomainfrom
support-readonly-virtiofs-mounts
Apr 7, 2026
Merged

Add ReadOnly support for VirtioFS mounts#55
JAORMX merged 1 commit intomainfrom
support-readonly-virtiofs-mounts

Conversation

@JAORMX
Copy link
Copy Markdown
Contributor

@JAORMX JAORMX commented Mar 30, 2026

Summary

  • Adds ReadOnly bool field to VirtioFSMount and plumbs it through the full type chain: microvm.VirtioFSMounthypervisor.FilesystemMountrunner.VirtioFSMount → runner binary duplicate → guest boot config
  • Guest-side enforcement via MS_RDONLY mount flags in mount.Workspace()
  • Host-to-guest communication via vmconfig.Config.VirtioFSMounts (written to /etc/go-microvm.json)
  • Runner logs a warning when ReadOnly is requested but can't be enforced host-side (libkrun limitation)
  • Fixes chown-after-read-only-mount bug (would have returned EROFS on every read-only workspace)
  • Documents that enforcement is guest-side only; a compromised guest kernel could bypass it

Closes #53

Details

Why guest-side only? libkrun's krun_add_virtiofs C API has no read-only parameter. The upstream virtiofsd has a PassthroughFsRo wrapper but libkrun's vendored copy doesn't include it. An upstream PR to add host-side support would provide defense-in-depth.

Files changed (18):

  • 5 struct definitions updated with ReadOnly bool
  • 3 conversion functions updated to pass through the field
  • guest/mount/mount.go — adds MS_RDONLY flag, skips chown on read-only mounts, unmounts on chown failure
  • guest/vmconfig/vmconfig.go — new VirtioFSMountInfo type for host→guest metadata
  • microvm.gobuildVMConfig() writes read-only mount info to guest config
  • guest/boot/options.go — new WithWorkspaceReadOnly() option
  • runner/cmd/.../main.go — warning log for host-side enforcement gap

Test plan

  • task fmt — no formatting changes
  • task lint — 0 issues
  • task test-nocgo — all tests pass
  • CGO_ENABLED=0 go vet — clean
  • Integration test with actual VM (requires libkrun)

🤖 Generated with Claude Code

Plumb a ReadOnly flag through the full VirtioFSMount chain so callers
can declare host directories as read-only inside the guest. Enforcement
is guest-side via MS_RDONLY mount flags; libkrun does not yet support
host-side read-only virtiofs.

Closes #53

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@JAORMX JAORMX merged commit 1c3a161 into main Apr 7, 2026
7 checks passed
@JAORMX JAORMX deleted the support-readonly-virtiofs-mounts branch April 7, 2026 03:15
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.

Support ReadOnly flag on VirtioFSMount

1 participant