ADR 002
Push-to-deploy with one locked key per app
Context
Every app should deploy automatically when main changes. Git must be the only source of truth, with no hand edits on the server. CI systems are a common attack path, though. A leaked CI secret that gives a shell on the production host would expose every app and every database.
Options considered
| Option | For | Against |
|---|---|---|
| One shared CI SSH key with a shell | Simplest | One leak means root-equivalent access to everything |
| Pull-based agent on the host (Watchtower, Argo-style) | No inbound access from CI | Needs registry credentials on the host and adds another always-on component; harder to see deploy results in CI |
| Webhook receiver on the host | No SSH | A new public endpoint to harden and authenticate |
| One SSH key per app, locked with a forced command | CI shows the deploy and health-check result; a leaked key can only redeploy that app's current main | Keys need rotating; setup takes a small privileged script |
Decision
- A push to
mainstarts GitHub Actions. It holds a private key whose public half sits in the server'sauthorized_keyswithcommand="deploy-app <app> <host>"and no port forwarding, agent forwarding or terminal. Whatever the client asks for, that single command is all that runs. deploy-apptakes a per-app lock, fetchesmainusing a separate read-only GitHub deploy key, runsgit reset --hard origin/main(Git wins, always), rebuilds with Compose, and then polls the app over HTTPS.- If the app isn't returning HTTP 200 within 60 seconds, the job fails and the run turns red.
- Onboarding is one command,
setup-new-app <app> <host>. It calls a root helper that validates the app name, refuses protected apps and hostnames already in use, creates both keys and logs the action to syslog.
Consequences
- Good: what's running always matches
main. Drift is impossible because the deploy wipes it. - Good: a leaked CI secret can't read data, open a shell or touch another app.
- Good: builds run inside Docker, so nothing is installed on the host.
- Cost: no automatic rollback yet. A failed health check leaves the broken version running until a fix or revert is pushed. See gaps.
- Cost: builds run on the production host, so a heavy build competes with live apps for CPU.
Revisit when
- Zero-downtime or canary deploys are needed. Then build images in CI, push them to a registry, and do blue-green switching in Traefik.
- More than one person merges to
main. Then add required reviews and branch protection.
At bank scale
Build once in CI, sign the image (Sigstore/cosign), scan it, and promote the same digest through dev, test and prod. Argo CD pulls from Git, so CI never holds production credentials. Use OIDC federation instead of long-lived keys, and keep change records linked to commits for audit. The forced-command idea carries over directly: every automated identity gets exactly one capability.