Skip to content

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

fix(sandbox): deny reads of credential stores in the folder-confined jail

M3gA-Mind57d422bf6963
diff --git a/crates/openhuman-core/src/sandbox/README.md b/crates/openhuman-core/src/sandbox/README.md
index 4a86ed779f..3f425155dd 100644
--- a/crates/openhuman-core/src/sandbox/README.md
+++ b/crates/openhuman-core/src/sandbox/README.md
@@ -98,14 +98,18 @@ read-write grants, TinyBox's scratch directory, `/private/tmp` and `/dev/null`.
Network follows `policy.allow_network` (on for a local session, off for a
remote one), which the jail's `allow_net` enforces.
-**Known limitation (`folder_confined`): reads are not confined.** Seatbelt's
-profile is allow-default for reads, so a command can read any file the user
-can, credential stores included (`~/.ssh`, `~/.gnupg`, `~/.aws`, Keychains), and
-with network on could send it out. The pinned TinyBox contract has no way to
-deny reads (`NativeJailConfig` carries no deny list). The capability is
-[tinyhumansai/tinybox#87](https://github.com/tinyhumansai/tinybox/pull/87)
-(`deny_read`, contract 1.20); once it is released and pinned, `folder_confined`
-requests will deny the `is_always_forbidden` credential stores.
+**`folder_confined`: credential stores are read-denied.** Seatbelt's profile
+is allow-default for reads, so `jail_request` sends the credential stores that
+`SecurityPolicy::is_always_forbidden` protects (`~/.ssh`, `~/.gnupg`, `~/.aws`,
+`~/.azure`, `~/.kube`, `~/Library/Keychains`, `~/.netrc`, `~/.git-credentials`,
+`~/.pgpass`, `~/.npmrc`, `~/.docker/config.json`, `~/.cargo/credentials.toml`)
+as `NativeJailConfig.deny_read` (TinyBox contract 1.20), built from the same
+lists by `security::policy::home_credential_stores`. Only stores that exist are
+sent. A store that holds the workspace root or a read-write grant is left out
+with a warning, because TinyBox refuses a denial that would take the command's
+workspace away; a store inside a grant is still denied. Other files the user
+can read stay readable. `isolated` (Landlock) sends none: it already denies
+every path it is not granted.
TinyBox owns the jail provider, child process, pipe capture,
and kill/reap acknowledgement; OpenHuman reads bounded output batches and
diff --git a/crates/openhuman-core/src/sandbox/native_jail.rs b/crates/openhuman-core/src/sandbox/native_jail.rs
index b1335ff2c6..02c510f05f 100644
--- a/crates/openhuman-core/src/sandbox/native_jail.rs
+++ b/crates/openhuman-core/src/sandbox/native_jail.rs
@@ -237,9 +237,59 @@ fn jail_request(
contract::JailEnforcement::Declared
},
require_process_isolation: isolated,
+ // Landlock denies every path it is not granted; Seatbelt reads
+ // allow-default, so folder confinement names the credential stores.
+ deny_read: if isolated {
+ Vec::new()
+ } else {
+ let home =
+ super::local_grants::grant_home(crate::core::runtime::is_saas(), dirs::home_dir);
+ credential_denials(
+ home.as_deref(),
+ &policy.workspace_root,
+ &policy.read_write_mounts,
+ )
+ },
})
}
+/// The credential stores under `home` that a folder-confined jail must not
+/// read: the stores [`SecurityPolicy::is_always_forbidden`] protects, as
+/// existing absolute paths (TinyBox drops absent ones anyway). A store that
+/// holds the jail root or a writable grant is left out, because TinyBox refuses
+/// a denial that would take the command's workspace away.
+///
+/// [`SecurityPolicy::is_always_forbidden`]: crate::security::SecurityPolicy
+#[cfg(any(feature = "modules", test))]
+fn credential_denials(
+ home: Option<&Path>,
+ root: &Path,
+ read_write: &[std::path::PathBuf],
+) -> Vec<String> {
+ let Some(home) = home else {
+ return Vec::new();
+ };
+ let granted: Vec<std::path::PathBuf> = std::iter::once(root)
+ .chain(read_write.iter().map(std::path::PathBuf::as_path))
+ .filter_map(|path| path.canonicalize().ok())
+ .collect();
+ crate::security::policy::home_credential_stores(home)
+ .into_iter()
+ .filter_map(|store| {
+ let real = store.canonicalize().ok()?;
+ if granted.iter().any(|path| path.starts_with(&real)) {
+ // The store's name only: the full path carries the user's login.
+ tracing::warn!(
+ store = ?store.file_name(),
+ "[sandbox:local] not denying reads of a credential store that holds the workspace or a writable grant"
+ );
+ return None;
+ }
+ real.to_str().map(str::to_owned)
+ })
+ .collect()
+}
+
#[cfg(feature = "modules")]
use super::shell_exec::path_string;
diff --git a/crates/openhuman-core/src/sandbox/native_jail_tests.rs b/crates/openhuman-core/src/sandbox/native_jail_tests.rs
index 344f8348e7..10fdf173a0 100644
--- a/crates/openhuman-core/src/sandbox/native_jail_tests.rs
+++ b/crates/openhuman-core/src/sandbox/native_jail_tests.rs
@@ -90,9 +90,119 @@ fn native_jail_request_preserves_grants_and_requires_enforcement() -> anyhow::Re
assert!(!confined.allow_net);
assert_eq!(confined.enforcement, contract::JailEnforcement::Declared);
assert!(!confined.require_process_isolation);
+
+ // Landlock is deny-default, so the isolated jail needs no read denials;
+ // Seatbelt reads allow-default, so folder confinement names the
+ // credential stores this host has.
+ assert!(request.deny_read.is_empty());
+ for denied in &confined.deny_read {
+ assert!(
+ crate::security::SecurityPolicy::is_always_forbidden(std::path::Path::new(denied)),
+ "{denied} is not a protected credential store"
+ );
+ }
Ok(())
}
+/// A home folder holding the given credential stores: a trailing `/` makes a
+/// directory, anything else a file.
+fn home_with(stores: &[&str]) -> tempfile::TempDir {
+ let home = tempfile::tempdir().unwrap();
+ for store in stores {
+ let path = home.path().join(store.trim_end_matches('/'));
+ if store.ends_with('/') {
+ std::fs::create_dir_all(&path).unwrap();
+ } else {
+ std::fs::create_dir_all(path.parent().unwrap()).unwrap();
+ std::fs::write(&path, "secret").unwrap();
+ }
+ }
+ home
+}
+
+fn real(home: &tempfile::TempDir, store: &str) -> String {
+ home.path()
+ .join(store)
+ .canonicalize()
+ .unwrap()
+ .to_str()
+ .unwrap()
+ .to_owned()
+}
+
+#[test]
+fn folder_confinement_denies_the_credential_stores_that_exist() {
+ let home = home_with(&[
+ ".ssh/",
+ ".aws/",
+ "Library/Keychains/",
+ ".netrc",
+ ".cargo/credentials.toml",
+ ]);
+ let root = tempfile::tempdir().unwrap();
+
+ let denied = credential_denials(Some(home.path()), root.path(), &[]);
+
+ // Absent stores (`.gnupg`, `.kube`, `.npmrc`, ...) are not sent.
+ assert_eq!(
+ denied,
+ [
+ real(&home, ".ssh"),
+ real(&home, ".aws"),
+ real(&home, "Library/Keychains"),
+ real(&home, ".netrc"),
+ real(&home, ".cargo/credentials.toml"),
+ ]
+ );
+}
+
+#[test]
+fn a_store_holding_the_root_or_a_writable_grant_is_not_denied() {
+ let home = home_with(&[
+ ".ssh/",
+ ".aws/project/",
+ ".kube/",
+ ".cargo/credentials.toml",
+ ]);
+
+ // TinyBox refuses a denial over the root or a writable grant, so those
+ // stores are dropped. A store inside a writable grant is still denied:
+ // Seatbelt carves it out of the grant.
+ let denied = credential_denials(
+ Some(home.path()),
+ &home.path().join(".aws/project"),
+ &[home.path().join(".kube"), home.path().join(".cargo")],
+ );
+
+ assert_eq!(
+ denied,
+ [real(&home, ".ssh"), real(&home, ".cargo/credentials.toml")]
+ );
+}
+
+#[test]
+fn no_home_means_no_credential_denials() {
+ let root = tempfile::tempdir().unwrap();
+ assert!(credential_denials(None, root.path(), &[]).is_empty());
+}
+
+#[test]
+fn every_denied_store_is_one_the_path_floor_forbids() {
+ let home = std::path::Path::new("/home/someone");
+ let stores = crate::security::policy::home_credential_stores(home);
+
+ assert!(stores.contains(&home.join(".ssh")));
+ assert!(stores.contains(&home.join("Library/Keychains")));
+ assert!(stores.contains(&home.join(".git-credentials")));
+ for store in &stores {
+ assert!(
+ crate::security::SecurityPolicy::is_always_forbidden(store),
+ "{} is not on the is_always_forbidden floor",
+ store.display()
+ );
+ }
+}
+
#[cfg(feature = "modules")]
#[test]
fn approved_environment_carries_only_the_callers_overrides() -> anyhow::Result<()> {
diff --git a/crates/openhuman-core/src/security/policy/mod.rs b/crates/openhuman-core/src/security/policy/mod.rs
index aaac97ec15..c68e431d14 100644
--- a/crates/openhuman-core/src/security/policy/mod.rs
+++ b/crates/openhuman-core/src/security/policy/mod.rs
@@ -10,6 +10,8 @@ mod types;
pub use enforcement::validate_path_within_root;
pub use enforcement::{ensure_openhuman_scratch_dir, openhuman_scratch_dir};
+#[cfg(any(feature = "modules", test))]
+pub(crate) use path_checks::home_credential_stores;
#[cfg(feature = "modules")]
pub(crate) use path_checks::{
ALWAYS_FORBIDDEN_PREFIXES, SENSITIVE_COMPONENTS, SENSITIVE_FILES, SENSITIVE_PAIRS,
diff --git a/crates/openhuman-core/src/security/policy/path_checks.rs b/crates/openhuman-core/src/security/policy/path_checks.rs
index 2bb5c2fa84..ebf447b411 100644
--- a/crates/openhuman-core/src/security/policy/path_checks.rs
+++ b/crates/openhuman-core/src/security/policy/path_checks.rs
@@ -23,6 +23,23 @@ pub(crate) const SENSITIVE_PAIRS: &[[&str; 2]] = &[
["microsoft", "crypto"],
["microsoft", "vault"],
];
+/// The credential stores above as absolute paths under `home`, for a jail that
+/// denies reads by path rather than by segment. macOS keeps keychains in
+/// `~/Library/Keychains`. The Windows DPAPI pairs have no fixed place under a
+/// home folder, so they stay with the segment check alone.
+#[cfg(any(feature = "modules", test))]
+pub(crate) fn home_credential_stores(home: &Path) -> Vec<PathBuf> {
+ let components = SENSITIVE_COMPONENTS.iter().map(|segment| match *segment {
+ "keychains" => home.join("Library").join("Keychains"),
+ segment => home.join(segment),
+ });
+ let files = SENSITIVE_FILES.iter().map(|file| home.join(file));
+ let pairs = SENSITIVE_PAIRS
+ .iter()
+ .filter(|[dir, _]| dir.starts_with('.'))
+ .map(|[dir, file]| home.join(dir).join(file));
+ components.chain(files).chain(pairs).collect()
+}
/// Core OS directories matched by absolute (lower-cased) prefix. `/private` is
/// intentionally absent: macOS temp dirs canonicalize under `/private/var`.
pub(crate) const ALWAYS_FORBIDDEN_PREFIXES: &[&str] = &[