[core] Device certificates: device_certs host field; edge config v3 and Caddy client_authentication with a CA bundle and an allow list, 403 without a certificate

This commit is contained in:
2026-11-07 22:46:07 +01:00
parent dc23bfe842
commit 18da3f5d5a
11 changed files with 201 additions and 14 deletions
+37 -6
View File
@@ -10,7 +10,7 @@
use serde_json::{Map, Value, json};
use super::{CompileOptions, join, strip_headers};
use super::{CompileOptions, DEVICE_ALLOW_FILE, DEVICE_CA_FILE, join, strip_headers};
use crate::{
AccessLog, AuthMode, ForwardAuth, HeaderRule, HeaderValue, Host, Model, Scheme, TlsMode,
Upstream,
@@ -52,13 +52,23 @@ pub(super) fn compile(model: &Model, o: &CompileOptions) -> Value {
routes.push(not_found());
let domi: Vec<&Host> = hosts.iter().filter(|h| h.tls == TlsMode::Domi).collect();
let mut policies: Vec<Value> = domi
// One policy per host that needs one: a Domi certificate, device certificates, or both.
let mut policies: Vec<Value> = hosts
.iter()
.filter(|h| h.tls == TlsMode::Domi || h.device_certs)
.map(|h| {
json!({
"match": { "sni": [h.hostname.as_str()] },
"certificate_selection": { "any_tag": [cert_tag(h)] }
})
let mut p = Map::new();
p.insert("match".into(), json!({ "sni": [h.hostname.as_str()] }));
if h.tls == TlsMode::Domi {
p.insert(
"certificate_selection".into(),
json!({ "any_tag": [cert_tag(h)] }),
);
}
if h.device_certs {
p.insert("client_authentication".into(), client_auth(o));
}
Value::Object(p)
})
.collect();
policies.push(json!({}));
@@ -203,6 +213,14 @@ fn logging(file: &str) -> Value {
fn host_route(h: &Host, fa: Option<&ForwardAuth>, o: &CompileOptions) -> Value {
let mut steps = Vec::new();
if h.device_certs {
// No client certificate on this connection: 403, like edge. A certificate that is not
// trusted or not on the allow list never gets this far (the handshake fails).
steps.push(json!({
"match": [{ "vars": { "{http.request.tls.client.fingerprint}": [""] } }],
"handle": [{ "handler": "static_response", "status_code": 403 }]
}));
}
if let (AuthMode::ForwardAuth, Some(fa)) = (h.auth, fa) {
// Client-sent identity headers never reach the auth server or the upstream.
steps.push(json!({ "handle": [{ "handler": "headers", "request": { "delete": strip_headers(fa) } }] }));
@@ -339,3 +357,16 @@ fn forward_auth(fa: &ForwardAuth) -> Value {
);
Value::Object(rp)
}
/// Device certificates: optional in the handshake (a missing one is a 403 in the route, as in
/// edge), but one that is presented must chain to the Domi CA bundle and be on the allow list.
fn client_auth(o: &CompileOptions) -> Value {
json!({
"ca": { "provider": "file", "pem_files": [join(&o.cert_dir, DEVICE_CA_FILE)] },
"verifiers": [{
"verifier": "leaf",
"leaf_certs_loaders": [{ "loader": "file", "files": [join(&o.cert_dir, DEVICE_ALLOW_FILE)] }]
}],
"mode": "verify_if_given"
})
}
+12 -3
View File
@@ -4,10 +4,10 @@
//! Model → [`EdgeConfig`] for the Pingora data plane.
use super::{CompileOptions, join, strip_headers};
use super::{CompileOptions, DEVICE_ALLOW_FILE, DEVICE_CA_FILE, join, strip_headers};
use crate::edge_config::{
EDGE_CONFIG_VERSION, EdgeAcme, EdgeConfig, EdgeForwardAuth, EdgeHeaderOp, EdgeHealthCheck,
EdgeHost, EdgeTls, EdgeUpstream, EdgeValue,
EDGE_CONFIG_VERSION, EdgeAcme, EdgeConfig, EdgeDeviceCerts, EdgeForwardAuth, EdgeHeaderOp,
EdgeHealthCheck, EdgeHost, EdgeTls, EdgeUpstream, EdgeValue,
};
use crate::{AccessLog, AuthMode, HeaderRule, HeaderValue, Model, Scheme, TlsMode, Upstream};
@@ -26,6 +26,14 @@ pub(super) fn compile(model: &Model, o: &CompileOptions) -> EdgeConfig {
directory: site.acme.directory.clone(),
email: site.acme.email.clone(),
}),
device_certs: model
.hosts()
.iter()
.any(|h| h.device_certs)
.then(|| EdgeDeviceCerts {
ca: join(&o.cert_dir, DEVICE_CA_FILE),
allow: join(&o.cert_dir, DEVICE_ALLOW_FILE),
}),
forward_auth: site.forward_auth.as_ref().map(|fa| EdgeForwardAuth {
upstream: upstream(&fa.upstream),
path_and_query: fa.path_and_query.clone(),
@@ -55,6 +63,7 @@ pub(super) fn compile(model: &Model, o: &CompileOptions) -> EdgeConfig {
}),
access_log: h.access_log == AccessLog::Truncated,
share_links: h.share_links,
device_certs: h.device_certs,
})
.collect(),
}
+5
View File
@@ -17,6 +17,11 @@
mod caddy;
mod edge;
/// In the certificate directory: the CA bundle for device certificates (written by control).
pub const DEVICE_CA_FILE: &str = "domi-devices-ca.pem";
/// In the certificate directory: every allowed (issued, not revoked) device certificate.
pub const DEVICE_ALLOW_FILE: &str = "domi-devices.pem";
use std::net::SocketAddr;
use crate::Model;