Skip to content

Update Rustls example and add to README for clarification #163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,21 @@ jobs:
run: |
echo "RUST_TEST_THREADS=1" >> $GITHUB_ENV

- name: Set environment variables
shell: bash
if: matrix.backend == 'postgres' && matrix.os == 'windows-2019'
run: |
echo "AWS_LC_SYS_NO_ASM=1"

- name: Set environment variables
shell: bash
if: matrix.rust == 'nightly'
run: |
echo "RUSTFLAGS=--cap-lints=warn" >> $GITHUB_ENV

- uses: ilammy/setup-nasm@v1
if: matrix.backend == 'postgres' && matrix.os == 'windows-2019'

- name: Install postgres (Linux)
if: runner.os == 'Linux' && matrix.backend == 'postgres'
run: |
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ let mut conn = pool.get().await?;
let res = users::table.select(User::as_select()).load::(&mut conn).await?;
```

## Diesel-Async with Secure Database

In the event of using this crate with a `sslmode=require` flag, it will be necessary to build a TLS cert.
There is an example provided for doing this using the `rustls` crate in the `postgres` examples folder.

## Crate Feature Flags

Diesel-async offers several configurable features:
Expand Down
8 changes: 4 additions & 4 deletions examples/postgres/pooled-with-rustls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
diesel = { version = "2.1.0", default-features = false, features = ["postgres"] }
diesel = { version = "2.2.0", default-features = false, features = ["postgres"] }
diesel-async = { version = "0.4.0", path = "../../../", features = ["bb8", "postgres"] }
futures-util = "0.3.21"
rustls = "0.20.8"
rustls-native-certs = "0.6.2"
rustls = "0.23.8"
rustls-native-certs = "0.7.1"
tokio = { version = "1.2.0", default-features = false, features = ["macros", "rt-multi-thread"] }
tokio-postgres = "0.7.7"
tokio-postgres-rustls = "0.9.0"
tokio-postgres-rustls = "0.12.0"
4 changes: 1 addition & 3 deletions examples/postgres/pooled-with-rustls/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ fn establish_connection(config: &str) -> BoxFuture<ConnectionResult<AsyncPgConne
let fut = async {
// We first set up the way we want rustls to work.
let rustls_config = rustls::ClientConfig::builder()
.with_safe_defaults()
.with_root_certificates(root_certs())
.with_no_client_auth();
let tls = tokio_postgres_rustls::MakeRustlsConnect::new(rustls_config);
Expand All @@ -63,7 +62,6 @@ fn establish_connection(config: &str) -> BoxFuture<ConnectionResult<AsyncPgConne
fn root_certs() -> rustls::RootCertStore {
let mut roots = rustls::RootCertStore::empty();
let certs = rustls_native_certs::load_native_certs().expect("Certs not loadable!");
let certs: Vec<_> = certs.into_iter().map(|cert| cert.0).collect();
roots.add_parsable_certificates(&certs);
roots.add_parsable_certificates(certs);
roots
}
10 changes: 5 additions & 5 deletions examples/postgres/run-pending-migrations-with-rustls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
diesel = { version = "2.1.0", default-features = false, features = ["postgres"] }
diesel = { version = "2.2.0", default-features = false, features = ["postgres"] }
diesel-async = { version = "0.4.0", path = "../../../", features = ["bb8", "postgres", "async-connection-wrapper"] }
diesel_migrations = "2.1.0"
diesel_migrations = "2.2.0"
futures-util = "0.3.21"
rustls = "0.20.8"
rustls-native-certs = "0.6.2"
rustls = "0.23.10"
rustls-native-certs = "0.7.1"
tokio = { version = "1.2.0", default-features = false, features = ["macros", "rt-multi-thread"] }
tokio-postgres = "0.7.7"
tokio-postgres-rustls = "0.9.0"
tokio-postgres-rustls = "0.12.0"
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ fn establish_connection(config: &str) -> BoxFuture<ConnectionResult<AsyncPgConne
let fut = async {
// We first set up the way we want rustls to work.
let rustls_config = rustls::ClientConfig::builder()
.with_safe_defaults()
.with_root_certificates(root_certs())
.with_no_client_auth();
let tls = tokio_postgres_rustls::MakeRustlsConnect::new(rustls_config);
Expand All @@ -49,7 +48,6 @@ fn establish_connection(config: &str) -> BoxFuture<ConnectionResult<AsyncPgConne
fn root_certs() -> rustls::RootCertStore {
let mut roots = rustls::RootCertStore::empty();
let certs = rustls_native_certs::load_native_certs().expect("Certs not loadable!");
let certs: Vec<_> = certs.into_iter().map(|cert| cert.0).collect();
roots.add_parsable_certificates(&certs);
roots.add_parsable_certificates(certs);
roots
}
Loading