Implement guarded Linux updater runtime and compatible baseline tooling
Rust development slice / linux (push) Failing after 8s

This commit is contained in:
2026-11-16 15:25:46 +01:00
parent 6497c79a91
commit 96a2b6e5ae
44 changed files with 6986 additions and 1024 deletions
+197 -3
View File
@@ -231,16 +231,28 @@ impl QualifiedRegistry {
Ok(())
}
pub fn verify_admission(&self, policy: &LocalUpdatePolicy, budget: &Budget) -> Result<()> {
self.verify_phase(policy, budget, false)
self.verify_phase(policy, budget, false, None)
}
pub fn verify_stopped(&self, policy: &LocalUpdatePolicy, budget: &Budget) -> Result<()> {
self.verify_phase(policy, budget, true)
self.verify_phase(policy, budget, true, None)
}
pub fn verify_known_failure_stopped(
&self,
policy: &LocalUpdatePolicy,
stopped: &rmm_updater_linux::services::StoppedServices,
budget: &Budget,
) -> Result<()> {
let source = stopped.early_full_failure(budget)?;
self.verify_phase(policy, budget, true, Some(source.failure()))?;
stopped.early_full_failure(budget)?;
Ok(())
}
fn verify_phase(
&self,
policy: &LocalUpdatePolicy,
budget: &Budget,
stopped: bool,
failed: Option<&rmm_updater_linux::services::FailedStartProof>,
) -> Result<()> {
budget.check()?;
self.verify_protected()?;
@@ -269,7 +281,15 @@ impl QualifiedRegistry {
for (index, unit) in self.registry.units.iter().enumerate() {
let active = index < 4 && (!stopped || index == 3);
let status = observe(unit, budget)?;
status.verify(unit, active, index < 4)?;
if let Some(failure) = failed.filter(|f| f.service.unit() == unit.unit) {
ensure!(
stopped && index < 3 && !active,
"UPDATE_FAILED_READER_SCOPE"
);
status.verify_known_failed(unit, failure)?;
} else {
status.verify(unit, active, index < 4)?;
}
first.insert(unit.unit.clone(), status);
}
for unit in &self.registry.rollback_timers {
@@ -586,6 +606,41 @@ impl Status {
&& self.connections.is_none_or(|n| n == 0)
&& self.fields["Job"].is_empty()
}
fn verify_known_failed(
&self,
unit: &Unit,
failure: &rmm_updater_linux::services::FailedStartProof,
) -> Result<()> {
let f = &self.fields;
ensure!(
!unit.composition.is_empty()
&& failure.service.unit() == unit.unit
&& f["ActiveState"] == "failed"
&& f["SubState"] == "failed"
&& self.main_pid == Some(0)
&& self.control_pid == Some(0)
&& f["Job"].is_empty()
&& f["LoadState"] == "loaded"
&& f["UnitFileState"] == unit.unit_file_state
&& relations(&f["Triggers"])? == unit.triggers
&& relations(&f["TriggeredBy"])? == unit.triggered_by,
"UPDATE_FAILED_READER_NOT_CLOSED"
);
let mut paths = vec![f["FragmentPath"].as_str()];
paths.extend(f["DropInPaths"].split_ascii_whitespace());
ensure!(
paths
.into_iter()
.eq(unit.composition.iter().map(|(p, _)| p.as_str())),
"UPDATE_FAILED_READER_UNIT_CHANGED"
);
for (key, value) in &failure.status {
if let Some(actual) = f.get(key) {
ensure!(actual == value, "UPDATE_FAILED_READER_STATUS_CHANGED");
}
}
Ok(())
}
fn verify(&self, unit: &Unit, active: bool, original_reader: bool) -> Result<()> {
let fields = &self.fields;
ensure!(
@@ -796,6 +851,145 @@ fn command(args: &[&str], budget: &Budget) -> Result<Vec<u8>> {
}
}
/// Public bootstrap metadata only. This does not publish policy, qualify a
/// reader, start the updater or grant any update/job authority. The operator
/// must bind the qualification receipt to actual freshly verified code/sync.
#[derive(Serialize)]
pub struct BootstrapMetadata {
pub registry_bytes: Vec<u8>,
pub reader_registry_sha256: String,
pub services: Vec<rmm_domain::agent_update_provisioning::LocalServicePin>,
pub updater_service: rmm_domain::agent_update_provisioning::LocalServicePin,
}
/// Read the actual fixed 21-unit closure AFTER compatible pair startup and
/// installation of the still-stopped stable updater unit. Never invent file IDs
/// or infer a registry from source unit text; retain each measured file until
/// the second identical actual observation. No filesystem/SCM mutations.
pub fn bootstrap_metadata(
qualification_sha256: &str,
budget: &Budget,
) -> Result<BootstrapMetadata> {
ensure!(
digest(qualification_sha256) && unsafe { libc::geteuid() } == 0,
"UPDATE_BOOTSTRAP_METADATA_SCOPE"
);
let host_context = current_host_context()?;
let first_rollback = rollback_names(budget)?;
let names = fixed_units()
.into_iter()
.chain(first_rollback.iter().cloned())
.collect::<Vec<_>>();
let mut retained = Vec::new();
let mut units = Vec::new();
let mut first = Vec::new();
for (index, name) in names.iter().enumerate() {
let mut unit = Unit {
unit: name.clone(),
unit_file_state: String::new(),
composition: Vec::new(),
triggers: Vec::new(),
triggered_by: Vec::new(),
};
let status = observe(&unit, budget)?;
let fields = &status.fields;
unit.unit_file_state = fields["UnitFileState"].clone();
unit.triggers = relations(&fields["Triggers"])?;
unit.triggered_by = relations(&fields["TriggeredBy"])?;
ensure!(
unit.triggers
.iter()
.chain(&unit.triggered_by)
.all(|n| names.contains(n)),
"UPDATE_BOOTSTRAP_UNKNOWN_ACTIVATION_RELATION"
);
if fields["LoadState"] == "loaded" {
let mut paths = vec![fields["FragmentPath"].as_str()];
paths.extend(fields["DropInPaths"].split_ascii_whitespace());
ensure!(
!paths[0].is_empty() && paths.len() <= 17,
"UPDATE_BOOTSTRAP_UNIT_PATHS"
);
for (position, path) in paths.into_iter().enumerate() {
let leaf = Path::new(path).file_name().and_then(|v| v.to_str());
ensure!(
unit_path(path)
&& if position == 0 {
leaf == Some(name.as_str())
} else {
leaf.is_some_and(|v| v.ends_with(".conf"))
},
"UPDATE_BOOTSTRAP_UNIT_PATH"
);
let held = Protected::open(Path::new(path))?;
unit.composition.push((path.into(), held.proof.clone()));
retained.push(held);
}
}
// The prospective updater is deliberately inactive until ALL protected
// trust/baseline/retained material has been independently provisioned.
status.verify(&unit, index < 3, index < 4)?;
if index >= 4 && !unit.composition.is_empty() {
ensure!(
unit.unit_file_state == "disabled",
"UPDATE_BOOTSTRAP_CLOSED_UNIT_AUTOSTART"
);
}
ensure!(retained.len() <= MAX_FILES, "UPDATE_BOOTSTRAP_FILE_LIMIT");
first.push(status);
units.push(unit);
}
ensure!(
units.len() == 21 + first_rollback.len() && !units[3].composition.is_empty(),
"UPDATE_BOOTSTRAP_UPDATER_UNIT_REQUIRED"
);
for (unit, status) in units.iter().zip(&first) {
ensure!(
observe(unit, budget)? == *status,
"UPDATE_BOOTSTRAP_UNIT_CHANGED"
);
}
for held in &retained {
held.verify()?;
}
ensure!(
rollback_names(budget)? == first_rollback && current_host_context()? == host_context,
"UPDATE_BOOTSTRAP_HOST_OR_TIMER_CHANGED"
);
let pin = |unit: &Unit| -> Result<rmm_domain::agent_update_provisioning::LocalServicePin> {
Ok(rmm_domain::agent_update_provisioning::LocalServicePin {
unit: unit.unit.clone(),
unit_sha256: hash(&serde_json::to_vec(&unit.composition)?),
})
};
let mut services = units[..3].iter().map(pin).collect::<Result<Vec<_>>>()?;
if !units[4].composition.is_empty() {
services.push(pin(&units[4])?);
}
let updater_service = pin(&units[3])?;
let rollback_timers = units.split_off(21);
let registry = Registry {
schema_version: 1,
profile: "linux_shared_readers_v1".into(),
bootstrap_receipt_sha256: qualification_sha256.into(),
reader_contract_sha256: reader_contract_sha256(),
host_context,
units,
rollback_timers,
};
let registry_bytes = serde_json::to_vec(&registry)?;
ensure!(
registry_bytes.len() <= MAX_BYTES as usize,
"UPDATE_BOOTSTRAP_REGISTRY_LIMIT"
);
budget.check()?;
Ok(BootstrapMetadata {
reader_registry_sha256: hash(&registry_bytes),
registry_bytes,
services,
updater_service,
})
}
#[cfg(test)]
mod tests {
use super::*;