Skip to content

refactor: overhaul RusTLS features - #4553

Draft
abonander wants to merge 11 commits into
mainfrom
ab/rustls-overhaul
Draft

abonander wants to merge 11 commits into
mainfrom
ab/rustls-overhaul

Conversation

@abonander

@abonander abonander commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

This PR is intended to be backwards-compatible, so the plan doesn't match #4408 exactly. However, I think this is a significant step in the right direction.

Please help test it and report any regressions.

Cargo Feature Changes

The intention is to decompose the TLS features in the same way that was previously done to the runtime-* features.

This PR adds a few temporary features to provide a migration path for changes to their existing counterparts:

  • Added tls-rustls-base which enables rustls but no crypto provider or TLS roots. In the future this will be folded into tls-rustls.
  • Added tls-rustls-aws-lc-rs-no-roots which enables the aws-lc-rs crypto provider without setting any TLS roots. In the future, this will be folded into tls-rustls-aws-lc-rs.
  • Added tls-rustls-ring-no-roots which does the same thing for ring.

These features are additive with the new TLS root features:

  • tls-rustls-native-roots enables just native roots without explicitly enabling a crypto provider.
  • tls-rustls-webpki-roots does the same for webpki-roots.

I considered adding rustls-platform-verifier but as discussed in #4408, I'm rather uncomfortable with how platform-dependent its guarantees are, and I am still worried about it exacerbating #3211. However, it's at least now possible to use rustls-platform-verifier by building a custom rustls::ClientConfig.

The existing combination features (e.g. tls-rustls-aws-lc-rs-native-roots) are hereby deprecated by this PR, though we unfortunately don't have a good way to signal this to the user.

Also documented are some future breaking changes (targeted for 0.10):

  • tls-rustls will subsume tls-rustls-base; it will no longer imply tls-rustls-ring.
  • tls-rustls-ring and tls-rustls-aws-lc-rs will subsume their -no-roots counterparts and no longer imply webpki-roots.

New APIs

MySqlConnectOptions and PgConnectOptions gain the following setters:

  • ssl_include_root_bundle, a boolean flag that enables or disables the root bundle provided by native-roots or webpki-roots.
  • rustls_crypto_provider, which allows setting a custom CryptoProvider. Included is an example for rustls-graviola since I'm not quite comfortable providing it as a default option yet due to its immaturity.
    • This patch does not enable the use of the process-global CryptoProvider (CryptoProvider::get_default()) because that API will be deleted in RusTLS 0.24. It thus does not make sense to write code that depends on this API. Instead, you can use the new setter to pass the global CryptoProvider yourself.
  • rustls_client_config allows passing a full rustls::ClientConfig which can bypass most of SQLx's default behavior regarding TLS. Besides MySqlSslMode/PgSslMode, which control whether the TLS handshake is made at all, all other TLS configuration options become no-ops.
    • This is the only option that takes precedent over the tls-native-tls feature if that is also enabled, which allows overriding native TLS if a transitive dependency enables it unconditionally.
    • ConnectOptions::to_url_lossy() adds danger-custom-rustls-config=true to the URL. Parsing a URL with this parameter will require rustls_client_config before attempting to connect, or else an error will be returned.

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