Repository navigation
test(agent): accept container actions and routes on real Docker and Caddy (#16, #17) - #424
Merged
Merged
Conversation
An HTTP health probe took the container's single exposed TCP port and failed when there were several. The image's own EXPOSE counts too, so any image exposing another port than the application's (whoami exposes 80 while the application listens on 8080; gitea, minio and many others expose several) failed its health check, and with it the deployment. The agent now records the one TCP port the spec declares in the label sk.probe_port when it creates the container, and the probe uses it. Containers created before keep the previous rule. No contract change: the label is the agent's own, and labels from the control plane cannot start with "sk.". Found by the acceptance test against a real Docker daemon (#16). Signed-off-by: samuel mbabhazi <[email protected]>
…addy Two tests behind the integration build tag, run by a new CI job: - Every container action through the agent's own handlers against the runner's Docker: network, pulls, volume, release command with its exit code, create (idempotent), start, health check, stop, remove, volume removal. Docker's own view is checked: not privileged, no bind, no host namespace, no-new-privileges, read-only root, user, limits, only volume and tmpfs mounts. A path traversal never reaches Docker. - A route switched from v1 to v2 under constant load from eight clients in the Caddy that compose.yml pins, then the replaced replica stopped and removed: no failed request. Without the switch, the same test fails with 502s. golangci-lint now reads the integration tag. Closes #16, closes #17. Signed-off-by: samuel mbabhazi <[email protected]>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 40 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
samuelmbabhazi
added a commit
that referenced
this pull request
Nov 23, 2026
…art of #18) (#426) Part of #18 (M1.6, self-reconciliation). It reuses the CI job and the real-Docker helpers of #424, now merged. ## The defect Caddy holds a route's upstreams as resolved addresses (ADR 0017), and Docker gives a restarted container whatever address is free. If another container starts while the first is down, it takes the old address. The route then sends the first application's traffic **to the second**: one application's requests are answered by another on the same environment network. It happens after a crash, an out-of-memory kill, a disk budget stop or a reboot, and it does not need the control plane to be down. I reproduced it on Docker 29: 1. container A had `.2`; 2. A was killed, and B started and got `.2`; 3. A restarted with `.3`. ADR 0017 had left "re-applying routes during reconciliation" to M1.6. ## The fix (agent only, no contract change) **The journal** (`route_records`) keeps one record per route that proxies to local containers: - the route's upstreams as asked: a container and its port, or an address, each with its weight; - the dial lists the agent wrote to Caddy, or is about to write: one or two. **The route actions:** - `UpsertRoute` writes the record *before* Caddy gets the route. - The maintenance page and address-only routes have no record. - `RemoveRoute` forgets the record only once Caddy has removed the route. **`actions.RouteRefresher`** runs at the end of every reconciliation pass (every 30 s, with or without the control plane), after containers are started again. For each recorded route: - It resolves every container again, and builds the whole upstream list in the route's order, with each upstream's weight. Replicas that swapped addresses keep their weights. - **A container that does not run gets no traffic**, since its old address may be another container's now. A route none of whose containers runs answers **503** until one runs again (`caddy.UnavailableHandler`). - It changes the route only while Caddy holds a dial list the agent recorded. A route written by anything else is left alone. - It records the new list before writing it to Caddy, and keeps only that list once Caddy has it. Whichever write fails, the next pass takes it up again. - If Docker does not answer, or two upstreams would share an address, it changes nothing and reports the error. **One lock** (`actions.RouteBook`, which the agent creates once) is shared by the route actions and the refresher. A route's write to Caddy and the write of its record happen under it together. **`caddy.Client.UpdateRoute`** reads and rewrites one route under the Caddy client's lock. **Docs:** - SPEC (self-reconciliation); - ADR 0017 (consequences); - THREAT_MODEL T5, which also states what remains: when Docker restarts a container itself, its route keeps the old address until the next pass; - PLAN M1.6. ## How it was tested **Unit tests:** - the journal record: written, replaced, read, forgotten, and invalid input refused; - the record written before Caddy gets the route, cleared for the maintenance page and on removal, and kept when Caddy fails to remove the route; - a route Caddy refused is not completed by the refresh; - the refresh: - follows a container that moved; - leaves a route the agent did not write; - follows replicas that swapped addresses with their weights; - sends nothing to a stopped container, answers 503 with none running, and proxies again once one runs; - changes nothing without Docker or with a duplicate address; - recovers from a failure at each of its three writes; - every route write, by the refresh and by both actions, happens under the shared lock. The lock, removal and write-ahead tests fail when those protections are taken out again. **Real Docker and Caddy** (`TestRealCaddyFollowsARestartedContainer`, in the CI job of #424), with no control plane: 1. A serves, then A is stopped behind the agent's back. B starts and takes A's address, and A's route now reaches B: the defect itself. 2. The refresh: the route answers 503 instead of B. 3. One reconciliation pass: the reconciler has started A, and the route reaches A again. **Locally:** the three real tests pass against Caddy 2.11.9 and the host's Docker. The switch test ran 8,878 requests with no failure. **Checks:** `go test ./agent/... ./lib/...`, `go vet -tags integration` and `golangci-lint` (0 issues). What is left for #18 is the acceptance of a whole machine reboot on a VM. ## Security considerations - This closes a path where an application could receive another application's requests after a restart, including while the first container stays down. - The refresh only ever points a route at the private addresses of the managed containers that route already named, resolved the way `UpsertRoute` resolves them (ADR 0017), and at the addresses it was given. It never adds an upstream. The 503 answer is a fixed static response built into the agent. - An absent or unmanaged container under a recorded name gets no traffic. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **New Features** * Routes to managed containers now refresh automatically when containers restart with different addresses, helping traffic continue reaching active instances. * When no managed containers are running for a route, requests receive a 503 response with a retry interval. * **Bug Fixes** * Route updates now avoid overwriting changes made outside the agent, and route records are kept in sync with successful changes. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- 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.
Closes #16 and closes #17: the acceptance of M1.4 and M1.5, which the plan allows in CI against a real Docker and Caddy. It also fixes a production bug that the first of these tests found.
The bug
An HTTP health check probed the container's single exposed TCP port, and failed when there were several. The image's own
EXPOSEcounts. So any image that exposes another port than the application's failed its health check, and with it the deployment:traefik/whoamiexposes 80 while the application listens on 8080;The lab never hit it: its applications listen on the port their image exposes.
Fix (agent only, no contract change):
sk.probe_port, and the HTTP probe uses it.sk..The acceptance tests
They sit behind the
integrationbuild tag and are run by a new CI job, "Agent against Docker and Caddy".real_docker_test.go(#16): every container action through the agent's own handlers and Engine API client, against the runner's Docker.no-new-privileges, read-only root, the user asked for;..is refused and never reaches Docker.real_caddy_test.go(#17): in the Caddy thatcompose.ymlpins, v1 serves.The CI job starts Caddy on the test network as the runner's user, so that the test reaches its admin socket. It reads the Caddy image from
compose.yml, so the pin stays in one place.golangci-lintnow reads theintegrationtag, so these files are linted like the others.PLAN: M1.4 and M1.5 are checked, and taken out of the list that waits for a server.
How it was tested
t.Cleanup).go test ./agent/...,golangci-lint(0 issues) andactionlintpass.Security considerations