Watch
0
0
Fork
You've already forked hyperhive
0

swarm ui: show when an agent's claude login was stored, and delete it

The agent's settings get a claude login row: when the swarm stored the
login, read by the minter from the leaf's metadata, or that none is, with a
delete that removes every version after a confirmation. New minter steps
(status, delete), controller routes (GET claude-login, DELETE
claude-login/stored) and a read and delete grant on the leaf's metadata,
pinned in the module-eval check.
This commit is contained in:
iris 2026-11-09 21:39:17 +01:00 • committed by mara
commit 7dd147adb4

View file

@ -36,6 +36,53 @@ const PREFIX: &str = "SWARM_CLAUDE_LOGIN";
/// The agent's store leaf, written under this service's certificate.
struct AgentLeaf;
impl AgentLeaf {
/// When the agent's stored login was written, read from the leaf's
/// metadata: this service may say it exists, and never reads it back.
async fn status(&self, agent: &str) -> Reply {
match self.stored_at(agent).await {
Ok(stored_at) => Reply::Login { stored_at },
Err(e) => Reply::Failed {
error: format!("reading when {agent}'s login was stored failed: {e:#}"),
},
}
}
async fn stored_at(&self, agent: &str) -> Result<Option<String>> {
let path = credentials_path(agent)?;
let store = swarm_secret_client::SecretStore::from_env(CERT_ROLE)
.await
.context("logging in to the secret store")?;
store
.updated_time(&path)
.await
.with_context(|| format!("reading the metadata of {path}"))
}
/// Delete the agent's stored login, every version: an older one would
/// still be a live session. The agent's harness sees the leaf gone on its
/// next read.
async fn delete(&self, agent: &str) -> Reply {
match self.delete_all(agent).await {
Ok(()) => Reply::Deleted,
Err(e) => Reply::Failed {
error: format!("deleting {agent}'s stored login failed: {e:#}"),
},
}
}
async fn delete_all(&self, agent: &str) -> Result<()> {
let path = credentials_path(agent)?;
let store = swarm_secret_client::SecretStore::from_env(CERT_ROLE)
.await
.context("logging in to the secret store")?;
store
.delete_all_versions(&path)
.await
.with_context(|| format!("deleting {path}"))
}
}
impl login::CredentialSink for AgentLeaf {
async fn put(&self, agent: &str, credentials: &Credentials) -> Result<()> {
let path = credentials_path(agent)?;
@ -142,9 +189,12 @@ async fn run_step(
}
};
// Before anything else: the name becomes a scratch directory's name and
// a store path, and this service holds write on every agent's leaf.
let (Request::Start { agent, .. } | Request::Code { agent, .. } | Request::Cancel { agent }) =
&request;
// a store path, and this service holds write and delete on every agent's leaf.
let (Request::Start { agent, .. }
| Request::Code { agent, .. }
| Request::Cancel { agent }
| Request::Status { agent }
| Request::Delete { agent }) = &request;
if let Err(reason) = hive_types::Ident::parse(agent) {
tracing::warn!(agent = ?agent, reason, "a login step for an invalid agent name; refused");
let error = format!("{agent:?} is not an agent name: {reason}");
@ -176,11 +226,22 @@ async fn run_step(
let reply = logins.cancel(&agent).await;
("cancel", agent, reply)
}
Request::Status { agent } => {
let reply = AgentLeaf.status(&agent).await;
("status", agent, reply)
}
Request::Delete { agent } => {
tracing::info!(%agent, "deleting the agent's stored claude login");
let reply = AgentLeaf.delete(&agent).await;
("delete", agent, reply)
}
};
match &reply {
Reply::Started { .. } => tracing::info!(%agent, "claude login waiting for its code"),
Reply::Stored => tracing::info!(%agent, "claude credentials stored"),
Reply::Cancelled => tracing::info!(%agent, "claude login cancelled"),
Reply::Login { .. } => {}
Reply::Deleted => tracing::info!(%agent, "claude login deleted"),
Reply::Failed { error } => tracing::warn!(%agent, %error, "claude login step failed"),
}
(step, reply)
@ -242,6 +303,12 @@ mod tests {
Request::Cancel {
agent: agent.to_owned(),
},
Request::Status {
agent: agent.to_owned(),
},
Request::Delete {
agent: agent.to_owned(),
},
] {
let payload = serde_json::to_vec(&request).expect("encodes");
let reply = handle(&payload, &logins, &Arc::new(Metrics::noop())).await;