Skip to content

Commit e4094d6

Browse files
committed
add knob to use ca_webpki_roots and defaults
Signed-off-by: Rajat Jindal <[email protected]>
1 parent 1527ca1 commit e4094d6

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

crates/trigger-http/src/lib.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,15 +1162,15 @@ fn get_client_tls_config_for_authority(
11621162
client_tls_opts: Option<HashMap<Authority, ParsedClientTlsOpts>>,
11631163
) -> Result<rustls::ClientConfig> {
11641164
// derived from https://github.com/tokio-rs/tls/blob/master/tokio-rustls/examples/client/src/main.rs
1165-
let mut root_cert_store = rustls::RootCertStore {
1165+
let ca_webpki_roots = rustls::RootCertStore {
11661166
roots: webpki_roots::TLS_SERVER_ROOTS.into(),
11671167
};
11681168

11691169
let client_tls_opts = match client_tls_opts {
11701170
Some(opts) => opts,
11711171
_ => {
11721172
return Ok(rustls::ClientConfig::builder()
1173-
.with_root_certificates(root_cert_store)
1173+
.with_root_certificates(ca_webpki_roots)
11741174
.with_no_client_auth());
11751175
}
11761176
};
@@ -1179,11 +1179,28 @@ fn get_client_tls_config_for_authority(
11791179
Some(opts) => opts,
11801180
_ => {
11811181
return Ok(rustls::ClientConfig::builder()
1182-
.with_root_certificates(root_cert_store)
1182+
.with_root_certificates(ca_webpki_roots)
11831183
.with_no_client_auth());
11841184
}
11851185
};
11861186

1187+
let custom_root_ca_provided = client_tls_opts_for_host.custom_root_ca.is_some();
1188+
1189+
// use_ca_webpki_roots is true if
1190+
// 1. ca_webpki_roots is explicitly true in runtime config OR
1191+
// 2. custom_root_ca is not provided
1192+
//
1193+
// if custom_root_ca is provided, use_ca_webpki_roots defaults to false
1194+
let use_ca_webpki_roots = client_tls_opts_for_host
1195+
.ca_webpki_roots
1196+
.unwrap_or(if custom_root_ca_provided { false } else { true });
1197+
1198+
let mut root_cert_store = if use_ca_webpki_roots {
1199+
ca_webpki_roots
1200+
} else {
1201+
rustls::RootCertStore::empty()
1202+
};
1203+
11871204
if let Some(custom_root_ca) = &client_tls_opts_for_host.custom_root_ca {
11881205
for cer in custom_root_ca {
11891206
match root_cert_store.add(cer.to_owned()) {

crates/trigger/src/runtime_config.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -537,9 +537,10 @@ mod tests {
537537
let input = ClientTlsOpts {
538538
component_ids: vec!["component-id-foo".to_string()],
539539
hosts: vec!["fermyon.com".to_string(), "fermyon.com:5443".to_string()],
540-
custom_root_ca_file: None,
540+
ca_roots_file: None,
541541
cert_chain_file: None,
542542
private_key_file: None,
543+
ca_webpki_roots: None,
543544
};
544545

545546
let parsed = parse_client_tls_opts(&input);
@@ -552,9 +553,10 @@ mod tests {
552553
let input = ClientTlsOpts {
553554
component_ids: vec!["component-id-foo".to_string()],
554555
hosts: vec!["".to_string(), "fermyon.com:5443".to_string()],
555-
custom_root_ca_file: None,
556+
ca_roots_file: None,
556557
cert_chain_file: None,
557558
private_key_file: None,
559+
ca_webpki_roots: None,
558560
};
559561

560562
let parsed = parse_client_tls_opts(&input);
@@ -570,9 +572,10 @@ mod tests {
570572
let input = ClientTlsOpts {
571573
component_ids: vec!["component-id-foo".to_string()],
572574
hosts: vec!["perc%ent:443".to_string(), "fermyon.com:5443".to_string()],
573-
custom_root_ca_file: None,
575+
ca_roots_file: None,
574576
cert_chain_file: None,
575577
private_key_file: None,
578+
ca_webpki_roots: None,
576579
};
577580

578581
let parsed = parse_client_tls_opts(&input);
@@ -606,10 +609,11 @@ pub struct ParsedClientTlsOpts {
606609
pub custom_root_ca: Option<Vec<rustls_pki_types::CertificateDer<'static>>>,
607610
pub cert_chain: Option<Vec<rustls_pki_types::CertificateDer<'static>>>,
608611
pub private_key: Option<Arc<rustls_pki_types::PrivateKeyDer<'static>>>,
612+
pub ca_webpki_roots: Option<bool>,
609613
}
610614

611615
fn parse_client_tls_opts(inp: &ClientTlsOpts) -> Result<ParsedClientTlsOpts, anyhow::Error> {
612-
let custom_root_ca = match &inp.custom_root_ca_file {
616+
let custom_root_ca = match &inp.ca_roots_file {
613617
Some(path) => Some(load_certs(path).context("loading custom root ca")?),
614618
None => None,
615619
};
@@ -643,5 +647,6 @@ fn parse_client_tls_opts(inp: &ClientTlsOpts) -> Result<ParsedClientTlsOpts, any
643647
custom_root_ca,
644648
cert_chain,
645649
private_key,
650+
ca_webpki_roots: inp.ca_webpki_roots,
646651
})
647652
}

crates/trigger/src/runtime_config/client_tls.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ use std::{
1212
pub struct ClientTlsOpts {
1313
pub component_ids: Vec<String>,
1414
pub hosts: Vec<String>,
15-
pub custom_root_ca_file: Option<PathBuf>,
15+
pub ca_roots_file: Option<PathBuf>,
1616
pub cert_chain_file: Option<PathBuf>,
1717
pub private_key_file: Option<PathBuf>,
18+
pub ca_webpki_roots: Option<bool>,
1819
}
1920

2021
// load_certs parse and return the certs from the provided file

0 commit comments

Comments
 (0)