fleet-manager: checkpoint 2 — gRPC agent plane (bidi mTLS stream)

The steady-state host<->manager transport, resolving the design's OPEN FORK to
bespoke gRPC (not OTLP+Wazuh). One long-lived, host-dialed, mTLS bidi stream:
health/metrics up, desired-state/commands down — no polling, real-time control,
still no inbound host port.

- proto/fleet_agent.proto: FleetAgent.Session(stream AgentUp) -> stream ManagerDown.
  AgentUp = Hello | HealthSnapshot | CommandResult; ManagerDown = DesiredState |
  Command(reboot/drain/resync). int64 unix times (no well-known-type dep).
  Generated stubs committed (CI needs no protoc).
- agent.go: gRPC server with mTLS verified by the FLEET CA (the host's reused TPM
  identity cert — distinct from the admin plane's admin CA). Identity is the peer
  cert SERIAL, taken from the verified cert = inventory key, never self-asserted;
  an unenrolled serial is refused (enrolment gates the stream). Per-conn send
  channel decouples admin pushes from stream.Send. Stream registry (serial->conn)
  with reconnect eviction. On connect + on change, desired-state is pushed live;
  inventory stays authoritative so offline hosts reconcile on reconnect. Metrics
  go through a MetricsSink seam (no-op now; InfluxDB in ckpt 4).
- main.go: agent plane starts only when its cert/key/CA are set; admin can run
  standalone. Lifecycle PUT now live-pushes and reports pushed_live.

Full mTLS integration test (in-process fleet CA + host client cert): initial
desired-state on connect, Hello+snapshot -> inventory + online presence, live
desired-state push, and unenrolled-serial rejection. go build/test/vet/gofmt clean.

Deps (server-side only): google.golang.org/grpc + protobuf.
This commit is contained in:
Audiobuzz
2026-07-04 03:40:55 +00:00
parent 0572d21c07
commit 80cbb833cc
11 changed files with 1700 additions and 13 deletions
+8 -3
View File
@@ -65,9 +65,14 @@ func (s *server) handleSetDesired(w http.ResponseWriter, r *http.Request) {
writeErr(w, http.StatusNotFound, "no such host")
return
}
// checkpoint 2: after persisting, push the new desired-state down the host's
// live agent stream here (if connected); offline hosts get it on reconnect.
writeJSON(w, http.StatusOK, h)
// Push the new desired-state down the host's live agent stream if connected;
// an offline host (or one we can't reach right now) picks it up from the
// persisted inventory record on its next connect — inventory is authoritative.
pushed := false
if s.hub != nil {
pushed = s.hub.pushDesired(serial, h.Desired)
}
writeJSON(w, http.StatusOK, map[string]any{"host": h, "pushed_live": pushed})
}
// adminCN returns the CN of the admin's mTLS client cert, for audit attribution.