[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:
@@ -15,6 +15,8 @@
|
||||
// A refusal is built once per failed request or apply; boxing it buys nothing.
|
||||
#![allow(clippy::result_large_err)]
|
||||
|
||||
mod caddy_apply;
|
||||
|
||||
use std::collections::{BTreeMap, BTreeSet, HashMap, VecDeque};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::Duration;
|
||||
@@ -160,6 +162,10 @@ pub struct Control {
|
||||
pause_saved: std::sync::atomic::AtomicBool,
|
||||
/// Serialises applies with share-revocation writes and recovery.
|
||||
pub(crate) apply_lock: tokio::sync::Mutex<()>,
|
||||
/// Held while an engine is switched or told to reload its device or certificate files.
|
||||
pub(crate) engine_lock: tokio::sync::Mutex<()>,
|
||||
/// Why the device files are not (yet) in force, until a retry succeeds.
|
||||
pub devices_problem: Mutex<Option<String>>,
|
||||
}
|
||||
|
||||
const MAX_RECORDS: usize = 1000;
|
||||
@@ -268,6 +274,8 @@ impl Control {
|
||||
paused: Mutex::new(paused),
|
||||
pause_saved: std::sync::atomic::AtomicBool::new(true),
|
||||
apply_lock: tokio::sync::Mutex::new(()),
|
||||
engine_lock: tokio::sync::Mutex::new(()),
|
||||
devices_problem: Mutex::new(None),
|
||||
cfg,
|
||||
});
|
||||
if let Ok((_, _, m)) = c.head_model()
|
||||
@@ -437,9 +445,6 @@ impl Control {
|
||||
/// `in_worker` is false when a request is first checked: a change that the worker may
|
||||
/// still let through (after it retried the files) is queued rather than refused.
|
||||
fn paused_for(&self, change: &Change, in_worker: bool) -> Option<Reason> {
|
||||
if let Some(e) = self.engine_pause() {
|
||||
return Some(e);
|
||||
}
|
||||
let p = self.paused()?;
|
||||
if !in_worker && p.code == "control.files_unwritten" {
|
||||
return None;
|
||||
@@ -669,6 +674,31 @@ impl Control {
|
||||
errors: fe,
|
||||
}
|
||||
})?;
|
||||
// The UI proof belongs to the [ui] host only (core already demands forward-auth for it).
|
||||
let ui_host = self.cfg.ui.as_ref().and_then(|u| u.hostname.as_deref());
|
||||
for h in model.hosts() {
|
||||
let proof = h.request_headers.iter().any(|r| {
|
||||
matches!(r, ianitor_core::HeaderRule::Set { value: ianitor_core::HeaderValue::Secret(s), .. } if s.as_str() == ianitor_core::UI_PROOF_SECRET)
|
||||
});
|
||||
if proof && ui_host != Some(h.hostname.as_str()) {
|
||||
let p = messages::params([("hostname", h.hostname.to_string())]);
|
||||
let fe = FieldError {
|
||||
code: "host.header.proof_host".into(),
|
||||
message: message("host.header.proof_host", &p),
|
||||
field: Some("request_headers".into()),
|
||||
params: p.clone(),
|
||||
detail: None,
|
||||
};
|
||||
return Err(Fail {
|
||||
status: 422,
|
||||
reason: reason(
|
||||
"apply.failed.validation",
|
||||
messages::params([("first_error", fe.message.clone())]),
|
||||
),
|
||||
errors: vec![fe],
|
||||
});
|
||||
}
|
||||
}
|
||||
Ok(Plan {
|
||||
kind,
|
||||
verb: host_verb(kind),
|
||||
@@ -1024,6 +1054,13 @@ impl Control {
|
||||
r.step("reload", "running");
|
||||
});
|
||||
|
||||
// Caddy serves: load the trial into Caddy and watch through it (Mark, 2026-11-08).
|
||||
if self.engine_running() == "caddy" {
|
||||
return self
|
||||
.run_under_caddy(&id, j, &plan, &caddy_text, &job.change)
|
||||
.await;
|
||||
}
|
||||
|
||||
// Which hosts to judge: those this change adds or changes, not those it removes.
|
||||
let watch_hosts: Vec<String> = plan
|
||||
.hosts
|
||||
@@ -1466,7 +1503,8 @@ impl Control {
|
||||
|
||||
/// The idempotent part of a revert. Returns the revert commit, if one was needed.
|
||||
async fn finish_revert(&self, j: &Journal) -> Result<Option<String>, String> {
|
||||
if self.edge.attached() {
|
||||
let caddy = self.engine_running() == "caddy";
|
||||
if self.edge.attached() && !caddy {
|
||||
match self.edge.abort().await {
|
||||
Ok(_) => {}
|
||||
// Edge down: it starts from edge.json, which is still the last good config.
|
||||
@@ -1502,6 +1540,11 @@ impl Control {
|
||||
for p in [self.cfg.trial_path(), self.cfg.caddy_trial_path()] {
|
||||
remove_if_exists(&p).map_err(|e| e.to_string())?;
|
||||
}
|
||||
if caddy {
|
||||
// Caddy must run caddy.json again, the last good config.
|
||||
self.caddy_reload().await?;
|
||||
return Ok(rev);
|
||||
}
|
||||
// Edge must now run edge.json, the last good config. If it confirmed the trial after
|
||||
// all (an answer lost on the way) it does not: reload it. If edge cannot be asked,
|
||||
// this is not a finished revert (a restart asks again).
|
||||
@@ -1660,6 +1703,11 @@ impl Control {
|
||||
self.unpause();
|
||||
self.sync_files().await;
|
||||
}
|
||||
if self.engine_running() == "caddy"
|
||||
&& let Err(e) = self.caddy_reload().await
|
||||
{
|
||||
log::warn!(target: "ianitor::control", "Caddy did not load caddy.json at start: {e}");
|
||||
}
|
||||
if let Err(e) = self.shares.ensure_revocation_file() {
|
||||
log::error!(target: "ianitor::share", "{e}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user