Skip to content

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

fix(credentials): normalize provider filter and defer keychain deletes

Steven Enamakel5129a0444285
diff --git a/src/openhuman/security/credentials/ops_part_01.rs b/src/openhuman/security/credentials/ops_part_01.rs
index 0c4a9f9036..d862e03d37 100644
--- a/src/openhuman/security/credentials/ops_part_01.rs
+++ b/src/openhuman/security/credentials/ops_part_01.rs
@@ -12,7 +12,7 @@ use crate::openhuman::security::credentials::session_support::{
use crate::openhuman::security::keyring::SecretStore;
use crate::rpc::RpcOutcome;
-use super::{AuthService, APP_SESSION_PROVIDER, DEFAULT_AUTH_PROFILE_NAME};
+use super::{normalize_provider, AuthService, APP_SESSION_PROVIDER, DEFAULT_AUTH_PROFILE_NAME};
use crate::openhuman::config::{
default_root_openhuman_dir, pre_login_user_dir, read_active_user_id, user_openhuman_dir,
write_active_user_id,
diff --git a/src/openhuman/security/credentials/ops_part_02.rs b/src/openhuman/security/credentials/ops_part_02.rs
index 41f1ab4dd9..0df4b6f4f4 100644
--- a/src/openhuman/security/credentials/ops_part_02.rs
+++ b/src/openhuman/security/credentials/ops_part_02.rs
@@ -351,6 +351,10 @@ pub async fn list_provider_credentials(
provider_filter: Option<String>,
) -> Result<RpcOutcome<Vec<super::responses::AuthProfileSummary>>, String> {
let auth = AuthService::from_config(config);
+ let provider_filter = provider_filter
+ .map(|provider| normalize_provider(&provider))
+ .transpose()
+ .map_err(|e| e.to_string())?;
let profiles = auth.load_profiles().map_err(|e| e.to_string())?;
let mut items = profiles
.profiles
diff --git a/src/openhuman/security/credentials/profiles_impl_01_part_01.rs b/src/openhuman/security/credentials/profiles_impl_01_part_01.rs
index ecf283266d..1421a24bb9 100644
--- a/src/openhuman/security/credentials/profiles_impl_01_part_01.rs
+++ b/src/openhuman/security/credentials/profiles_impl_01_part_01.rs
@@ -274,6 +274,7 @@ impl AuthProfilesStore {
// `keychain_migrated` tracks enc2: → keychain promotions: when true the
// persisted JSON must be rewritten with secret fields cleared.
let mut keychain_migrated = false;
+ let mut pending_keychain_deletes = Vec::new();
let mut dropped_ids: Vec<String> = Vec::new();
let mut profiles = BTreeMap::new();
@@ -601,8 +602,7 @@ impl AuthProfilesStore {
let mut active_migration_conflicts = 0;
for (k, v) in active_entries {
let lower = k.to_ascii_lowercase();
- let lower_val = v.to_ascii_lowercase();
- if &lower != k || &lower_val != v {
+ if &lower != k {
key_migrated = true;
}
if new_active.contains_key(&lower) {
@@ -610,17 +610,17 @@ impl AuthProfilesStore {
// If this is the canonical lowercase key, it supersedes any non-canonical
// variant seen earlier in iteration order.
if k == &lower {
- new_active.insert(lower.clone(), lower_val.clone());
+ new_active.insert(lower.clone(), v.clone());
log::debug!(
"[auth] active-profile key migration collision: canonical key={k} replaced a non-canonical entry"
);
} else {
log::debug!(
- "[auth] active-profile key migration collision: dropped mixed-case entry for key={k} target_profile_id={lower_val}"
+ "[auth] active-profile key migration collision: dropped mixed-case entry for key={k}"
);
}
} else {
- new_active.insert(lower, lower_val);
+ new_active.insert(lower, v.clone());
}
}
if active_migration_conflicts > 0 {
@@ -657,16 +657,27 @@ impl AuthProfilesStore {
if let Some(mut ap) = profiles.remove(&id) {
if new_profiles.contains_key(&normalized_id) {
profile_migration_conflicts += 1;
+ key_migrated = true;
if id == normalized_id {
- let old = new_profiles.insert(normalized_id.clone(), ap);
+ let old_id = new_profiles
+ .insert(normalized_id.clone(), ap)
+ .map(|old| old.id);
new_persisted_profiles.insert(normalized_id.clone(), p);
profile_id_migration_targets
- .insert(normalized_id.to_ascii_lowercase(), normalized_id.clone());
+ .insert(id.clone(), normalized_id.clone());
+ if self.use_keychain {
+ if let Some(old_id) = &old_id {
+ pending_keychain_deletes.push(old_id.clone());
+ }
+ }
log::debug!(
"[auth] profile id migration collision: dropped mixed-case profile_id={:?}",
- old.map(|o| o.id)
+ old_id
);
} else {
+ if self.use_keychain {
+ pending_keychain_deletes.push(id.clone());
+ }
log::debug!(
"[auth] profile id migration collision: dropped mixed-case profile_id={id}"
);
@@ -686,8 +697,8 @@ impl AuthProfilesStore {
{
match self.keychain_store_secrets(&ap) {
Ok(()) => {
- self.keychain_delete_secrets(&id);
keychain_migrated = true;
+ pending_keychain_deletes.push(id.clone());
true
}
Err(e) => {
@@ -713,7 +724,7 @@ impl AuthProfilesStore {
id.clone()
};
profile_id_migration_targets
- .insert(normalized_id.to_ascii_lowercase(), final_id.clone());
+ .insert(id.clone(), final_id.clone());
new_profiles.insert(final_id.clone(), ap);
new_persisted_profiles.insert(final_id, p);
}
@@ -749,6 +760,9 @@ impl AuthProfilesStore {
// is already correct.
if persist && (!dropped_ids.is_empty() || migrated || keychain_migrated || key_migrated) {
self.write_persisted_locked(&persisted)?;
+ for id in pending_keychain_deletes {
+ self.keychain_delete_secrets(&id);
+ }
}
Ok(AuthProfilesData {