Repository navigation
feat(db): connect to Postgres over TLS - #847
Merged
Merged
Conversation
Dipper's sqlx was built without TLS, so it could only reach Postgres in plain text: a `db.url` asking for `sslmode=require`, `verify-ca` or `verify-full` failed at startup, and a managed database that refuses unencrypted connections could not be used at all. sqlx now carries its rustls backend on aws-lc-rs, which dipper already builds for Kafka, so the only new crate is a small webpki-roots shim. `db.url`'s query string now sets the connection's TLS the way libpq's does: `verify-full`, `verify-ca` or `require`, and `sslrootcert=<path>` for a CA to trust beyond the public roots. Without `sslmode`, dipper now uses TLS when the server offers it (`prefer`, sqlx's default) instead of always staying in plain text; `prefer` does not check the certificate, so a server that offers TLS keeps working. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review found `sslmode=verify-ca` made dipper panic at startup. sqlx checks a certificate without its hostname through rustls's process-wide crypto provider, and with both of rustls's backends linked (ring through some dependencies, aws-lc-rs through others) rustls cannot pick one by itself. The Kafka producer installed aws-lc-rs, but only after the database connected. dipper now installs it first thing in main and again in `db::connect`, which a test without main also goes through; installing is idempotent and the producer installs the same provider. The one test only checked that dipper starts a TLS handshake. 6 tests now run a TLS server with a certificate from a throwaway CA: `verify-full` accepts it for its host and refuses it for another host or without the CA, `verify-ca` accepts it (which panicked before), and refuses it for another host. That last one is sqlx 0.8 with rustls 0.23: sqlx skips the name check only on the error rustls used to give for a mismatch, so `verify-ca` behaves as `verify-full`. The docs on `db.url` and in the k8s README now say so, recommend `verify-full` with a name the certificate covers, and add that `sslrootcert` adds to the public roots, takes effect only with a `verify-*` mode and applies to connections opened after it changes, and that `prefer` does not fall back to plain text when the handshake fails. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tgres-over-tls # Conflicts: # Cargo.lock # bin/dipper-service/Cargo.toml # bin/dipper-service/src/db.rs # k8s/README.md
cjorge-thegraph
marked this pull request as ready for review
November 19, 2026 20:22
cjorge-thegraph
added a commit
that referenced
this pull request
Nov 19, 2026
…res-and-iisa-at-start Resolves db.rs against #847 and #850. The startup probe now fails before the pool does, so a refused password check gets #850's explanation there as well, and the TLS tests, whose stub drops each connection after its handshake, set a 1s connect wait instead of waiting 120s out. Co-Authored-By: Claude Opus 5.5 <[email protected]>
MoonBoi9001
pushed a commit
that referenced
this pull request
Nov 23, 2026
🤖 I have created a release *beep* *boop* --- ## [0.3.4](v0.3.3...v0.3.4) (2026-11-23) ### Added * **config:** type secrets as such and read config from several files ([#857](#857)) ([fe92407](fe92407)) * **db:** connect to Postgres over TLS ([#847](#847)) ([2673181](2673181)) * **db:** let only 1 dipper process write, enforced by the database ([#858](#858)) ([6f88900](6f88900)) * **db:** make the database password optional ([#850](#850)) ([cb5d3b1](cb5d3b1)) * **metrics:** serve Prometheus metrics and optionally log as JSON ([#851](#851)) ([523819e](523819e)) * **rpc:** expose effective indexing targets and chain identity ([#860](#860)) ([aafc0ce](aafc0ce)) * **startup:** wait for Postgres and IISA instead of exiting ([#849](#849)) ([d1406d4](d1406d4)) ### Fixed * **db:** sslmode=verify-ca skips the hostname check, as libpq does ([#859](#859)) ([5fec97d](5fec97d)) * **k8s:** roll dipper out one pod at a time ([#846](#846)) ([de57e46](de57e46)) * **shutdown:** stop taking jobs first and fit the teardown in its budget ([#854](#854)) ([a1bc47d](a1bc47d)) ### Tests * run each test's Postgres on its Unix socket only ([#861](#861)) ([bc9e2b2](bc9e2b2)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.
Dipper's sqlx was built without TLS (
features = ["postgres", "time", "uuid"]), so it could only reach Postgres in plain text. Adb.urlwithsslmode=require,verify-caorverify-fullfailed at startup before sending anything, and a managed database that refuses unencrypted connections could not be used at all.tls-rustls-aws-lc-rs), which dipper already builds for Kafka. The only new crate is a smallwebpki-roots0.26 shim over the 1.0 already in the tree.db.url's query string sets the connection's TLS:verify-full,verify-ca,require, andsslrootcert=<path>for a CA to trust in addition to the public roots (only with averify-*mode). sqlx reads that file each time it opens a connection, so a replaced CA applies to connections opened after it.DbConfig.urlandk8s/README.mddocument it.Note
Without
sslmode, sqlx's defaultprefernow uses TLS when the server offers it, where dipper always stayed in plain text before.preferdoes not check the certificate, so a server that offers TLS keeps working.Tests:
sslmode_require_starts_a_tls_handshakeruns a stub server that accepts the SSLRequest and checks the next bytes are a TLS handshake. Onmaindipper hung up without asking for TLS (early eof); now it passes.just fmt-check,just checkandjust test-unitpass locally.Changes after review
sslmode=verify-ca. sqlx checks such a certificate through rustls's process-wide crypto provider, and with both of rustls's backends linked (ring and aws-lc-rs) rustls could not pick one. dipper now installs aws-lc-rs first thing inmainand again indb::connect(idempotent; the Kafka producer installs the same one). The earlier claim that there was no ambiguous default provider was wrong.verify-cabehaves asverify-fullfor now. sqlx 0.8 skips the name check only on the mismatch error rustls used to return; rustls 0.23 returns a newer one. A test pins this, so a sqlx that fixes it fails the test and prompts a docs update. The docs recommendverify-fullwith a name the certificate covers, and no longer suggestverify-cafor a private IP.verify-fullaccepts it for its host and refuses it for another host or without the CA;verify-caaccepts it (this panicked before) and refuses it for another host.preferdoes not fall back to plain text when a TLS handshake fails.🤖 Generated with Claude Code