Skip to content

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

fix(profiles): refuse profiles named like the operator state dir

Steven Enamakel5eacab918eeb
diff --git a/crates/openhuman-core/src/profiles/ops.rs b/crates/openhuman-core/src/profiles/ops.rs
index 2eb8d2bf81..560ea73f62 100644
--- a/crates/openhuman-core/src/profiles/ops.rs
+++ b/crates/openhuman-core/src/profiles/ops.rs
@@ -24,6 +24,13 @@ 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 +46,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).await
diff --git a/crates/openhuman-core/src/profiles/ops_tests.rs b/crates/openhuman-core/src/profiles/ops_tests.rs
index 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();
+}