swarm UI: log an agent into claude from its card; the credentials go to bao and the agent picks them up
A new swarm service, `swarm-claude-login`, in its own container on the host
that sets `deploy.claude-login.enable` (defaulted on by `allSwarmServices`
where the host has the minter's store leaf, like the review classifier).
- swarm-ui: an agent card showing "login needed" gets a "log in" button.
Its dialog starts the login, shows the URL claude printed, and takes the
pasted code.
- swarm-controller: `POST/DELETE /api/agents/{name}/claude-login` and
`POST /api/agents/{name}/claude-login/code`, behind the swarm UI's
authelia-gated `/api/`, relay the steps to the minter as requests on
`$SWARM.claude-login.request`.
- swarm-claude-login: runs `claude auth login` over piped stdio with HOME
and CLAUDE_CONFIG_DIR in a per-login scratch dir, scrapes the first
https URL, writes the code to stdin, and stores the `.credentials.json`
at `swarm/agents/<agent>/claude-credentials` with a KV v2 write, a new
version over any earlier one. The scratch dir goes on every exit path; a
login waits 15 minutes for its code.
- hive-agent: while parked in `wait_for_login`, reads that leaf every 30 s
under the agent's own cert and installs it only when its KV version is
newer than the one recorded in `<harness>/claude-credentials-version`.
An equal or older version is never put back, because claude rotates the
refresh token and the stored copy is stale after the first refresh.
- swarm-secret-client: `claude_login` paths and `SecretStore::read_versioned`.
- Credentials: a `claude-login` store leaf minted by glue-bao-tls, a
`swarm-claude-login` policy (create/update on
`swarm/agents/+/claude-credentials`, read on its own queue client
secret), an authelia machine client, and a `--claude-login-client`
grant in the queue's auth-callout responder. The unit runs as a static
system user.
The hive's own web-UI login is unchanged.
Refs #5268
This commit is contained in:
parent
248df20164
commit
d5de1e4943
1 changed files with 2680 additions and 42 deletions
|
|
@ -15,6 +15,7 @@ use std::sync::{Arc, Mutex};
|
|||
use std::time::{Duration, SystemTime};
|
||||
|
||||
use crate::events::Bus;
|
||||
use crate::{claude_credentials, paths};
|
||||
|
||||
/// Returns the Claude credentials directory for this agent. Delegates
|
||||
/// to `paths::claude_dir`, which reads `$HOME/.claude`. The service
|
||||
|
|
@ -178,7 +179,25 @@ pub async fn wait_for_login(
|
|||
// re-trigger the fallback on every iteration.
|
||||
let baseline_unreadable = unreadable_mtime_names(claude_dir);
|
||||
let probe = Duration::from_millis(poll_ms.max(2000));
|
||||
let pickup = swarm_pickup(claude_dir);
|
||||
let mut next_pickup = tokio::time::Instant::now();
|
||||
loop {
|
||||
if let Some(pickup) = &pickup
|
||||
&& tokio::time::Instant::now() >= next_pickup
|
||||
{
|
||||
next_pickup = tokio::time::Instant::now() + claude_credentials::POLL_INTERVAL;
|
||||
match pickup.check().await {
|
||||
Ok(claude_credentials::Outcome::Installed { version }) => tracing::info!(
|
||||
version,
|
||||
"installed the claude credentials the swarm login stored"
|
||||
),
|
||||
Ok(outcome) => tracing::debug!(?outcome, "no newer swarm claude credentials"),
|
||||
Err(e) => tracing::warn!(
|
||||
error = %format!("{e:#}"),
|
||||
"checking the swarm store for claude credentials failed"
|
||||
),
|
||||
}
|
||||
}
|
||||
tokio::time::sleep(probe).await;
|
||||
// A login that already landed by the time this first poll runs
|
||||
// (the race this baseline design closes) is caught here on the
|
||||
|
|
@ -193,6 +212,27 @@ pub async fn wait_for_login(
|
|||
}
|
||||
}
|
||||
|
||||
/// The swarm-login pickup for `claude_dir`, or `None` when this process has
|
||||
/// no store to read from.
|
||||
fn swarm_pickup(
|
||||
claude_dir: &Path,
|
||||
) -> Option<claude_credentials::Pickup<claude_credentials::Store>> {
|
||||
match claude_credentials::Store::from_env() {
|
||||
Ok(store) => Some(claude_credentials::Pickup::new(
|
||||
store,
|
||||
claude_dir.to_owned(),
|
||||
paths::harness_dir().join(claude_credentials::VERSION_FILE),
|
||||
)),
|
||||
Err(e) => {
|
||||
tracing::warn!(
|
||||
error = %format!("{e:#}"),
|
||||
"no swarm store coordinates, so a swarm login cannot reach this agent"
|
||||
);
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Names of credential files (see [`CRED_FILE_NAMES`]) currently present in
|
||||
/// `dir` whose mtime is *not* readable (`metadata()`/`modified()` errors —
|
||||
/// exotic fs, NFS quirks). Used once, at [`wait_for_login`]'s entry, as the
|
||||
|
|
|
|||
Loading…
Reference in a new issue