Skip to content

Allow running tokio-postgres with rustls - #426

Merged
jxs merged 9 commits into
rust-db:mainfrom
tomasol:pr-rustls-postgres
Apr 27, 2026
Merged

Allow running tokio-postgres with rustls#426
jxs merged 9 commits into
rust-db:mainfrom
tomasol:pr-rustls-postgres

Conversation

@tomasol

@tomasol tomasol commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

This adds tokio-postgres-rustls feature, which in turn adds tokio-postgres-rustls dependency.
This makes it possible to use rustls instead of openssl for TLS termination. It only works for async connections.

Please note: I have added ISC to the list of allowed licenses, as this check was failing.

tomasol and others added 3 commits April 22, 2026 19:24
When tokio-postgres or postgres features are enabled without the tls
feature, config.rs still referenced native_tls and postgres_native_tls
crates that are no longer pulled in. Guard those code paths with
#[cfg(feature = "tls")] so that no-TLS builds do not require openssl.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Instead of silently falling back to an unencrypted connection when
use_tls() is true but the 'tls' feature is disabled, panic with a
clear message so the misconfiguration is immediately visible.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds a new `tokio-postgres-rustls` feature to refinery/refinery-core
that provides TLS for the config-based tokio-postgres connection path
using rustls instead of native-tls/openssl.

Design: no crypto provider is bundled. Callers must install a global
provider (e.g. ring or aws-lc-rs) before running migrations with TLS.
System trust roots are loaded via rustls-native-certs. When use_tls()
is true but the feature is disabled, a clear panic is raised.

Note: tokio-postgres-rustls 0.13 has an unconditional ring dep for
certificate fingerprinting (unrelated to the TLS crypto provider).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@tomasol
tomasol force-pushed the pr-rustls-postgres branch from ce4d5a2 to 2a06555 Compare April 22, 2026 17:27

@jxs jxs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, and thanks for this, overall looks good to me! Can you add a test case for this? I think we have one for the native tls one

@tomasol
tomasol force-pushed the pr-rustls-postgres branch from e1d4b7b to 2d55cf1 Compare April 23, 2026 19:20
Also make postgres connection string configurable via `POSTGRES_URL` environment
variable.
@tomasol
tomasol force-pushed the pr-rustls-postgres branch from 2d55cf1 to 70e90e0 Compare April 23, 2026 19:36
@tomasol
tomasol requested a review from jxs April 25, 2026 20:13
@tomasol

tomasol commented Apr 25, 2026

Copy link
Copy Markdown
Contributor Author

Hi, and thanks for this, overall looks good to me! Can you add a test case for this? I think we have one for the native tls one

sure, I've added a test.

@jxs jxs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@jxs
jxs merged commit 6074795 into rust-db:main Apr 27, 2026
56 of 58 checks passed
@tomasol

tomasol commented Apr 27, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for working on this awesome library!

jxs added a commit that referenced this pull request Jun 10, 2026
* Prepare 0.9.2

- Bump versions to 0.9.2 in all crates
- Update inter-crate dependency references
- Add 0.9.2 changelog entries for TLS opt-in (#408),
  tokio-postgres-rustls feature (#426), rusqlite 0.39.x (#425),
  and toml 1.1.2 (#430)

* Bump mysql to 0.28.x and mysql_async to 0.37.x

* Apply suggestion from @jxs

* Apply suggestion from @jxs
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.

2 participants