[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
+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);
}