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
3.7 KiB
Claude login from the swarm UI
An operator logs an agent in to claude from the agent's card in the swarm UI.
No hive is in the path: the login runs in the swarm's swarm-claude-login
service, the credentials go to the agent's own leaf in the secret store, and the
agent's harness installs them from there.
Where it runs and how it's enabled: services.md.
What happens on a login
- The agent publishes
needs_loginin its turn-state header, and its card shows login needed with a log in button. - log in opens a dialog, which calls
POST /api/agents/<agent>/claude-login. swarm-controller relays the start as a request on the queue subject$SWARM.claude-login.request. - The minter runs
claude auth loginwithHOMEandCLAUDE_CONFIG_DIRin a fresh scratch directory, over plain stdio pipes, and answers with the firsthttps://URL it prints. The dialog shows that URL. - The operator opens the URL, signs in to the agent's own claude account, and
pastes the code the page shows into the dialog, which posts it to
POST /api/agents/<agent>/claude-login/code. - The minter writes the code to claude's stdin and waits for it to exit. It
stores the
.credentials.jsonclaude wrote atswarm/agents/<agent>/claude-credentials(fieldvalue), as a new version over any stored before, and removes the scratch directory. - The agent's harness, while it waits for a login, reads that leaf every 30
seconds under the agent's own certificate. When the stored version is newer
than the one it installed last, it writes the file to
~/.claude/.credentials.json, records the version, and resumes its turn loop as it does after a login from the agent's web UI.
A started login waits 15 minutes for its code, then the minter stops it. Starting another login for the same agent replaces the running one. Each step has a minute to finish; a refused code fails the login, and the dialog shows what claude printed.
Why the harness takes only a newer version
claude rotates the refresh token in .credentials.json as it uses the
session, and the agent can't write the store. After the first refresh the
stored copy is stale. A harness that installed it whenever the bytes differed
would replace the agent's live session with a stale copy and log the agent
out. The harness therefore compares the store's KV version with the last
version it installed (claude-credentials-version under the harness dir):
- it installs a newer version, that is, a new login;
- it leaves an equal or older version alone, even when the agent needs a login again, so it never puts back a session that has gone bad;
- it reads nothing while the agent has a session.
Credentials
| Principal | Grant |
|---|---|
swarm-claude-login, in its container |
create, update on swarm/agents/+/claude-credentials; read on swarm/services/<minter client id>/oidc/client |
| the agent, under its own certificate | read on its own swarm/agents/<agent>/*, which covers the leaf |
The minter has no read on the leaf and nothing else under an agent. Every
hive's policy reads swarm/agents/*, so every hive can read every agent's
claude session, as it can read the GitHub token.
What stays
The agent's own web UI login (/login) still works, unchanged. It goes away
once the operator has confirmed the swarm login works.