Repository navigation
3.x.x: let sslmode=verify-ca accept a CA-valid certificate whatever its host name (backport launchbadge/sqlx#3861) (#713) - #807
Conversation
…er name, backporting transact-rs/sqlx#3861 (#713) Cause. sqlx-postgres runs sslmode=verify-ca through sqlx-core's NoHostnameTlsVerifier. It runs rustls's WebPKI checks, which verify the chain before the name, and accepts the certificate when the name is the only failure. sqlx-core 0.8.6 matched only CertificateError:: NotValidForName, but rustls 0.23.24 and later (the lock has 0.23.46) report a name mismatch as NotValidForNameContext. So verify-ca refused a CA-signed certificate for another name, as verify-full does. The load harness's delay proxy is dialled as 127.0.0.1 with sslmode kept, so a verify-ca run through it failed with "certificate not valid for name 127.0.0.1". Change. - vendor/sqlx-core carries transact-rs/sqlx#3861 (merge 2970559e, first released in 0.9.0) as upstream wrote it, without its Cargo.lock hunk: the verifier matches NotValidForName | NotValidForNameContext { .. }, and sqlx-core's rustls requirement rises from 0.23.15 to 0.23.24, the first release with that variant (Cargo.toml.orig and the same requirement in Cargo.toml). Both lock files already build rustls 0.23.46, so neither changes. Every other error and every other sslmode are unchanged, and verify-full still checks the name. - vendor/sqlx-core/README.md records it as the second local change next to #4251, with its regression test and the 0.9.0 removal condition. The root Cargo.toml, the check script's docstring and the server's dev-dependency comment name both fixes. - crates/qbit-prism-load/README.md's --database-url row says sslmode is kept, that verify-full refuses the certificate through the proxy at 127.0.0.1, and that verify-ca passes. #713's interim advice to use sslmode=require is not needed with the fix. The test. tests/sqlx_tls_verify_ca.rs runs sqlx-core's rustls client against a rustls server over an in-memory socket, polling by hand, with a CA, a server certificate it signs for db.internal only, and the same certificate from an untrusted issuer, all Ed25519 from fixed seeds. verify-ca at 127.0.0.1 connects; verify-full there is refused with NotValidForNameContext for 127.0.0.1; both connect for db.internal; and verify-ca still refuses the untrusted issuer as UnknownIssuer. Against the unpatched verifier only the first fails, with the #713 error. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
| | `--example-artifact` | off | Emit `artifact_kind: example` from a clean tree | | ||
| | `--pg-bin-dir` | `QBIT_PRISM_LOAD_PG_BIN_DIR`, then `pg_config --bindir` | PostgreSQL server binaries. The harness keeps its own variable rather than reading one of the shared test-gate variables, which belong to the gate crate (#322) | | ||
| | `--database-url` | none | Use an existing database; no standby is managed, and the replication mode is detected, never assumed: it must be the one `--replication` declares, at entry and again after the load, or the run exits 8. The host may be a name: the delay proxy resolves it once at entry and records the addresses in the side report's `delay_proxy` block. The libpq-style `host`, `hostaddr` and `port` parameters are honoured for the proxy's upstream and dropped from the URL the frontends receive, because SQLx applies them over the authority and they would otherwise route every frontend around the proxy; every other option is kept | | ||
| | `--database-url` | none | Use an existing database; no standby is managed, and the replication mode is detected, never assumed: it must be the one `--replication` declares, at entry and again after the load, or the run exits 8. The host may be a name: the delay proxy resolves it once at entry and records the addresses in the side report's `delay_proxy` block. The libpq-style `host`, `hostaddr` and `port` parameters are honoured for the proxy's upstream and dropped from the URL the frontends receive, because SQLx applies them over the authority and they would otherwise route every frontend around the proxy; every other option is kept, `sslmode` included. The frontends dial the proxy as `127.0.0.1`, so `sslmode=verify-full` refuses the database's certificate for its name there; `verify-ca` checks the certificate against the trusted CAs (`sslrootcert`) and not the name, so it passes through the proxy (#713) | |
There was a problem hiding this comment.
1. [medium · security] verify-ca now accepts any public-CA certificate for any name, though the README says it checks sslrootcert
crates/qbit-prism-load/README.md:120
vendor/sqlx-core/src/net/tls/tls_rustls.rs:141 always starts the trust store from certs_from_webpki(), the Mozilla public roots. sqlx's runtime-tokio-rustls feature, used in crates/qbit-prism-server/Cargo.toml:42, selects that store. Lines 145-155 then add sslrootcert to it rather than replacing it. Before this PR, NoHostnameTlsVerifier did not match NotValidForNameContext, so verify-ca still checked the name. Now lines 309-311 accept any chain that WebPKI validates, whatever the name. Anyone on the path between the delay proxy and the database, or between any sqlx client using verify-ca and its server, can present an ordinary publicly issued certificate for their own domain (for example one from Let's Encrypt). The connection is accepted and the credentials and data are exposed. libpq's verify-ca trusts only sslrootcert. The new README text (line 120) says verify-ca checks the certificate against the trusted CAs (sslrootcert), which leads operators to use verify-ca through the proxy, believing the database certificate is still pinned to their CA. It is not.
…ssued certificate can't pass it (follow-up to #807) (#818) * vendor/sqlx-core: under sslmode=verify-ca, trust only sslrootcert sqlx-core seeds its rustls trust store with Mozilla's public roots and adds the sslrootcert certificates to them, for every mode that verifies certificates. With the #3861 backport (#807), verify-ca no longer checks the host name, so any certificate that chains to a public root passed for any name, such as a Let's Encrypt certificate for an attacker's own domain, and sqlx-postgres then answers a cleartext password request. 3.1.0 still refused the name mismatch, so 3.1.1 as it stood weakened every verify-ca configuration. As libpq does, verify-ca's verifier now starts from an empty root store and holds only the sslrootcert certificates. verify-ca without sslrootcert, or with one holding no certificate, fails with a configuration error naming sslrootcert before the TLS handshake starts. verify-full, require, prefer and allow are unchanged. This is a local change, not upstream's: vendor/sqlx-core/README.md records it, and says to check upstream's verify-ca trust store before dropping the directory. sqlx_tls_verify_ca.rs gains three tests, each failing without the change: verify-ca without sslrootcert, and with one holding no certificate, is a configuration error with no byte sent; and a certificate naming ISRG Root X1 as its issuer is refused as from an unknown issuer under verify-ca, while verify-full, which keeps the public roots, takes that root as the issuer and refuses the signature. The load harness README and the comments describing the vendored crate say so too. Co-Authored-By: Claude Opus 5.5 <[email protected]> * doc: 3.1.1 notes: verify-ca trusts only sslrootcert, and its upgrade note The #807 bullet said verify-ca checks against sslrootcert as libpq does, which it did not: it also trusted the public roots. It now says verify-ca checks the chain against sslrootcert only and not the name, that it is refused without sslrootcert, and to use verify-full wherever the certificate's names match. The upgrade note tells an operator with a verify-ca URL and no sslrootcert to switch to verify-full, which is 3.1.0's check and survives a rollback, or to set sslrootcert. Co-Authored-By: Claude Opus 5.5 <[email protected]> * verify-ca test: the verify-full control asserts only a known issuer; fuzz patch comment verify_ca_does_not_trust_the_public_roots's verify-full control asserted the exact signature error rustls reports for a certificate that names ISRG Root X1 as its issuer. Which error comes back depends on how webpki ranks its errors, so the control now asserts only that the issuer was not unknown, which is what shows a public root was a candidate. Its message names a webpki-roots change as the likely cause. verify-ca's UnknownIssuer assertion is unchanged. The fuzz workspace's [patch.crates-io] comment now describes the vendored crate as the root Cargo.toml's does: both backports and the local verify-ca change. Co-Authored-By: Claude Opus 5.5 <[email protected]> * doc: 3.1.1 notes: verify-ca refuses a chain sslrootcert doesn't anchor; verify-full still trusts the public roots The upgrading note warned only about verify-ca without sslrootcert. It now also says that verify-ca trusts only sslrootcert's certificates, so a URL whose sslrootcert does not anchor the server's chain, such as one for a publicly issued certificate 3.1.0 accepted through the public roots, fails with an unknown-issuer error. The fix is verify-full, or an sslrootcert that names the CA that actually signs the certificate. The #807 bullet now says verify-full is unchanged and still trusts the public roots beside sslrootcert, unlike libpq's verify-full, so only verify-ca now matches libpq. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Fixes #713. With the sqlx-core vendored in #794,
sslmode=verify-castill checked the host name. The verify-ca verifier accepted onlyCertificateError::NotValidForName, but rustls 0.23.46 reportsNotValidForNameContext, so a CA-valid certificate whose name didn't match was refused. The load harness rewrites the host to 127.0.0.1 and keeps sslmode, so a verify-ca run through its delay proxy always failed.What changes
vendor/sqlx-coreexactly as upstream wrote it, without its Cargo.lock hunk.NoHostnameTlsVerifier, which sqlx-postgres uses only for verify-ca, now acceptsNotValidForName | NotValidForNameContext. verify-full is unchanged and still checks the name.Cargo.toml, the check script and the dev-dependency comments name both fixes. The qbit-prism-load README says verify-full is refused through the 127.0.0.1 proxy while verify-ca passes.Tests
tests/sqlx_tls_verify_ca.rs, using an in-memory socket polled by hand and Ed25519 certificates from fixed seeds. It covers four cases:NotValidForNameContext;UnknownIssuer).sqlx_tls_readiness2/2,check_vendored_sqlx_core.pyand its 11 unit tests, fmt, clippy and the guards pass.🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need.