Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

feat(sandbox): add host grant checks to sandbox operations

Steven Enamakel2d0b39d277f6
diff --git a/crates/openhuman-core/src/modules/tinybox.rs b/crates/openhuman-core/src/modules/tinybox.rs
index 95cef98071..a560f15ecd 100644
--- a/crates/openhuman-core/src/modules/tinybox.rs
+++ b/crates/openhuman-core/src/modules/tinybox.rs
@@ -53,6 +53,7 @@ const DOCKER_STATUS: &str = contract::METHODS[28];
const CLEANUP_DOCKER: &str = contract::METHODS[29];
const RUN_DOCKER_WITHOUT_WORKSPACE: &str = contract::METHODS[30];
const SELECT_SHELL: &str = contract::names::SELECT_SHELL;
+const RESOLVE_LOCAL_GRANTS: &str = contract::names::RESOLVE_LOCAL_GRANTS;
const START_SHELL_EXEC: &str = contract::names::START_SHELL_EXEC;
const DOCKER_CALL_GRACE: Duration = Duration::from_secs(5);
@@ -189,6 +190,18 @@ pub async fn start_shell_exec(
call(config, START_SHELL_EXEC, (request,), true).await
}
+/// Ask TinyBox to resolve the existing toolchain and configured grants for the
+/// local jail.
+///
+/// The request carries the host's protected-path floor as input; the reply is
+/// a candidate set the host must still pass through its own floor.
+pub async fn resolve_local_grants(
+ config: &Config,
+ request: contract::ResolveLocalGrantsRequest,
+) -> Result<contract::LocalGrants, String> {
+ call(config, RESOLVE_LOCAL_GRANTS, (request,), false).await
+}
+
/// Run one bounded Docker-isolated command through TinyBox.
///
/// The caller applies authorization and Docker policy before sending this
diff --git a/crates/openhuman-core/src/sandbox/grants.rs b/crates/openhuman-core/src/sandbox/grants.rs
deleted file mode 100644
index 7aaecac397..0000000000
--- a/crates/openhuman-core/src/sandbox/grants.rs
+++ /dev/null
@@ -1,265 +0,0 @@
-//! The filesystem grant set for the local OS jail.
-//!
-//! A real jail (Landlock, Seatbelt) denies everything it is not told about, so
-//! the host must grant what everyday commands need: the toolchain homes
-//! (`cargo`, `rustc`, `node`, `npm`) and the user's git config. The set is
-//! computed from [`LocalJailConfig`] and the machine, once per policy; per-call
-//! directories (output capture, `TMPDIR` scratch) are added by `ops`.
-//!
-//! **Credential floor.** `~/.ssh`, `~/.gnupg`, `~/.aws` and the rest of
-//! `SecurityPolicy::is_always_forbidden` are never granted, whatever the config
-//! says. Landlock grants are recursive, so a grant on a *parent* of a credential
-//! store exposes it too; those are dropped as well. `/proc` is reachable only
-//! through `LocalJailConfig::allow_proc`, never through the `extra_*` lists.
-
-use crate::config::LocalJailConfig;
-use crate::security::SecurityPolicy;
-use std::collections::HashSet;
-use std::path::{Path, PathBuf};
-
-/// Credential directories under `$HOME` that no grant may reach or contain.
-const HOME_CREDENTIAL_DIRS: &[&str] = &[".ssh", ".gnupg", ".aws", ".azure", ".kube"];
-
-/// System toolchain roots granted read-only when present.
-const SYSTEM_TOOLCHAIN_DIRS: &[&str] = &["/usr/local", "/opt"];
-
-/// `$HOME`-relative toolchain homes granted read-only when present.
-const HOME_READ_ONLY_DIRS: &[&str] = &[".rustup", ".nvm", ".npm"];
-
-/// Files Cargo needs read access to inside `~/.cargo` when the directory also
-/// holds registry credentials and so cannot be granted whole.
-const CARGO_READ_ONLY_FILES: &[&str] = &["config.toml", "config", "env"];
-
-/// Git config files read at startup, relative to `$HOME`.
-const GITCONFIG_FILES: &[&str] = &[".gitconfig", ".config/git/config", ".config/git/ignore"];
-
-/// Deepest `include` chain followed when collecting git config files.
-const GITCONFIG_MAX_DEPTH: usize = 8;
-
-/// Paths the jail is granted beyond the workspace root, all canonical and
-/// existing.
-#[derive(Debug, Clone, Default, PartialEq, Eq)]
-pub struct JailGrants {
- pub read_only: Vec<PathBuf>,
- pub read_write: Vec<PathBuf>,
-}
-
-/// Build the grant set for `home` (the user's home directory, if known).
-pub fn resolve_local_jail_grants(home: Option<&Path>, cfg: &LocalJailConfig) -> JailGrants {
- let home = home.map(|h| h.canonicalize().unwrap_or_else(|_| h.to_path_buf()));
- let mut b = Builder::new(home.as_deref());
-
- if cfg.toolchain_homes {
- if let Some(h) = home.as_deref() {
- b.add_cargo_home(&h.join(".cargo"));
- for dir in HOME_READ_ONLY_DIRS {
- b.read_only(&h.join(dir), "toolchain");
- }
- }
- for dir in SYSTEM_TOOLCHAIN_DIRS {
- b.read_only(Path::new(dir), "toolchain");
- }
- if let Some(h) = home.as_deref() {
- b.add_gitconfig(h);
- }
- }
- for raw in &cfg.extra_read_only {
- if let Some(p) = b.expand(raw) {
- b.read_only(&p, "config");
- }
- }
- for raw in &cfg.extra_read_write {
- if let Some(p) = b.expand(raw) {
- b.read_write(&p, "config");
- }
- }
- // The one sanctioned route to `/proc`: it bypasses the floor deliberately.
- if cfg.allow_proc && Path::new("/proc").exists() {
- tracing::debug!("[sandbox:grants] granting read-only /proc (allow_proc = true)");
- b.grants.read_only.push(PathBuf::from("/proc"));
- }
- tracing::debug!(
- read_only = b.grants.read_only.len(),
- read_write = b.grants.read_write.len(),
- "[sandbox:grants] resolved local jail grants"
- );
- b.grants
-}
-
-struct Builder<'a> {
- home: Option<&'a Path>,
- grants: JailGrants,
- seen: HashSet<PathBuf>,
-}
-
-impl<'a> Builder<'a> {
- fn new(home: Option<&'a Path>) -> Self {
- Self {
- home,
- grants: JailGrants::default(),
- seen: HashSet::new(),
- }
- }
-
- /// Expand a leading `~` / `~/` against the home directory.
- fn expand(&self, raw: &str) -> Option<PathBuf> {
- let raw = raw.trim();
- if raw.is_empty() {
- return None;
- }
- if raw == "~" {
- return self.home.map(Path::to_path_buf);
- }
- if let Some(rest) = raw.strip_prefix("~/") {
- return self.home.map(|h| h.join(rest));
- }
- Some(PathBuf::from(raw))
- }
-
- /// Canonicalize `path` and return it only if it exists and clears the
- /// credential floor. Canonicalizing first means a symlink into `~/.ssh`
- /// is judged by its target.
- fn admit(&self, path: &Path, source: &str) -> Option<PathBuf> {
- let canonical = match path.canonicalize() {
- Ok(c) => c,
- Err(_) => {
- tracing::debug!(source, path = %path.display(), "[sandbox:grants] skipped missing path");
- return None;
- }
- };
- if SecurityPolicy::is_always_forbidden(&canonical) || self.exposes_credentials(&canonical) {
- tracing::warn!(
- source,
- path = %canonical.display(),
- "[sandbox:grants] refused: grant would reach a credential store or system root"
- );
- return None;
- }
- Some(canonical)
- }
-
- /// True when `path` is, contains, or sits inside a credential directory.
- fn exposes_credentials(&self, path: &Path) -> bool {
- let Some(home) = self.home else { return false };
- HOME_CREDENTIAL_DIRS.iter().any(|d| {
- let cred = home.join(d);
- let cred = cred.canonicalize().unwrap_or(cred);
- path.starts_with(&cred) || cred.starts_with(path)
- })
- }
-
- fn read_only(&mut self, path: &Path, source: &str) {
- if let Some(p) = self.admit(path, source) {
- if self.seen.insert(p.clone()) {
- self.grants.read_only.push(p);
- }
- }
- }
-
- fn read_write(&mut self, path: &Path, source: &str) {
- if let Some(p) = self.admit(path, source) {
- // A path granted writable subsumes an earlier read-only grant.
- self.grants.read_only.retain(|g| g != &p);
- self.seen.insert(p.clone());
- if !self.grants.read_write.contains(&p) {
- self.grants.read_write.push(p);
- }
- }
- }
-
- /// 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;
- }
- 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");
- for f in CARGO_READ_ONLY_FILES {
- self.read_only(&cargo.join(f), "toolchain");
- }
- }
-
- /// Read-only grants for the user's git config files and everything they
- /// `include`, each canonicalized (a config is often a symlink into a
- /// dotfiles repo, and the jail needs the target).
- fn add_gitconfig(&mut self, home: &Path) {
- let mut roots: Vec<PathBuf> = GITCONFIG_FILES.iter().map(|f| home.join(f)).collect();
- if let Some(xdg) = std::env::var_os("XDG_CONFIG_HOME") {
- roots.push(Path::new(&xdg).join("git/config"));
- }
- let mut visited = HashSet::new();
- for root in roots {
- self.add_gitconfig_file(&root, home, 0, &mut visited);
- }
- }
-
- fn add_gitconfig_file(
- &mut self,
- file: &Path,
- home: &Path,
- depth: usize,
- visited: &mut HashSet<PathBuf>,
- ) {
- let Ok(canonical) = file.canonicalize() else {
- return;
- };
- if !canonical.is_file() || !visited.insert(canonical.clone()) {
- return;
- }
- self.read_only(&canonical, "gitconfig");
- if depth >= GITCONFIG_MAX_DEPTH {
- return;
- }
- let Ok(text) = std::fs::read_to_string(&canonical) else {
- return;
- };
- // Relative includes resolve against the directory of the file *as
- // named*, which for a symlinked config is the link's directory.
- let base = file.parent().unwrap_or(home);
- for target in include_paths(&text) {
- let resolved = if let Some(rest) = target.strip_prefix("~/") {
- home.join(rest)
- } else if Path::new(&target).is_absolute() {
- PathBuf::from(&target)
- } else {
- base.join(&target)
- };
- self.add_gitconfig_file(&resolved, home, depth + 1, visited);
- }
- }
-}
-
-/// `path = …` values inside `[include]` / `[includeIf …]` sections.
-fn include_paths(config: &str) -> Vec<String> {
- let mut in_include = false;
- let mut out = Vec::new();
- for line in config.lines() {
- let line = line.trim();
- if let Some(section) = line.strip_prefix('[') {
- let name = section.split([']', ' ', '"']).next().unwrap_or("");
- in_include =
- name.eq_ignore_ascii_case("include") || name.eq_ignore_ascii_case("includeif");
- continue;
- }
- if !in_include {
- continue;
- }
- if let Some((key, value)) = line.split_once('=') {
- if key.trim().eq_ignore_ascii_case("path") {
- let value = value.trim().trim_matches('"');
- if !value.is_empty() {
- out.push(value.to_string());
- }
- }
- }
- }
- out
-}
-
-#[cfg(test)]
-#[path = "grants_tests.rs"]
-mod tests;
diff --git a/crates/openhuman-core/src/sandbox/grants_tests.rs b/crates/openhuman-core/src/sandbox/grants_tests.rs
deleted file mode 100644
index 6c0dde7bef..0000000000
--- a/crates/openhuman-core/src/sandbox/grants_tests.rs
+++ /dev/null
@@ -1,274 +0,0 @@
-use super::*;
-use std::fs;
-use std::path::{Path, PathBuf};
-
-fn fake_home() -> tempfile::TempDir {
- let home = tempfile::tempdir().unwrap();
- for d in [
- ".ssh", ".gnupg", ".aws", ".cargo", ".rustup", ".nvm", ".npm",
- ] {
- fs::create_dir_all(home.path().join(d)).unwrap();
- }
- home
-}
-
-fn canon(p: &Path) -> PathBuf {
- p.canonicalize().unwrap()
-}
-
-fn has(grants: &[PathBuf], p: &Path) -> bool {
- grants.iter().any(|g| g == p)
-}
-
-fn all(g: &JailGrants) -> Vec<PathBuf> {
- g.read_only.iter().chain(&g.read_write).cloned().collect()
-}
-
-/// A grant reaches a credential store if it IS one, is inside one, or contains
-/// one (Landlock grants are recursive, so a parent grant exposes the child).
-fn reaches_credentials(grants: &[PathBuf], home: &Path) -> Option<PathBuf> {
- for cred in [".ssh", ".gnupg", ".aws"] {
- let cred = home.join(cred);
- for g in grants {
- if g.starts_with(&cred) || cred.starts_with(g) {
- return Some(g.clone());
- }
- }
- }
- None
-}
-
-#[test]
-fn credential_dirs_are_never_granted_by_default() {
- let home = fake_home();
- let g = resolve_local_jail_grants(Some(home.path()), &LocalJailConfig::default());
- assert_eq!(reaches_credentials(&all(&g), home.path()), None);
-}
-
-#[test]
-fn credential_dirs_are_never_granted_even_when_extras_ask() {
- let home = fake_home();
- let cfg = LocalJailConfig {
- extra_read_only: vec![
- "~/.ssh".into(),
- "~/.gnupg/".into(),
- format!("{}", home.path().join(".aws").display()),
- "~".into(),
- format!("{}", home.path().display()),
- "/".into(),
- ],
- extra_read_write: vec!["~/.ssh".into(), "~".into()],
- ..LocalJailConfig::default()
- };
- let g = resolve_local_jail_grants(Some(home.path()), &cfg);
- assert_eq!(reaches_credentials(&all(&g), home.path()), None);
- assert!(!g.read_only.iter().any(|p| p == Path::new("/")));
-}
-
-#[test]
-fn credential_floor_holds_for_a_symlink_into_a_credential_dir() {
- let home = fake_home();
- #[cfg(unix)]
- std::os::unix::fs::symlink(home.path().join(".ssh"), home.path().join("innocent")).unwrap();
- #[cfg(windows)]
- std::os::windows::fs::symlink_dir(home.path().join(".ssh"), home.path().join("innocent"))
- .unwrap();
- let cfg = LocalJailConfig {
- extra_read_only: vec!["~/innocent".into()],
- ..LocalJailConfig::default()
- };
- let g = resolve_local_jail_grants(Some(home.path()), &cfg);
- assert_eq!(reaches_credentials(&all(&g), home.path()), None);
-}
-
-#[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());
- 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!(
- !has(&g.read_write, &h.join(ro)),
- "{ro} must not be writable"
- );
- }
- for sys in ["/usr/local", "/opt"] {
- if Path::new(sys).exists() {
- assert!(has(&g.read_only, &canon(Path::new(sys))), "{sys} missing");
- }
- }
-}
-
-#[test]
-fn absent_toolchain_homes_are_not_granted() {
- let home = tempfile::tempdir().unwrap();
- fs::create_dir_all(home.path().join(".nvm")).unwrap();
- let g = resolve_local_jail_grants(Some(home.path()), &LocalJailConfig::default());
- let h = canon(home.path());
- assert!(has(&g.read_only, &h.join(".nvm")));
- assert!(!all(&g).iter().any(|p| p.starts_with(h.join(".cargo"))));
- assert!(!all(&g).iter().any(|p| p.starts_with(h.join(".rustup"))));
-}
-
-#[test]
-fn toolchain_homes_can_be_switched_off() {
- let home = fake_home();
- fs::write(home.path().join(".gitconfig"), "[user]\n name = x\n").unwrap();
- let cfg = LocalJailConfig {
- toolchain_homes: false,
- ..LocalJailConfig::default()
- };
- let g = resolve_local_jail_grants(Some(home.path()), &cfg);
- assert!(g.read_only.is_empty() && g.read_write.is_empty(), "{g:?}");
-}
-
-#[test]
-fn cargo_home_with_registry_credentials_is_granted_piecewise() {
- let home = fake_home();
- let cargo = home.path().join(".cargo");
- for d in ["bin", "registry", "git"] {
- fs::create_dir_all(cargo.join(d)).unwrap();
- }
- fs::write(
- cargo.join("credentials.toml"),
- "[registry]\ntoken = \"x\"\n",
- )
- .unwrap();
- fs::write(cargo.join("config.toml"), "").unwrap();
- let g = resolve_local_jail_grants(Some(home.path()), &LocalJailConfig::default());
- let c = canon(&cargo);
- assert!(
- !has(&g.read_write, &c),
- "whole ~/.cargo would expose credentials.toml"
- );
- assert!(!all(&g).iter().any(|p| p.ends_with("credentials.toml")));
- assert!(has(&g.read_write, &c.join("registry")));
- assert!(has(&g.read_write, &c.join("git")));
- assert!(has(&g.read_only, &c.join("bin")));
- assert!(has(&g.read_only, &c.join("config.toml")));
-}
-
-#[test]
-fn a_writable_grant_subsumes_the_same_path_read_only() {
- let home = fake_home();
- let cfg = LocalJailConfig {
- extra_read_only: vec!["~/.npm".into()],
- extra_read_write: vec!["~/.npm".into()],
- ..LocalJailConfig::default()
- };
- let g = resolve_local_jail_grants(Some(home.path()), &cfg);
- let npm = canon(&home.path().join(".npm"));
- assert!(has(&g.read_write, &npm));
- assert!(!has(&g.read_only, &npm));
-}
-
-#[cfg(target_os = "linux")]
-#[test]
-fn proc_is_off_by_default_and_only_the_toggle_grants_it() {
- let home = fake_home();
- let g = resolve_local_jail_grants(Some(home.path()), &LocalJailConfig::default());
- assert!(!all(&g).iter().any(|p| p.starts_with("/proc")));
-
- // An `extra_*` entry cannot smuggle it in: only `allow_proc` does.
- let cfg = LocalJailConfig {
- extra_read_only: vec!["/proc".into()],
- ..LocalJailConfig::default()
- };
- let g = resolve_local_jail_grants(Some(home.path()), &cfg);
- assert!(!all(&g).iter().any(|p| p.starts_with("/proc")));
-
- let cfg = LocalJailConfig {
- allow_proc: true,
- ..LocalJailConfig::default()
- };
- let g = resolve_local_jail_grants(Some(home.path()), &cfg);
- assert!(has(&g.read_only, Path::new("/proc")));
- assert!(!has(&g.read_write, Path::new("/proc")));
-}
-
-#[test]
-fn extras_expand_tilde_and_skip_missing_paths() {
- let home = fake_home();
- fs::create_dir_all(home.path().join("dotfiles")).unwrap();
- fs::create_dir_all(home.path().join("data")).unwrap();
- let cfg = LocalJailConfig {
- extra_read_only: vec!["~/dotfiles".into(), "~/nope".into()],
- extra_read_write: vec!["~/data/../data".into()],
- ..LocalJailConfig::default()
- };
- let g = resolve_local_jail_grants(Some(home.path()), &cfg);
- assert!(has(&g.read_only, &canon(&home.path().join("dotfiles"))));
- assert!(has(&g.read_write, &canon(&home.path().join("data"))));
- assert!(!all(&g).iter().any(|p| p.ends_with("nope")));
-}
-
-#[test]
-fn gitconfig_symlink_and_include_targets_are_canonicalized() {
- let home = fake_home();
- let dots = home.path().join("dotfiles");
- fs::create_dir_all(&dots).unwrap();
- fs::write(dots.join("work.gitconfig"), "[user]\n email = a@b\n").unwrap();
- fs::write(dots.join("local.gitconfig"), "").unwrap();
- fs::write(
- dots.join("gitconfig"),
- "[user]\n name = x\n[include]\n path = dotfiles/work.gitconfig\n\
- [includeIf \"gitdir:~/w/\"]\n\tpath = ~/dotfiles/local.gitconfig\n\
- [include]\n path = ~/.ssh/leaky\n",
- )
- .unwrap();
- #[cfg(unix)]
- std::os::unix::fs::symlink(dots.join("gitconfig"), home.path().join(".gitconfig")).unwrap();
- #[cfg(windows)]
- std::os::windows::fs::symlink_file(dots.join("gitconfig"), home.path().join(".gitconfig"))
- .unwrap();
- // The credential include must be dropped even though the file exists.
- fs::write(home.path().join(".ssh/leaky"), "").unwrap();
-
- let g = resolve_local_jail_grants(Some(home.path()), &LocalJailConfig::default());
- let d = canon(&dots);
- assert!(has(&g.read_only, &d.join("gitconfig")), "{g:?}");
- assert!(has(&g.read_only, &d.join("work.gitconfig")), "{g:?}");
- assert!(has(&g.read_only, &d.join("local.gitconfig")), "{g:?}");
- assert_eq!(reaches_credentials(&all(&g), home.path()), None);
-}
-
-#[test]
-fn gitconfig_include_cycles_terminate() {
- let home = fake_home();
- fs::write(home.path().join(".gitconfig"), "[include]\n path = ~/b\n").unwrap();
- fs::write(home.path().join("b"), "[include]\n path = ~/.gitconfig\n").unwrap();
- let g = resolve_local_jail_grants(Some(home.path()), &LocalJailConfig::default());
- assert!(has(&g.read_only, &canon(&home.path().join("b"))));
-}
-
-#[test]
-fn no_home_yields_only_system_toolchain_dirs() {
- let g = resolve_local_jail_grants(None, &LocalJailConfig::default());
- assert!(g.read_write.is_empty());
- assert!(g
- .read_only
- .iter()
- .all(|p| p.starts_with("/usr/local") || p.starts_with("/opt")));
-}
diff --git a/crates/openhuman-core/src/sandbox/mod.rs b/crates/openhuman-core/src/sandbox/mod.rs
index da66cb57f1..457d5d2679 100644
--- a/crates/openhuman-core/src/sandbox/mod.rs
+++ b/crates/openhuman-core/src/sandbox/mod.rs
@@ -11,7 +11,7 @@
//! explicit elevated escape paths.
pub mod docker;
-pub mod grants;
+pub(crate) mod local_grants;
pub(crate) mod native_jail;
pub mod ops;
pub mod schemas;
diff --git a/crates/openhuman-core/src/sandbox/ops.rs b/crates/openhuman-core/src/sandbox/ops.rs
index 7c05132ddc..cc353baa3b 100644
--- a/crates/openhuman-core/src/sandbox/ops.rs
+++ b/crates/openhuman-core/src/sandbox/ops.rs
@@ -2,7 +2,6 @@
//! routed execution.
use super::docker;
-use super::grants::{resolve_local_jail_grants, JailGrants};
use super::types::{
ElevatedOp, SandboxBackendHandle, SandboxBackendKind, SandboxExecRequest, SandboxExecResult,
SandboxPolicy, SandboxStatus, ELEVATED_TOOLS,
@@ -165,21 +164,14 @@ pub fn resolve_sandbox_policy(
_ => true,
};
- // The jail denies whatever it is not told about, so a local policy carries
- // the toolchain/git grants everyday commands need (see `sandbox::grants`).
- let grants = if backend == SandboxBackendKind::Local {
- host_local_jail_grants(runtime_config)
- } else {
- JailGrants::default()
- };
-
+ // The jail denies whatever it is not told about; the toolchain/git grants
+ // everyday commands need are resolved by TinyBox at spawn time
+ // (`sandbox::local_grants`), so the policy starts without mounts.
tracing::debug!(
mode = ?mode,
backend = ?backend,
is_remote = is_remote_session,
action_dir = %action_dir.display(),
- read_only_grants = grants.read_only.len(),
- read_write_grants = grants.read_write.len(),
"[sandbox] resolved policy"
);
@@ -187,8 +179,8 @@ pub fn resolve_sandbox_policy(
backend,
workspace_root: action_dir.to_path_buf(),
state_dir: state_dir.to_path_buf(),
- read_only_mounts: grants.read_only,
- read_write_mounts: grants.read_write,
+ read_only_mounts: Vec::new(),
+ read_write_mounts: Vec::new(),
allow_network,
env_passthrough: SANDBOX_ENV_PASSTHROUGH
.iter()
@@ -343,9 +335,11 @@ pub async fn execute_in_sandbox(
anyhow::anyhow!("Cannot read module configuration: {error}")
})?,
};
+ let policy =
+ super::local_grants::with_resolved_grants(&config, policy).await?;
super::native_jail::execute(
&config,
- policy,
+ &policy,
command,
working_dir,
&extra_env,
@@ -405,11 +399,6 @@ pub(crate) async fn apply_requested_backend(
}
SandboxBackend::Landlock => {
super::native_jail::require_backend(config, "landlock").await?;
- if policy.backend != SandboxBackendKind::Local {
- let grants = host_local_jail_grants(runtime);
- policy.read_only_mounts = grants.read_only;
- policy.read_write_mounts = grants.read_write;
- }
policy.backend = SandboxBackendKind::Local;
policy.docker_overrides = None;
Ok(true)
@@ -524,27 +513,6 @@ pub fn is_elevated_op(tool_name: &str) -> bool {
ELEVATED_TOOLS.contains(&tool_name)
}
-fn host_local_jail_grants(runtime: &RuntimeConfig) -> JailGrants {
- local_jail_grants_with_home(runtime, crate::core::runtime::is_saas(), || {
- dirs::home_dir()
- })
-}
-
-// Shared by initial selection and an explicit backend switch. SaaS callers
-// have no operator-home grants, even if the helper is reached directly.
-fn local_jail_grants_with_home(
- runtime: &RuntimeConfig,
- saas: bool,
- home: impl FnOnce() -> Option<PathBuf>,
-) -> JailGrants {
- let home = if saas { None } else { home() };
- resolve_local_jail_grants(home.as_deref(), &runtime.local_jail)
-}
-
-#[cfg(test)]
-#[path = "ops_host_grants_tests.rs"]
-mod host_grants_tests;
-
/// Build an `ElevatedOp` for audit logging when a tool bypasses the sandbox.
pub fn build_elevated_op(tool_name: &str, command: &str, reason: &str) -> ElevatedOp {
tracing::info!(
diff --git a/crates/openhuman-core/src/sandbox/ops_host_grants_tests.rs b/crates/openhuman-core/src/sandbox/ops_host_grants_tests.rs
deleted file mode 100644
index 3484e09daa..0000000000
--- a/crates/openhuman-core/src/sandbox/ops_host_grants_tests.rs
+++ /dev/null
@@ -1,25 +0,0 @@
-use super::*;
-
-#[test]
-fn saas_local_grants_never_consult_the_operator_home() {
- let runtime = RuntimeConfig::default();
- let grants = local_jail_grants_with_home(&runtime, true, || {
- panic!("a tenant must not read the operator's home")
- });
- assert!(grants.read_write.is_empty());
- assert!(grants
- .read_only
- .iter()
- .all(|path| path.starts_with("/usr/local") || path.starts_with("/opt")));
-}
-
-#[test]
-fn single_user_local_grants_keep_the_configured_toolchain_home() {
- let home = tempfile::tempdir().unwrap();
- std::fs::create_dir(home.path().join(".rustup")).unwrap();
- let runtime = RuntimeConfig::default();
- let grants = local_jail_grants_with_home(&runtime, false, || Some(home.path().to_path_buf()));
- assert!(grants
- .read_only
- .contains(&home.path().join(".rustup").canonicalize().unwrap()));
-}
diff --git a/crates/openhuman-core/src/security/policy/mod.rs b/crates/openhuman-core/src/security/policy/mod.rs
index d674b209a6..0cabf7a63f 100644
--- a/crates/openhuman-core/src/security/policy/mod.rs
+++ b/crates/openhuman-core/src/security/policy/mod.rs
@@ -8,6 +8,10 @@ mod path_checks;
mod types;
+#[cfg(feature = "modules")]
+pub(crate) use path_checks::{
+ ALWAYS_FORBIDDEN_PREFIXES, SENSITIVE_COMPONENTS, SENSITIVE_FILES, SENSITIVE_PAIRS,
+};
pub use enforcement::validate_path_within_root;
pub use enforcement::{ensure_openhuman_scratch_dir, openhuman_scratch_dir};
pub use types::{