The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(sandbox): restrict Cargo home grants to specific subpaths
Steven Enamakel88d1b09e921d
diff --git a/crates/openhuman-core/src/config/schema/runtime_local_jail.rs b/crates/openhuman-core/src/config/schema/runtime_local_jail.rsindex 28cfb469a6..d357baabd3 100644--- a/crates/openhuman-core/src/config/schema/runtime_local_jail.rs+++ b/crates/openhuman-core/src/config/schema/runtime_local_jail.rs@@ -2,9 +2,10 @@//! (Landlock on Linux, Seatbelt on macOS).//!//! With a real jail in force, a command can touch only what the policy grants.-//! The built-in set covers the everyday toolchain (`~/.cargo`, `~/.rustup`,-//! `~/.nvm`, `~/.npm`, `/usr/local`, `/opt`, git config); this section extends-//! or trims it.+//! The built-in set covers the everyday toolchain (`~/.cargo/bin` and Cargo+//! configuration read-only, the registry and git caches read-write,+//! `~/.rustup`, `~/.nvm`, `~/.npm`, `/usr/local`, `/opt`, and git config); this+//! section extends or trims it.//!//! Credential stores (`~/.ssh`, `~/.gnupg`, `~/.aws`, ...) are never granted://! entries naming one, or a parent that would expose one (such as `~`), are@@ -16,9 +17,10 @@ use serde::{Deserialize, Serialize};#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]#[serde(default)]pub struct LocalJailConfig {- /// Grant the built-in toolchain homes that exist on this machine- /// (`~/.cargo` read-write; `~/.rustup`, `~/.nvm`, `~/.npm`, `/usr/local`- /// and `/opt` read-only) plus the user's git config. Set `false` to+ /// Grant built-in toolchain paths that exist on this machine (Cargo's+ /// `bin` and configuration read-only, its `registry` and `git` caches+ /// read-write; `~/.rustup`, `~/.nvm`, `~/.npm`, `/usr/local` and `/opt`+ /// read-only), plus the user's git config. Set `false` to/// confine commands to the workspace, the system baseline and/// `extra_read_only` / `extra_read_write`.#[serde(default = "default_true")]diff --git a/crates/openhuman-core/src/sandbox/README.md b/crates/openhuman-core/src/sandbox/README.mdindex eccfb3b5fc..349c1617d6 100644--- a/crates/openhuman-core/src/sandbox/README.md+++ b/crates/openhuman-core/src/sandbox/README.md@@ -75,12 +75,13 @@ backend, and delegates local OS-level confinement to `tinybox-jail`.- Local grants: a real jail (Landlock, Seatbelt) denies everything it is nottold about, so `resolve_sandbox_policy` adds the grant set from`grants::resolve_local_jail_grants` and `[runtime.local_jail]`- (`LocalJailConfig`): `~/.cargo` read-write; `~/.rustup`, `~/.nvm`, `~/.npm`,- `/usr/local`, `/opt` and the user's git config files (symlink and `include`- targets canonicalized) read-only, each only when it exists; plus the- `extra_read_only` / `extra_read_write` lists. When `~/.cargo` holds- `credentials.toml` only its `bin`, `registry`, `git` and config files are- granted. Credential stores (`~/.ssh`, `~/.gnupg`, `~/.aws`, ... and any+ (`LocalJailConfig`): `~/.cargo/bin` and its configuration files read-only;+ `~/.cargo/registry` and `~/.cargo/git` read-write; `~/.rustup`, `~/.nvm`,+ `~/.npm`, `/usr/local`, `/opt` and the user's git config files (symlink and+ `include` targets canonicalized) read-only, each only when it exists; plus+ the `extra_read_only` / `extra_read_write` lists. Cargo binaries and+ configuration remain read-only whether or not registry credentials exist.+ Credential stores (`~/.ssh`, `~/.gnupg`, `~/.aws`, ... and anyparent that would contain one) are never granted, and `/proc` only with`allow_proc = true` (off by default: `/proc/<pid>/environ` exposes everyprocess's environment). Each call also gets a private writable scratchdiff --git a/crates/openhuman-core/src/sandbox/grants.rs b/crates/openhuman-core/src/sandbox/grants.rsindex 092c6dd7d2..7aaecac397 100644--- a/crates/openhuman-core/src/sandbox/grants.rs+++ b/crates/openhuman-core/src/sandbox/grants.rs@@ -167,22 +167,14 @@ impl<'a> Builder<'a> {}}- /// `~/.cargo` is read-write (registry, git checkouts, `cargo install`).- /// When it also holds registry credentials (`credentials.toml`), granting- /// it whole would hand the token to every jailed command, so grant only the- /// parts Cargo needs.+ /// Grant only the parts of `~/.cargo` that jailed Cargo needs. The root is+ /// never writable: `bin` and Cargo configuration run later outside the+ /// jail, so writable access there would persist an escape for host tools.fn add_cargo_home(&mut self, cargo: &Path) {if !cargo.is_dir() {return;}- let has_credentials = ["credentials.toml", "credentials"]- .iter()- .any(|f| cargo.join(f).exists());- if !has_credentials {- self.read_write(cargo, "toolchain");- return;- }- tracing::debug!("[sandbox:grants] ~/.cargo holds credentials; granting its parts only");+ tracing::debug!("[sandbox:grants] granting ~/.cargo parts with host code read-only");self.read_only(&cargo.join("bin"), "toolchain");self.read_write(&cargo.join("registry"), "toolchain");self.read_write(&cargo.join("git"), "toolchain");diff --git a/crates/openhuman-core/src/sandbox/grants_tests.rs b/crates/openhuman-core/src/sandbox/grants_tests.rsindex b5c53ee6d2..3207348187 100644--- a/crates/openhuman-core/src/sandbox/grants_tests.rs+++ b/crates/openhuman-core/src/sandbox/grants_tests.rs@@ -80,9 +80,23 @@ fn credential_floor_holds_for_a_symlink_into_a_credential_dir() {#[test]fn toolchain_homes_are_granted_when_they_exist() {let home = fake_home();+ let cargo = home.path().join(".cargo");+ for dir in ["bin", "registry", "git"] {+ fs::create_dir_all(cargo.join(dir)).unwrap();+ }+ for file in ["config.toml", "config", "env"] {+ fs::write(cargo.join(file), "").unwrap();+ }let g = resolve_local_jail_grants(Some(home.path()), &LocalJailConfig::default());let h = canon(home.path());- assert!(has(&g.read_write, &h.join(".cargo")));+ let cargo = h.join(".cargo");+ assert!(!has(&g.read_write, &cargo), "Cargo home must never be writable");+ assert!(has(&g.read_only, &cargo.join("bin")));+ assert!(has(&g.read_write, &cargo.join("registry")));+ assert!(has(&g.read_write, &cargo.join("git")));+ for file in ["config.toml", "config", "env"] {+ assert!(has(&g.read_only, &cargo.join(file)), "{file} should be read-only");+ }for ro in [".rustup", ".nvm", ".npm"] {assert!(has(&g.read_only, &h.join(ro)), "{ro} should be read-only");assert!(diff --git a/tests/cwd_jail_e2e.rs b/tests/cwd_jail_e2e.rsindex eabc81b2db..20a5dde4f3 100644--- a/tests/cwd_jail_e2e.rs+++ b/tests/cwd_jail_e2e.rs@@ -41,24 +41,22 @@ fn unique_tempdir(tag: &str) -> PathBuf {//// Landlock is always compiled in on Linux (tinybox-jail enables it by default),// but the running kernel may not support it; then `spawn` answers-// `Unsupported` rather than running the command unconfined, and these tests-// skip.+// `Unsupported` rather than running the command unconfined. These tests require+// Landlock so CI cannot report an unexercised confinement check as passing.#[cfg(target_os = "linux")]-fn landlock_in_force() -> bool {- let ok = openhuman_core::sandbox::cwd_jail::default_backend().name() == "landlock";- if !ok {- eprintln!("SKIP: this kernel has no Landlock");- }- ok+fn require_landlock() {+ assert_eq!(+ openhuman_core::sandbox::cwd_jail::default_backend().name(),+ "landlock",+ "the Linux Rust E2E job requires Landlock support"+ );}#[cfg(target_os = "linux")]#[test]fn linux_landlock_blocks_write_outside_root() {- if !landlock_in_force() {- return;- }+ require_landlock();let root = unique_tempdir("ll-root");let outside = unique_tempdir("ll-outside");let outside_target = outside.join("forbidden.txt");@@ -85,9 +83,7 @@ fn linux_landlock_blocks_write_outside_root() {#[cfg(target_os = "linux")]#[test]fn linux_landlock_allows_write_inside_root() {- if !landlock_in_force() {- return;- }+ require_landlock();let root = unique_tempdir("ll-root-write");let inside = root.join("ok.txt");