Skip to content

[M1.4b1] Typed Docker client with network, image and volume handlers - #149

Merged
samuelmbabhazi merged 5 commits into
mainfrom
feat/m1.4b-docker-volumes
Nov 5, 2026
Merged

samuelmbabhazi merged 5 commits into
mainfrom
feat/m1.4b-docker-volumes

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

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.

@samuelmbabhazi
samuelmbabhazi merged commit dce84bf into main Nov 5, 2026
1 of 10 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the feat/m1.4b-docker-volumes branch November 5, 2026 19:50
samuelmbabhazi added a commit that referenced this pull request Nov 5, 2026
Closes #135 (with #149).

## What changed

M1.4b2: the agent verifies confirmation tokens and removes volumes only
with one.

- **`agent/internal/confirm`.** A Go verifier as strict as the control
plane's parser (SPEC 3.6):
- the exact header, the exact claim set in canonical order (re-encoded
and byte-compared, with HTML escaping off), unknown fields disallowed;
  - strict unpadded base64url, a 64-byte signature, at most 2 KiB.
- It then checks the Ed25519 signature with the public key received at
enrollment, that `org` is the agent's own organization, that action and
target match, that `iat` is at most 60 s ahead and that the token is
unexpired.
- Finally it spends the `jti` in the journal's `used_confirmations`
table.
  - Every failure gives the single `ErrRejected`.
- **`remove_volume` handler:**
- the plan rejects malformed names and tokens without touching any
state;
- step 1, `confirm`, verifies and spends a `volume.remove` token for
exactly that volume. It is not retryable: after an uncertain crash, the
operator needs a new confirmation;
- step 2, `remove`, is idempotent, removes the volume only if it carries
`sk.managed=true` and treats an already-missing volume as done.
- **Wiring.** The agent builds the verifier from the bundle's
confirmation key and organization, and registers the handler.
- **Docs.** SPEC 3.6 describes agent verification. The PLAN ticks M1.4b.
The control plane will issue `volume.remove` confirmations once volumes
are resources (M5).

## How it was tested

- **Cross-language vector.** A token signed by Node.js with a fixed test
key, exactly as the control plane signs, verifies in Go. A replay is
refused.
- **Binding.** Other target, other action, other organization, expired,
and issued in the future: all rejected.
- **Malformed and forged tokens, 12 cases:** `alg: none`, a reordered
header, padding, an extra claim, an unknown claim, whitespace, a longer
lifetime, a truncated signature, a signature from another key, oversize.
All rejected.
- **Fuzz target:** no altered token verifies.
- **Handler:** no removal with a rejected confirmation; the confirmed
removal of a managed volume works; an unmanaged volume is refused;
malformed tokens and traversal names never reach the daemon.
- The test tokens are marked `gitleaks:allow`: they are signed with a
fixed, public test seed (0x07…), so they are not secrets.
- `go test -race ./agent/...`, `golangci-lint` (0 issues) and the local
gate pass.

## Security considerations

- Destructive volume removal now needs a single-use token bound to the
organization, action and volume.
- The verifier is fail-closed with a uniform error.

---------

Signed-off-by: Samuel Mbabhazi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant