From 144b488a6d1fb966734e3c1c6d21e5ff0e012102 Mon Sep 17 00:00:00 2001 From: Brobb954 <119805322+Brobb954@users.noreply.github.com> Date: Thu, 4 Jul 2024 10:21:17 -0600 Subject: [PATCH 1/3] Update rustls exmaple for work with newest updates to the crate. Also README section added to point out the need for this example --- README.md | 5 +++++ examples/postgres/pooled-with-rustls/src/main.rs | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e945352..31ecae0 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/examples/postgres/pooled-with-rustls/src/main.rs b/examples/postgres/pooled-with-rustls/src/main.rs index 9983099..cbf79e2 100644 --- a/examples/postgres/pooled-with-rustls/src/main.rs +++ b/examples/postgres/pooled-with-rustls/src/main.rs @@ -63,7 +63,6 @@ fn establish_connection(config: &str) -> BoxFuture 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 } From 1f51d3153a1680cc259ec5329dafba094e58702d Mon Sep 17 00:00:00 2001 From: Georg Semmler Date: Fri, 5 Jul 2024 14:01:13 +0200 Subject: [PATCH 2/3] Update rustls to work as expected --- examples/postgres/pooled-with-rustls/Cargo.toml | 8 ++++---- examples/postgres/pooled-with-rustls/src/main.rs | 1 - .../run-pending-migrations-with-rustls/Cargo.toml | 10 +++++----- .../run-pending-migrations-with-rustls/src/main.rs | 4 +--- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/examples/postgres/pooled-with-rustls/Cargo.toml b/examples/postgres/pooled-with-rustls/Cargo.toml index 257c0c1..a646848 100644 --- a/examples/postgres/pooled-with-rustls/Cargo.toml +++ b/examples/postgres/pooled-with-rustls/Cargo.toml @@ -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" diff --git a/examples/postgres/pooled-with-rustls/src/main.rs b/examples/postgres/pooled-with-rustls/src/main.rs index cbf79e2..a18451c 100644 --- a/examples/postgres/pooled-with-rustls/src/main.rs +++ b/examples/postgres/pooled-with-rustls/src/main.rs @@ -43,7 +43,6 @@ fn establish_connection(config: &str) -> BoxFuture BoxFuture BoxFuture 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 } From 3d5cf55decfdfa9eb74228830a318a6177d69fcd Mon Sep 17 00:00:00 2001 From: Georg Semmler Date: Fri, 5 Jul 2024 14:19:52 +0200 Subject: [PATCH 3/3] CI fixes --- .github/workflows/ci.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f5fd5f2..20ecb70 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: |