feat(iroh-relay): trust a custom CA for the ACME server TLS

Add an `IROH_RELAY_ACME_CA` environment variable to the relay binary and a
`tls_config` option on `AcmeConfig` that feeds a `CaTlsConfig` into the
rustls-acme client. This lets the relay reach an ACME directory whose
certificate is not signed by a publicly trusted CA, such as a local pebble
server used for testing. The default stays the embedded webpki roots, so
existing deployments are unaffected.
This commit is contained in:
Frando
2026-06-12 12:36:09 +02:00
parent bc2b14b88f
commit 6f73f1f45e
2 changed files with 44 additions and 5 deletions
+13 -1
View File
@@ -21,6 +21,7 @@ use iroh_relay::{
self as relay, Access, AccessControl, AcmeConfig, ClientRateLimit, ClientRequest,
DEFAULT_CERT_RELOAD_INTERVAL, QuicConfig, reloading_resolver,
},
tls::CaTlsConfig,
};
use n0_error::{AnyError, Result, StdResultExt, bail_any};
use serde::{Deserialize, Serialize};
@@ -645,10 +646,21 @@ async fn load_cert_config(tls: &TlsConfig) -> Result<relay::CertConfig> {
} else {
AcmeConfig::letsencrypt(tls.prod_tls)
};
let acme_config = acme_config
let mut acme_config = acme_config
.domains(domains)
.contact(vec![format!("mailto:{contact}")])
.cache_path(tls.cert_dir());
// Trust an additional CA for the ACME server's TLS certificate. Useful for testing
// against a local ACME server such as pebble, whose certificate is not signed by a
// publicly trusted CA.
if let Ok(ca_path) = std::env::var("IROH_RELAY_ACME_CA") {
let extra_roots = CertificateDer::pem_file_iter(&ca_path)
.std_context("failed to read IROH_RELAY_ACME_CA")?
.collect::<Result<Vec<_>, _>>()
.std_context("failed to parse IROH_RELAY_ACME_CA")?;
acme_config =
acme_config.tls_config(CaTlsConfig::default().with_extra_roots(extra_roots));
}
relay::CertConfig::LetsEncrypt {
acme_config,
server_config_builder: server_config,
+31 -4
View File
@@ -58,6 +58,7 @@ use crate::{
defaults::DEFAULT_KEY_CACHE_CAPACITY,
http::{AUTH_TOKEN_URL_QUERY_PARAM, ProtocolVersion, RELAY_PROBE_PATH},
quic::server::{QuicServer, QuicSpawnError, ServerHandle as QuicServerHandle},
tls::CaTlsConfig,
};
pub mod client;
@@ -549,6 +550,7 @@ pub struct AcmeConfig {
pub(crate) domains: Vec<String>,
pub(crate) contact: Vec<String>,
pub(crate) cache_path: Option<PathBuf>,
pub(crate) tls_config: CaTlsConfig,
}
impl AcmeConfig {
@@ -559,6 +561,7 @@ impl AcmeConfig {
domains: Vec::new(),
contact: Vec::new(),
cache_path: None,
tls_config: CaTlsConfig::default(),
}
}
@@ -593,6 +596,16 @@ impl AcmeConfig {
self.cache_path = Some(path);
self
}
/// Sets the [`CaTlsConfig`] used to verify the ACME server's TLS certificate.
///
/// Defaults to [`CaTlsConfig::embedded`]. Set a config with extra roots when targeting
/// an ACME server whose certificate is not signed by a publicly trusted CA, such as a
/// local test server.
pub fn tls_config(mut self, tls_config: CaTlsConfig) -> Self {
self.tls_config = tls_config;
self
}
}
/// A running Relay + QAD server.
@@ -636,6 +649,11 @@ pub enum SpawnError {
TlsHeaderParse { source: InvalidHeaderValue },
#[error("Failed to bind TcpListener")]
BindTlsListener { source: std::io::Error },
#[error("Failed to build ACME client TLS config")]
AcmeClientTlsConfig {
#[error(std_err)]
source: std::io::Error,
},
#[error("No local address")]
NoLocalAddr { source: std::io::Error },
#[error("Failed to bind server socket to {addr}")]
@@ -731,11 +749,20 @@ impl Server {
server_config_builder,
} => {
let cache = acme_config.cache_path.map(DirCache::new);
let crypto_provider =
server_config_builder.crypto_provider().clone();
let client_tls_config = acme_config
.tls_config
.client_config(crypto_provider)
.map_err(|err| e!(SpawnError::AcmeClientTlsConfig, err))?;
let config =
tokio_rustls_acme::AcmeConfig::new(acme_config.domains)
.contact(acme_config.contact)
.directory(acme_config.directory_url)
.cache_option(cache);
tokio_rustls_acme::AcmeConfig::new_with_client_tls_config(
acme_config.domains,
Arc::new(client_tls_config),
)
.contact(acme_config.contact)
.directory(acme_config.directory_url)
.cache_option(cache);
let mut state = config.state();
let resolver = state.resolver().clone();
let server_config =