Merge B2: one per-target route ledger, a typed gate, generation v4

TargetSupervision holds a sliding actuation log and the continuity restart
log (Q-B2-1 a); Forward can be refused (fails at once with the reopen
time, Q-B2-2), Survival is never refused and counted when it can be;
continuity restarts are Survival; a full disk neither spins supervision
nor reports unlanded writes as progress. Generation v4 with a typed lift
from v3 (irreversible; back up control.cc and history.cc before install).
Four Soul passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-09-30 07:36:34 +02:00
commit 46d9c2f9dc
7 changed files with 2644 additions and 472 deletions

View file

@ -82,8 +82,8 @@ running a script, and a dead `muninn serve` is seen the tick it dies.
2. No path on yggdrasil can start, stop or observe a host workload except
through the actuator session bound to that host's anchor.
3. A host with no attached actuator is a failed observation, which
continuity counts and gives up on after three attempts, exactly like a
unit that will not start.
continuity counts and gives up on after six restarts inside one hour,
exactly like a unit that will not start.
4. The actuator cannot be told to run a program the recipe did not declare;
`allowed_programs` on the host-native runner is enforced on the host.

View file

@ -3,6 +3,8 @@
# (the Eureka verify image has both); a Windows workstation proves nothing.
# The Windows check runs first: it is fast, and a hung test cannot mask it.
# --lib because the tests under tests/ assume the host layout.
# The Windows --lib --tests check keeps unix-only test code from leaking out of its cfg.
set -euo pipefail
cargo check --locked --target x86_64-pc-windows-gnu --bin idunn-host
cargo check --locked --target x86_64-pc-windows-gnu --lib --tests
cargo test --locked --lib

File diff suppressed because it is too large Load diff

View file

