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
refactor(security): clean up secret storage and storage layout code
Steven Enamakel640c9a9cb651
diff --git a/crates/openhuman-core/src/security/secret_storage/adapter.rs b/crates/openhuman-core/src/security/secret_storage/adapter.rsindex 24588184c4..d25826e2d4 100644--- a/crates/openhuman-core/src/security/secret_storage/adapter.rs+++ b/crates/openhuman-core/src/security/secret_storage/adapter.rs@@ -87,7 +87,9 @@ fn recover_corrupt_file_after_probe(// writer did not replace the corrupt bytes with a healthy store.let _guard = file_store::lock_for_write(path)?;if file_store::fingerprint(path)? != before_probe {- log::info!("[keyring:encrypted_file] secrets file changed after the failed probe; not quarantining");+ log::info!(+ "[keyring:encrypted_file] secrets file changed after the failed probe; not quarantining"+ );return Ok(());}log::error!(diff --git a/crates/openhuman-core/src/security/secret_storage/encrypted_file_backend/key_source_tests.rs b/crates/openhuman-core/src/security/secret_storage/encrypted_file_backend/key_source_tests.rsindex 70b244f18f..aac5196dd6 100644--- a/crates/openhuman-core/src/security/secret_storage/encrypted_file_backend/key_source_tests.rs+++ b/crates/openhuman-core/src/security/secret_storage/encrypted_file_backend/key_source_tests.rs@@ -58,10 +58,12 @@ fn host_key_write_requires_matching_readback() {wrong_readback: true,..Default::default()};- assert!(load_or_mint_master_key(&source)- .unwrap_err()- .to_string()- .contains("verification failed"));+ assert!(+ load_or_mint_master_key(&source)+ .unwrap_err()+ .to_string()+ .contains("verification failed")+ );}#[test]@@ -112,7 +114,7 @@ fn corrupt_workspace_key_is_never_replaced() {#[cfg(unix)]#[test]fn workspace_key_rejects_shared_permissions_and_symlinks() {- use std::os::unix::fs::{symlink, PermissionsExt};+ use std::os::unix::fs::{PermissionsExt, symlink};let dir = tempfile::tempdir().unwrap();let path = dir.path().join("keyring/master.key");workspace_master_key(dir.path()).unwrap();diff --git a/crates/openhuman-core/src/security/secret_storage/encrypted_file_backend_disabled.rs b/crates/openhuman-core/src/security/secret_storage/encrypted_file_backend_disabled.rsnew file mode 100644index 0000000000..f49dcb554d--- /dev/null+++ b/crates/openhuman-core/src/security/secret_storage/encrypted_file_backend_disabled.rs@@ -0,0 +1,85 @@+//! Explicit unavailable adapter for builds that omit `secret-file`.+//!+//! The host keeps this type in the public facade so it can compile against a+//! core built without the encrypted-file implementation. Selecting this+//! backend fails closed at the first operation; it never falls back to+//! plaintext or memory storage.++use std::path::{Path, PathBuf};++use crate::security::secret_storage::backend::SecretBackend;+use crate::security::secret_storage::error::SecretStorageError;+use crate::security::secret_storage::{crypto, file_store};+use zeroize::Zeroizing;++pub const MASTER_KEY_ENV: &str = "OPENHUMAN_KEYRING_MASTER_KEY";+pub const MASTER_KEY_FILE_ENV: &str = "OPENHUMAN_KEYRING_MASTER_KEY_FILE";+const KEY_LEN: usize = 32;++#[path = "encrypted_file_backend/key_source.rs"]+pub mod key_source;+pub use key_source::{+ MasterKeySource, clear_master_key_source, install_master_key_source,+ installed_master_key_source,+};++/// There is no encrypted-file initialization in a build without `secret-file`.+pub fn init_master_key() -> Result<(), String> {+ Ok(())+}++/// Storage-backed encryption needs a host key source when `secret-file` is off.+pub(crate) fn storage_master_key() -> Result<[u8; KEY_LEN], String> {+ Err("encrypted secret key storage is disabled; enable the secret-file feature".into())+}++pub(crate) fn storage_master_key_resolvable() -> bool {+ false+}++pub(crate) fn master_key_available() -> bool {+ false+}++pub(crate) fn resolvable(loaded: bool, env: bool, host: bool, key_file: bool) -> bool {+ loaded || env || host || key_file+}++pub(crate) fn secrets_file(workspace_dir: &Path) -> PathBuf {+ workspace_dir.join("secrets.enc")+}++/// Placeholder that returns a specific unavailable error if selected.+pub struct EncryptedFileBackend;++impl EncryptedFileBackend {+ /// Construct the unavailable adapter. Its path is intentionally unused.+ #[must_use]+ pub fn new(_workspace_dir: &Path) -> Self {+ Self+ }+}++impl SecretBackend for EncryptedFileBackend {+ fn get(&self, _: &str) -> Result<Option<String>, SecretStorageError> {+ Err(unavailable())+ }++ fn set(&self, _: &str, _: &str) -> Result<(), SecretStorageError> {+ Err(unavailable())+ }++ fn delete(&self, _: &str) -> Result<(), SecretStorageError> {+ Err(unavailable())+ }++ fn name(&self) -> &'static str {+ "encrypted_file"+ }+}++fn unavailable() -> SecretStorageError {+ SecretStorageError::Backend(+ "encrypted file secret backend is disabled; enable the secret-file feature".into(),+ )+}diff --git a/crates/openhuman-core/src/security/secret_storage/encrypted_file_backend_tests.rs b/crates/openhuman-core/src/security/secret_storage/encrypted_file_backend_tests.rsindex c1af887e97..f9f7cbbe31 100644--- a/crates/openhuman-core/src/security/secret_storage/encrypted_file_backend_tests.rs+++ b/crates/openhuman-core/src/security/secret_storage/encrypted_file_backend_tests.rs@@ -48,9 +48,11 @@ fn invalid_legacy_plaintext_is_preserved_for_recovery() {std::fs::write(&legacy_path, b"invalid JSON").unwrap();let backend = EncryptedFileBackend::new(dir.path());- assert!(backend- .get_with_key(&[0x42; KEY_LEN], "user:token")- .is_err());+ assert!(+ backend+ .get_with_key(&[0x42; KEY_LEN], "user:token")+ .is_err()+ );assert_eq!(std::fs::read(&legacy_path).unwrap(), b"invalid JSON");assert!(!backend.path.exists());}@@ -255,9 +257,11 @@ fn malformed_env_key_is_rejected_without_leaking_the_value() {#[test]fn empty_env_values_fall_through_to_the_keychain() {- assert!(master_key_from_env(None, None, file_must_not_be_read)- .expect("nothing set is fine")- .is_none());+ assert!(+ master_key_from_env(None, None, file_must_not_be_read)+ .expect("nothing set is fine")+ .is_none()+ );assert!(master_key_from_env(Some(""), Some(" "), file_must_not_be_read).expect("empty values count as unset")diff --git a/crates/openhuman-core/src/security/secret_storage/file_store.rs b/crates/openhuman-core/src/security/secret_storage/file_store.rsindex ef6ba19377..eedc584c9a 100644--- a/crates/openhuman-core/src/security/secret_storage/file_store.rs+++ b/crates/openhuman-core/src/security/secret_storage/file_store.rs@@ -322,7 +322,7 @@ fn replace_durably_with_sync(fn replace_durably(source: &Path, destination: &Path) -> std::io::Result<()> {use std::os::windows::ffi::OsStrExt;use windows_sys::Win32::Storage::FileSystem::{- MoveFileExW, MOVEFILE_REPLACE_EXISTING, MOVEFILE_WRITE_THROUGH,+ MOVEFILE_REPLACE_EXISTING, MOVEFILE_WRITE_THROUGH, MoveFileExW,};let source: Vec<u16> = source.as_os_str().encode_wide().chain(Some(0)).collect();diff --git a/crates/openhuman-core/src/security/secret_storage/mod.rs b/crates/openhuman-core/src/security/secret_storage/mod.rsindex b198301d31..fd337a6b86 100644--- a/crates/openhuman-core/src/security/secret_storage/mod.rs+++ b/crates/openhuman-core/src/security/secret_storage/mod.rs@@ -4,9 +4,14 @@//! Otherwise an explicit environment override wins, followed by in-memory//! storage. Persistent hosts select an encrypted-file or native provider.+#[cfg(feature = "secret-file")]mod adapter;pub mod backend;pub mod crypto;+#[cfg(feature = "secret-file")]+pub mod encrypted_file_backend;+#[cfg(not(feature = "secret-file"))]+#[path = "encrypted_file_backend_disabled.rs"]pub mod encrypted_file_backend;pub mod encrypted_store;pub mod error;@@ -19,19 +24,19 @@ pub mod store;// ── Public re-exports ─────────────────────────────────────────────────────────pub use backend::SecretBackend;+pub use encrypted_file_backend::EncryptedFileBackend;pub use encrypted_file_backend::init_master_key;pub use encrypted_file_backend::key_source::{- clear_master_key_source, install_master_key_source, installed_master_key_source,- MasterKeySource,+ MasterKeySource, clear_master_key_source, install_master_key_source,+ installed_master_key_source,};-pub use encrypted_file_backend::EncryptedFileBackend;pub use encrypted_store::SecretStore;pub use error::SecretStorageError;pub use install::{clear_secret_backend, install_secret_backend, installed_secret_backend};pub use memory_backend::MemoryBackend;pub use ops::{- backend_name, delete, get, get_or_create_random, is_available, migrate_from_file,- reset_availability_cache, set, MigrationOutcome,+ MigrationOutcome, backend_name, delete, get, get_or_create_random, is_available,+ migrate_from_file, reset_availability_cache, set,};pub use store::init_workspace;diff --git a/crates/openhuman-core/src/security/secret_storage/mod_tests.rs b/crates/openhuman-core/src/security/secret_storage/mod_tests.rsindex 1d6af398de..8fd6ca07b7 100644--- a/crates/openhuman-core/src/security/secret_storage/mod_tests.rs+++ b/crates/openhuman-core/src/security/secret_storage/mod_tests.rs@@ -367,7 +367,7 @@ fn get_or_create_random_idempotent_file_backend() {// Manually implement the get_or_create_random logic using FileBackend.let first = {let mut bytes = vec![0u8; 32];- use chacha20poly1305::aead::{rand_core::RngCore, OsRng};+ use chacha20poly1305::aead::{OsRng, rand_core::RngCore};OsRng.fill_bytes(&mut bytes);let hex: String = bytes.iter().map(|b| format!("{b:02x}")).collect();fb.set(&nk, &hex).unwrap();diff --git a/crates/openhuman-core/src/security/secret_storage/ops.rs b/crates/openhuman-core/src/security/secret_storage/ops.rsindex 73bce25a77..43eff70505 100644--- a/crates/openhuman-core/src/security/secret_storage/ops.rs+++ b/crates/openhuman-core/src/security/secret_storage/ops.rs@@ -4,7 +4,7 @@use std::path::Path;-use chacha20poly1305::aead::{rand_core::RngCore, OsRng};+use chacha20poly1305::aead::{OsRng, rand_core::RngCore};use parking_lot::Mutex;use crate::security::secret_storage::error::SecretStorageError;@@ -47,8 +47,8 @@ pub enum MigrationOutcome {// belong to this process, not to an agent./// The storage-backed secret store for this call, when one is configured.-fn storage_secrets(-) -> Result<Option<tinystoragedrivers::secrets::DocumentSecrets>, SecretStorageError> {+fn storage_secrets()+-> Result<Option<tinystoragedrivers::secrets::DocumentSecrets>, SecretStorageError> {crate::storage::secrets::current().map_err(|error| SecretStorageError::Backend(format!("storage secrets: {error}")))}diff --git a/crates/openhuman-core/src/security/secret_storage/ops_adoption_tests.rs b/crates/openhuman-core/src/security/secret_storage/ops_adoption_tests.rsindex d5d5647f01..31552ea80c 100644--- a/crates/openhuman-core/src/security/secret_storage/ops_adoption_tests.rs+++ b/crates/openhuman-core/src/security/secret_storage/ops_adoption_tests.rs@@ -7,8 +7,8 @@ use std::sync::Arc;use tinystoragedrivers::secrets::{DerivedKeys, SecretStore as _};use zeroize::Zeroizing;-use crate::security::secret_storage::backend::MockBackend;use crate::security::secret_storage::SecretBackend;+use crate::security::secret_storage::backend::MockBackend;use crate::storage::{MemoryStorage, Scope, StorageBackend};#[test]diff --git a/crates/openhuman-core/src/security/secret_storage/store_test_scope_tests.rs b/crates/openhuman-core/src/security/secret_storage/store_test_scope_tests.rsindex 1c9a92c2de..e8e7e12ed2 100644--- a/crates/openhuman-core/src/security/secret_storage/store_test_scope_tests.rs+++ b/crates/openhuman-core/src/security/secret_storage/store_test_scope_tests.rs@@ -5,7 +5,7 @@ use std::sync::{Arc, OnceLock};use parking_lot::Mutex;-use super::{build_backend_at, SecretBackend};+use super::{SecretBackend, build_backend_at};thread_local! {/// Workspace bound by [`ScopedWorkspace`] on this thread, if any.diff --git a/crates/openhuman-core/src/security/secret_storage/store_tests.rs b/crates/openhuman-core/src/security/secret_storage/store_tests.rsindex 4be057a2b7..f3fd09d013 100644--- a/crates/openhuman-core/src/security/secret_storage/store_tests.rs+++ b/crates/openhuman-core/src/security/secret_storage/store_tests.rs@@ -19,8 +19,8 @@ use std::path::PathBuf;use super::test_scope::ScopedWorkspace;use super::{resolve_workspace_dir, workspace_dir_for_file_backend};-use crate::config::test_env::EnvVarGuard;use crate::config::TEST_ENV_LOCK;+use crate::config::test_env::EnvVarGuard;use crate::security::secret_storage;/// The root-cause pin: in test builds the keyring workspace must not bediff --git a/crates/openhuman-core/src/security/secret_storage/store_tests_2_tests.rs b/crates/openhuman-core/src/security/secret_storage/store_tests_2_tests.rsindex a312aa21c8..26d88de553 100644--- a/crates/openhuman-core/src/security/secret_storage/store_tests_2_tests.rs+++ b/crates/openhuman-core/src/security/secret_storage/store_tests_2_tests.rs@@ -1,4 +1,4 @@-use super::{effective_backend_kind_for, BackendKind};+use super::{BackendKind, effective_backend_kind_for};#[test]fn explicit_file_backend_wins_over_staging_environment() {@@ -91,15 +91,19 @@ fn explicit_os_backend_requires_a_host_provider() {let _env =crate::config::test_env::EnvVarGuard::locked().with("OPENHUMAN_KEYRING_BACKEND", "os");let dir = tempfile::tempdir().unwrap();- assert!(super::validate_backend_selection()- .unwrap_err()- .contains("host-installed OS"));+ assert!(+ super::validate_backend_selection()+ .unwrap_err()+ .contains("host-installed OS")+ );let backend = super::build_backend_at(dir.path());- assert!(backend- .get("user:key")- .unwrap_err()- .to_string()- .contains("host-installed OS"));+ assert!(+ backend+ .get("user:key")+ .unwrap_err()+ .to_string()+ .contains("host-installed OS")+ );assert!(backend.set("user:key", "value").is_err());assert!(backend.delete("user:key").is_err());}diff --git a/crates/openhuman-core/src/storage/layout/credentials.rs b/crates/openhuman-core/src/storage/layout/credentials.rsindex e9acb87b96..ad96e3caa1 100644--- a/crates/openhuman-core/src/storage/layout/credentials.rs+++ b/crates/openhuman-core/src/storage/layout/credentials.rs@@ -20,8 +20,8 @@ use std::path::Path;use tinystoragedrivers::secrets::SecretStore as _;-use super::state::LayoutError;use super::Target;+use super::state::LayoutError;use crate::security::credentials::http_creds::{self, STORAGE_SECRET_NAME, STORE_FILENAME};use crate::security::credentials::profiles::{self, PROFILES_FILENAME, PROFILES_SECRET_NAME};use crate::storage;diff --git a/crates/openhuman-core/src/storage/layout/credentials_tests.rs b/crates/openhuman-core/src/storage/layout/credentials_tests.rsindex e4e8499d88..8c93253a37 100644--- a/crates/openhuman-core/src/storage/layout/credentials_tests.rs+++ b/crates/openhuman-core/src/storage/layout/credentials_tests.rs@@ -1,9 +1,9 @@use super::*;use crate::security::secret_storage::{- clear_master_key_source, install_master_key_source, MasterKeySource, SecretStorageError,+ MasterKeySource, SecretStorageError, clear_master_key_source, install_master_key_source,};-use crate::storage::layout::test_fixtures::{v1_profile, write, Fixture};-use crate::storage::layout::{migrate, restore, Options, Outcome};+use crate::storage::layout::test_fixtures::{Fixture, v1_profile, write};+use crate::storage::layout::{Options, Outcome, migrate, restore};use std::sync::Arc;use tinystoragedrivers::secrets::DerivedKeys;use zeroize::Zeroizing;diff --git a/crates/openhuman-core/src/storage/secrets_tests.rs b/crates/openhuman-core/src/storage/secrets_tests.rsindex 6dcd5a2b14..f2a72eb886 100644--- a/crates/openhuman-core/src/storage/secrets_tests.rs+++ b/crates/openhuman-core/src/storage/secrets_tests.rs@@ -7,11 +7,7 @@ fn keys(byte: u8) -> Arc<dyn KeyProvider> {fn secrets_in(storage: &MemoryStorage, scope: &str, key: u8) -> DocumentSecrets {let scope = Scope::new(scope).unwrap();- over(- &storage.for_scope(&scope).unwrap(),- scope,- keys(key),- )+ over(&storage.for_scope(&scope).unwrap(), scope, keys(key))}#[test]