Repository navigation
feat(server): production hosts refuse unsafe config and expose a deep health check - #519
Merged
Merged
Conversation
… health check A production host fell back to the container's disk without PATCHY_S3_BUCKET, accepted a plain-HTTP public origin and Clerk's test keys, and /healthz answered ok even with the database gone. Before it touches Postgres, a NODE_ENV=production host now refuses a non-HTTPS PATCHY_PUBLIC_BASE_URL and a missing or incomplete Neon Object Storage configuration. With PATCHY_ENVIRONMENT=production it also refuses pk_test_/sk_test_ keys; staging and the spike keep theirs. GET /healthz/deep answers 200 only while the platform database does, 503 otherwise, and names PATCHY_DEPLOYMENT_REVISION either way. /healthz stays shallow for the load balancer and ECS. Neither probe emits wide events. Part of #415. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
3 of 4 tasks
Owner
Author
|
Codex review (GPT 6.1 Sol, xhigh), before the first push. Two findings; both dismissed.
|
allisonmahmood
added a commit
that referenced
this pull request
Oct 4, 2026
# What changed Production had no infrastructure in code. The tier 2 spike runs on a hand-built stack driven by `scripts/tier2-spike.mjs`, and nothing describes the network, load balancer, hosts, exec task definition, secrets or alerts that #416 will deploy. `apps/infra` is a CDK app with two stacks per environment, named from context (`-c environment=production`), so a staging stack later is one more command. Nothing in it is deployed by this PR. **Base stack** (deploys first, outlives releases): the ECR repository with immutable tags and the last 30 images kept; the GitHub OIDC provider and a deploy role trusted only for this repo's `production` environment; the $300 forecast budget emailing the alert addresses; the host secret, declared without a value; and the fleet management secret with two slots, `a` (generated once) and `b` (empty until a rotation writes into it). The provider and budget are account-wide, so only production declares them. **App stack** (one release, pinned to an image digest): - VPC: two public subnets for the ALB and hosts (public IPs, no NAT), and an isolated exec subnet whose only ways out are ECR API/Docker and Logs interface endpoints and an S3 gateway endpoint. No Secrets Manager endpoint. - Security groups: ALB, host, `exec-bootstrap`, `exec-sealed` and endpoints, with the rules from `docs/OPERATIONS.md`. The endpoint group admits the hosts too, since private DNS covers the whole VPC (the prototype's live finding). - ALB: 443 with the existing certificate (from context), 80 redirecting, HTTP/2, 3,600 s idle timeout. The target group has app-cookie stickiness on `patchy_stream_affinity`, a 90 s deregistration delay and the shallow `/healthz` check. - Hosts: two tasks at 0.5 vCPU / 2 GB, rolling 100/200, circuit breaker **with rollback**, user 1000, stop timeout 120 s. Settings come from the host secret by key; the host task role is the fleet policy, scoped to this cluster and the exec family. - Exec: a `CfnTaskDefinition` with **no task role**, user 0, the spike's capability drops, port 8788, and its own execution role (ECR pull and logs only). - Uptime: a Route 53 HTTPS check on `/healthz/deep` → CloudWatch alarm → SNS email. - Host config: `NODE_ENV=production`, `PATCHY_ENVIRONMENT`, the public origin and authorized party, `PATCHY_TRUST_PROXY` set to the VPC range, fleet budget 15, the deployment revision, and the `ECS_*`/`EXECUTION_*` settings from the stack. **Tests and CI.** A vitest synthesizes both stacks offline and snapshots every security group and rule. It also pins the stickiness and ALB attributes, circuit-breaker rollback, the credential-free exec definition, the previous-release mapping, and the secrets' shapes. CI's `lint` job and `pnpm check` run `cdk synth` with example context; it runs with no network at all (no credentials, lookups, notices or telemetry). Account ids, the certificate ARN and alert addresses come only from context. **Choices worth checking** - **The host secret is in the base stack, not the app stack.** Hosts can't start until a person fills it, so an app stack that created it would fail its first deploy and roll the secret away. This matches #416's order: deploy the base stack, fill the secret, then the first release. - **Every release names the slot its hosts read, and the promoted release as previous** (its revision, exec task definition and slot). Until promotion the fleet still replenishes the promoted revision's spares, and a host that can't launch that revision would reserve tasks it can never start or stop, holding fleet budget for good. For the same reason, replaced exec task definitions are retained (`UpdateReplacePolicy: Retain`). The deploy role may read and write the SSM parameter where PR 3's workflow records the promoted release, and stop promote tasks a cancelled run left behind. - **Closed egress.** CDK drops its inline "no traffic" egress placeholder when every egress rule of a group names another group, which leaves AWS's default allow-all in place. The ALB and `exec-bootstrap` groups put it back, and the test fails if any group but the hosts' lacks inline egress. - `exec-sealed` keeps the spike's one rule (8788 from hosts) and no egress. The S3 prefix list `pl-63a5400a` is AWS's managed list for us-east-1, the same in every account. The uptime check targets #519's `/healthz/deep`, and the hosts set #519's `PATCHY_ENVIRONMENT`. Part of #415. ## How it was verified - [x] `pnpm check` and `pnpm verify` pass locally; `cdk synth` runs inside a network-less namespace - [x] Added `apps/infra/src/stacks.test.ts` (security-group snapshot and contract checks) ## Release impact - [ ] **Breaking** - [x] **Not breaking** — a new package; nothing is deployed Made by Claude Opus 5.5 (1M context) via Claude Code, in T3 Code.
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.
What changed
A production host could start in ways that lose data or trust. Without
PATCHY_S3_BUCKETit kept patch bytes on the container's disk, which the next deploy throws away; it accepted a plain-HTTP public origin; and nothing kept Clerk's test keys out of production./healthzalways answered ok, so an uptime check could see neither the database nor which build was live.Before it touches Postgres, a
NODE_ENV=productionhost now refuses a non-HTTPSPATCHY_PUBLIC_BASE_URLand a missing or incomplete Neon Object Storage configuration. WithPATCHY_ENVIRONMENT=productionit also refusespk_test_/sk_test_keys; staging and the tier 2 spike keep theirs. Each refusal is a config error that names the setting and never prints a key.GET /healthz/deep(Serving) answers{ ok, revision }: 200 while the platform database answers within two seconds, 503 otherwise, namingPATCHY_DEPLOYMENT_REVISIONeither way./healthzstays shallow for the load balancer and ECS, so a database blip does not make ECS replace every host. Neither probe emits wide events.First of three stacked PRs for #415, based on
main. Part of #415.How it was verified
pnpm checkandpnpm verifypass locallyRelease impact
NODE_ENV=productionserver no longer starts on a plain-HTTP origin or without Neon Object Storage, andPATCHY_ENVIRONMENT=productionneeds live Clerk keys. The tier 2 spike already meets all three.Made by Claude Opus 5.5 (1M context) via Claude Code, in T3 Code.