tpt-linux-sandbox

Rust

Composable Linux sandboxing in Rust — Landlock, seccomp, namespaces, and cgroups behind one declarative API. Pure-Rust alternative to bwrap/firejail.

0 stars0 forks0 watchersApache License 2.0

Languages

Rust100.0%
README

tpt-linux-sandbox

Dual-licensed MIT OR Apache-2.0 · Copyright TPT Solutions · Rust 2024 · MSRV 1.82

Composable Linux sandboxing primitives: Landlock + seccomp + namespaces + cgroups, layered behind one declarative API with a correct, enforced ordering.

Architecture

┌─────────────────────────────────────────────────────┐
│                  tpt-l-sandbox-cli                   │
│              (CLI frontend, clap-based)              │
├─────────────────────────────────────────────────────┤
│                   tpt-l-sandbox                      │
│            (Orchestrator / State Machine)            │
├──────────┬──────────┬──────────┬────────────────────┤
│ Landlock │ Seccomp  │Namespaces│  Cgroups           │
│(fs rules)│(syscall  │(isolation)│ (resource limits)  │
│          │ filters) │          │                    │
├──────────┼──────────┼──────────┴────────────────────┤
│ Caps     │ Chroot   │ AppArmor  │ SELinux │ Audit   │
│ (drop)   │ (jail)   │ (parser)  │(context)│(logger) │
└──────────┴──────────┴───────────┴─────────┴─────────┘

State Machine

StageOperationReversibleDescription
1ValidationyesParse & validate entire policy before any kernel calls
2Cgroup setupyesCreate cgroup hierarchy and enter it
3Namespace creationnounshare(CLONE_NEW*)
4Filesystem jailnopivot_root + pseudo-fs mounts
5Capability dropnoDrop bounding capabilities
6Seccomp enforcementnoseccomp_load BPF filters
7Landlock enforcementnoApply Landlock ruleset

Crates

CratePurpose
tpt-l-landlock-highlevelDeclarative Landlock builder
tpt-l-seccomp-builderSeccomp BPF policy DSL
tpt-l-namespaces-rsSafe unshare/clone3 wrappers
tpt-l-cgroup-v2cgroup v2 hierarchy management
tpt-l-caps-dropCapability bounding set control
tpt-l-chroot-jailpivot_root + pseudo-fs mounting
tpt-l-apparmor-parserAppArmor profile parser
tpt-l-selinux-contextSELinux context parser
tpt-l-audit-loggerKernel audit netlink reader
tpt-l-sandboxOrchestrator library
tpt-l-sandbox-cliCLI frontend

Usage

use tpt_l_sandbox::Sandbox;

Sandbox::new()
    .allow_read("/etc")
    .allow_write("/tmp")
    .no_network()
    .memory_limit(256 * 1024 * 1024)
    .apply()
    .exec(&["cat", "/etc/hostname"])?;

License

Dual-licensed under MIT OR Apache-2.0. See LICENSE-MIT and LICENSE-APACHE.