Skip to content

feat(jailer): bwrap sandbox improvements and PID namespace watchdog fix#275

Merged
DorianZheng merged 4 commits intomainfrom
feat/jailer-bwrap-improvements
Feb 16, 2026
Merged

feat(jailer): bwrap sandbox improvements and PID namespace watchdog fix#275
DorianZheng merged 4 commits intomainfrom
feat/jailer-bwrap-improvements

Conversation

@DorianZheng
Copy link
Copy Markdown
Member

Summary

  • Chrome-style user namespace probe with targeted diagnostics for bwrap failures
  • Auto-generate AppArmor profile for bundled bwrap binary
  • Add rootfs and user volume mounts to bwrap sandbox
  • Skip parent watchdog when inside PID namespace (bwrap --die-with-parent handles it)

Test plan

  • cargo check -p boxlite passes
  • Verify bwrap sandbox works on Linux with user namespaces
  • Verify AppArmor profile generation on systems with AppArmor
  • Verify shim watchdog behavior inside PID namespace

…tics

Port Chrome's CanCreateProcessInNewUserNS() and CheckCloneNewUserErrno()
from sandbox/linux/services/credentials.cc. Dual-probe approach:
1. Raw clone(CLONE_NEWUSER) for kernel-level errno diagnosis
2. bwrap --unshare-user for actual bwrap capability (handles AppArmor
   per-binary profiles where bwrap may work even if our clone fails)

When bwrap fails, build_diagnostic() combines Chrome errno + sysctl
detection to provide targeted fix commands for each scenario:
- AppArmor restrict_unprivileged_userns (Ubuntu 23.10+)
- kernel.unprivileged_userns_clone (Debian/older distros)
- user.max_user_namespaces (RHEL/CentOS)
When bundled bwrap fails on Ubuntu 23.10+ with
kernel.apparmor_restrict_unprivileged_userns=1, generate an AppArmor
profile at ~/.boxlite/apparmor/boxlite-bwrap and include the
`sudo apparmor_parser -r` command in the diagnostic.

- Add apparmor.rs with generate_bwrap_profile() and write_bwrap_profile()
- Profile mirrors Ubuntu's bwrap-userns-restrict with unique names
  (boxlite_bwrap/boxlite_unpriv_bwrap) to avoid collision
- Caller in bwrap.rs computes apparmor_dir (Minimal Knowledge)
The bwrap sandbox was missing two critical mount categories:
1. ~/.boxlite/rootfs (ro) - VM init rootfs (Alpine bootstrap)
2. User volume host_paths - from BoxOptions.volumes

Without the rootfs mount, libkrun couldn't boot the VM inside bwrap,
causing the shim to exit immediately.
@DorianZheng DorianZheng force-pushed the feat/jailer-bwrap-improvements branch from 796983b to ecdb49a Compare February 16, 2026 07:51
Add explicit unsafe block in credentials.rs for unsafe-op-in-unsafe-fn
compliance and fix cargo fmt formatting in bwrap.rs.
@DorianZheng DorianZheng merged commit ccf1bff into main Feb 16, 2026
14 checks passed
@DorianZheng DorianZheng deleted the feat/jailer-bwrap-improvements branch February 16, 2026 08:00
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.

1 participant