feat(jailer): add Landlock LSM sandbox with composable Sandbox API#416
Merged
Conversation
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.
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
Sandboxtrait fromwrap() -> Commandtoapply(&mut Command), enabling natural composition of multiple isolation layersLandlockSandbox— Linux Landlock LSM for inode-based filesystem/network access control (kernel 5.13+)CompositeSandbox— chains N sandboxes viaVec<Box<dyn Sandbox>>, each modifying the sameCommandin orderPlatformSandboxis nowCompositeSandbox([BwrapSandbox, LandlockSandbox])— bwrap handles namespaces, Landlock handles filesystem ACLlandlock_restrict_self()syscall inpre_exec(async-signal-safe, zero-gap enforcement)Test plan
#[cfg(target_os = "linux")])cargo clippy -- -D warningsclean on both platforms