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(profiles): refuse profile ids named like the operator state dir
Steven Enamakelb05ea2b446a2
diff --git a/crates/openhuman-core/src/profiles/README.md b/crates/openhuman-core/src/profiles/README.mdindex b49bbf1585..ce8ce51f7b 100644--- a/crates/openhuman-core/src/profiles/README.md+++ b/crates/openhuman-core/src/profiles/README.md@@ -40,6 +40,10 @@ not migrated.- Anything else, or every id under `"hashed"`, becomes `h-` + the first 32 hexcharacters of `sha256(user_id)`.+Provisioning also refuses a profile id equal to the file name of the node's+`operator_dir`: keyring secrets are namespaced by their store's directory name,+so such a profile would share the operator's credential slots.+Both forms fit the agent-id charset and can never contain a path separator.Changing the mode re-maps users onto different profiles.diff --git a/crates/openhuman-core/src/profiles/ops.rs b/crates/openhuman-core/src/profiles/ops.rsindex 2eb8d2bf81..1af8cbaf78 100644--- a/crates/openhuman-core/src/profiles/ops.rs+++ b/crates/openhuman-core/src/profiles/ops.rs@@ -24,6 +24,15 @@ pub(crate) async fn provision_on(user_id: &str,) -> Result<Outcome<ProvisionResult>, String> {let profile_id = ProfileId::for_user(user_id, host.saas().profile_ids)?;+ if names_operator_state(&profile_id, &host.saas().operator_dir()) {+ log::warn!(+ "[profiles] refusing to provision a profile named like the operator's state dir"+ );+ return Err(format!(+ "profile id {profile_id} is reserved on this deployment: it is the name of the \+ operator's state directory"+ ));+ }let created = host.provision(&profile_id).await?;let log = if created {format!("provisioned {profile_id}")@@ -39,6 +48,18 @@ pub(crate) async fn provision_on())}+/// Whether `id` is the file name of the operator's state directory.+///+/// Credential secrets are namespaced in the process keyring by the name of+/// the directory their store sits in: `users/<id>` for a profile, the+/// operator directory for the operator. A profile named like the operator+/// directory (`operator` is reserved for the default; a configured+/// `operator_dir` can be any name) would read and overwrite the operator's+/// own secrets.+fn names_operator_state(id: &ProfileId, operator_dir: &std::path::Path) -> bool {+ operator_dir.file_name().and_then(|name| name.to_str()) == Some(id.as_str())+}+/// Close profile `profile_id` and archive its state.pub async fn deprovision(profile_id: &str) -> Result<Outcome<DeprovisionResult>, String> {deprovision_on(&*require_host()?, profile_id).awaitdiff --git a/crates/openhuman-core/src/profiles/ops_tests.rs b/crates/openhuman-core/src/profiles/ops_tests.rsindex 4766bffd29..f21be6ef40 100644--- a/crates/openhuman-core/src/profiles/ops_tests.rs+++ b/crates/openhuman-core/src/profiles/ops_tests.rs@@ -81,3 +81,19 @@ async fn credentials_are_set_and_cleared_per_profile_and_never_echoed() {clear_credential_on(&host, alice.as_str()).await.unwrap();assert!(!host.summary(&alice).await.unwrap().unwrap().has_credential);}++/// Keyring secrets are namespaced by their store's directory name, so a+/// profile named like a configured operator directory would share the+/// operator's credential slots.+#[tokio::test]+async fn a_profile_named_like_the_operator_dir_is_refused() {+ let tmp = tempfile::tempdir().unwrap();+ let mut saas = SaasConfig::new(tmp.path());+ saas.operator_dir = Some(tmp.path().join("node-a"));+ let host = ProfileHost::new(saas, CoreContext::for_test(DomainSet::full(), None));++ let err = provision_on(&host, "node-a").await.unwrap_err();+ assert!(err.contains("reserved"), "{err}");+ assert!(!tmp.path().join("users").join("node-a").exists());+ provision_on(&host, "node-b").await.unwrap();+}