W19-04 — kryptkeeper-agent live UAT fixture
Proves the agent-mode path against a real hub: a Linux container running
cmd/kryptkeeper-agent (1) registers with a token the hub issued, (2) pushes
a real inventory of certificates found on its filesystem, and (3) attempts
the renewal task the hub queues for it.
Run
bash tests/live/agent/run.sh
Requires podman (no docker) and a free host port 80 (real RFC 8555 HTTP-01
challenges always target port 80 — see "Why CN=localhost" below) and 8091/8445.
Builds the agent binary for the podman machine's arch, builds the fixture
image, runs the hub on the host and the agent+nginx in a container, and prints
PASS/FAIL per step. Idempotent: tears down any prior kk-uat-agent*
container/image state before running, and always cleans up on exit (trap).
Update: the hub's ACME server now refuses
localhostnames (RFC 6761) and http-01 fetches over loopback, so the harness no longer uses the host hub, host port 80 orCN=localhostdescribed in the sections below. The hub runs in a container and the agent host is a container namedagenthoston one podman network (certificate and ACME identifieragenthost). Sections below describe the original W19-04 findings and are kept as history.
What it proves, and what it found
-
Enrol —
KRYPTKEEPER_AGENT_ENROLLMENT_SECRETSgatesPOST /api/v1/agent/register(internal/bootstrap/agent_attestation.go). run.sh pre-registers via curl with that secret (mirroring what a human would do fromTargetSetup.tsx's pairing flow, since the agent's ownRegister()only logs credentials to stdout —cmd/kryptkeeper-agent/ main.go:93-101— rather than persisting them) and injects the returnedKRYPTKEEPER_AGENT_ID/KRYPTKEEPER_AGENT_TOKENinto the container.GET /api/v1/agents(bearer auth) is asserted to show the agentactiveafter its first heartbeat. -
Inventory — the fixture nginx vhost's short-lived (2-day) self-signed cert plus 3 extra placeholder PEMs under
/etc/ssl/certs-extraare picked up byagentdiscovery.WalkCerts/WalkConfigCerts(internal/agentdiscovery/linux.go,configparser.go) and pushed viaPOST /api/v1/agent/inventory. Asserted via the agent's own container log ("hub accepted N certificates") andGET /api/v1/agents'inventory_count. -
Renewal task queue —
internal/bootstrap/managed_target_store.go's own doc comment saysManagedTarget.InstallModeis not consumed anywhere;errRenewalTargetNotSSH(renewal_executor.go:41) confirms the per-target renewal executor refusesinstall_mode=agentoutright. The actual "agent task queue" ismatchRenewalTasks(handlers_agents.go:289-348), driven purely by the agent's own reported inventory:AutoRenewable && NotAfter <= now+RENEWAL_THRESHOLD_DAYS &&endpoint-matched-by-cert-path. Creating aManagedTargetwithinstall_mode=agentis exercised by run.sh to document that inertness directly (acceptance-checked, not asserted as the trigger).The fixture's 2-day cert is inside the default 30-day threshold, so a
renewtask is assigned automatically on the first inventory push — no CSR issuance through the hub's certificate API is needed to reach this step; that API is not in the loop for agent-mode task assignment at all.Renewal now completes end-to-end (fixed on
kk/w19-04-agent-rerun, 2026-09-10). Three compounding defects had to clear, in order:-
The ACME server's self-advertised base URL was unreachable whenever the hub bound a wildcard address — fixed by W19-13's
resolvePublicBaseURL(cmd/kryptkeeper/main.go:686).KRYPTKEEPER_BASE_URLnow wins when set; run.sh sets it tohttp://host.containers.internal:$HUB_PORTand a container-sidecurlof/acme/directoryconfirms every URL (newAccount,newOrder,finalize, ...) is rooted there instead of0.0.0.0. -
AgentRenewalTask.Subjectcarried the full RDN string, not a bare hostname — fixed by W19-13'sIdentifiers []stringfield (handlers_agents.go'srenewalIdentifiers/parseCNHostname). The queued task now also carries"identifiers":["localhost"], andAcmeRenewer.Renew(internal/agentclient/acme_renewer.go:64) uses that instead of the Subject RDN. -
A third, previously undiscovered defect:
agentinstall. Installer.Install's post-reload verify step raced nginx's reload.nginx -s reload(internal/agentinstall/installer.go'sreloadCommand) sends a signal and returns before the master has actually swapped workers; the very next TLS dial (defaultVerifier,verify.go:27), issued microseconds later, observed the pre-reload leaf on every one of five separately-issued renewals in a row. Fixed byverifyWithRetry(10 attempts, 300ms apart) — no fingerprint comparison was loosened, it just tolerates the reload's inherent async handover.
ca_urlin the task JSON (AgentRenewalTask.CAURL,handlers_agents.go:83) is still always""— traced and confirmed dead, not a bug: it is declared but never assigned inmatchRenewalTasks, and the agent never reads it, deriving its ACME directory URL from its ownKRYPTKEEPER_HUB_URLinstead (AcmeRenewer.Renew,acme_renewer.go:64).See
docs/STATUS.md's 2026-09-10 "W19-04 done (rerun)" entry for the full per-step evidence and log excerpts. -
Why CN=localhost, and port 80
RFC 8555 HTTP-01 always dials the identifier on port 80 — there is no
configurable port (internal/acme/server.go:1104). localhost needs no
/etc/hosts edits on the host, since it already resolves to 127.0.0.1.
run.sh publishes the container's :80 to the host's :80
(podman run -p 80:80) so the hub's HTTP-01 fetch (from the host) reaches
the agent's challenge file. On this podman machine that required a
one-time, best-effort podman machine ssh -- sudo sysctl -w net.ipv4.ip_unprivileged_port_start=0 (run.sh runs it automatically,
ignoring failure) — the rootless port forwarder otherwise refuses
privileged ports; this tunes the podman VM, not the product, and reverts
on VM restart. Port 8445→443 is the TLS vhost openssl s_client checks
against and is unaffected by any of this.
Fixture layout
Containerfile— Ubuntu 24.04 + nginx + openssl-minted fixture certs, COPYs in a prebuiltkryptkeeper-agentbinary (never built inside the image).nginx-agent-uat.conf— the vhost pair (:80 ACME webroot, :443 TLS)agentdiscovery's config parser must byte-for-byte match against.entrypoint.sh— starts nginx, then execs the agent in the foreground.run.sh— builds both binaries, drives the hub + container lifecycle, and prints PASS/FAIL per step. No real key material is committed; every cert/key here is generated fresh at build time.
W24-16: keystores, kubeconfig and out-of-band replacement
fixtures/ is COPYd into the image as /opt/keystores and
KRYPTKEEPER_SCAN_PATHS gains it. fixtures/gen-keystores.sh regenerates the
binaries (needs openssl 3 and keytool; it can run inside an ubuntu container):
| file | content | inventory source |
|---|---|---|
store3.jks |
JKS, 3 trusted certs, password changeit |
jks:/opt/keystores/store3.jks x3 |
store2.p12 |
PKCS#12 (leaf + CA), legacy SHA-1 MAC profile, password changeit |
pkcs12:/opt/keystores/store2.p12 x2 |
kubeconfig |
one client-certificate-data user |
kubeconfig:/opt/keystores/kubeconfig x1 |
New checks (after the existing inventory-count check, 8 more checks, so 25 in
a full run): JKS 3, PKCS#12 2, kubeconfig 1, 6 keystore-sourced rows in total;
overwriting /etc/ssl/certs-extra/extra1.pem raises CERTIFICATE_REPLACED
within 2 * poll interval + 10 s, the inventory fingerprint changes, and no
alert names a keystore source; the inventory API response and the hub DB's
agent_* tables hold 0 PRIVATE KEY headers (one more check than the 25 above
since W24-45; this harness edit has not been re-run live, see the W38-05 notes).
Decisions: the inventory checks read GET /api/v1/agents/{id}/inventory
(W24-45; they read the hub's SQLite file before that). The file is still copied
with its WAL via podman cp, only for the PRIVATE KEY hygiene dump of the
agent_* tables. The alert is observed in the audit trail
(discovery.scan_diff.certificate_replaced), which the notifier always writes
before fanning out, so the check does not depend on a delivering channel.
The P12 key is imported and discarded by the generator (no key file is kept),
so the "leaf.key appears nowhere" grep is not possible; the 0 PRIVATE KEY
dump check covers the property.