Skip to content

feat(jailer): add Landlock LSM sandbox with composable Sandbox API#416

Merged
DorianZheng merged 8 commits into
mainfrom
feat/landlock-sandbox
Apr 1, 2026
Merged

feat(jailer): add Landlock LSM sandbox with composable Sandbox API#416
DorianZheng merged 8 commits into
mainfrom
feat/landlock-sandbox

Conversation

@DorianZheng

Copy link
Copy Markdown
Member

Summary

  • Redesign the Sandbox trait from wrap() -> Command to apply(&mut Command), enabling natural composition of multiple isolation layers
  • Add LandlockSandbox — Linux Landlock LSM for inode-based filesystem/network access control (kernel 5.13+)
  • Add CompositeSandbox — chains N sandboxes via Vec<Box<dyn Sandbox>>, each modifying the same Command in order
  • Linux PlatformSandbox is now CompositeSandbox([BwrapSandbox, LandlockSandbox]) — bwrap handles namespaces, Landlock handles filesystem ACL
  • Each sandbox owns its full isolation story (BwrapSandbox handles cgroups, LandlockSandbox handles Landlock) — no cross-sandbox plumbing
  • Landlock degrades gracefully on older kernels (BestEffort mode logs warning and continues)
  • Split parent/child pattern: parent builds Landlock ruleset (crate API, allocates freely), child applies via single landlock_restrict_self() syscall in pre_exec (async-signal-safe, zero-gap enforcement)

Test plan

  • 6 CompositeSandbox unit tests (ordering, availability, setup chaining, empty)
  • 12 Landlock tests on Linux (ruleset building, enforcement e2e, read-only denial, multi-path, network deny)
  • E2e enforcement verified: allowed read/write, denied read (EACCES), read-only denies write (EACCES)
  • 611 total tests pass on Linux (1 pre-existing failure on main)
  • 599 tests pass on macOS (Landlock tests behind #[cfg(target_os = "linux")])
  • cargo clippy -- -D warnings clean on both platforms

Redesign the Sandbox trait from `wrap() -> Command` to `apply(&mut Command)`
enabling natural composition of multiple isolation layers.

New architecture:
- BwrapSandbox: namespace isolation + cgroup join (replaces cmd + adds pre_exec)
- LandlockSandbox: filesystem/network ACL (adds Landlock pre_exec)
- CompositeSandbox: chains N sandboxes via Vec<Box<dyn Sandbox>>
- Linux PlatformSandbox = CompositeSandbox([BwrapSandbox, LandlockSandbox])

Landlock (kernel 5.13+) adds inode-based filesystem restrictions as defense-in-depth,
complementing bwrap namespaces and seccomp syscall filtering. Degrades gracefully on
older kernels (BestEffort mode logs warning and continues).

Key design: split parent/child pattern for zero-gap enforcement. Parent builds the
Landlock ruleset (full crate API, allocates freely), child applies via single
landlock_restrict_self() syscall in pre_exec (async-signal-safe).
Replace the trivial restrict_self_in_thread test with a real e2e test that:
1. Creates a temp directory with a test file
2. Builds a Landlock ruleset allowing only that directory
3. Applies the restriction via restrict_self_raw
4. Verifies: allowed file is readable, allowed dir is writable
5. Verifies: home directory access is DENIED (EACCES)
- test_landlock_readonly_denies_write: verifies writable:false allows read but denies write (EACCES)
- test_landlock_multiple_paths_enforcement: 3 dirs with different access levels, verifies each
- test_landlock_network_deny: verifies network_enabled=false blocks TCP (graceful on < 6.7)
Landlock rules are hierarchical — /tmp has system write access, so
subdirs inherit that regardless of per-path restrictions. Use dirs
under $HOME instead, which are outside the system path ruleset.
@DorianZheng DorianZheng merged commit c6b33c7 into main Apr 1, 2026
20 checks passed
@DorianZheng DorianZheng deleted the feat/landlock-sandbox branch April 1, 2026 07:53
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