Repository navigation
[M1.6b1] Collect and transport managed-container state reports - #172
Conversation
Signed-off-by: Samuel Mbabhazi <[email protected]>
|
Review: changes requested. One blocking fix, one small fix. The structure is good: one stream writer, a reporter owned and joined by the session, no partial snapshots, and only Blocking: Docker's
|
Signed-off-by: review <[email protected]>
A container in Docker's removing state failed the whole inventory, so one stuck removal hid every other container. It now counts as absent. Collection failures log once when they start and once when they end instead of every second. Signed-off-by: review <[email protected]>
## What changed M1.6b2: agents now send their state reports, and the control plane records what they observe. The owner approved the separate observed-state model on 2026-11-07. - **`allocation_observations` table:** one row per allocation with container id, observed state and time, under forced tenant RLS. It is separate from `allocations.state`, so an observation never frees or takes scheduler capacity. `assertTenantDatabaseRole` now covers 17 tables. - **`observationChanges` (domain):** - containers matching no replica of the node are ignored; - a seen container now absent reads as `missing`; - a replica never seen stays unobserved, because its container may not exist yet; - an unchanged state is refreshed at most once a minute, and only real changes are audited. - **`AllocationObservations`** handles a report in one tenant transaction, using the node identity from its certificate. A report with any invalid container (name, id, state, duplicate, over 256 containers) is ignored whole, keeping the last good state. Changes are audited as `allocation.observed`, with the node as actor. - **`NodeStream`** refuses a report with a stale epoch. It hands valid ones to `StateReports`, a small fleet registry, because deployments depends on fleet and fleet cannot import it back. - **Agent daemon:** the reporter from #172 is now switched on. ## How it was tested - Domain and service unit tests: first sighting, changes, missing versus never seen, the refresh boundary, foreign containers, malicious reports (traversal name, short id, unknown state, duplicates, 257 containers), registry delivery. - Stream test: a state report reaches the registry. - Full local gate passes: 287 API tests, Go race tests, lint, drift, Semgrep, Prettier. - **Not run:** the new `allocation-observations.integration.spec.ts` (another node's report touches nothing, audit sequence, reservation unchanged), because Docker is not reachable from this environment. It needs a run on a machine with Docker. ## Security considerations - A node can only affect its own placed allocations. - Reports hold no labels other than `sk.managed`, no environment and no commands. - Audit volume: a container in a restart loop produces one event per transition. This is bounded by the agent's 1 Hz sampling, and worth revisiting if it proves noisy. --------- Signed-off-by: review <[email protected]> Co-authored-by: review <[email protected]>
Task
[M1.6b1] Agent StateReport collection and transport, split from M1.6b to keep each PR under 500 changed lines. Daemon activation and control-plane persistence belong to M1.6b2, pending approval of a separate allocation observed-state model; the existing placed/stopped reservation invariant is untouched.
What changed / why
Add a bounded, read-only Docker inventory of managed containers, including stopped ones. Snapshots exclude arbitrary labels and credentials, validate identities/states, reject duplicates and inventories above 256 containers, and never truncate a failed or oversized observation into a misleading partial snapshot.
The gateway runner can sample changes every second, refresh every 30 seconds and send a fresh snapshot after Welcome. Collection is independent of heartbeats, carries the session epoch and observation time, and stops with the stream. The daemon does not enable this callback until the receiver exists, preserving compatibility with the current control plane. No protocol/action-catalog or data-model changes.
Validation
Passed locally:
pnpm nx run-many -t lint typecheck test build;go test -race ./agent/... ./cli/... ./lib/...;golangci-lint run ./agent/... ./cli/... ./lib/...;pnpm genwith identical tracked diff before/after;pnpm exec prettier --check ..Tests cover stopped/removed containers, malformed and oversized inventories, private-label redaction, collection failure, periodic/changed reports, actual TLS/gRPC transmission and cancellation. Docker acceptance created a disposable network-isolated, read-only Ubuntu container, verified running/exited/removed observations and removed it. Reproduce with a local pinned image containing
/usr/bin/sleep:SHIPKEEP_DOCKER_TEST_IMAGE=ubuntu@sha256:fe81560990fae86dc4743202b2cb4d3df98d0bcf949173cecef15ce1127ef852 go test -race ./agent/internal/reporting -run TestDockerReportsOperatorStoppedAndRemovedContainerThe existing real-Go-daemon/PostgreSQL enrollment, reconnect and revocation integration test also passed. Full unrelated integration failures previously reproduced on main remain outside this PR. CI remains off. No VM acceptance is claimed.
Security
No shell execution, new dependency, external service, action or persistence mutation. Only the management label leaves the Docker inventory. Collection failures log a fixed message. One writer owns the gRPC stream; session cancellation owns and joins its reporter. State-changing workload operations are unchanged.
Checklist