[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:
@@ -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"
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user