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(credentials): keep the API key on sign-out when profiles live in storage
M3gA-Mind699fa1424702
diff --git a/crates/openhuman-core/src/security/credentials/ops/credential.rs b/crates/openhuman-core/src/security/credentials/ops/credential.rsindex 0056cad19a..85a147bddd 100644--- a/crates/openhuman-core/src/security/credentials/ops/credential.rs+++ b/crates/openhuman-core/src/security/credentials/ops/credential.rs@@ -410,6 +410,7 @@ pub async fn clear_credential(let mut effective_config = config.clone();let mut cleared_source_api_key = false;+ let mut carried_api_key = false;if matches!(kind,None | Some(CredentialKind::Session) | Some(CredentialKind::Local)@@ -437,16 +438,28 @@ pub async fn clear_credential(// the effective credential a moment ago (#6318).api_key::store_api_key(&effective_config, key).map_err(|e| e.to_string())?;logs.push("api key carried forward to the signed-out workspace".to_string());+ carried_api_key = true;+ }+ // With a storage backend the auth profiles are one secret in+ // the acting scope (`profiles::persistence::STORAGE_SECRET_NAME`),+ // not a file per state directory, so the source and the+ // destination above are the same record: clearing the+ // "source" would delete the key just carried forward.+ let shares_store =+ carried_api_key && matches!(crate::storage::secrets::current(), Ok(Some(_)));+ if shares_store {+ log::debug!("[credentials] api key kept: the storage profile store is shared");+ } else {+ // Either the key was just moved to the post-teardown config+ // above, or `kind` is `None` and it must be removed outright.+ // `config` here is still the pre-teardown, user-scoped+ // reference, so this clears the *source* location — never+ // leave that copy behind, or a later login to the same+ // account (or an api-key clear against the wrong location)+ // would silently resurrect it (#6318).+ cleared_source_api_key =+ api_key::clear_api_key(config).map_err(|e| e.to_string())?;}- // Either the key was just moved to the post-teardown config- // above, or `kind` is `None` and it must be removed outright.- // `config` here is still the pre-teardown, user-scoped- // reference, so this clears the *source* location — never- // leave that copy behind, or a later login to the same- // account (or an api-key clear against the wrong location)- // would silently resurrect it (#6318).- cleared_source_api_key =- api_key::clear_api_key(config).map_err(|e| e.to_string())?;}}}diff --git a/crates/openhuman-core/src/security/credentials/ops_credential_tests.rs b/crates/openhuman-core/src/security/credentials/ops_credential_tests.rsindex d12602bca0..f811683bd0 100644--- a/crates/openhuman-core/src/security/credentials/ops_credential_tests.rs+++ b/crates/openhuman-core/src/security/credentials/ops_credential_tests.rs@@ -748,3 +748,84 @@ async fn store_session_local_token_succeeds_without_network_and_forces_local_useassert_eq!(user["_id"], expected_local_user_id);assert_eq!(user["name"], "Local User");}++// #6318 on the desktop's storage: the host boot installs a SQLite backend+// (`session_store::install_for_host`), and with one installed the auth+// profiles are a single secret in the acting scope rather than a file per+// state directory. A session-only sign-out must still leave the API key+// usable from the signed-out config.+#[cfg(feature = "storage-sqlite")]+#[tokio::test(flavor = "multi_thread")]+#[allow(clippy::await_holding_lock)] // Serializes the process-wide storage slot.+async fn clearing_the_session_keeps_the_api_key_on_a_storage_backend() {+ let _module = crate::integrations::composio::module_client::module_guard().await;+ let _env_guard = crate::config::TEST_ENV_LOCK.lock().await;+ let _slot = crate::storage::test_support::lock_storage_slot();+ let fixture = crate::storage::test_support::sqlite_backend().unwrap();+ assert!(+ crate::storage::install(std::sync::Arc::clone(&fixture.backend)).is_none(),+ "no storage backend may be left installed by another test"+ );+ struct Uninstall;+ impl Drop for Uninstall {+ fn drop(&mut self) {+ crate::storage::clear();+ }+ }+ let _uninstall = Uninstall;+ let tmp = TempDir::new().unwrap();+ std::fs::create_dir_all(tmp.path().join("workspace")).unwrap();+ let _home = EnvVarGuard::set("HOME", tmp.path());+ let config = test_config(&tmp);+ assert!(+ matches!(crate::storage::secrets::current(), Ok(Some(_))),+ "the auth profiles must be served from storage secrets in this test"+ );++ let exp = chrono::Utc::now() + chrono::Duration::hours(1);+ let token = jwt_with_payload(json!({ "sub": "user-42", "exp": exp.timestamp() }));+ store_session(+ &DispatchCtx::process_default(),+ &config,+ &token,+ None,+ Some(json!({ "id": "user-42" })),+ )+ .await+ .unwrap();+ let user_scoped = crate::config::load_config_with_timeout().await.unwrap();+ set_credential(+ &DispatchCtx::process_default(),+ &user_scoped,+ SetCredentialRequest {+ token: "sk-live".into(),+ kind: Some("api-key".into()),+ ..Default::default()+ },+ )+ .await+ .unwrap();+ assert!(api_key::has_api_key(&user_scoped));++ let cleared = clear_credential(+ &DispatchCtx::process_default(),+ &user_scoped,+ Some(session_support::CredentialKind::Session),+ )+ .await+ .unwrap()+ .value;+ assert_eq!(cleared["removedSession"], true);+ assert_eq!(cleared["removedApiKey"], false);++ let signed_out = crate::config::load_config_with_timeout().await.unwrap();+ assert_ne!(signed_out.config_path, user_scoped.config_path);+ assert_eq!(+ api_key::get_api_key(&signed_out).unwrap().as_deref(),+ Some("sk-live"),+ "the API key must survive a session sign-out on a storage backend"+ );+ let state = auth_get_state(&signed_out).await.unwrap().value;+ assert!(state.is_authenticated);+ assert_eq!(state.credential.as_deref(), Some("api-key"));+}