Skip to content

Commit beefef3

Browse files
committed
fix: rustls - explicitly setting the process wide default crypto provider
1 parent 707f959 commit beefef3

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rustrial-k8s-aws-iam-controller/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ kube = { workspace = true, features = [
2424
"client",
2525
"rustls-tls",
2626
] }
27+
# TODO: make sure the following rustls version matches the one used by kube, tokio, hyper, ...
28+
# as we have to call CryptoProvider::install_default() on the appropriate crate version used
29+
# by those other crates (see main.rs).
30+
rustls = { version = "0.23.20", features = ["aws_lc_rs"]}
2731
json-patch = "3.0.1"
2832
kube-runtime = "0.98.0"
2933
schemars = {workspace = true}

rustrial-k8s-aws-iam-controller/src/main.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use kube::{Api, Client, Config};
1010
use kube_runtime::{reflector, reflector::store::Writer, watcher};
1111
use log::{error, info, warn};
1212
use metrics_exporter_prometheus::PrometheusBuilder;
13+
use rustls::crypto;
1314
use rustrial_k8s_aws_iam_apis::{RoleUsagePolicy, TrustPolicyStatement};
1415
use std::future::pending;
1516

@@ -136,6 +137,16 @@ async fn get_aws_provider() -> anyhow::Result<SdkConfig> {
136137

137138
#[tokio::main]
138139
async fn main() -> anyhow::Result<()> {
140+
// We must explicitly set the process wide default crypto provider for rustls, see
141+
// https://docs.rs/rustls/latest/rustls/crypto/struct.CryptoProvider.html.
142+
// Otherwise we will get the following runtime error:
143+
// "no process-level CryptoProvider available -- call CryptoProvider::install_default() before this point"
144+
//
145+
// This is necessary, as several of our dependencies (transitively) depend on rustls with overlapping
146+
// crypto provider (ring vs aws-lc-sys) features. If multiple crypto provders are enabled rustls must
147+
// be explicitly configured at runtime to tell it what is the default (fallback) crypto provider.
148+
let _ = crypto::aws_lc_rs::default_provider().install_default();
149+
//
139150
env_logger::init();
140151
let config = get_aws_provider().await?;
141152
let sts_client = aws_sdk_sts::Client::new(&config);

0 commit comments

Comments
 (0)