Wire preserved update control, health evidence and record publication
Rust development slice / linux (push) Failing after 7s

This commit is contained in:
2026-11-14 23:51:59 +01:00
parent 328e440f73
commit 8e93c9ead5
34 changed files with 7071 additions and 97 deletions
+190 -25
View File
@@ -53,14 +53,26 @@ impl Protected {
}
}
pub struct TrustState {
updater_binding: rmm_domain::agent_update::UpdaterBinding,
predecessor: rmm_domain::agent_update::Predecessor,
protected: Vec<Protected>,
policy: LocalUpdatePolicy,
installed: InstalledReleaseRecord,
installed_raw: Vec<u8>,
keyring: UpdateKeyring,
keyring_file: UpdateKeyringFile,
baseline_signer_revoked: bool,
health_public_key: [u8; 32],
}
impl TrustState {
pub fn load(original: &Original, binding: &Binding, clock: &NativeClock) -> Result<Self> {
let result = Self::load_retained(original, binding)?;
result.recheck(original, clock)?;
Ok(result)
}
/// EXACT ORIGINAL evidence only. The separate historical keyring below
/// never supplies current admission, Health, Finalize or effect authority.
pub fn load_retained(original: &Original, binding: &Binding) -> Result<Self> {
let update = original.update();
let mut protected = Vec::new();
let (file, raw) = Protected::read(Path::new("/etc/rmm-agent-updater/policy.json"), 65536)?;
@@ -88,6 +100,7 @@ impl TrustState {
protected.push(file);
let job_key = hex::decode(&binding.public_key_hex)?;
let mut trusted = Vec::new();
let mut historical_keys = Vec::new();
let mut baseline_key = None;
for entry in &keys.keys {
ensure!(entry.platform == Platform::LinuxX64, "UPDATE_KEY_PLATFORM");
@@ -108,23 +121,30 @@ impl TrustState {
entry.last_sequence,
entry.revoked,
)?);
historical_keys.push(TrustedUpdateKey::new(
public,
ReleasePlatform::LinuxX64,
entry.first_sequence,
entry.last_sequence,
false,
)?);
}
let keyring = UpdateKeyring::new(keys.generation, trusted)?;
let historical = UpdateKeyring::new(keys.generation, historical_keys)?;
let baseline = policy
.initial_baseline
.decode()
.map_err(anyhow::Error::msg)?;
let (baseline_entry, public) = baseline_key.context("UPDATE_BASELINE_KEY_NOT_TRUSTED")?;
ensure!(
!baseline_entry.revoked
&& baseline
.record
.release_envelope
.decode()
.map_err(anyhow::Error::msg)?
.manifest
.release_sequence
>= baseline_entry.first_sequence
baseline
.record
.release_envelope
.decode()
.map_err(anyhow::Error::msg)?
.manifest
.release_sequence
>= baseline_entry.first_sequence
&& baseline
.record
.release_envelope
@@ -161,18 +181,23 @@ impl TrustState {
"UPDATE_INSTALLED_RECORD_CHANGED"
);
let installed = InstalledReleaseRecord::from_bytes(&raw).map_err(anyhow::Error::msg)?;
// This first concrete activation is bootstrap-bound. A future Updated
// predecessor must have its complete guarded Health/record chain proved;
// never accept its mutable fields merely because parsing succeeded.
ensure!(
matches!(
installed.activation_evidence,
ActivationEvidence::Bootstrap { .. }
) && raw == baseline.payload_bytes
&& hash(&raw) == policy.initial_record_sha256
&& installed.activation_floor == policy.initial_activation_floor,
"UPDATE_INSTALLED_CHAIN_NOT_QUALIFIED"
!installed.rolled_back
&& installed.activation_floor >= policy.initial_activation_floor
&& installed.activated_at <= original.handoff().consumed_at,
"UPDATE_INSTALLED_FLOOR_OR_TIME"
);
if matches!(
installed.activation_evidence,
ActivationEvidence::Bootstrap { .. }
) {
ensure!(
raw == baseline.payload_bytes
&& hash(&raw) == policy.initial_record_sha256
&& installed.activation_floor == policy.initial_activation_floor,
"UPDATE_INSTALLED_BASELINE_CHANGED"
);
}
let active = installed
.release_envelope
.decode()
@@ -185,13 +210,13 @@ impl TrustState {
&& active.manifest.artifacts[1].sha256 == update.predecessor.helper_sha256,
"UPDATE_INSTALLED_PREDECESSOR_BINDING"
);
verify_installed_release(&keyring, &installed, keys.generation)?;
verify_installed_release(&historical, &installed, keys.generation)?;
verify(
&keyring,
&historical,
&update.release_envelope,
&TrustedContext {
platform: ReleasePlatform::LinuxX64,
now_utc_seconds: u64::try_from(clock.now()?.timestamp())?,
now_utc_seconds: u64::try_from(original.delegation().prepared_at.timestamp())?,
keyring_generation: keys.generation,
protocol_major: active.manifest.protocol_major,
state_schema: active.manifest.state_schema,
@@ -204,18 +229,35 @@ impl TrustState {
},
)?;
protected.push(file);
let baseline_signer_revoked = baseline_entry.revoked;
Ok(Self {
updater_binding: update.updater.clone(),
predecessor: update.predecessor.clone(),
protected,
policy,
installed,
installed_raw: raw,
keyring,
keyring_file: keys,
baseline_signer_revoked,
health_public_key,
})
}
pub fn recheck(&self, original: &Original, clock: &NativeClock) -> Result<()> {
for file in &self.protected {
file.verify()?;
}
self.recheck_original_binding(original)?;
self.recheck_protected()?;
self.recheck_crypto(original, clock)
}
fn recheck_crypto(&self, original: &Original, clock: &NativeClock) -> Result<()> {
ensure!(
!self.baseline_signer_revoked,
"UPDATE_BASELINE_SIGNER_REVOKED"
);
verify_installed_release(
&self.keyring,
&self.installed,
original.update().updater.keyring_generation,
)?;
let active = self
.installed
.release_envelope
@@ -239,6 +281,129 @@ impl TrustState {
},
)
}
pub fn installed_raw(&self) -> &[u8] {
&self.installed_raw
}
/// Exact typed active-record namespace only. Every other protected name
/// remains mandatory; neither caller booleans nor path wildcards can skip it.
pub fn recheck_record_namespace(
&self,
original: &Original,
clock: &NativeClock,
namespace: &crate::record::RecordNamespaceProof<'_>,
) -> Result<()> {
self.recheck_original_binding(original)?;
self.recheck_protected_record_namespace(original, namespace)?;
self.recheck_crypto(original, clock)
}
pub fn recheck_protected_record_namespace(
&self,
original: &Original,
namespace: &crate::record::RecordNamespaceProof<'_>,
) -> Result<()> {
self.recheck_original_binding(original)?;
namespace.verify()?;
ensure!(
namespace.grant_id() == original.permit().grant_id
&& namespace.owner_nonce() == original.handoff().owner_nonce
&& namespace.old_sha256() == original.handoff().predecessor_record_sha256
&& namespace.old_sha256() == hash(&self.installed_raw),
"UPDATE_RECORD_NAMESPACE_ORIGINAL_BINDING"
);
let mut matched = 0;
for protected in &self.protected {
if protected.name == "installed-record.json"
&& protected.dir.identity() == namespace.directory_identity()
{
ensure!(
protected.file.proof() == namespace.old_file(),
"UPDATE_RECORD_ORIGINAL_HELD_IDENTITY_CHANGED"
);
matched += 1;
} else {
protected.verify()?;
}
}
ensure!(matched == 1, "UPDATE_RECORD_EXACT_PROTECTED_NAME_REQUIRED");
namespace.verify()
}
pub fn recheck_protected(&self) -> Result<()> {
for file in &self.protected {
file.verify()?;
}
Ok(())
}
pub fn recheck_original_binding(&self, original: &Original) -> Result<()> {
ensure!(
original.update().updater == self.updater_binding
&& original.update().predecessor == self.predecessor,
"UPDATE_TRUST_ORIGINAL_CONTEXT_CHANGED"
);
Ok(())
}
/// Full admission/Stop claims call this under THEIR actual guard. The
/// updater repeats it after all readers stop and before the first swap.
/// Never gate Unknown-only adjudication on this admission-oriented check.
pub fn qualify_history(
&self,
db: &rusqlite::Connection,
guard: &impl rmm_agent_core::helper_reconcile::ExecutorLedgerGuard,
binding: &Binding,
) -> Result<()> {
self.recheck_protected()?;
let baseline = self
.policy
.initial_baseline
.decode()
.map_err(anyhow::Error::msg)?;
let baseline_hash = hash(&baseline.payload_bytes);
let mut records = Vec::new();
let mut held = Vec::new();
let mut seen = std::collections::BTreeSet::new();
let mut next = self.installed.previous_record_sha256.clone();
let mut total = self.installed_raw.len() + baseline.payload_bytes.len();
while let Some(digest) = next {
ensure!(
rmm_domain::agent_update::digest(&digest)
&& seen.insert(digest.clone())
&& seen.len() < 64,
"UPDATE_RECORD_ARCHIVE_CHAIN"
);
if digest == baseline_hash {
break;
}
let (file, raw) = Protected::read(
&Path::new("/var/lib/rmm-agent-updater/records").join(format!("{digest}.json")),
32768,
)?;
ensure!(hash(&raw) == digest, "UPDATE_RECORD_ARCHIVE_HASH_CHANGED");
total = total
.checked_add(raw.len())
.context("UPDATE_RECORD_ARCHIVE_SIZE")?;
ensure!(total <= 2 * 1024 * 1024, "UPDATE_RECORD_ARCHIVE_SIZE");
let record = InstalledReleaseRecord::from_bytes(&raw).map_err(anyhow::Error::msg)?;
next = record.previous_record_sha256.clone();
records.push(raw);
held.push(file);
}
let record = crate::history::verify_history(
db,
guard,
binding,
&self.keyring_file,
&self.policy.initial_baseline,
&records,
&self.installed_raw,
)?;
ensure!(
record.bytes().map_err(anyhow::Error::msg)? == self.installed_raw,
"UPDATE_HISTORY_ACTIVE_CHANGED"
);
for file in &held {
file.verify()?;
}
self.recheck_protected()
}
pub fn policy(&self) -> &LocalUpdatePolicy {
&self.policy
}