[control] Tests first: Domi CA flows through the API (offline-signed intermediate, domi host chains, device approval by code, one-time install, revocation, no root key) and UI sign-in that refuses a forged Remote-User (red)
This commit is contained in:
@@ -141,6 +141,12 @@ pub struct Control {
|
||||
pub tokens: Tokens,
|
||||
pub shares: Shares,
|
||||
pub share_key: Option<ShareKey>,
|
||||
/// The Domi CA, when `[pki]` is configured.
|
||||
pub pki: Option<crate::pki::Pki>,
|
||||
/// Which engine serves (see `switch`).
|
||||
pub engine: Mutex<crate::switch::EngineState>,
|
||||
/// How control starts and stops the engines; `None` without `[engine]`.
|
||||
pub units: Option<Arc<dyn crate::switch::Units>>,
|
||||
records: Mutex<Vec<ApplyRecord>>,
|
||||
queue: Mutex<VecDeque<Job>>,
|
||||
wake: Notify,
|
||||
@@ -151,7 +157,7 @@ pub struct Control {
|
||||
/// False while the pause is only in memory (paused.json could not be written).
|
||||
pause_saved: std::sync::atomic::AtomicBool,
|
||||
/// Serialises applies with share-revocation writes and recovery.
|
||||
apply_lock: tokio::sync::Mutex<()>,
|
||||
pub(crate) apply_lock: tokio::sync::Mutex<()>,
|
||||
}
|
||||
|
||||
const MAX_RECORDS: usize = 1000;
|
||||
@@ -207,6 +213,21 @@ impl Control {
|
||||
if share_key.is_none() {
|
||||
log::warn!(target: "ianitor::control", "no usable share-link-key credential: share links cannot be made");
|
||||
}
|
||||
let keys = crate::pki::root_key_files(&cfg.state_dir);
|
||||
if let Some(k) = keys.first() {
|
||||
return Err(format!(
|
||||
"{} looks like a root CA key inside the state directory; the Domi root key must never be on the server (ROADMAP §1.2). Move it to the offline machine.",
|
||||
k.display()
|
||||
));
|
||||
}
|
||||
let pki = match &cfg.pki {
|
||||
Some(p) => Some(crate::pki::Pki::open(
|
||||
p,
|
||||
&cfg.state_dir,
|
||||
cfg.credential(&p.password_credential),
|
||||
)?),
|
||||
None => None,
|
||||
};
|
||||
let records: Vec<ApplyRecord> =
|
||||
read_json(&cfg.state_dir.join("applies.json"))?.unwrap_or_default();
|
||||
let push: PushState = read_json(&cfg.state_dir.join("push.json"))?.unwrap_or_default();
|
||||
@@ -217,6 +238,19 @@ impl Control {
|
||||
repo,
|
||||
edge,
|
||||
share_key,
|
||||
pki,
|
||||
engine: Mutex::new(crate::switch::EngineState {
|
||||
running: cfg
|
||||
.engine
|
||||
.as_ref()
|
||||
.map(|e| crate::switch::read_engine_file(&e.file))
|
||||
.unwrap_or_else(|| "pingora".into()),
|
||||
state: "running".into(),
|
||||
since: now(),
|
||||
target: None,
|
||||
last_error: None,
|
||||
}),
|
||||
units: crate::switch::units_for(cfg.engine.as_ref()),
|
||||
records: Mutex::new(records),
|
||||
queue: Mutex::new(VecDeque::new()),
|
||||
wake: Notify::new(),
|
||||
@@ -228,6 +262,11 @@ impl Control {
|
||||
apply_lock: tokio::sync::Mutex::new(()),
|
||||
cfg,
|
||||
});
|
||||
if let Ok((_, _, m)) = c.head_model()
|
||||
&& let Err(f) = c.pki_prepare(&m)
|
||||
{
|
||||
log::error!(target: "ianitor::pki", "{}", f.reason.message);
|
||||
}
|
||||
c.recover().await?;
|
||||
Ok(c)
|
||||
}
|
||||
@@ -390,6 +429,9 @@ 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;
|
||||
@@ -863,6 +905,11 @@ impl Control {
|
||||
Ok(x) => x,
|
||||
Err(f) => return self.finish(&id, "failed", Some(f.reason), Vec::new()),
|
||||
};
|
||||
// Domi certificates for the hosts of the new tree, before anything is committed (new
|
||||
// files only: a certificate edge serves now is never replaced by a worse one).
|
||||
if let Err(f) = self.pki_prepare(&plan.model) {
|
||||
return self.finish(&id, "failed", Some(f.reason), Vec::new());
|
||||
}
|
||||
self.update(&id, |r| {
|
||||
r.step("compile", "done");
|
||||
r.step("write", "running");
|
||||
|
||||
Reference in New Issue
Block a user