Skip to content

[M1.5] Route management through the Caddy admin API - #154

Merged
samuelmbabhazi merged 4 commits into
mainfrom
feat/m1.5-caddy-routes
Nov 5, 2026
Merged

samuelmbabhazi merged 4 commits into
mainfrom
feat/m1.5-caddy-routes

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

Part of #17.

What changed

M1.5: the agent manages HTTP routes through Caddy's admin API (ADR 0005).

  • agent/internal/caddy. A typed admin client over the Unix socket. Request bodies are Go structs (no Caddyfile, no templates), responses are capped at 4 MiB, and Caddy's error text is never echoed.
    • EnsureServer creates the shipkeep server (:80, :443) at the deepest missing configuration level only. It never calls /load, which would also reset the admin endpoint the installer put on a Unix socket.
    • Routes are Caddy objects with @id = sk-route-<route_id>, read and patched in place by id or appended. Removing a missing route counts as done.
    • SetPlainHosts maintains automatic_https.skip for TLS_MODE_OFF routes.
  • upsert_route and remove_route handlers:
    • Route id: [a-z0-9][a-z0-9-]{0,62}.
    • Hosts: 1–32 lowercase DNS names, at most 253 bytes each, *. allowed; IP addresses, localhost and duplicates refused.
    • Upstreams: 1–64 canonical private IP address:port literals only (Docker or WireGuard), so no public, loopback, metadata, hostname or unix upstreams. Weights 1–100 map to weighted_round_robin.
    • TLS: automatic HTTPS by default; OFF adds the hosts to the skip list, and switching back removes them. AUTO_DNS is refused until a DNS provider is configured.
    • Switch-then-drain: the switch is one atomic Caddy change. When an existing route was replaced, the action waits the drain timeout (default 30 s, at most 5 min) before succeeding, so the control plane stops the old instance only after draining. Removal drains too.
  • Wiring. The agent builds the router from caddy.admin_socket.
  • Docs. The SPEC describes routing. In the PLAN, M1.5's handlers are done but the task stays open until its acceptance runs: a switch under constant load against a real Caddy.

How it was tested

  • Handlers with a fake router:
    • a new route does not drain; the switch replaces the upstreams, then drains 10 s; removal drains the default 30 s;
    • TLS off is skipped and weights applied, and switching back to HTTPS clears the skip.
  • 19 malicious routes, all rejected without touching Caddy:
    • hosts: none, IP, upper case, JSON injection, localhost, duplicate, oversize;
    • upstreams: public, metadata, loopback admin port, hostname, unix socket, port 0;
    • weight overflow, DNS TLS, a one-hour drain;
    • route id: traversal, upper case;
    • no upstreams.
  • Client against a fake Caddy admin server on a Unix socket: bootstrap without /load, append then PATCH /id/sk-route-api, read back, idempotent removal, Caddy error text hidden, relative socket path refused.
  • go test -race ./agent/..., golangci-lint (0 issues) and the local gate pass.
  • Not run locally: a real Caddy. The load-switch acceptance runs in CI-1 or the VM suite.

Security considerations

  • Upstreams cannot point at the host, Caddy's admin port, cloud metadata or the internet.
  • Configuration is typed and id-addressed.
  • The admin endpoint is never reset.

@samuelmbabhazi
samuelmbabhazi merged commit de87694 into main Nov 5, 2026
@samuelmbabhazi
samuelmbabhazi deleted the feat/m1.5-caddy-routes branch November 5, 2026 20:13
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