[control] Start and resolver (QC nits): the live tree goes through the same rules as an apply before control writes it to the engines, and a guard frees an edge name lookup's entry and thread on every way out, a panic included
This commit is contained in:
@@ -678,6 +678,25 @@ impl Control {
|
||||
errors: fe,
|
||||
}
|
||||
})?;
|
||||
self.policy(&model)?;
|
||||
Ok(Plan {
|
||||
kind,
|
||||
verb: host_verb(kind),
|
||||
summary,
|
||||
hosts,
|
||||
target,
|
||||
model,
|
||||
attempted,
|
||||
undo_of,
|
||||
restore_of,
|
||||
effect,
|
||||
})
|
||||
}
|
||||
|
||||
/// What control allows beyond core's schema, for every tree it applies and for the live
|
||||
/// tree at start: the UI proof only on the [ui] host, a socket upstream only there and only
|
||||
/// to control's own UI socket.
|
||||
fn policy(&self, model: &ianitor_core::Model) -> Result<(), Fail> {
|
||||
// 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());
|
||||
// A socket upstream likewise: only the [ui] host, and only control's own UI socket (a
|
||||
@@ -717,8 +736,8 @@ impl Control {
|
||||
}
|
||||
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)
|
||||
});
|
||||
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 {
|
||||
@@ -738,18 +757,7 @@ impl Control {
|
||||
});
|
||||
}
|
||||
}
|
||||
Ok(Plan {
|
||||
kind,
|
||||
verb: host_verb(kind),
|
||||
summary,
|
||||
hosts,
|
||||
target,
|
||||
model,
|
||||
attempted,
|
||||
undo_of,
|
||||
restore_of,
|
||||
effect,
|
||||
})
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn compile(&self, model: &ianitor_core::Model) -> Result<(String, String), Fail> {
|
||||
@@ -1794,6 +1802,18 @@ impl Control {
|
||||
return;
|
||||
}
|
||||
};
|
||||
// A tree kept under an earlier control.toml may break today's rules (a changed [ui]
|
||||
// hostname or socket): it is not written to the engines, and the reason is logged; the
|
||||
// engines keep the last files written. The next apply is refused for the same reason.
|
||||
if let Err(f) = self.policy(&model) {
|
||||
let detail = f
|
||||
.errors
|
||||
.first()
|
||||
.map(|e| e.message.clone())
|
||||
.unwrap_or_else(|| f.reason.message.clone());
|
||||
log::error!(target: "ianitor::control", "the routes repository breaks control's rules ({detail}); the engines keep the files they have");
|
||||
return;
|
||||
}
|
||||
let Ok((edge_text, caddy_text)) = self.compile(&model) else {
|
||||
return;
|
||||
};
|
||||
|
||||
@@ -130,12 +130,28 @@ impl Resolver {
|
||||
.spawn({
|
||||
let key = key.clone();
|
||||
move || {
|
||||
// Removes the name's entry and frees the thread's place on every way out, a
|
||||
// panic in the resolver included: the next request for the name starts a
|
||||
// new lookup instead of joining a dead one.
|
||||
struct Done {
|
||||
inflight: Arc<Inflight>,
|
||||
key: (String, u16),
|
||||
_permit: OwnedSemaphorePermit,
|
||||
}
|
||||
impl Drop for Done {
|
||||
fn drop(&mut self) {
|
||||
lock(&self.inflight).remove(&self.key);
|
||||
}
|
||||
}
|
||||
let _done = Done {
|
||||
inflight,
|
||||
key: key.clone(),
|
||||
_permit: permit,
|
||||
};
|
||||
let answer = lookup(&key.0, key.1)
|
||||
.map(Arc::new)
|
||||
.map_err(|e| (e.kind(), e.to_string()));
|
||||
let _ = tx.send(Some(answer));
|
||||
lock(&inflight).remove(&key);
|
||||
drop(permit);
|
||||
}
|
||||
});
|
||||
if let Err(e) = spawned {
|
||||
|
||||
Reference in New Issue
Block a user