Skip to content

[M1.4c2] Container start, stop and confirmed removal - #152

Merged
samuelmbabhazi merged 2 commits into
mainfrom
feat/m1.4c2-container-lifecycle
Nov 5, 2026
Merged

samuelmbabhazi merged 2 commits into
mainfrom
feat/m1.4c2-container-lifecycle

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

Part of #136.

What changed

M1.4c2: container lifecycle handlers.

  • start_container, stop_container and remove_container accept a full 64-hex Docker id or an sk- name, never an id prefix. They act only on containers carrying sk.managed=true.
  • They are idempotent:
    • starting or stopping a container already in that state is fine (the daemon answers 304);
    • stopping or removing a missing container counts as done;
    • starting a missing container fails.
  • The stop timeout defaults to 10 s, with a maximum of 10 min.
  • remove_volumes=true destroys data. It needs a container.remove confirmation for that exact container, spent in a non-retryable first step. A token sent without remove_volumes is refused as malformed input.
  • Docs. The SPEC describes the lifecycle rules, and the PLAN ticks M1.4c2.

How it was tested

  • On a managed container, start, stop and remove reach the daemon, with volumes kept. Once the container is gone, stop and remove succeed and start fails.
  • Unmanaged containers are never touched.
  • Volume removal without a token is rejected. With a token for that container, the token is spent and the daemon receives v=true.
  • Malicious references are rejected for each action: empty, short id, 63 hex, injection, traversal, upper case, host, and a suffixed id. A one-hour stop timeout is also rejected.
  • go test -race ./agent/..., golangci-lint (0 issues) and the local gate pass.

Security considerations

  • No action reaches containers Shipkeep does not manage.
  • Data destruction requires a single-use confirmation.

@samuelmbabhazi
samuelmbabhazi merged commit 2f60c5d into main Nov 5, 2026
@samuelmbabhazi
samuelmbabhazi deleted the feat/m1.4c2-container-lifecycle branch November 5, 2026 20:02
samuelmbabhazi added a commit that referenced this pull request Nov 5, 2026
Closes #136 (with #151, #152).

## What changed

M1.4c3: health checks and release tasks. Every container action of M1.4
now has a handler.

- **Docker client:**
  - inspect now returns network addresses and exposed ports;
- `WaitContainer` uses a second HTTP client without the 30 s
response-header timeout, because the daemon answers only when the
container exits.
- **`health_check`.** The agent probes a managed container itself:
- **Target:** only its private network address, never loopback,
link-local (cloud metadata) or public addresses. The port is the
requested TCP port, or for HTTP the single exposed TCP port; it is
refused when ambiguous.
- **HTTP:** a GET that never follows redirects, reads at most 4 KiB and
treats 2xx/3xx as healthy. The path must be absolute, not network-path
(`//…`), printable and at most 2048 bytes.
- **Timing:** bounded intervals, timeouts, start period, thresholds and
deadline.
- **Result:** `HealthCheckResult{healthy, consecutive_successes}`; an
unhealthy container fails the action.
- **`run_release_task`:**
- The spec is validated like `CreateContainer`, with the restart policy
forced to `no`.
- Step 1 creates the container, reusing it by fingerprint and refusing
unmanaged ones.
- Step 2 is non-retryable: start, wait within the timeout (1 s–1 h),
then remove, so the exit code is the final outcome. On timeout the task
is killed and removed. After a crash it is compensated (removed), never
run again.
  - Result: `ReleaseTaskResult{exit_code}`.
- **Docs.** The SPEC describes both actions. In the PLAN all M1.4
handlers are done, but M1.4 stays open until the integration tests
against a real Docker daemon run (CI-1).

## How it was tested

- **Health check:**
- reaches its threshold after a failure, on the exposed port of the
private address;
  - an unhealthy container fails;
- metadata (`169.254.169.254`), loopback, public and empty addresses are
never probed;
  - ambiguous ports are refused;
- 11 malicious specs are rejected (relative path, `//evil` network path,
space, CRLF injection, oversize, port 0 or overflow, a tiny interval, a
timeout longer than the interval, a threshold storm), as is a one-hour
deadline.
- **Release task:**
- exit code 3 is reported, the task runs once with restart `no` and is
removed;
  - a hanging task is killed and removed;
  - an unmanaged container is never run;
  - a two-hour timeout is refused.
- `go test -race ./agent/...`, `golangci-lint` (0 issues) and the local
gate pass.
- **Not run locally:** a real Docker daemon. It runs in CI-1.

## Security considerations

- Probes cannot be aimed at host, metadata or external addresses.
- Migrations never run twice after a crash.

---------

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