[edge] Device certificates: mTLS on hosts with device_certs only (asked per SNI), chain to the Domi CA bundle and the allow list in the handshake, checked again per request; 403 without one
This commit is contained in:
@@ -118,6 +118,8 @@ pub struct Runtime {
|
||||
pub file_cert_expiry: HashMap<String, i64>,
|
||||
/// Loaded when any host has share links.
|
||||
pub share_key: Option<Arc<ShareKey>>,
|
||||
/// Loaded when any host has `device_certs`.
|
||||
pub device_trust: Option<Arc<crate::tls::DeviceTrust>>,
|
||||
/// SHA-256 (hex) of the config file bytes this runtime was built from; empty when it was
|
||||
/// built from a parsed config.
|
||||
pub sha256: String,
|
||||
@@ -400,6 +402,38 @@ pub fn build(cfg: EdgeConfig, credentials_dir: Option<&Path>) -> Result<Runtime,
|
||||
);
|
||||
}
|
||||
|
||||
let device_hosts: std::collections::HashSet<String> = cfg
|
||||
.hosts
|
||||
.iter()
|
||||
.filter(|h| h.device_certs)
|
||||
.map(|h| h.hostname.clone())
|
||||
.collect();
|
||||
let device_trust = match (&cfg.device_certs, device_hosts.is_empty()) {
|
||||
(_, true) => None,
|
||||
(None, false) => {
|
||||
return Err(EdgeError::Config {
|
||||
path: PathBuf::from("<config>"),
|
||||
message: "a host needs device certificates but the config names no CA bundle"
|
||||
.into(),
|
||||
});
|
||||
}
|
||||
(Some(dc), false) => {
|
||||
let read = |p: &str| {
|
||||
std::fs::read(p).map_err(|source| EdgeError::Read {
|
||||
path: PathBuf::from(p),
|
||||
source,
|
||||
})
|
||||
};
|
||||
let trust =
|
||||
crate::tls::DeviceTrust::new(&read(&dc.ca)?, &read(&dc.allow)?, device_hosts)
|
||||
.map_err(|message| EdgeError::Config {
|
||||
path: PathBuf::from(&dc.ca),
|
||||
message,
|
||||
})?;
|
||||
Some(Arc::new(trust))
|
||||
}
|
||||
};
|
||||
|
||||
let forward_auth = match &cfg.forward_auth {
|
||||
Some(fa) => Some(ForwardAuthRt {
|
||||
upstream: upstream(&fa.upstream)?,
|
||||
@@ -438,6 +472,7 @@ pub fn build(cfg: EdgeConfig, credentials_dir: Option<&Path>) -> Result<Runtime,
|
||||
file_certs,
|
||||
file_cert_expiry,
|
||||
share_key,
|
||||
device_trust,
|
||||
sha256: String::new(),
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user