Skip to content

Commit f48b05e

Browse files
sauagarwadrew
andauthored
fix(gateway-interceptors): apply tls-native-roots for HTTPS interceptor endpoints (#2666)
* fix(gateway-interceptors): apply tls-native-roots for HTTPS interceptor endpoints Endpoint::connect() does not apply TLS configuration automatically for https:// URLs even with tls-native-roots feature enabled. Add explicit .tls_config(ClientTlsConfig::new()) when the endpoint uses HTTPS so tonic uses the system's native root certificate store. Fixes #2665 * fix(gateway-interceptors): detect parsed HTTPS scheme Signed-off-by: Drew Newberry <anewberry@nvidia.com> --------- Signed-off-by: Drew Newberry <anewberry@nvidia.com> Co-authored-by: Drew Newberry <anewberry@nvidia.com>
1 parent 5e2f0d1 commit f48b05e

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

  • crates/openshell-gateway-interceptors/src

crates/openshell-gateway-interceptors/src/plan.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use openshell_core::proto::gateway_interceptor::v1::{
1919
use tokio::net::UnixStream;
2020
use tonic::Request;
2121
use tonic::codegen::http::Uri;
22-
use tonic::transport::{Channel, Endpoint};
22+
use tonic::transport::{Channel, ClientTlsConfig, Endpoint};
2323
use tower::service_fn;
2424
use tracing::{info, warn};
2525

@@ -862,11 +862,19 @@ async fn connect_endpoint(endpoint: &str) -> Result<Channel> {
862862
if let Some(path) = endpoint.strip_prefix("unix://") {
863863
return connect_unix_endpoint(PathBuf::from(path)).await;
864864
}
865-
Endpoint::from_shared(endpoint.to_string())
866-
.map_err(|e| {
867-
InterceptorError::Config(format!("invalid interceptor endpoint '{endpoint}': {e}"))
868-
})?
869-
.connect()
865+
let mut ep = Endpoint::from_shared(endpoint.to_string()).map_err(|e| {
866+
InterceptorError::Config(format!("invalid interceptor endpoint '{endpoint}': {e}"))
867+
})?;
868+
if ep.uri().scheme_str() == Some("https") {
869+
ep = ep
870+
.tls_config(ClientTlsConfig::new().with_enabled_roots())
871+
.map_err(|e| {
872+
InterceptorError::Config(format!(
873+
"TLS config for interceptor endpoint '{endpoint}': {e}"
874+
))
875+
})?;
876+
}
877+
ep.connect()
870878
.await
871879
.map_err(|e| InterceptorError::Transport(format!("connect {endpoint}: {e}")))
872880
}

0 commit comments

Comments
 (0)