[control] Fix round 1: changes apply while Caddy serves (admin socket, watch through Caddy), revocations that fail are errors and catch up, proof only on the forward-auth UI host, root keys found by content, intermediates checked before install, stale SNI cleared before each handshake

This commit is contained in:
2026-11-08 10:49:31 +01:00
parent 0749119f19
commit e84eb1ba74
36 changed files with 934 additions and 131 deletions
+1
View File
@@ -114,6 +114,7 @@ impl Env {
access_log: dir.str("logs/access.log"),
caddy_credentials_dir: dir.str("creds"),
caddy_admin: None,
caddy_admin_socket: None,
};
// Edge starts from an empty config; control brings it in line on its first start.
let empty = load(
+34 -14
View File
@@ -661,7 +661,11 @@ mod unix {
std::fs::write(
&p,
// (Split so that this file does not match the pre-commit hook itself.)
concat!("-----BEGIN ", "PRIVATE KEY-----\nx\n-----END ", "PRIVATE KEY-----\n"),
concat!(
"-----BEGIN ",
"PRIVATE KEY-----\nx\n-----END ",
"PRIVATE KEY-----\n"
),
)
.unwrap();
if ianitor_control::pki::root_key_files(&d.join(".")).is_empty() {
@@ -680,8 +684,6 @@ mod unix {
async fn a_revocation_that_cannot_be_written_is_an_error_and_catches_up() {
let (mut env, off) = env_with_pki().await;
install_intermediate(&env, &off).await;
env.kill_control();
env.start_control_env(None, &[("IANITOR_TEST_FAIL_WRITE", "domi-devices.pem")]);
let r = env
.call(
"POST",
@@ -695,16 +697,23 @@ mod unix {
assert!(cli(&env, &["pki", "approve", &code]).status.success());
let done = wait_request(&env, &rid, "approved").await;
let did = done["device_id"].as_str().unwrap().to_owned();
// The allow list could not be written: the screen says so.
let allow_file = env.dir.join("certs/domi-devices.pem");
let on_list = || {
std::fs::read_to_string(&allow_file)
.unwrap_or_default()
.contains("BEGIN CERTIFICATE")
};
let deadline = Instant::now() + Duration::from_secs(10);
loop {
let c = env.call("GET", "/api/v1/certs", None).await;
if !c.json["devices_problem"].is_null() {
break;
}
assert!(Instant::now() < deadline, "no problem shown: {}", c.text);
while !on_list() {
assert!(
Instant::now() < deadline,
"the device never reached the allow list"
);
tokio::time::sleep(Duration::from_millis(200)).await;
}
// From now on the allow list cannot be written.
env.kill_control();
env.start_control_env(None, &[("IANITOR_TEST_FAIL_WRITE", "domi-devices.pem")]);
let d = env
.call("DELETE", &format!("/api/v1/certs/devices/{did}"), None)
.await;
@@ -714,16 +723,27 @@ mod unix {
"{}",
d.text
);
// The disk works again.
// The certificates screen keeps saying so; the device is still on the list.
let c = env.call("GET", "/api/v1/certs", None).await;
assert_eq!(
c.json["devices_problem"]["code"], "pki.devices_unwritten",
"{}",
c.text
);
assert!(on_list());
// The disk works again: the list catches up by itself, without another Revoke.
env.kill_control();
env.start_control(None);
let deadline = Instant::now() + Duration::from_secs(10);
while on_list() {
assert!(Instant::now() < deadline, "the revocation never caught up");
tokio::time::sleep(Duration::from_millis(200)).await;
}
// A repeated Revoke is fine and nudges the engine again.
let d = env
.call("DELETE", &format!("/api/v1/certs/devices/{did}"), None)
.await;
assert_eq!(d.status, 204, "{}", d.text);
let allow =
std::fs::read_to_string(env.dir.join("certs/domi-devices.pem")).unwrap_or_default();
assert!(!allow.contains("BEGIN CERTIFICATE"), "{allow}");
let c = env.call("GET", "/api/v1/certs", None).await;
assert!(c.json["devices_problem"].is_null(), "{}", c.text);
}
+14 -6
View File
@@ -203,11 +203,19 @@ mod unix {
"tls": "domi", "auth": "none",
"request_headers": [{"action": "set", "name": "X-Ianitor-Proof", "secret": "ui-proof"}]
}});
let rec = env.apply("POST", "/api/v1/hosts", Some(host)).await;
// Refused before it goes live: the proof belongs to the [ui] host behind forward-auth.
assert_eq!(rec["state"], "failed", "{rec}");
assert!(rec.to_string().contains("host.header.proof"), "{rec}");
if rec["state"] != "kept" {
let r = env.call("POST", "/api/v1/hosts", Some(host)).await;
// Refused at the door: the proof belongs to the [ui] host behind forward-auth.
assert_eq!(r.status, 422, "{}", r.text);
assert_eq!(
r.json["errors"][0]["code"], "host.header.proof",
"{}",
r.text
);
assert!(
env.call("GET", "/api/v1/hosts/a.test", None).await.status == 404,
"the host went live"
);
if r.status != 202 {
return;
}
let edge = env.edge.as_ref().unwrap();
@@ -265,7 +273,7 @@ mod unix {
assert_eq!(r.status, 200, "{}", r.text());
eprintln!(
"QC viewer: {}",
&r.text()[r.text().find("\"viewer\"").unwrap_or(0)..]
r.text()[r.text().find("\"viewer\"").unwrap_or(0)..]
.chars()
.take(80)
.collect::<String>()