Skip to content
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

Configure explicit tls roots for tonic client #157

Merged
merged 1 commit into from
Aug 13, 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
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