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): deny OpenHuman's own credential files in the folder-confined jail
M3gA-Mind090a429da6c9
diff --git a/crates/openhuman-core/src/sandbox/README.md b/crates/openhuman-core/src/sandbox/README.mdindex 3f425155dd..c7eb1955e7 100644--- a/crates/openhuman-core/src/sandbox/README.md+++ b/crates/openhuman-core/src/sandbox/README.md@@ -104,8 +104,14 @@ is allow-default for reads, so `jail_request` sends the credential stores that`~/.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+lists by `security::policy::home_credential_stores`. OpenHuman's own credential+files are denied too (`security::credentials::credential_files`, at the paths+their stores write): the keyring's `secrets.enc`, `auth-profiles.json`,+`http-credentials.json` and the account `config.toml`. The rest of the+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 outwith a warning, because TinyBox refuses a denial that would take the command'sworkspace away; a store inside a grant is still denied. Other files the usercan read stay readable. `isolated` (Landlock) sends none: it already deniesdiff --git a/crates/openhuman-core/src/sandbox/native_jail.rs b/crates/openhuman-core/src/sandbox/native_jail.rsindex 02c510f05f..0127e5a6bb 100644--- a/crates/openhuman-core/src/sandbox/native_jail.rs+++ b/crates/openhuman-core/src/sandbox/native_jail.rs@@ -187,7 +187,7 @@ async fn execute_owned(run.meter = meter;// TinyBox adds its own per-call scratch directory to the writable grants and// points TMPDIR, TMP and TEMP at it unless the caller overrides them.- run.jail = Some(jail_request(policy, isolation)?);+ run.jail = Some(jail_request(config, policy, isolation)?);super::shell_exec::run(ctx, config, run).await}@@ -212,6 +212,7 @@ fn approved_environment(#[cfg(feature = "modules")]fn jail_request(+ config: &Config,policy: &SandboxPolicy,isolation: SandboxIsolation,) -> anyhow::Result<contract::NativeJailConfig> {@@ -238,42 +239,40 @@ fn jail_request(},require_process_isolation: isolated,// Landlock denies every path it is not granted; Seatbelt reads- // allow-default, so folder confinement names the credential stores.+ // allow-default, so folder confinement names the credential stores:+ // the user's, and OpenHuman's own credential files.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,- )+ let stores = home+ .as_deref()+ .map(crate::security::policy::home_credential_stores)+ .unwrap_or_default()+ .into_iter()+ .chain(crate::security::credentials::credential_files(config))+ .collect();+ credential_denials(stores, &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+/// 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.#[cfg(any(feature = "modules", test))]fn credential_denials(- home: Option<&Path>,+ stores: Vec<std::path::PathBuf>,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)+ stores.into_iter().filter_map(|store| {let real = store.canonicalize().ok()?;diff --git a/crates/openhuman-core/src/sandbox/native_jail_tests.rs b/crates/openhuman-core/src/sandbox/native_jail_tests.rsindex 10fdf173a0..68811ec7bb 100644--- a/crates/openhuman-core/src/sandbox/native_jail_tests.rs+++ b/crates/openhuman-core/src/sandbox/native_jail_tests.rs@@ -71,7 +71,14 @@ fn native_jail_request_preserves_grants_and_requires_enforcement() -> anyhow::Reenv_passthrough: Vec::new(),docker_overrides: None,};- let request = jail_request(&policy, SandboxIsolation::Isolated)?;+ let account = tempfile::tempdir()?;+ let mut config = Config::default();+ config.config_path = account.path().join("config.toml");+ std::fs::write(&config.config_path, "")?;+ let _keyring = crate::security::secret_storage::store::test_scope::ScopedWorkspace::new(+ account.path().join("workspace"),+ );+ let request = jail_request(&config, &policy, SandboxIsolation::Isolated)?;assert_eq!(request.read_only, [readonly.path().to_str().unwrap()]);// TinyBox appends its own per-call scratch directory to the writable grants.@@ -84,7 +91,7 @@ fn native_jail_request_preserves_grants_and_requires_enforcement() -> anyhow::Re// Folder confinement keeps the grants and the network decision, and asks// TinyBox for what Seatbelt can give: declared constraints, no process// isolation.- let confined = jail_request(&policy, SandboxIsolation::FolderConfined)?;+ let confined = jail_request(&config, &policy, SandboxIsolation::FolderConfined)?;assert_eq!(confined.read_only, request.read_only);assert_eq!(confined.read_write, request.read_write);assert!(!confined.allow_net);@@ -93,12 +100,19 @@ fn native_jail_request_preserves_grants_and_requires_enforcement() -> anyhow::Re// 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.+ // credential stores this host has and OpenHuman's own credential files.assert!(request.deny_read.is_empty());+ let account_config = config.config_path.canonicalize()?;+ assert!(confined+ .deny_read+ .contains(&account_config.to_str().unwrap().to_owned()));for denied in &confined.deny_read {+ let denied = std::path::Path::new(denied);assert!(- crate::security::SecurityPolicy::is_always_forbidden(std::path::Path::new(denied)),- "{denied} is not a protected credential store"+ crate::security::SecurityPolicy::is_always_forbidden(denied)+ || denied == account_config,+ "{} is not a protected credential store",+ denied.display());}Ok(())@@ -141,7 +155,11 @@ fn folder_confinement_denies_the_credential_stores_that_exist() {]);let root = tempfile::tempdir().unwrap();- let denied = credential_denials(Some(home.path()), root.path(), &[]);+ let denied = credential_denials(+ crate::security::policy::home_credential_stores(home.path()),+ root.path(),+ &[],+ );// Absent stores (`.gnupg`, `.kube`, `.npmrc`, ...) are not sent.assert_eq!(@@ -169,7 +187,7 @@ fn a_store_holding_the_root_or_a_writable_grant_is_not_denied() {// 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()),+ crate::security::policy::home_credential_stores(home.path()),&home.path().join(".aws/project"),&[home.path().join(".kube"), home.path().join(".cargo")],);@@ -181,9 +199,65 @@ fn a_store_holding_the_root_or_a_writable_grant_is_not_denied() {}#[test]-fn no_home_means_no_credential_denials() {+fn nothing_to_deny_means_no_credential_denials() {let root = tempfile::tempdir().unwrap();- assert!(credential_denials(None, root.path(), &[]).is_empty());+ assert!(credential_denials(Vec::new(), root.path(), &[]).is_empty());+}++#[test]+fn openhumans_own_credential_files_are_denied_when_present() {+ // The account folder: config.toml and the credential stores beside it, the+ // core workspace below it with the keyring file and TinyBox's scratch.+ let account = tempfile::tempdir().unwrap();+ let workspace = account.path().join("workspace");+ let scratch = workspace.join("artifacts/sandbox-scratch/shell-1");+ std::fs::create_dir_all(&scratch).unwrap();+ let mut config = Config::default();+ config.config_path = account.path().join("config.toml");+ let _keyring =+ crate::security::secret_storage::store::test_scope::ScopedWorkspace::new(&workspace);+ let files = [+ config.config_path.clone(),+ account.path().join("auth-profiles.json"),+ account.path().join("http-credentials.json"),+ workspace.join("secrets.enc"),+ ];+ for file in &files {+ std::fs::write(file, "secret").unwrap();+ }+ let root = tempfile::tempdir().unwrap();++ let denied = credential_denials(+ crate::security::credentials::credential_files(&config),+ root.path(),+ &[scratch.clone()],+ );++ let mut expected: Vec<String> = files+ .iter()+ .map(|file| file.canonicalize().unwrap().to_str().unwrap().to_owned())+ .collect();+ let mut sorted = denied.clone();+ sorted.sort();+ expected.sort();+ assert_eq!(sorted, expected);+ // Files only: none of them is, or contains, the jail's scratch directory.+ let scratch = scratch.canonicalize().unwrap();+ for file in &denied {+ assert!(!scratch.starts_with(file), "{file} covers the scratch dir");+ }++ // A credential file that does not exist is not sent.+ std::fs::remove_file(account.path().join("http-credentials.json")).unwrap();+ let denied = credential_denials(+ crate::security::credentials::credential_files(&config),+ root.path(),+ &[],+ );+ assert_eq!(denied.len(), 3);+ assert!(!denied+ .iter()+ .any(|file| file.ends_with("http-credentials.json")));}#[test]diff --git a/crates/openhuman-core/src/security/credentials/core.rs b/crates/openhuman-core/src/security/credentials/core.rsindex 9a894f7703..f7314347d5 100644--- a/crates/openhuman-core/src/security/credentials/core.rs+++ b/crates/openhuman-core/src/security/credentials/core.rs@@ -149,6 +149,23 @@ pub fn state_dir_from_config(config: &Config) -> PathBuf {.map_or_else(|| PathBuf::from("."), PathBuf::from)}+/// The files holding OpenHuman's own credentials for `config`, at the paths+/// their stores write: the encrypted keyring (`secrets.enc`), the auth+/// profiles, the HTTP credentials and the account config. A path may not+/// exist.+#[cfg(any(feature = "modules", test))]+pub(crate) fn credential_files(config: &Config) -> Vec<PathBuf> {+ let state_dir = state_dir_from_config(config);+ vec![+ crate::security::secret_storage::encrypted_file_backend::secrets_file(+ &crate::security::secret_storage::store::workspace_dir_for_file_backend(),+ ),+ super::profiles::profiles_file(&state_dir),+ super::http_creds::store_file(&state_dir),+ config.config_path.clone(),+ ]+}+pub fn default_profile_id(provider: &str) -> String {profile_id(provider, DEFAULT_PROFILE_NAME)}diff --git a/crates/openhuman-core/src/security/credentials/http_creds.rs b/crates/openhuman-core/src/security/credentials/http_creds.rsindex 81d3d245fa..bf1311bc28 100644--- a/crates/openhuman-core/src/security/credentials/http_creds.rs+++ b/crates/openhuman-core/src/security/credentials/http_creds.rs@@ -26,6 +26,10 @@ use crate::config::Config;use crate::security::secret_storage::SecretStore;const STORE_FILENAME: &str = "http-credentials.json";+/// The HTTP credentials file a store over `state_dir` keeps.+pub(crate) fn store_file(state_dir: &Path) -> PathBuf {+ state_dir.join(STORE_FILENAME)+}const CURRENT_SCHEMA_VERSION: u32 = 1;/// How a credential is presented on the outbound request.@@ -220,7 +224,7 @@ impl HttpCredentialsStore {pub fn new(state_dir: &Path, encrypt_secrets: bool) -> Self {Self {- path: state_dir.join(STORE_FILENAME),+ path: store_file(state_dir),secret_store: SecretStore::new(state_dir, encrypt_secrets),}}diff --git a/crates/openhuman-core/src/security/credentials/profiles.rs b/crates/openhuman-core/src/security/credentials/profiles.rsindex be10d29aeb..122e5ae1c1 100644--- a/crates/openhuman-core/src/security/credentials/profiles.rs+++ b/crates/openhuman-core/src/security/credentials/profiles.rs@@ -39,6 +39,10 @@ struct KeychainSecrets {pub id_token: Option<String>,}const PROFILES_FILENAME: &str = "auth-profiles.json";+/// The auth-profiles file a store over `state_dir` keeps.+pub(crate) fn profiles_file(state_dir: &Path) -> PathBuf {+ state_dir.join(PROFILES_FILENAME)+}const LOCK_FILENAME: &str = "auth-profiles.lock";const LOCK_WAIT_MS: u64 = 50;/// A lock file that has existed for longer than this is treated as leakeddiff --git a/crates/openhuman-core/src/security/credentials/profiles/store_core.rs b/crates/openhuman-core/src/security/credentials/profiles/store_core.rsindex 19629e43f0..b546cdb321 100644--- a/crates/openhuman-core/src/security/credentials/profiles/store_core.rs+++ b/crates/openhuman-core/src/security/credentials/profiles/store_core.rs@@ -9,10 +9,7 @@ use std::sync::atomic::{AtomicBool, AtomicUsize};#[cfg(test)]use std::sync::Arc;-use super::{- is_lock_create_unwritable_fs, AuthProfile, AuthProfilesData, AuthProfilesStore,- PROFILES_FILENAME,-};+use super::{is_lock_create_unwritable_fs, AuthProfile, AuthProfilesData, AuthProfilesStore};use crate::security::secret_storage::SecretStore;use super::LOCK_FILENAME;@@ -51,7 +48,7 @@ impl AuthProfilesStore {}}Self {- path: state_dir.join(PROFILES_FILENAME),+ path: super::profiles_file(state_dir),lock_path: state_dir.join(LOCK_FILENAME),secret_store: SecretStore::new(state_dir, encrypt_secrets),user_id,diff --git a/crates/openhuman-core/src/security/secret_storage/encrypted_file_backend.rs b/crates/openhuman-core/src/security/secret_storage/encrypted_file_backend.rsindex e5fec5dc43..b0e1d33cf7 100644--- a/crates/openhuman-core/src/security/secret_storage/encrypted_file_backend.rs+++ b/crates/openhuman-core/src/security/secret_storage/encrypted_file_backend.rs@@ -317,10 +317,15 @@ pub struct EncryptedFileBackend {workspace_dir: PathBuf,}+/// The encrypted secrets file a backend rooted at `workspace_dir` keeps.+pub(crate) fn secrets_file(workspace_dir: &Path) -> PathBuf {+ workspace_dir.join(SECRETS_FILENAME)+}+impl EncryptedFileBackend {pub fn new(workspace_dir: &Path) -> Self {Self {- path: workspace_dir.join(SECRETS_FILENAME),+ path: secrets_file(workspace_dir),workspace_dir: workspace_dir.to_path_buf(),}}