Watch
0
0
Fork
You've already forked hyperhive
0

swarm: an agent's backend secrets get a store leaf of their own, and its backend environment reads back

The credentials of an agent's backend (ANTHROPIC_API_KEY and the like) move to their own leaf, swarm/agents/<agent>/backend-secrets, written through new PUT, GET and DELETE routes on /api/hives/{hive}/agents/{agent}/backend-secrets. GET says only whether any are stored. The backend environment at backend-env now reads back as stored through GET on its route, so it holds configuration only.

The agent's hive-agent-backend-env unit now runs on every agent with a store, reads both leaves and writes the configuration and then the secrets into the one file the harness and the subagent daemon load, so a secret wins over a variable of the same name. It removes the file when the store holds neither. The harness counts an agent whose environment holds ANTHROPIC_API_KEY or ANTHROPIC_AUTH_TOKEN as API-billed, so it tries the key instead of waiting for a Claude login; a real 401 still sets needs-login. The controller's policy may delete the new leaf.

Tests: the secret-client path, the controller routes, the script test of the unit with a stub bao, the module-eval cases and the harness's mode check. Docs: the swarm UI routes, the credentials reference and the API-key provider page.
This commit is contained in:
iris 2026-11-20 20:18:43 +01:00
commit 33fdd5205e

View file

@ -267,7 +267,8 @@ is a no-op without the other:
- **`useApiKey`** tells the harness itself not to wait for a Claude OAuth
session: at boot, `LoginState::from_dir` reports `Online` without
checking `~/.claude/` (`hive_agent::login::using_api_key`, reads
`HIVE_USE_API_KEY`), and the harness stamps the fact into the
`HIVE_USE_API_KEY`, and counts an environment that holds `ANTHROPIC_API_KEY`
or `ANTHROPIC_AUTH_TOKEN` too, see below), and the harness stamps the fact into the
consolidated harness state file so the operator dashboard also stops reading this
agent's empty `~/.claude/` as "needs login." An api-key agent that hits
a real 401 (the key itself is bad) still surfaces `needs_login` — the
@ -283,8 +284,8 @@ is a no-op without the other:
(`hive-subagent-daemon`) loads the same file, so the agent's claude
subagents run on the same key.
On an agent with a secret store (`services.hyperhive.agent.bao.addr`) that uses
`useApiKey` or the `acp` runtime, `hive-agent-backend-env.service` also keeps the
On an agent with a secret store (`services.hyperhive.agent.bao.addr`),
`hive-agent-backend-env.service` also keeps the
file's text in the store at `swarm/agents/<agent>/backend-env`, field `env`, and
writes it to `/run/hive-agent-backend-env/env` every 2 minutes. When the store
holds nothing there, the unit creates the leaf from `backendEnvironmentFile`,
@ -295,7 +296,18 @@ the store down at a start the file alone carries the agent. Both read it at
their own start, so a changed value reaches a running agent at its next
restart.
To set or replace a key, use **set the API-key environment** on the agent in the swarm UI:
An operator can also store the credentials apart from that text, at
`swarm/agents/<agent>/backend-secrets`, field `env`, with
`PUT /api/hives/{hive}/agents/{agent}/backend-secrets` (`GET` says whether the
store holds any and never returns them; `DELETE` removes them). The unit writes them into the
`/run` file after the text, so a secret wins over a variable of the same name, and
removes the file when the store holds neither. An agent whose environment holds
`ANTHROPIC_API_KEY` or `ANTHROPIC_AUTH_TOKEN` counts as an api-key agent even with
`useApiKey` off, so it tries the key instead of waiting for a Claude login, and a
real 401 still surfaces `needs_login`. `GET …/backend-env` reads the
text back, so it holds configuration only.
To set or replace the whole environment text, use **set the API-key environment** on the agent in the swarm UI:
it sends `PUT /api/hives/{hive}/agents/{agent}/backend-env` with the file text,
which must be blank lines, `#` or `;` comments, and `NAME=VALUE` lines of at
most 16 KiB. A save overwrites the stored text, including text the agent wrote