Repository navigation
[M1.4a1] Agent action dispatch with journaled, validated execution - #147
Merged
Merged
Conversation
Signed-off-by: Samuel Mbabhazi <[email protected]>
Signed-off-by: Samuel Mbabhazi <[email protected]>
Signed-off-by: Samuel Mbabhazi <[email protected]>
Signed-off-by: Samuel Mbabhazi <[email protected]>
samuelmbabhazi
added a commit
that referenced
this pull request
Nov 5, 2026
Closes #134 (with #147). ## What changed M1.4a2: the control-plane side of action dispatch. - **`agent_actions` table.** - Forced tenant RLS, a composite foreign key to the node (cascade), and an idempotency key unique per node. - CHECK constraints on kind, key, state, epoch and attempts. The runtime role gets SELECT, INSERT and UPDATE; `assertTenantDatabaseRole` now covers 11 tables. - The action message is stored encrypted with `EnvelopeService`: scope `organization:<id>`, purpose bound to the action id. - **`AgentActions` service:** - `enqueue` validates the kind against the proto catalog, the key grammar and a deadline within 24 h, and requires a node that has not been removed. It stamps the node's lease epoch, is idempotent per key (including a concurrent insert) and audits `fleet.action.queued`. - `deliverable` first expires overdue actions (audited as `fleet.action.expired`), then returns the node's unfinished actions not yet sent on this stream as `ActionRequest`s. - `record` applies an agent `ActionUpdate` only to that node's own non-terminal action. Terminal states never change again, and each terminal state is audited as `fleet.action.<state>` with the node as actor. The step and error are bounded, and the result is stored as JSON. - **`NodeStream`.** After Hello, each poll (at most every second) sends unfinished actions once per stream, and the stream accepts `actionUpdate` frames. A new stream redelivers everything unfinished; the agent journal (#147) replays known keys. - **Docs.** The SPEC describes delivery, and the PLAN ticks M1.4a. ## How it was tested - Unit tests: a stream test delivers an action once (welcome, then actionRequest) and records the agent's update. Existing stream tests are updated. API tests (218) and the local gate pass. - New TLS integration case in `gateway.integration.spec.ts`: - an action queued for a really enrolled node is delivered with its key and kind, and redelivered on a new stream after a dropped connection; - RUNNING then SUCCEEDED updates move it to `succeeded`; - the audit shows queued then succeeded; - re-enqueueing the same key returns the same action; - the stored payload does not contain the plaintext. - **Not run locally:** the integration tests (no Docker). They run in CI-1. ## Security considerations - Payloads are encrypted at rest. - A node can only update its own actions, through its authenticated identity and RLS. - Final states are immutable. - Delivery stays inside the closed action list. --------- Signed-off-by: Samuel Mbabhazi <[email protected]>
samuelmbabhazi
added a commit
that referenced
this pull request
Nov 5, 2026
…149) Part of #135. ## What changed M1.4b1: the agent can ensure networks and volumes and pull pinned images. These are the first real handlers behind the #147 dispatcher. - **`agent/internal/docker`.** A minimal typed Docker Engine API client instead of the Go SDK: no new dependency, and a much smaller surface. It: - talks only to the local `unix://` socket, with API `v1.47` pinned; - exposes only the needed calls: network list and create, volume inspect, create and remove, image inspect and pull; - uses typed JSON bodies and path-escaped names; - caps responses at 1 MiB and pull streams at 100k lines; - reports errors by status code only, never the daemon's text; - matches networks by exact name (the Engine's inspect endpoint also accepts id prefixes); - detects pull failures from in-stream `error` objects. - **Handlers** (`actions.DockerHandlers`): - `ensure_network` and `ensure_volume`: name grammar `^sk-[a-z0-9-]{1,60}$`; create with `sk.managed=true`; adopt an existing resource only if it carries that label (a same-named unmanaged resource is refused); never delete to compensate. - `ensure_volume` labels: at most 16; keys match `[a-z0-9][a-z0-9._-]{0,62}`; the `sk.` namespace is reserved; values are printable and at most 256 bytes. - `pull_image`: digest-pinned references only (`repo@sha256:<64 hex>`, lowercase, optional registry host and port, at most 512 bytes). Optional credentials must be for the image's own registry, unexpired and bounded; the password stays a `secret.String`. The step is skipped when the exact repo@digest is already present, and the digest is checked after the pull. - **Wiring.** The agent builds the client from `docker.host` and registers the handlers. - **Docs.** SPEC 3.3 describes the client and the managed-label rule. CLAUDE.md rule 1 points to the client. The PLAN splits M1.4b (b2: Go confirmation verifier and `RemoveVolume`). ## How it was tested Everything runs locally, without Docker. - Handlers through the real dispatcher and journal with a fake engine: - create once and refuse foreign resources; - pull with scoped credentials, then skip the pull when the image is present; - labels preserved, and the managed label added. - Malicious-input table, 34 cases: - names: traversal, upper case, injection, oversize, `host`/`bridge`, newline; - images: tags, `latest`, upper case, short digest, traversal, appended flags, oversize; - credentials: expired, other registry, Docker Hub; - labels: reserved key, control characters, too many. - Each gets the fixed `invalid action input` error and never reaches the daemon. - A fuzz target over the name and image validators, run for 20 s (about 290k executions) with no finding. - Client against a fake daemon on a Unix socket: exact network names over substring filters, a 404 mapped to not-found, daemon text not leaked, a pull stream error detected, non-unix hosts refused. - `go test -race ./agent/...`, `golangci-lint` (0 issues) and the local gate pass. - **Not run locally:** a real Docker daemon. Integration against Docker comes with CI-1. ## Security considerations - No shell anywhere. - Every input is validated before the journal and the daemon. - Only Shipkeep-labelled resources are touched. - Registry passwords are wrapped and scoped. - Daemon errors never leak to the control plane. --------- Signed-off-by: Samuel Mbabhazi <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #134.
What changed
M1.4a1: the agent side of action dispatch.
agent/internal/actions.Dispatcher.ActionRequestbefore journaling anything:[A-Za-z0-9._:-]{1,128};FAILEDupdate with a fixed, redacted message.journal.Store.Execute, under the request deadline, and sends anActionUpdateon every transition plus a final one with the mappedActionResult.Cancelcancels a running action's context, and the journal compensates per its plan.actions.Registry(). Empty for now: every kind is answered "not supported" until handlers land with their own malicious-input tests (M1.4b, M1.4c, M1.5).gateway.Runner:ActionRequestframes to the handler on the agent's lifetime, not the stream's, so a dropped connection never interrupts an action;CancelAction;Runwaits for in-flight actions before returning. Receivers became pointers.How it was tested
Everything runs locally: pure-Go SQLite, a real TLS test gateway.
CancelActionreaches the handler.go test -race ./agent/...,golangci-lint(0 issues) and the local gate pass.Security considerations