From 33fdd5205e20ba9c77f5a0ceaa84a5fad002f523 Mon Sep 17 00:00:00 2001 From: iris Date: Fri, 20 Nov 2026 20:18:43 +0100 Subject: [PATCH] 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//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. --- .../swarm/credentials-reference.md | 3 +- docs/4-implementation/turn-loop/config.md | 20 +- docs/4-implementation/web-ui/swarm-ui.md | 11 + hive-agent/src/login.rs | 47 +++- nix/agent-modules/agent-service.nix | 18 +- nix/agent-modules/backend-env.nix | 130 ++++++---- nix/agent-modules/mcp.nix | 9 +- nix/host-modules/swarm-bao.nix | 4 + nix/module-eval/agent-runtime.nix | 9 +- nix/module-eval/bao-grants.nix | 5 +- .../agent-backend-env-fake-bao.sh | 13 +- nix/script-tests/agent-backend-env.sh | 78 +++++- swarm-controller/src/backend_env.rs | 82 ++++++- swarm-controller/src/backend_secrets.rs | 224 ++++++++++++++++++ swarm-controller/src/linked_accounts.rs | 73 +++++- swarm-controller/src/main.rs | 1 + swarm-controller/src/startup.rs | 18 +- swarm-secret-client/src/backend_secrets.rs | 96 ++++++++ swarm-secret-client/src/lib.rs | 3 +- 19 files changed, 737 insertions(+), 107 deletions(-) create mode 100644 swarm-controller/src/backend_secrets.rs create mode 100644 swarm-secret-client/src/backend_secrets.rs diff --git a/docs/4-implementation/swarm/credentials-reference.md b/docs/4-implementation/swarm/credentials-reference.md index 61bdb96ad..f6f0ef5f3 100644 --- a/docs/4-implementation/swarm/credentials-reference.md +++ b/docs/4-implementation/swarm/credentials-reference.md @@ -34,6 +34,7 @@ the rest of the cell says how. | `swarm/agents//forge/