Skip to content

chore(infra): authenticated TLS to CNPG through a Cloudflare Origin CA server certificate and verify_ca (infra repo work, tracked here) #41

Closed

Description

@aRustyDev

Context

Thrust's Postgres is CNPG thrust-pg (production) and thrust-pg-dev in woven-o11y. Both are built from the infra repository's shared chart modules/kube/cnpg-cluster/chart and reached through the tunnel thrust-pg and two Workers VPC TCP services (hosts thrust-pg-rw.thrust.svc.cluster.local and thrust-pg-dev-rw.thrust.svc.cluster.local), with Hyperdrive on top (ADR-0094 Option 1; research/0010 §11 and §12). pg_hba accepts TLS only, and the hop runs TLSv1.3. Because verify_ca failed against CNPG's private CA, both VPC services run with cert_verification_mode = disabled, which is now the default in products/thrust/cloudflare/variables.tf (ADR-0094:111; research/0010:324). The work happens in the infra repository (ApiraTech/infrastructure); this issue tracks it.

Problem

The database is not authenticated: whoever answers the connector's connection to the -rw Service becomes Hyperdrive's TLS peer. That was the finding of the PR #810 security review (ADR-0094:120). The owner accepted the state as temporary, with the deadline "closed before Thrust holds real data" (ADR-0094:120; Q-0094.9, QUESTIONS.md:351; beads plane-byd.9 and infra-qnyi). Q-0094.9 lists three options and picks none.

Two documented facts narrow the choice:

  • Workers VPC trusts publicly trusted certificates and Cloudflare Origin CA, and in verify_ca mode it verifies the certificate chain only and skips hostname verification (workers-vpc/configuration/vpc-services; ADR-0094:82).
  • Hyperdrive's own CA upload cannot be used with VPC-service origins (ADR-0094:82).

Proposal

Implements the ADR-0094 round-29 note. Start after the engine decision in #37; if the Durable Object cell wins, this issue is moot.

  • Issue a Cloudflare Origin CA certificate for a hostname in a zone the account owns (validity up to 15 years). verify_ca skips hostname verification, so the name does not have to match the cluster-local Service host.
  • Expose spec.certificates (serverTLSSecret, serverCASecret) in the shared chart as a strictly opt-in value, with the same shape as zoneSpread (research/0010:289-296). The nine other releases then see a chart version bump with byte-identical manifests; Q-0094.8 accepts that churn. Give the green copy in ApiraTech/helm-charts the same value.
  • Deliver the certificate and key through ESO like the other Thrust secrets, never through the repository. Mount them on thrust-pg-dev first, then on thrust-pg.
  • Set both VPC services back to verify_ca, and make verify_ca the default in variables.tf.
  • Fallback, if Workers VPC rejects the chain: ADR-0094 Option 2, i.e. the tunnel plus an Access application and a service token, which is a connection-string origin. Upload CNPG's CA to Hyperdrive (wrangler cert upload certificate-authority, then --ca-certificate-id and --sslmode verify-full).
  • Neither path has been tested. The first hyperdrive.sh ensure against the new mode is the test.

Acceptance criteria

  • thrust-pg-dev presents the Origin CA chain. Verify with OpenSSL 3 s_client -starttls postgres -CAfile <origin-ca.pem> and expect Verify return code: 0. Control: an unrelated throwaway CA must give a non-zero code; if the control passes, both results are void.
  • A clean tofu plan shows both VPC services at cert_verification_mode = verify_ca, hyperdrive.sh check passes for both configs, and a Worker reads ssl = true from pg_stat_ssl.
  • Control for the mode itself: a server certificate from a private CA still fails under verify_ca, as it did on 2026-10-18, so the check discriminates.
  • Chart change: just cnpg-cluster-conformance passes with the existing goldens unchanged, a raw helm template of the nine other releases is byte-identical before and after, and a mutation that always renders spec.certificates fails the conformance check.
  • Q-0094.9 is answered with the measured result, plane-byd.9 and infra-qnyi are closed, and the ADR-0094 note records which path shipped.

References

  • Review: .agents/plans/contrail/reviews/2026-10-19-fable-architecture-review.md (FR-09)
  • ADR-0094 (.agents/plans/contrail/adrs/infra/0094-postgres-hosting-cnpg-tunnel-vpc.md:53-56,82,111,120); infra repo ADR 0022 (D4, TLS wording, per ADR-0094:96)
  • Q-0094.9 (QUESTIONS.md:351), Q-0094.8 (QUESTIONS.md:345), Q-0094.2 (QUESTIONS.md:301)
  • research/0010-thrust-postgres-infra-plan.md:280-282,289-296,311,324
  • Cloudflare docs: workers-vpc/configuration/vpc-services; Hyperdrive CA upload (changelog 2025-04-09)
  • Beads: plane-byd.9, infra-qnyi

Blocked by: #37

Finding: FR-09

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:infraprio:p0review:fable-2026-10-19type:security

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions