Skip to content

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

fix(sandbox): refuse a folder-confined jail whose workspace is inside a credential store

M3gA-Mind06d3852d679a
diff --git a/crates/openhuman-core/src/sandbox/README.md b/crates/openhuman-core/src/sandbox/README.md
index c7eb1955e7..8b6ceb03b1 100644
--- a/crates/openhuman-core/src/sandbox/README.md
+++ b/crates/openhuman-core/src/sandbox/README.md
@@ -111,10 +111,13 @@ their stores write): the keyring's `secrets.enc`, `auth-profiles.json`,
OpenHuman state folder stays readable for now, because TinyBox keeps the jail's
scratch directory (its `TMPDIR`) under `<state_dir>/artifacts/sandbox-scratch`,
and a denial is the profile's last rule, overriding that write grant. 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
+stores that exist are sent. When the workspace root or a read-write grant sits
+inside a store (an action dir of `~/.aws/project`), the folder-confined jail is
+refused with an error naming the store: TinyBox cannot deny a store that holds
+the command's workspace, and running without the denial would leave the rest of
+the store readable. A store inside a grant is still denied. Credential files
+outside these home locations, such as a project's own `.npmrc`, are not covered
+yet; that needs pattern denials in TinyBox. 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,
diff --git a/crates/openhuman-core/src/sandbox/native_jail.rs b/crates/openhuman-core/src/sandbox/native_jail.rs
index 0127e5a6bb..1cde42e79a 100644
--- a/crates/openhuman-core/src/sandbox/native_jail.rs
+++ b/crates/openhuman-core/src/sandbox/native_jail.rs
@@ -253,40 +253,54 @@ fn jail_request(
.into_iter()
.chain(crate::security::credentials::credential_files(config))
.collect();
- credential_denials(stores, &policy.workspace_root, &policy.read_write_mounts)
+ credential_denials(stores, &policy.workspace_root, &policy.read_write_mounts)?
},
})
}
/// The credential `stores` a folder-confined jail must not read, as existing
-/// canonical 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.
+/// canonical paths (TinyBox drops absent ones anyway).
+///
+/// # Errors
+///
+/// Refuses the jail when its root or a writable grant sits inside a store:
+/// TinyBox cannot deny a store that holds the command's workspace, and running
+/// without that denial would leave the rest of the store readable. A store
+/// inside a grant is fine; Seatbelt carves it out.
#[cfg(any(feature = "modules", test))]
fn credential_denials(
stores: Vec<std::path::PathBuf>,
root: &Path,
read_write: &[std::path::PathBuf],
-) -> Vec<String> {
+) -> anyhow::Result<Vec<String>> {
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();
- stores
- .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()
+ let mut denied = Vec::new();
+ for store in stores {
+ let Ok(real) = store.canonicalize() else {
+ continue;
+ };
+ if granted.iter().any(|path| path.starts_with(&real)) {
+ // The store's name only: the full path carries the user's login.
+ let name = store
+ .file_name()
+ .map_or_else(String::new, |name| name.to_string_lossy().into_owned());
+ tracing::warn!(
+ store = %name,
+ "[sandbox:local] refusing the folder-confined jail: its workspace or a writable grant is inside a credential store"
+ );
+ anyhow::bail!(
+ "the sandbox workspace or a writable folder is inside the credential store `{name}`; \
+ choose a working folder outside it"
+ );
+ }
+ if let Some(real) = real.to_str() {
+ denied.push(real.to_owned());
+ }
+ }
+ Ok(denied)
}
#[cfg(feature = "modules")]
diff --git a/crates/openhuman-core/src/sandbox/native_jail_tests.rs b/crates/openhuman-core/src/sandbox/native_jail_tests.rs
index 68811ec7bb..0a11ed1e8a 100644
--- a/crates/openhuman-core/src/sandbox/native_jail_tests.rs
+++ b/crates/openhuman-core/src/sandbox/native_jail_tests.rs
@@ -159,7 +159,8 @@ fn folder_confinement_denies_the_credential_stores_that_exist() {
crate::security::policy::home_credential_stores(home.path()),
root.path(),
&[],
- );
+ )
+ .unwrap();
// Absent stores (`.gnupg`, `.kube`, `.npmrc`, ...) are not sent.
assert_eq!(
@@ -175,22 +176,53 @@ fn folder_confinement_denies_the_credential_stores_that_exist() {
}
#[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",
- ]);
+fn a_workspace_inside_a_credential_store_is_refused() {
+ let home = home_with(&[".ssh/", ".aws/project/"]);
- // 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(
+ // Denying `~/.aws` would take the workspace away, and skipping it would
+ // leave `~/.aws/credentials` readable, so the jail is refused.
+ let err = credential_denials(
crate::security::policy::home_credential_stores(home.path()),
&home.path().join(".aws/project"),
- &[home.path().join(".kube"), home.path().join(".cargo")],
- );
+ &[],
+ )
+ .unwrap_err()
+ .to_string();
+
+ assert!(err.contains("`.aws`"), "{err}");
+ // The error names the store, never the user's path to it.
+ assert!(!err.contains(home.path().to_str().unwrap()), "{err}");
+}
+
+#[test]
+fn a_writable_grant_inside_a_credential_store_is_refused() {
+ let home = home_with(&[".kube/"]);
+ let root = tempfile::tempdir().unwrap();
+
+ let err = credential_denials(
+ crate::security::policy::home_credential_stores(home.path()),
+ root.path(),
+ &[home.path().join(".kube")],
+ )
+ .unwrap_err()
+ .to_string();
+
+ assert!(err.contains("`.kube`"), "{err}");
+}
+
+#[test]
+fn a_store_inside_a_writable_grant_is_still_denied() {
+ let home = home_with(&[".ssh/", ".cargo/credentials.toml"]);
+ let root = tempfile::tempdir().unwrap();
+
+ // Seatbelt carves the store out of the grant; a store that holds nothing
+ // of the jail's is denied as usual.
+ let denied = credential_denials(
+ crate::security::policy::home_credential_stores(home.path()),
+ root.path(),
+ &[home.path().join(".cargo")],
+ )
+ .unwrap();
assert_eq!(
denied,
@@ -201,7 +233,9 @@ fn a_store_holding_the_root_or_a_writable_grant_is_not_denied() {
#[test]
fn nothing_to_deny_means_no_credential_denials() {
let root = tempfile::tempdir().unwrap();
- assert!(credential_denials(Vec::new(), root.path(), &[]).is_empty());
+ assert!(credential_denials(Vec::new(), root.path(), &[])
+ .unwrap()
+ .is_empty());
}
#[test]
@@ -231,7 +265,8 @@ fn openhumans_own_credential_files_are_denied_when_present() {
crate::security::credentials::credential_files(&config),
root.path(),
&[scratch.clone()],
- );
+ )
+ .unwrap();
let mut expected: Vec<String> = files
.iter()
@@ -253,7 +288,8 @@ fn openhumans_own_credential_files_are_denied_when_present() {
crate::security::credentials::credential_files(&config),
root.path(),
&[],
- );
+ )
+ .unwrap();
assert_eq!(denied.len(), 3);
assert!(!denied
.iter()