All green. Report:
**Verified / implemented (final pass of `15_agent_mtls`)**
- Wrote `data/logs/verify-15-tls-e2e.py`: a real `host_agent.py --cert-bundle` + a real dashboard process over a scratch DB (`HOST_TARGETS=loop=https://…`) — **27/27 PASS**, transcript `verify-15-tls-e2e.out`, notes `data/logs/NOTES-tls-rollout.md`.
- Read-only checks against the running dev store: 5 `certs.*` rows byte-identical across a restart; served bundle == the `meta` row (1430 B); 0 events containing `-----BEGIN`; unsigned `/certs`→`303 ?next=`, unsigned `/api/certs`→`401`, signed-in `200`; screenshots `data/logs/15-final-{certs,system}.png`.
- Docs (step 6, full review): README — added *Protecting an agent, host by host* (the rollout task-07 left out), a `tests/test_certs.py`/TLS-matrix/sandbox-installer paragraph, and fixed two stale “the one write endpoint in the app” claims (`NUT_ALLOW_ACTIONS`, Battery-test buttons). AGENTS.md — test count 1424→1427, bundle-fetch command in *Commands*, a Testing-policy bullet on structurally pinning a key-holding module, fleet transport bullet (token mode is now the compatibility path), gap 11 final state.
**Tests / lint (full suite 100% green)**
- `uv run pytest` → **1427 passed, 15 skipped**, exit 0 · `bash .agents/validate.sh` → **exit 0** (coverage **98.94%** vs 94% floor, `certs.py` 100%; ruff “All checks passed”; pyright 0 errors; `node --check` clean; hygiene clean)
- `uv run pytest -m live --live` → **11 passed / 0 failed** · `./scripts/dev-server.sh status` → all 9 sources `ok`
- `uv pip list --outdated` → empty after bumping `fastapi 0.152.0 → 0.153.0` (`uv.lock` only); full suite re-run green.
**Completion criteria**
- Fresh-DB root CA, idempotent: ✅ (tests + live store hashes) · agent TLS matrix incl. wrong-CA/certless 403/`/health` CA-only/revoked 403 + live denylist re-read: ✅
- `https` `host:`/`disks:` `ok` + revoked says “agent certificate revoked” with no dial: ✅ on loopback (real agent + real dashboard) and spy-pinned hermetically; **not** on the fleet (below)
- Signed-in `/certs` + rotate/revoke/root-rotate + byte-identical bundle download: ✅ · installer bundle/unit/`--status` over TLS: ✅ (0640, see deviation)
- `pytest`/`validate.sh`/`--outdated`: ✅ · token-mode byte-identical, engine/UPS untouched, public surface unchanged (route walk): ✅
- **Live fleet TLS (deskwork+gateway flip): NOT done** — no live changes. It needs root on hosts without the installer grant (`deskwork`), has no both-ways-working window (`http://` dashboard vs https-only agent), and would deploy the agent from this not-yet-committed tree. Exact procedure recorded in README + `data/logs/NOTES-tls-rollout.md`.
**Deviations**: bundle mode `0640 root:dashboards-agent` instead of the task file’s `0600` (the agent re-reads its own bundle for the denylist; 0600 breaks the unit — already recorded in AGENTS.md); the loopback dashboard substitutes for the fleet flip. Incidental: a stray `pkill` of mine killed the dev server mid-pass; restarted and verified healthy.
**Next pending phase**: `.agents/phases/todo/16_agent_smart_pass_budget` (then `17_installer_device_filter`).
6.4 KiB
Phase 15 — Protected exporter web servers, auth by certificate
Source: TODO.md L3 — "I want all exporters to be protected web servers. The collector should generate and manage a root certificate that needs to be installed with each exporter. Use the certs as auth to each exporter."
Story: n/a
Context: agent/host_agent.py (the stdlib-only exporter web server; today: a bearer token via --token/--token-file, refuses an off-loopback bind without one, ThreadingHTTPServer, the resolve_token idiom), src/dashboards/config.py (Target/parse_targets — token in URL userinfo, https:// URLs already accepted; no change needed), src/dashboards/collectors.py (fetch_snapshot, the one UpstreamError, redacted display URLs, the one shared httpx.AsyncClient from the lifespan), src/dashboards/app.py (the PAGES dict with the settings-page comment, build_hub/build_context, the lifespan that builds ctx.auth), src/dashboards/api.py (AppContext, the gated-write + event pattern), src/dashboards/store.py (get_meta/set_meta/delete_meta — the only durable key/value state, home of auth.*), deploy/install-agent.sh (the token-file idiom 0640 root:agent-user, the ProtectSystem=strict unit with no RuntimeDirectory, the --status probe), tests/test_agent.py (the in-process agent harness), tests/test_collectors.py, tests/test_deploy_scripts.py, tests/test_api.py (the route walk, the settings-page pin, the orphan-id audit), src/dashboards/web/pages/settings.html + src/dashboards/web/static/page-settings.js (the "a page, not a dashboard" pattern the new /certs admin page follows)
Objective
Every exporter (host agent) web server is protected end-to-end by certificates the dashboard itself generates and manages: the dashboard holds a root CA in the meta table, signs its own client cert and each agent's server cert, the agent serves TLS with a per-path client-cert check (only the dashboard can read it), the dashboard dials https:// with its client cert, and a new /certs admin page lists every cert with its expiry and status and triggers rotation, revocation, and bundle re-delivery. The operator's stated follow-up — firewalling upsd 3051 and talking to the agent only — is the motivation, not part of this phase. The agent's bearer-token mode stays a compatibility mode; the dashboard's own login is a separate auth domain and is untouched.
Scope (operator-confirmed): "exporters" = the host agents this repo installs. gufo / vLLM / upsd are third-party services this repo does not deploy; their TLS (e.g. upsd STARTTLS) is a separate operator concern.
Dependencies
14_store_performance(todo) — shared-file, run-order note: 14 rewrites the hot paths instore.py/api.py; 15 only adds meta keys and new routes/pages. Apply on top of the file state at the time it runs; never restore a line the other phase owns.11_admin_login(complete) — the session gate (invariant 12) for the new routes, the gated-write + CSRF + event pattern for the newPOST /api/certs/*, themetahelpers, and the settings-page pattern/certsfollows.
Tasks
01_cert_management.md—src/dashboards/certs.py: the dashboard-managed root CA, client cert, per-agent server certs, revocation and reissue, all inmeta; thecryptographydependency (dashboard-side only).02_agent_tls.md—host_agent.pyTLS mode: one installed--cert-bundle, the per-path client-cert check, the bundle revocation list,bundle_revin the snapshot; token mode unchanged.03_collector_tls.md— the dashboard dialshttps://agent URLs with its client cert, verifies against its root, refuses a revoked agent without dialing; error sentences stay redacted.04_cert_api.md— the gated/api/certssurface: list, per-host bundle, rotate, revoke, root-rotate; fixed-text events, no keys out ofmeta.05_certs_admin_page.md— the/certsadmin page (the settings pattern): every cert with its expiry and status, issued vs deployed bundle rev, rotate/revoke/root-rotate actions, bundle download.06_deploy_cert_bundle.md—install-agent.sh --cert-bundleinstalls/etc/dashboards-agent.certs(0600 root:agent-user), the unit gains the flag +RuntimeDirectory,--statusprobes over TLS; the script pins move with it.07_live_rollout.md— the two live agents flip to TLS,HOST_TARGETSgoeshttps://, the live suite + health table + screenshot prove it; thedriveripperinstall procedure is documented.
Testing & Quality
- Unit:
tests/test_certs.py(new) — the whole lifecycle against a dictMetaStore, exactly howtests/test_auth.pydoes it. - Integration:
tests/test_agent.py(the TLS handshake matrix against the in-process agent),tests/test_collectors.py(thehttpsdial, the revoked refusal with a no-dial spy, the error sentences),tests/test_api.py(the/api/certsshapes, the gate/CSRF on the new writes, the served/certspage pins),tests/test_deploy_scripts.py(the new flags/files/permissions). - Live: task 07 (AGENTS.md invariant 10 — the dev server stays up; screenshots in
data/logs/). - Coverage: >90% on new/modified code; the 94% gate holds.
uv pip list --outdatedempty (thecryptographydependency — invariant 8).
Completion Criteria
- a fresh database boots with a
metaroot CA, generated once and idempotent across restarts (pinned intests/test_certs.py) - an agent run with a bundle answers
/snapshotonly to a client cert signed by its root; a wrong-CA or certless client is refused; a revoked serial gets the 403;/healthstays probeable with the CA only - with
https://HOST_TARGETS, the dev server'shost:/disks:jobs areok, and a revoked host says "certificate revoked" without any dial (spy-pinned) - signed-in
GET /certslists every cert with expiry and status; rotate/revoke/root-rotate work through the gated API; the bundle download is byte-identical to the stored bundle - the installer places the bundle
0600 root:agent-user, the unit comes up in TLS mode,--statusis green over TLS uv run pytestgreen,bash .agents/validate.shgreen,uv pip list --outdatedempty- live: deskwork + gateway in TLS mode,
https://dials, live suite green, screenshots indata/logs/ - no behaviour change in completed phases: the token-mode agent is byte-identical, the engine/UPS polling is untouched, the public surface is unchanged (the route walk)