Skip to content

Commit

Permalink
Configure explicit tls roots for tonic client (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
declark1 committed Aug 13, 2024
1 parent d9a9343 commit 4a74fb3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
15 changes: 15 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ thiserror = "1.0.63"
tokio = { version = "1.39.2", features = ["rt", "rt-multi-thread", "parking_lot", "signal", "sync", "fs"] }
tokio-rustls = { version = "0.26.0" }
tokio-stream = { version = "0.1.15", features = ["sync"] }
tonic = { version = "0.12.1", features = ["tls"] }
tonic = { version = "0.12.1", features = ["tls", "tls-roots", "tls-webpki-roots"] }
tower-service = "0.3"
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["json", "env-filter"] }
Expand Down
2 changes: 1 addition & 1 deletion src/clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ async fn create_grpc_clients<C>(
.unwrap_or_else(|error| panic!("error reading key from {key_path:?}: {error}"));
let identity = tonic::transport::Identity::from_pem(cert_pem, key_pem);
let mut client_tls_config =
tonic::transport::ClientTlsConfig::new().identity(identity);
tonic::transport::ClientTlsConfig::new().identity(identity).with_native_roots().with_webpki_roots();
if let Some(client_ca_cert_path) = &tls_config.client_ca_cert_path {
let client_ca_cert_pem = tokio::fs::read(client_ca_cert_path)
.await
Expand Down
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ struct Args {
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
let args = Args::parse();
rustls::crypto::aws_lc_rs::default_provider()
.install_default()
.expect("Failed to install rustls crypto provider");

let args = Args::parse();
if args.tls_key_path.is_some() != args.tls_cert_path.is_some() {
panic!("tls: must provide both cert and key")
}
Expand Down

0 comments on commit 4a74fb3

Please sign in to comment.