[control] Domi CA and UI sign-in: intermediate renewal by CSR with manual offline signing, domi host certificates, device requests approved by code, one-time PKCS#12 installs, revocation; Remote-User trusted only with edge's per-boot proof

This commit is contained in:
2026-11-07 23:21:49 +01:00
parent 211b851c3e
commit c18ae154ad
17 changed files with 1300 additions and 54 deletions
+4
View File
@@ -235,6 +235,10 @@ async fn handle(shared: Arc<Shared>, req: Request<Incoming>) -> Resp {
}
}
("POST", "/v1/abort") => reply(StatusCode::OK, json!({ "reverted": shared.abort() })),
("POST", "/v1/device-certs/reload") => match shared.reload_device_trust() {
Ok(n) => reply(StatusCode::OK, json!({ "reloaded": true, "allowed": n })),
Err(e) => error(StatusCode::UNPROCESSABLE_ENTITY, e),
},
("POST", "/v1/share-revocations/reload") => match shared.reload_revocations() {
Ok(()) => {
let r = shared.revocations();
+6 -4
View File
@@ -131,7 +131,9 @@ impl ProxyHttp for EdgeProxy {
let rt = self.shared.current();
ctx.rt = Some(rt.clone());
ctx.host_header = host_header(session.req_header());
if rt.device_trust.is_some() && sni_mismatch(session, &hostname(&ctx.host_header)) {
if self.shared.devices.current().is_some()
&& sni_mismatch(session, &hostname(&ctx.host_header))
{
// Like Caddy once client certificates are configured: a request for another host
// than the one the TLS connection was opened for is refused, so a connection
// that was never asked for a certificate cannot reach a device host.
@@ -144,7 +146,7 @@ impl ProxyHttp for EdgeProxy {
};
ctx.host = Some(host.clone());
if host.cfg.device_certs && !has_allowed_device_cert(session, &rt) {
if host.cfg.device_certs && !has_allowed_device_cert(session, &self.shared) {
// No certificate on this connection (one that is presented but not allowed never
// gets here: the handshake fails). Same as Caddy's route: 403, nothing upstream.
respond_empty(session, 403).await?;
@@ -441,8 +443,8 @@ fn sni_mismatch(session: &Session, host: &str) -> bool {
/// Did this connection present a device certificate that the current config allows? The
/// handshake already checked the chain and the list; this checks again against the runtime
/// serving the request, so a revocation also ends requests on connections made before it.
fn has_allowed_device_cert(session: &Session, rt: &crate::runtime::Runtime) -> bool {
let Some(trust) = rt.device_trust.as_ref() else {
fn has_allowed_device_cert(session: &Session, shared: &crate::shared::Shared) -> bool {
let Some(trust) = shared.devices.current() else {
return false;
};
session
+43 -1
View File
@@ -187,7 +187,16 @@ impl Shared {
fn install(&self, rt: Arc<Runtime>) {
self.certs.replace_files(rt.file_certs.clone());
self.devices.replace(rt.device_trust.clone());
// Read the device files again: the runtime may be older than the latest allow list
// (a revert after a revocation must not let a revoked device back in).
let trust = match fresh_trust(&rt) {
Ok(t) => t,
Err(e) => {
log::error!(target: "ianitor::tls", "{e}; keeping the device check this config was built with");
rt.device_trust.clone()
}
};
self.devices.replace(trust);
self.current.store(rt);
self.generation.fetch_add(1, Ordering::SeqCst);
self.notify();
@@ -496,3 +505,36 @@ fn poisoned() -> AdminError {
fn short(sha: &str) -> &str {
sha.get(..12).unwrap_or(sha)
}
/// The device check for a runtime, built from the files as they are now.
fn fresh_trust(rt: &Runtime) -> Result<Option<Arc<crate::tls::DeviceTrust>>, String> {
let Some(dc) = &rt.cfg.device_certs else {
return Ok(None);
};
let hosts: std::collections::HashSet<String> = rt
.cfg
.hosts
.iter()
.filter(|h| h.device_certs)
.map(|h| h.hostname.clone())
.collect();
if hosts.is_empty() {
return Ok(None);
}
let ca = std::fs::read(&dc.ca).map_err(|e| format!("cannot read {}: {e}", dc.ca))?;
let allow = std::fs::read(&dc.allow).map_err(|e| format!("cannot read {}: {e}", dc.allow))?;
crate::tls::DeviceTrust::new(&ca, &allow, hosts).map(|t| Some(Arc::new(t)))
}
impl Shared {
/// Re-read the device CA bundle and allow list now (control calls this after an issue
/// or a revocation; allowed during a trial). Returns how many devices are allowed.
pub fn reload_device_trust(&self) -> Result<usize, String> {
let rt = self.current();
let t = fresh_trust(&rt)?;
let n = t.as_ref().map_or(0, |t| t.allowed());
self.devices.replace(t);
log::info!(target: "ianitor::tls", "device certificates re-read: {n} allowed");
Ok(n)
}
}
+4
View File
@@ -159,6 +159,10 @@ impl DeviceTrust {
})
}
pub fn allowed(&self) -> usize {
self.allow.len()
}
pub fn allows(&self, cert_sha256: &[u8]) -> bool {
<[u8; 32]>::try_from(cert_sha256).is_ok_and(|d| self.allow.contains(&d))
}