Skip to content

fix(db): enforce verified TLS when configured - #592

Merged
imshashank merged 2 commits into
mainfrom
codex/fix-verified-database-tls
Nov 16, 2026
Merged

imshashank merged 2 commits into
mainfrom
codex/fix-verified-database-tls

Conversation

@imshashank

Copy link
Copy Markdown
Contributor

Adds an explicit DATABASE_REQUIRE_TLS policy across the application pool, schema checks, migrations and backup/recovery connections. Optional public CA certificates augment runtime trust; certificate and hostname verification remain required even when URL or PGSSL settings request weaker modes. Local defaults remain unchanged.

Native pg_dump and pg_restore receive a verified temporary CA context with owner-only permissions and cleanup after success, failure or cancellation. Pool cache identity includes the TLS policy. No migration is required.

Validation: clean full verify passed 7,148 tests with zero failures or skips on ee3e72d; all static and type checks passed. Actual Node24 TLS fixtures cover trusted certificates, incorrect CA/hostname, literal IP identity and TLS refusal. Native adapter cleanup tests and real pg_dump17 loopback TLS controls also passed. Deployment configuration and production promotion remain separate release steps.

@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

Walkthrough

The change adds an opt-in verified PostgreSQL TLS policy, applies its options to database and backup service connections, and uses verified TLS URLs for native database dump and restore operations.

Changes: PostgreSQL TLS policy and connections

Layer / File(s) Summary
Define and validate the TLS policy
.env.example, docs/database-tls.md, packages/shared/src/validators/*, packages/db/src/tls-policy.ts, packages/db/tests/tls-policy.test.ts, packages/db/tests/fixtures/tls-node.ts
The environment schema defaults DATABASE_REQUIRE_TLS to false and validates optional CA input. The policy requires certificate verification when enabled, supports additional CA certificates, and rejects invalid or unsupported configuration. Tests cover policy validation and TLS connection outcomes.
Apply TLS options to database clients
packages/db/package.json, packages/db/src/client.ts, packages/db/src/apply-catchup.ts, packages/db/src/check-drift.ts, packages/db/src/drop-test-lanes.ts, packages/db/src/ensure-extensions.ts, packages/db/src/ensure-test-databases.ts, packages/db/src/migration-release.ts, packages/db/src/test-lane.ts, packages/db/tests/client.test.ts, packages/db/tests/fixtures/tls-wiring.ts, packages/db/tests/tls-wiring.test.ts
The database package exports the TLS policy. Database pools include resolved TLS settings in their cache keys, and database maintenance and migration connections receive URL-specific TLS options. Tests check pool keys and selected connection paths.
Apply TLS options to backup service clients
packages/services/src/backup/preflight.ts, packages/services/src/backup/readiness.ts, packages/services/src/backup/recovery-drill.ts, packages/services/src/backup/snapshot.ts, packages/services/src/backup/upgrade-matrix.ts, packages/services/src/backup/validate.ts
Backup preflight, readiness, recovery, snapshot, upgrade, and validation clients receive TLS options derived from their connection URLs.
Configure TLS for native dump and restore
packages/services/src/backup/database-tls.ts, packages/services/src/backup/database.ts, packages/services/src/backup/restore-database.ts, packages/services/tests/backup/database-tls.test.ts
Dump and restore run through a TLS context that writes CA certificates to a temporary PEM file and supplies a verify-full URL. Tests cover password handling, process outcomes, cancellation, and temporary-file cleanup.

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant dumpDatabase
  participant withDatabaseTlsContext
  participant pg_dump
  dumpDatabase->>withDatabaseTlsContext: Pass sanitized database URL and operation
  withDatabaseTlsContext->>withDatabaseTlsContext: Write CA bundle to temporary PEM file
  withDatabaseTlsContext->>pg_dump: Provide verify-full URL with sslrootcert
  pg_dump-->>withDatabaseTlsContext: Return process result
  withDatabaseTlsContext->>withDatabaseTlsContext: Remove temporary directory
  withDatabaseTlsContext-->>dumpDatabase: Return operation result
Loading

Suggested reviewers: pallavikumarimdb

Merge Risk: Moderate · up to ee3e7

This adds an opt-in setting that requires verified TLS for PostgreSQL connections. When it is enabled, some connection forms can still skip verification, and some valid multi-host URLs are rejected. Default behavior is unchanged. Resolve the security gaps in the native backup helper and the IP identity handling before relying on the policy.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@github-actions github-actions Bot added documentation Docs, the README, or anything that explains Orbit tests Test coverage and test infrastructure area: database Schema, migrations, queries, seed dependencies Dependency updates labels Nov 16, 2026
@imshashank
imshashank marked this pull request as ready for review November 16, 2026 21:05
@imshashank
imshashank requested a review from pulkitxm as a code owner November 16, 2026 21:05
@vercel

vercel Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
orbit Ready Ready Preview Nov 16, 2026 9:10pm UTC

Request Review

Copy link
Copy Markdown
Contributor Author

Independent review found no remaining code blocker. Full local bun run verify passed7,148 tests with0 failures/0 skipped at exact ee3e72d4; actual Node/native controls cover trusted certificates, hostname validation, untrusted/wrong-host certificates and no plaintext fallback. All six exact-head CI jobs, both CodeQL workflows, recovery, docs and link checks pass.

A separate never-promoted staged diagnostic using this exact client/TLS policy is READY. Its actual Node24.22.3 pool reports verified TLS with the official public Supabase CA, and the unchanged canonical production schema guard connected successfully. It has zero actual aliases; public application and cron targets remain on the prior release. The two new public TLS settings were added for future production/preview deployments without changing credentials. A fresh normal exact-source preview under these project settings is required before merge. No schema migration is required by this PR.

@imshashank
imshashank merged commit b00577e into main Nov 16, 2026
19 of 20 checks passed
@imshashank
imshashank deleted the codex/fix-verified-database-tls branch November 16, 2026 21:11

Copy link
Copy Markdown
Contributor Author

Released reviewed main squash b00577e as normal production deployment dpl_A2EVrnDuRGjp4yXp3ZCKExHRgvpe; its tree exactly matches reviewed ee3e72d4. Public health200, realtime Redisready under Node24.22.3 and authenticated reads passed. The complete active firewall10 comparison against historical9 confirms only the scheduler hostname changed, with no unrelated policy changes or pending draft. One transitional notification cron got403 before the hostname update; subsequently15 natural requests spanning419.93seconds allreturned200 with the scheduled cron useragent. No error/fatal runtime log groups were retrieved on the new deployment. Diagnostic deployments were never promoted. Existing GitHub App authentication401s and the Supabase quota restriction remain separately tracked.

This branch was successfully deployed

1 active deployment
Preview — ee3e72d4 Deployed Nov 16, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: database Schema, migrations, queries, seed dependencies Dependency updates documentation Docs, the README, or anything that explains Orbit tests Test coverage and test infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant