[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
+65
View File
@@ -277,3 +277,68 @@ fn websocket_refusal_in_caddy_matches_any_upgrade_token() {
"token-aware Upgrade matcher"
);
}
#[test]
fn device_cert_hosts_check_client_certificates_in_both_engines() {
let m = model(false);
let edge: EdgeConfig = serde_json::from_str(&compile::edge(&m, &options()).unwrap()).unwrap();
let dc = edge.device_certs.expect("a host needs device certificates");
assert_eq!(dc.ca, "/var/lib/ianitor/certs/domi-devices-ca.pem");
assert_eq!(dc.allow, "/var/lib/ianitor/certs/domi-devices.pem");
let on: Vec<&str> = edge
.hosts
.iter()
.filter(|h| h.device_certs)
.map(|h| h.hostname.as_str())
.collect();
assert_eq!(on, ["status.example.org"]);
let v: serde_json::Value =
serde_json::from_str(&compile::caddy(&m, &options()).unwrap()).unwrap();
let https = &v["apps"]["http"]["servers"]["ianitor_https"];
let policies = https["tls_connection_policies"].as_array().unwrap();
let with_auth: Vec<&serde_json::Value> = policies
.iter()
.filter(|p| p.get("client_authentication").is_some())
.collect();
assert_eq!(
with_auth.len(),
1,
"only the device host asks for a certificate"
);
assert_eq!(with_auth[0]["match"]["sni"][0], "status.example.org");
assert_eq!(
with_auth[0]["client_authentication"]["mode"],
"verify_if_given"
);
let routes = https["routes"].as_array().unwrap();
let status = routes
.iter()
.find(|r| r["match"][0]["host"][0] == "status.example.org")
.unwrap();
let first = &status["handle"][0]["routes"][0];
assert_eq!(
first["handle"][0]["status_code"], 403,
"no certificate: 403 first"
);
// Without a device host, neither engine asks for client certificates.
let plain = ianitor_core::load(
&SourceFile {
name: "ianitor.toml",
contents: "",
},
&[SourceFile {
name: "hosts/a.test.toml",
contents: "hostname = \"a.test\"\nupstreams = [\"http://127.0.0.1:1\"]\n",
}],
)
.unwrap();
let e: EdgeConfig = serde_json::from_str(&compile::edge(&plain, &options()).unwrap()).unwrap();
assert!(e.device_certs.is_none());
assert!(
!compile::caddy(&plain, &options())
.unwrap()
.contains("client_authentication")
);
}