@ -5055,15 +5055,82 @@ pub struct NginxRouteDriver {
pub preflight_root: PathBuf,
}
/// The host programs and scratch directory the route driver actuates through.
/// The daemon owns one value and every driver is built from it, so the paths
/// are chosen in one place and a test can point them at stubs.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct RouteActuators {
pub nginx: PathBuf,
pub systemd_run: PathBuf,
pub systemctl: PathBuf,
pub ufw: PathBuf,
pub preflight_root: PathBuf,
}
impl Default for RouteActuators {
fn default() -> Self {
Self {
nginx: PathBuf::from("/usr/sbin/nginx"),
systemd_run: PathBuf::from("/usr/bin/systemd-run"),
systemctl: PathBuf::from("/usr/bin/systemctl"),
ufw: PathBuf::from("/usr/sbin/ufw"),
preflight_root: PathBuf::from("/run/idunn/route-preflight"),
}
}
}
/// Why a route actuation is being asked for. Only a `Forward` change can be
/// refused: restoring the admitted or incumbent route, and every actuation of a
/// continuity, is survival, not deployment, so a `Survival` is always admitted
/// and counted whenever the ledger can record it.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum RouteActuation {
Forward,
Survival,
}
/// A forward route actuation the ceiling refused. `reopens_at_unix_millis` is
/// when the oldest counted actuation leaves the window.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RouteActuationRefused {
pub target: String,
pub used: usize,
pub reopens_at_unix_millis: u64,
}
impl std::fmt::Display for RouteActuationRefused {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
formatter,
"route actuation ceiling reached for {}: {} in the window, reopens at unix ms {}",
self.target, self.used, self.reopens_at_unix_millis
)
}
}
impl std::error::Error for RouteActuationRefused {}
/// The one rate authority over route actuation. The driver asks it before
/// every group of host mutations (fragment write, firewall, `nginx -t`,
/// reload, private-mount validation) and does none of them when it refuses.
/// Its owner keeps the count durably, so the ceiling survives a restart.
pub trait RouteActuationGate {
fn admit(&self, kind: RouteActuation) -> Result<()>;
}
impl NginxRouteDriver {
pub fn new(binding: RouteBinding) -> Self {
Self::with_actuators(binding, &RouteActuators::default())
}
pub fn with_actuators(binding: RouteBinding, actuators: &RouteActuators) -> Self {
Self {
binding,
nginx_program: PathBuf::from("/usr/sbin/nginx"),
systemd_run_program: PathBuf::from("/usr/bin/systemd-run"),
systemctl_program: PathBuf::from("/usr/bin/systemctl"),
ufw_program: PathBuf::from("/usr/sbin/ufw"),
preflight_root: PathBuf::from("/run/idunn/route-preflight"),
nginx_program: actuators.nginx.clone(),
systemd_run_program: actuators.systemd_run.clone(),
systemctl_program: actuators.systemctl.clone(),
ufw_program: actuators.ufw.clone(),
preflight_root: actuators.preflight_root.clone(),
}
}
@ -5265,7 +5332,8 @@ impl NginxRouteDriver {
}
}
fn restore(&self, prior: Option<&[u8]>) -> Result<()> {
fn restore(&self, prior: Option<&[u8]>, gate: &dyn RouteActuationGate) -> Result<()> {
gate.admit(RouteActuation::Survival)?;
self.write_fragment(prior)?;
self.reload()?;
// No prior membership means the stable endpoint no longer routes to
@ -5281,8 +5349,9 @@ impl NginxRouteDriver {
prior: Option<&[u8]>,
failure: anyhow::Error,
context: &str,
gate: &dyn RouteActuationGate,
) -> Result<T> {
match self.restore(prior) {
match self.restore(prior, gate) {
Ok(()) => Err(failure).context(context.to_owned()),
Err(rollback) => Err(failure).context(format!(
"{context}; route rollback also failed: {rollback:#}"
@ -5295,6 +5364,7 @@ impl NginxRouteDriver {
expected: &IdunnExpectedIncarnationRecord,
runtime_instance_id: &str,
incumbent: Option<&RouteObservation>,
gate: &dyn RouteActuationGate,
) -> Result<RoutePreflightReceipt> {
let rendered = self.render(expected)?;
ensure!(!rendered.is_empty(), "candidate route rendered empty");
@ -5312,6 +5382,7 @@ impl NginxRouteDriver {
"route preflight found an unadmitted incumbent"
),
}
gate.admit(RouteActuation::Forward)?;
self.validate_candidate_in_private_mount(&rendered)?;
let after = self.current_configuration()?;
ensure!(
@ -5341,6 +5412,7 @@ impl NginxRouteDriver {
runtime_instance_id: &str,
preflight: &RoutePreflightReceipt,
rollback_allowed: bool,
gate: &dyn RouteActuationGate,
) -> Result<String> {
preflight.validate()?;
let rendered = self.render(expected)?;
@ -5359,6 +5431,7 @@ impl NginxRouteDriver {
&& prior_sha256 == preflight.incumbent_membership_sha256),
"route baseline changed after preflight"
);
gate.admit(RouteActuation::Forward)?;
if !candidate_already_written {
atomic_replace(&self.binding.config_path, &rendered)?;
}
@ -5368,6 +5441,7 @@ impl NginxRouteDriver {
preflight.incumbent_configuration.as_deref(),
error,
"candidate route validation or reload failed",
gate,
);
}
return Err(error).context(
@ -5406,13 +5480,17 @@ impl NginxRouteDriver {
/// candidate's membership was installed, so restoring it is precise whether
/// there was an incumbent (its bytes) or none (removal). Used when a
/// transaction is abandoned after the fence.
pub fn withdraw_candidate_membership(&self, preflight: &RoutePreflightReceipt) -> Result<()> {
pub fn withdraw_candidate_membership(
&self,
preflight: &RoutePreflightReceipt,
gate: &dyn RouteActuationGate,
) -> Result<()> {
preflight.validate()?;
ensure!(
preflight.route_id == self.binding.route_id,
"route preflight receipt describes another route"
);
self.restore(preflight.incumbent_configuration.as_deref())
self.restore(preflight.incumbent_configuration.as_deref(), gate)
}
/// A fragment already equal to the admitted membership is left alone: no
@ -5421,6 +5499,7 @@ impl NginxRouteDriver {
&self,
expected: &IdunnExpectedIncarnationRecord,
membership_sha256: &str,
gate: &dyn RouteActuationGate,
) -> Result<()> {
let rendered = self.render(expected)?;
ensure!(
@ -5430,6 +5509,7 @@ impl NginxRouteDriver {
if self.current_configuration()?.as_deref() == Some(rendered.as_slice()) {
return Ok(());
}
gate.admit(RouteActuation::Survival)?;
self.validate_candidate_in_private_mount(&rendered)?;
atomic_replace(&self.binding.config_path, &rendered)?;
if let Err(reload) = self.admit_endpoint().and_then(|()| self.reload()) {
@ -5557,6 +5637,7 @@ impl NginxRouteDriver {
expected: &IdunnExpectedIncarnationRecord,
runtime_instance_id: &str,
preflight: &RoutePreflightReceipt,
gate: &dyn RouteActuationGate,
) -> Result<()> {
preflight.validate()?;
let rendered = self.render(expected)?;
@ -5570,7 +5651,7 @@ impl NginxRouteDriver {
self.current_configuration()?.as_deref() == Some(rendered.as_slice()),
"candidate route changed before rollback"
);
self.restore(preflight.incumbent_configuration.as_deref())
self.restore(preflight.incumbent_configuration.as_deref(), gate)
}
}
@ -8254,6 +8335,15 @@ fn apply_identity(command: &mut Command, identity: Option<ProcessIdentity>) -> R
mod tests {
use super::*;
/// A gate that never refuses, for driver tests that are not about the ceiling.
struct Unmetered;
impl RouteActuationGate for Unmetered {
fn admit(&self, _kind: RouteActuation) -> Result<()> {
Ok(())
}
}
// ---------------------------------------------------------------------
// A direct challenge fails one of two ways. Silence waits; a bad answer,
// or a challenge that cannot be made, is an error.
@ -11570,13 +11660,160 @@ Content-Le".to_vec()), |_| {}),
"allow in to 10.77.0.1 port 17971 proto udp"
);
driver.restore(None)?;
driver.restore(None, &Unmetered)?;
assert_eq!(
fs::read_to_string(ufw.with_extension("calls"))?,
"delete allow in to 10.77.0.1 port 17971 proto udp\n"
);
fs::write(ufw.with_extension("absent"), b"gone\n")?;
driver.restore(None)?;
driver.restore(None, &Unmetered)?;
Ok(())
}
/// Refuses every `Forward` actuation, admits every `Survival`, and records
/// what it was asked.
struct ForwardRefusing(std::cell::RefCell<Vec<RouteActuation>>);
impl RouteActuationGate for ForwardRefusing {
fn admit(&self, kind: RouteActuation) -> Result<()> {
self.0.borrow_mut().push(kind);
match kind {
RouteActuation::Forward => Err(RouteActuationRefused {
target: "service".into(),
used: 12,
reopens_at_unix_millis: 99,
}
.into()),
RouteActuation::Survival => Ok(()),
}
}
}
/// Stub host programs that log every call, a driver over them, and a
/// candidate whose membership it can render.
#[cfg(unix)]
fn stubbed_route_driver(
temp: &Path,
) -> Result<(NginxRouteDriver, IdunnExpectedIncarnationRecord, PathBuf)> {
use std::os::unix::fs::PermissionsExt;
let calls = temp.join("calls");
let program = |name: &str| -> Result<PathBuf> {
let path = temp.join(name);
fs::write(
&path,
format!("#!/bin/sh\necho \"{name} $*\" >> '{}'\nexit 0\n", calls.display()),
)?;
fs::set_permissions(&path, fs::Permissions::from_mode(0o755))?;
Ok(path)
};
let driver = NginxRouteDriver::with_actuators(
RouteBinding {
driver: RouteDriver::NginxStreamTcp,
route_id: "service-route".into(),
stable_endpoint: "http://127.0.0.1:4103".into(),
private_host: "127.0.0.1".into(),
private_port_start: 4104,
private_port_end: 4109,
config_path: temp.join("service.conf"),
reload_unit: "nginx.service".into(),
},
&RouteActuators {
nginx: program("nginx")?,
systemd_run: program("systemd-run")?,
systemctl: program("systemctl")?,
ufw: program("ufw")?,
preflight_root: temp.join("preflight"),
},
);
let mut candidate = expected();
candidate.route = Some(cultnet_rs::IdunnExpectedRoute {
route_id: "service-route".into(),
transport: "http".into(),
stable_endpoint: "http://127.0.0.1:4103".into(),
candidate_endpoint: "http://127.0.0.1:4104".into(),
});
Ok((driver, candidate, calls))
}
#[cfg(unix)]
fn preflight_receipt(
driver: &NginxRouteDriver,
candidate: &IdunnExpectedIncarnationRecord,
) -> Result<RoutePreflightReceipt> {
Ok(RoutePreflightReceipt {
route_id: "service-route".into(),
candidate_runtime_instance_id: digest('a'),
candidate_membership_sha256: sha256_id(&driver.render(candidate)?),
incumbent_runtime_instance_id: None,
incumbent_membership_sha256: None,
incumbent_configuration: None,
})
}
/// A refused forward change stops before any host mutation: no program
/// runs, no fragment is written, and no private-mount unit starts.
#[cfg(unix)]
#[test]
fn a_refused_forward_actuation_runs_no_program_and_writes_nothing() -> Result<()> {
let temp = tempfile::tempdir()?;
let (driver, candidate, calls) = stubbed_route_driver(temp.path())?;
let gate = ForwardRefusing(Default::default());
let receipt = preflight_receipt(&driver, &candidate)?;
let refused = driver
.preflight(&candidate, &digest('a'), None, &gate)
.unwrap_err();
assert!(refused.downcast_ref::<RouteActuationRefused>().is_some());
let refused = driver
.install(&candidate, &digest('a'), &receipt, true, &gate)
.unwrap_err();
assert!(refused.downcast_ref::<RouteActuationRefused>().is_some());
assert!(!calls.exists(), "a refused actuation must run no program");
assert!(!driver.binding.config_path.exists());
assert_eq!(
*gate.0.borrow(),
[RouteActuation::Forward, RouteActuation::Forward]
);
Ok(())
}
/// Restoring the admitted or incumbent route is never refused, whatever
/// the gate says about forward changes, and is always asked as survival.
#[cfg(unix)]
#[test]
fn survival_actuations_run_under_a_gate_that_refuses_forward_changes() -> Result<()> {
let temp = tempfile::tempdir()?;
let (driver, candidate, calls) = stubbed_route_driver(temp.path())?;
let gate = ForwardRefusing(Default::default());
let receipt = preflight_receipt(&driver, &candidate)?;
let rendered = driver.render(&candidate)?;
let membership = sha256_id(&rendered);
let reloads = || -> Result<usize> {
Ok(fs::read_to_string(&calls)?
.lines()
.filter(|line| line.starts_with("systemctl reload"))
.count())
};
fs::write(&driver.binding.config_path, b"drifted bytes\n")?;
driver.restore_admitted_membership(&candidate, &membership, &gate)?;
assert_eq!(fs::read(&driver.binding.config_path)?, rendered);
assert_eq!(reloads()?, 1);
driver.withdraw_candidate_membership(&receipt, &gate)?;
assert!(!driver.binding.config_path.exists());
assert_eq!(reloads()?, 2);
fs::write(&driver.binding.config_path, &rendered)?;
driver.rollback(&candidate, &digest('a'), &receipt, &gate)?;
assert_eq!(reloads()?, 3);
assert_eq!(
*gate.0.borrow(),
[RouteActuation::Survival, RouteActuation::Survival, RouteActuation::Survival]
);
Ok(())
}
@ -11636,22 +11873,22 @@ Content-Le".to_vec()), |_| {}),
fs::write(&config, &rendered)?;
let modified = fs::metadata(&config)?.modified()?;
driver.restore_admitted_membership(&candidate, &membership_sha256)?;
driver.restore_admitted_membership(&candidate, &membership_sha256)?;
driver.restore_admitted_membership(&candidate, &membership_sha256, &Unmetered)?;
driver.restore_admitted_membership(&candidate, &membership_sha256, &Unmetered)?;
assert!(!calls.exists(), "an exact fragment must run no program");
assert!(!driver.preflight_root.exists());
assert_eq!(fs::read(&config)?, rendered);
assert_eq!(fs::metadata(&config)?.modified()?, modified);
fs::write(&config, b"drifted bytes\n")?;
driver.restore_admitted_membership(&candidate, &membership_sha256)?;
driver.restore_admitted_membership(&candidate, &membership_sha256, &Unmetered)?;
assert_eq!(fs::read(&config)?, rendered);
assert_eq!(count("systemctl reload")?, 1);
assert_eq!(count("systemd-run")?, 1);
assert_eq!(count("ufw allow")?, 1);
assert_eq!(count("nginx -t")?, 1);
driver.restore_admitted_membership(&candidate, &membership_sha256)?;
driver.restore_admitted_membership(&candidate, &membership_sha256, &Unmetered)?;
assert_eq!(count("systemctl reload")?, 1, "restored bytes never reload again");
assert_eq!(count("ufw")?, 1);
Ok(())
@ -11773,13 +12010,13 @@ Content-Le".to_vec()), |_| {}),
stable_endpoint: "http://127.0.0.1:4103".into(),
candidate_endpoint: "http://127.0.0.1:4104".into(),
});
let preflight = driver.preflight(&candidate, &digest('a'), None)?;
let preflight = driver.preflight(&candidate, &digest('a'), None, &Unmetered)?;
assert!(!config.exists());
assert_eq!(fs::read_dir(&driver.preflight_root)?.count(), 0);
let candidate_bytes = driver.render(&candidate)?;
fs::write(&config, &candidate_bytes)?;
let membership_sha256 = driver.install(&candidate, &digest('a'), &preflight, true)?;
let membership_sha256 = driver.install(&candidate, &digest('a'), &preflight, true, &Unmetered)?;
assert_eq!(
fs::read_to_string(systemctl.with_extension("calls"))?,
"reload\n"
@ -11801,24 +12038,24 @@ Content-Le".to_vec()), |_| {}),
observed_at_unix_millis: 1,
};
let next_preflight = driver.preflight(&candidate, &digest('b'), Some(&admitted))?;
let next_preflight = driver.preflight(&candidate, &digest('b'), Some(&admitted), &Unmetered)?;
assert_eq!(fs::read(&config)?, admitted_bytes);
fs::write(systemctl.with_extension("fail"), b"fail\n")?;
assert!(
driver
.install(&candidate, &digest('b'), &next_preflight, false)
.install(&candidate, &digest('b'), &next_preflight, false, &Unmetered)
.is_err()
);
assert_eq!(fs::read(&config)?, admitted_bytes);
fs::remove_file(systemctl.with_extension("fail"))?;
driver.install(&candidate, &digest('b'), &next_preflight, false)?;
driver.install(&candidate, &digest('b'), &next_preflight, false, &Unmetered)?;
fs::write(&config, b"foreign route\n")?;
assert!(
driver
.install(&candidate, &digest('b'), &next_preflight, true)
.install(&candidate, &digest('b'), &next_preflight, true, &Unmetered)
.is_err()
);
driver.restore_admitted_membership(&candidate, &admitted.membership_sha256)?;
driver.restore_admitted_membership(&candidate, &admitted.membership_sha256, &Unmetered)?;
assert_eq!(fs::read(&config)?, admitted_bytes);
assert!(driver.observe_membership(&candidate, &admitted.membership_sha256)?);
@ -11826,12 +12063,12 @@ Content-Le".to_vec()), |_| {}),
fs::write(systemctl.with_extension("fail"), b"fail\n")?;
assert!(
driver
.restore_admitted_membership(&candidate, &admitted.membership_sha256)
.restore_admitted_membership(&candidate, &admitted.membership_sha256, &Unmetered)
.is_err()
);
assert!(!config.exists());
fs::remove_file(systemctl.with_extension("fail"))?;
driver.restore_admitted_membership(&candidate, &admitted.membership_sha256)?;
driver.restore_admitted_membership(&candidate, &admitted.membership_sha256, &Unmetered)?;
assert_eq!(fs::read(&config)?, admitted_bytes);
Ok(())
}

View file

@ -42,3 +42,21 @@ borrowed from `transaction-fencing`.
| `transaction-pre-fence-abort-terminal` | the same abort finished: Complete, `FailedBeforeFencing` |
| `transaction-post-fence-abort` | Fencing continuity, post-fencing abort in flight |
| `provider-anchor` | one line: the provider trust-anchor file bytes, hex. A test writes it to the fixed path so the Engine can read the plan's anchor |
## Generation v3 (the B2 lift)
`generation-v3-odin` and `generation-v3-route-proof` are the exact
`idunn.admitted_generation.v3` payloads the encoder at Idunn `583b2a7` wrote
(`admitted_envelope` over `rmp_serde::to_vec`), printed by a throwaway test that
is not kept. The first is the v2 `generation-with-receipts` record lifted by that
revision's own `LegacyAdmittedGeneration::into_current`, the second is the
generation `route_proof::committed_generation` admits through a real route-proof
deployment. Both are synthetic.
| File | Schema | What it is |
|---|---|---|
| `generation-v3-odin` | `idunn.admitted_generation.v3` | routed, Odin-correlated generation |
| `generation-v3-route-proof` | `idunn.admitted_generation.v3` | routed, route-proof generation, no Odin receipts |
`control_plane.rs` decodes them through `LegacyAdmittedGenerationV3`; the
fixtures die with that struct.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long