Skip to content

fix(db): sslmode=verify-ca skips the hostname check, as libpq does - #859

Merged
cjorge-thegraph merged 2 commits into
mainfrom
carlos/sqlx-verify-ca-name-context
Nov 21, 2026
Merged

cjorge-thegraph merged 2 commits into
mainfrom
carlos/sqlx-verify-ca-name-context

Conversation

@cjorge-thegraph

@cjorge-thegraph cjorge-thegraph commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

sslmode=verify-ca now skips the hostname check, as libpq does, so dipper can verify a Cloud SQL private-IP instance's certificate.

Problem

  • A Cloud SQL private-IP (PSA) instance's server certificate carries one name only: its DNS name with a trailing dot, e.g. DNS:d0b150ab5022.76ws9odrdkfn.us-central1.sql-psa.goog.. rustls (webpki) never accepts a presented name with a trailing dot, so verify-full can't connect, whatever the URL says.
  • verify-ca should be the answer (check the chain against sslrootcert, skip the name), but with sqlx 0.8 it behaves as verify-full. sqlx's NoHostnameTlsVerifier swallows only CertificateError::NotValidForName, while rustls ≥ 0.23.24 returns CertificateError::NotValidForNameContext. dipper's own test verify_ca_still_checks_the_hostname recorded exactly this and said to update the docs once a later sqlx fixed it.
  • Seen on testnet's dipper on Cloud SQL (2026-11-21): invalid peer certificate: certificate not valid for name "<host>"; certificate is only valid for DnsName("<host>."). It runs with sslmode=require (encrypted, unverified) until this lands.

Fix

  • sqlx 0.8.2 → 0.9.1. sqlx fixed the verifier upstream (Fix NoHostnameTlsVerifier for rustls 0.23.24 and above transact-rs/sqlx#3861, Fix NoHostnameTlsVerifier for rustls 0.23.24 and above); it shipped in 0.9.0 and no 0.8.x has it. sqlx 0.8 has no hook to plug in a verifier of dipper's own, so the bump is the fix.
  • Rust 1.91.0 → 1.94.0 (rust-toolchain.toml, both Dockerfiles; rust:1.94.0-slim-bookworm exists), which sqlx 0.9 requires.
  • sqlx 0.9 API changes:
    • ArgumentBuffer has no lifetime.
    • [u8; N] now also implements Type/Encode for Any, so the bytea new-types name Postgres.
    • The one dynamically built query is wrapped in AssertSqlSafe, because only numbered placeholders are interpolated and the values are bound.
  • Docs: db.url describes verify-ca as it now behaves, with Cloud SQL as the example.

Tests

  • verify_ca_still_checks_the_hostname → verify_ca_skips_the_hostname_check.
  • New: verify_ca_accepts_a_cloud_sql_certificate (a CA-signed certificate whose only name has a trailing dot), verify_full_refuses_a_cloud_sql_certificate_even_by_its_name (why verify-ca is the mode to use there) and verify_ca_still_refuses_a_certificate_from_an_unknown_ca (the chain is still checked).
  • Local, Rust 1.94.0:
    • cargo clippy --all-targets -- -D warnings --force-warn deprecated -D dead-code: clean.
    • cargo +nightly fmt --check: clean.
    • Unit tests: 1085 passed, 0 failed (db::tests: 12/12).
    • Integration tests (tests::it_): 12 passed, 0 failed (pgtemp Postgres); the public-API integration tests (--test '*') run in CI.

Not in this PR

  • No release. After it's released, the testnet deployment switches db.url from sslmode=require to sslmode=verify-ca.

🤖 Generated with Claude Code

cjorge-thegraph and others added 2 commits November 21, 2026 14:44
sqlx 0.8 skips the name check for verify-ca only when rustls returns
CertificateError::NotValidForName; rustls 0.23.24 and later return
NotValidForNameContext instead, so verify-ca behaved as verify-full.
sqlx 0.9 accepts both (transact-rs/sqlx#3861). It needs Rust 1.94.

This matters for Cloud SQL private-IP instances: their server
certificate names only the instance's DNS name with a trailing dot,
which rustls never accepts as a presented name, so neither verify-full
nor (until now) verify-ca could connect.

- sqlx 0.8.2 -> 0.9.1; Rust 1.91.0 -> 1.94.0 (toolchain, Dockerfiles).
- sqlx 0.9 API: ArgumentBuffer has no lifetime; [u8; N] also implements
  Type/Encode for Any, so the bytea new-types name Postgres; the one
  dynamic query is marked AssertSqlSafe (only numbered placeholders are
  interpolated).
- Tests: verify_ca_still_checks_the_hostname becomes
  verify_ca_skips_the_hostname_check; new tests for a Cloud SQL style
  certificate (trailing-dot name) and an unknown CA under verify-ca.
- db.url docs describe verify-ca as it now behaves.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
sqlx 0.9 takes SQL as SqlSafeStr; the fixture loader passes the repository's own SQL files.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cjorge-thegraph
cjorge-thegraph marked this pull request as ready for review November 21, 2026 15:17
@cjorge-thegraph
cjorge-thegraph merged commit 5fec97d into main Nov 21, 2026
13 checks passed
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>
@MoonBoi9001
MoonBoi9001 deleted the carlos/sqlx-verify-ca-name-context branch November 26, 2026 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant