Implement guarded Linux updater runtime and compatible baseline tooling
Rust development slice / linux (push) Failing after 8s
Rust development slice / linux (push) Failing after 8s
This commit is contained in:
@@ -73,19 +73,98 @@ impl TrustState {
|
||||
/// 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();
|
||||
Self::load_inputs(
|
||||
Some(original.update()),
|
||||
binding,
|
||||
original.delegation().prepared_at,
|
||||
)
|
||||
}
|
||||
/// Explicit PRE-consumption verification. No Original/start/consumption is
|
||||
/// fabricated to reuse a retained-evidence API. Caller still needs fresh
|
||||
/// independent HelperSync admission and atomic durable handoff afterwards.
|
||||
pub fn load_prepared(
|
||||
update: &rmm_domain::agent_update::ResolvedAgentUpdate,
|
||||
binding: &Binding,
|
||||
clock: &NativeClock,
|
||||
) -> Result<Self> {
|
||||
ensure!(
|
||||
update.validate() && update.execution_identity() == Some("root"),
|
||||
"UPDATE_PREPARED_ACTION"
|
||||
);
|
||||
let state = Self::load_inputs(Some(update), binding, clock.now()?)?;
|
||||
state.recheck_prepared(update, clock)?;
|
||||
Ok(state)
|
||||
}
|
||||
pub fn load_observed(binding: &Binding, clock: &NativeClock) -> Result<Self> {
|
||||
let state = Self::load_inputs(None, binding, clock.now()?)?;
|
||||
state.recheck_observed()?;
|
||||
Ok(state)
|
||||
}
|
||||
pub fn recheck_observed(&self) -> Result<()> {
|
||||
self.recheck_protected()?;
|
||||
ensure!(
|
||||
!self.baseline_signer_revoked,
|
||||
"UPDATE_BASELINE_SIGNER_REVOKED"
|
||||
);
|
||||
verify_installed_release(
|
||||
&self.keyring,
|
||||
&self.installed,
|
||||
self.updater_binding.keyring_generation,
|
||||
)
|
||||
}
|
||||
pub fn updater_binding(&self) -> &rmm_domain::agent_update::UpdaterBinding {
|
||||
&self.updater_binding
|
||||
}
|
||||
pub fn predecessor(&self) -> &rmm_domain::agent_update::Predecessor {
|
||||
&self.predecessor
|
||||
}
|
||||
pub fn activation_floor(&self) -> u64 {
|
||||
self.installed.activation_floor
|
||||
}
|
||||
pub fn verify_candidate(
|
||||
&self,
|
||||
envelope: &rmm_domain::agent_update::ReleaseEnvelope,
|
||||
clock: &NativeClock,
|
||||
) -> Result<()> {
|
||||
self.recheck_observed()?;
|
||||
let active = self
|
||||
.installed
|
||||
.release_envelope
|
||||
.decode()
|
||||
.map_err(anyhow::Error::msg)?;
|
||||
verify(
|
||||
&self.keyring,
|
||||
envelope,
|
||||
&TrustedContext {
|
||||
platform: ReleasePlatform::LinuxX64,
|
||||
now_utc_seconds: u64::try_from(clock.now()?.timestamp())?,
|
||||
keyring_generation: self.updater_binding.keyring_generation,
|
||||
protocol_major: active.manifest.protocol_major,
|
||||
state_schema: active.manifest.state_schema,
|
||||
updater_version: 1,
|
||||
minimum_release_sequence: self.installed.activation_floor,
|
||||
active_release: Some(ActiveRelease {
|
||||
sequence: active.manifest.release_sequence,
|
||||
manifest_sha256: self.installed.manifest_sha256.clone(),
|
||||
}),
|
||||
},
|
||||
)
|
||||
}
|
||||
fn load_inputs(
|
||||
update: Option<&rmm_domain::agent_update::ResolvedAgentUpdate>,
|
||||
binding: &Binding,
|
||||
prepared_at: chrono::DateTime<chrono::Utc>,
|
||||
) -> Result<Self> {
|
||||
let mut protected = Vec::new();
|
||||
let (file, raw) = Protected::read(Path::new("/etc/rmm-agent-updater/policy.json"), 65536)?;
|
||||
let (policy, policy_hash) =
|
||||
LocalUpdatePolicy::from_bytes(&raw).map_err(anyhow::Error::msg)?;
|
||||
ensure!(
|
||||
policy_hash == update.updater.policy_sha256
|
||||
&& policy.tenant_id == binding.tenant_id
|
||||
policy.tenant_id == binding.tenant_id
|
||||
&& policy.asset_id == binding.asset_id
|
||||
&& policy.agent_id == binding.agent_id
|
||||
&& policy.enrollment_generation == binding.enrollment_generation
|
||||
&& policy.assignment_version == binding.assignment_version
|
||||
&& policy.updater_binary_sha256 == update.updater.binary_sha256,
|
||||
&& policy.assignment_version == binding.assignment_version,
|
||||
"UPDATE_PROTECTED_POLICY_CHANGED"
|
||||
);
|
||||
protected.push(file);
|
||||
@@ -97,12 +176,8 @@ impl TrustState {
|
||||
protected.push(file);
|
||||
let (file, raw) = Protected::read(Path::new(&policy.keyring_path), 16384)?;
|
||||
let keys: UpdateKeyringFile = serde_json::from_slice(&raw)?;
|
||||
ensure!(
|
||||
keys.validate()
|
||||
&& keys.generation == update.updater.keyring_generation
|
||||
&& hash(&raw) == update.updater.keyring_sha256,
|
||||
"UPDATE_PROTECTED_KEYRING_CHANGED"
|
||||
);
|
||||
ensure!(keys.validate(), "UPDATE_PROTECTED_KEYRING_CHANGED");
|
||||
let keyring_sha256 = hash(&raw);
|
||||
protected.push(file);
|
||||
let job_key = hex::decode(&binding.public_key_hex)?;
|
||||
let mut trusted = Vec::new();
|
||||
@@ -171,8 +246,6 @@ impl TrustState {
|
||||
let health_public_key = health.public_key().map_err(anyhow::Error::msg)?;
|
||||
ensure!(
|
||||
!VerifyingKey::from_bytes(&health_public_key)?.is_weak()
|
||||
&& hash(&raw) == update.updater.health_key_pin_sha256
|
||||
&& hex::encode(health_public_key) == update.updater.health_public_key_hex
|
||||
&& health_public_key.as_slice() != job_key
|
||||
&& keys
|
||||
.keys
|
||||
@@ -180,17 +253,14 @@ impl TrustState {
|
||||
.all(|key| key.public_key_hex != hex::encode(health_public_key)),
|
||||
"UPDATE_HEALTH_KEY_NOT_SEPARATE_OR_CHANGED"
|
||||
);
|
||||
let health_key_pin_sha256 = hash(&raw);
|
||||
protected.push(file);
|
||||
let (file, raw) = Protected::read(Path::new(&policy.installed_record_path), 32768)?;
|
||||
ensure!(
|
||||
hash(&raw) == update.predecessor.installed_record_sha256,
|
||||
"UPDATE_INSTALLED_RECORD_CHANGED"
|
||||
);
|
||||
let installed = InstalledReleaseRecord::from_bytes(&raw).map_err(anyhow::Error::msg)?;
|
||||
ensure!(
|
||||
!installed.rolled_back
|
||||
&& installed.activation_floor >= policy.initial_activation_floor
|
||||
&& installed.activated_at <= original.handoff().consumed_at,
|
||||
&& installed.activated_at <= u64::try_from(prepared_at.timestamp())?,
|
||||
"UPDATE_INSTALLED_FLOOR_OR_TIME"
|
||||
);
|
||||
if matches!(
|
||||
@@ -208,37 +278,53 @@ impl TrustState {
|
||||
.release_envelope
|
||||
.decode()
|
||||
.map_err(anyhow::Error::msg)?;
|
||||
ensure!(
|
||||
active.manifest.release_id == update.predecessor.release_id
|
||||
&& active.manifest.release_sequence == update.predecessor.release_sequence
|
||||
&& installed.manifest_sha256 == update.predecessor.manifest_sha256
|
||||
&& active.manifest.artifacts[0].sha256 == update.predecessor.agent_sha256
|
||||
&& active.manifest.artifacts[1].sha256 == update.predecessor.helper_sha256,
|
||||
"UPDATE_INSTALLED_PREDECESSOR_BINDING"
|
||||
);
|
||||
let predecessor = rmm_domain::agent_update::Predecessor {
|
||||
release_id: active.manifest.release_id,
|
||||
release_sequence: active.manifest.release_sequence,
|
||||
manifest_sha256: installed.manifest_sha256.clone(),
|
||||
installed_record_sha256: hash(&raw),
|
||||
agent_sha256: active.manifest.artifacts[0].sha256.clone(),
|
||||
helper_sha256: active.manifest.artifacts[1].sha256.clone(),
|
||||
};
|
||||
let updater_binding = rmm_domain::agent_update::UpdaterBinding {
|
||||
binary_sha256: policy.updater_binary_sha256.clone(),
|
||||
policy_sha256: policy_hash,
|
||||
keyring_generation: keys.generation,
|
||||
keyring_sha256,
|
||||
health_public_key_hex: hex::encode(health_public_key),
|
||||
health_key_pin_sha256,
|
||||
};
|
||||
if let Some(update) = update {
|
||||
ensure!(
|
||||
update.predecessor == predecessor && update.updater == updater_binding,
|
||||
"UPDATE_PROTECTED_INPUT_BINDING"
|
||||
);
|
||||
}
|
||||
verify_installed_release(&historical, &installed, keys.generation)?;
|
||||
verify(
|
||||
&historical,
|
||||
&update.release_envelope,
|
||||
&TrustedContext {
|
||||
platform: ReleasePlatform::LinuxX64,
|
||||
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,
|
||||
updater_version: 1,
|
||||
minimum_release_sequence: installed.activation_floor,
|
||||
active_release: Some(ActiveRelease {
|
||||
sequence: active.manifest.release_sequence,
|
||||
manifest_sha256: installed.manifest_sha256.clone(),
|
||||
}),
|
||||
},
|
||||
)?;
|
||||
if let Some(update) = update {
|
||||
verify(
|
||||
&historical,
|
||||
&update.release_envelope,
|
||||
&TrustedContext {
|
||||
platform: ReleasePlatform::LinuxX64,
|
||||
now_utc_seconds: u64::try_from(prepared_at.timestamp())?,
|
||||
keyring_generation: keys.generation,
|
||||
protocol_major: active.manifest.protocol_major,
|
||||
state_schema: active.manifest.state_schema,
|
||||
updater_version: 1,
|
||||
minimum_release_sequence: installed.activation_floor,
|
||||
active_release: Some(ActiveRelease {
|
||||
sequence: active.manifest.release_sequence,
|
||||
manifest_sha256: installed.manifest_sha256.clone(),
|
||||
}),
|
||||
},
|
||||
)?;
|
||||
}
|
||||
protected.push(file);
|
||||
let baseline_signer_revoked = baseline_entry.revoked;
|
||||
Ok(Self {
|
||||
updater_binding: update.updater.clone(),
|
||||
predecessor: update.predecessor.clone(),
|
||||
updater_binding,
|
||||
predecessor,
|
||||
protected,
|
||||
policy,
|
||||
installed,
|
||||
@@ -255,6 +341,25 @@ impl TrustState {
|
||||
self.recheck_crypto(original, clock)
|
||||
}
|
||||
fn recheck_crypto(&self, original: &Original, clock: &NativeClock) -> Result<()> {
|
||||
self.recheck_crypto_inputs(original.update(), clock)
|
||||
}
|
||||
pub fn recheck_prepared(
|
||||
&self,
|
||||
update: &rmm_domain::agent_update::ResolvedAgentUpdate,
|
||||
clock: &NativeClock,
|
||||
) -> Result<()> {
|
||||
ensure!(
|
||||
update.updater == self.updater_binding && update.predecessor == self.predecessor,
|
||||
"UPDATE_PREPARED_CONTEXT_CHANGED"
|
||||
);
|
||||
self.recheck_protected()?;
|
||||
self.recheck_crypto_inputs(update, clock)
|
||||
}
|
||||
fn recheck_crypto_inputs(
|
||||
&self,
|
||||
update: &rmm_domain::agent_update::ResolvedAgentUpdate,
|
||||
clock: &NativeClock,
|
||||
) -> Result<()> {
|
||||
ensure!(
|
||||
!self.baseline_signer_revoked,
|
||||
"UPDATE_BASELINE_SIGNER_REVOKED"
|
||||
@@ -262,7 +367,7 @@ impl TrustState {
|
||||
verify_installed_release(
|
||||
&self.keyring,
|
||||
&self.installed,
|
||||
original.update().updater.keyring_generation,
|
||||
update.updater.keyring_generation,
|
||||
)?;
|
||||
let active = self
|
||||
.installed
|
||||
@@ -271,11 +376,11 @@ impl TrustState {
|
||||
.map_err(anyhow::Error::msg)?;
|
||||
verify(
|
||||
&self.keyring,
|
||||
&original.update().release_envelope,
|
||||
&update.release_envelope,
|
||||
&TrustedContext {
|
||||
platform: ReleasePlatform::LinuxX64,
|
||||
now_utc_seconds: u64::try_from(clock.now()?.timestamp())?,
|
||||
keyring_generation: original.update().updater.keyring_generation,
|
||||
keyring_generation: update.updater.keyring_generation,
|
||||
protocol_major: active.manifest.protocol_major,
|
||||
state_schema: active.manifest.state_schema,
|
||||
updater_version: 1,
|
||||
|
||||
Reference in New Issue
Block a user