Connect one-shot Linux updater worker flow behind the census gate
Rust development slice / linux (push) Failing after 7s
Rust development slice / linux (push) Failing after 7s
This commit is contained in:
@@ -0,0 +1,605 @@
|
||||
//! One live original-attempt pass. Activation queues only; the fixed listener
|
||||
//! must finish its reply before this runtime can stop the calling Fullhelper.
|
||||
//! No daemon entrypoint, admission/capability registration or restart recovery.
|
||||
use crate::{
|
||||
agent_startup::BoundAgentLock,
|
||||
bridge::{BridgeContext, FullBridge, Generation},
|
||||
bundle,
|
||||
clock::NativeClock,
|
||||
fence::LedgerFence,
|
||||
ledger::{OwnedInputs, OwnedLedger},
|
||||
original::Original,
|
||||
participants::{StableParticipant, verify_original_helper},
|
||||
retained::RetainedSet,
|
||||
returned,
|
||||
trust::TrustState,
|
||||
};
|
||||
use anyhow::{Context, Result, ensure};
|
||||
use rmm_agent_core::{
|
||||
auth::Binding,
|
||||
reconcile::SyncClock,
|
||||
update_handoff::{NativeControlOperation, NativeEffect, NativeEffectClaim, NativeService},
|
||||
};
|
||||
use rmm_domain::{
|
||||
agent_update::{ParticipantIdentity, ParticipantRole, UpdateInflightProof},
|
||||
agent_update_provisioning::{HealthKeyPin, InstalledReleaseRecord, LocalUpdatePolicy},
|
||||
jobs::hash,
|
||||
};
|
||||
use rmm_updater_handoff::{Evidence, Phase, Process};
|
||||
use rmm_updater_linux::{
|
||||
Budget, DurableEffectFence, Effect,
|
||||
files::{Directory, HeldFile, LedgerGuard, Role},
|
||||
ipc::{self, Request, Response, State},
|
||||
services::{Service, ServicePolicy, ServiceProof, Systemd},
|
||||
};
|
||||
use std::{ffi::OsStr, path::Path, time::Duration};
|
||||
use uuid::Uuid;
|
||||
|
||||
struct Protected {
|
||||
directory: Directory,
|
||||
file: HeldFile,
|
||||
name: String,
|
||||
max: u64,
|
||||
}
|
||||
impl Protected {
|
||||
fn read(path: &str, max: u64) -> Result<(Self, Vec<u8>)> {
|
||||
let path = Path::new(path);
|
||||
let directory = Directory::open(path.parent().context("UPDATE_ENGINE_PARENT")?, 0, false)?;
|
||||
let name = path
|
||||
.file_name()
|
||||
.context("UPDATE_ENGINE_NAME")?
|
||||
.to_str()
|
||||
.context("UPDATE_ENGINE_NAME")?
|
||||
.to_owned();
|
||||
let mut file = directory.inspect(OsStr::new(&name), 0, max)?;
|
||||
let raw = file.bytes(max)?;
|
||||
Ok((
|
||||
Self {
|
||||
directory,
|
||||
file,
|
||||
name,
|
||||
max,
|
||||
},
|
||||
raw,
|
||||
))
|
||||
}
|
||||
fn verify(&self) -> Result<()> {
|
||||
self.directory
|
||||
.file(OsStr::new(&self.name), self.file.proof(), self.max)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Construct only in the separately provisioned stable service, with the
|
||||
/// independently protected original job Binding. It offers no approval API.
|
||||
pub struct Runtime {
|
||||
binding: Binding,
|
||||
policy: LocalUpdatePolicy,
|
||||
policy_sha256: String,
|
||||
installed: InstalledReleaseRecord,
|
||||
installed_sha256: String,
|
||||
health_key: [u8; 32],
|
||||
health_pin_sha256: String,
|
||||
protected: Vec<Protected>,
|
||||
old_policies: Vec<ServicePolicy>,
|
||||
updater: StableParticipant,
|
||||
clock: NativeClock,
|
||||
queued: Option<Queued>,
|
||||
accepted: bool,
|
||||
failed: bool,
|
||||
terminal: bool,
|
||||
head: Option<String>,
|
||||
}
|
||||
struct Queued {
|
||||
agent_startup: BoundAgentLock,
|
||||
original: Original,
|
||||
witnesses: bundle::Loaded,
|
||||
trust: TrustState,
|
||||
budget: Budget,
|
||||
proof: UpdateInflightProof,
|
||||
}
|
||||
impl Runtime {
|
||||
pub fn new(binding: Binding) -> Result<Self> {
|
||||
let clock = NativeClock::new()?;
|
||||
let budget = observation_budget()?;
|
||||
let (policy_file, raw) = Protected::read("/etc/rmm-agent-updater/policy.json", 65536)?;
|
||||
let (policy, policy_sha256) =
|
||||
LocalUpdatePolicy::from_bytes(&raw).map_err(anyhow::Error::msg)?;
|
||||
ensure!(
|
||||
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,
|
||||
"UPDATE_ENGINE_LOCAL_IDENTITY"
|
||||
);
|
||||
let (record_file, raw) = Protected::read(&policy.installed_record_path, 32768)?;
|
||||
let installed = InstalledReleaseRecord::from_bytes(&raw).map_err(anyhow::Error::msg)?;
|
||||
let installed_sha256 = hash(&raw);
|
||||
let old_policies = service_policies(&policy, &installed, None)?;
|
||||
let (health_file, raw) = Protected::read(&policy.health_pin_path, 4096)?;
|
||||
let health: HealthKeyPin = serde_json::from_slice(&raw)?;
|
||||
let health_key = health.public_key().map_err(anyhow::Error::msg)?;
|
||||
let updater = StableParticipant::observe(
|
||||
ServicePolicy {
|
||||
service: Service::Updater,
|
||||
image_sha256: policy.updater_binary_sha256.clone(),
|
||||
unit_sha256: policy.updater_service.unit_sha256.clone(),
|
||||
},
|
||||
&budget,
|
||||
)?;
|
||||
Ok(Self {
|
||||
binding,
|
||||
policy,
|
||||
policy_sha256,
|
||||
installed,
|
||||
installed_sha256,
|
||||
health_key,
|
||||
health_pin_sha256: hash(&raw),
|
||||
protected: vec![policy_file, record_file, health_file],
|
||||
old_policies,
|
||||
updater,
|
||||
clock,
|
||||
queued: None,
|
||||
accepted: false,
|
||||
failed: false,
|
||||
terminal: false,
|
||||
head: None,
|
||||
})
|
||||
}
|
||||
/// A lost activation reply disables this live runtime before any stop.
|
||||
/// Drive is deliberately private: it cannot run inside Engine::handle.
|
||||
pub fn serve_one(&mut self, listener: &ipc::Listener) -> Result<()> {
|
||||
self.require_reader_registry_and_census()?;
|
||||
ensure!(!self.failed && !self.terminal, "UPDATE_ENGINE_CLOSED");
|
||||
let services = Systemd::new(self.old_policies.clone())?;
|
||||
let budget = observation_budget()?;
|
||||
if let Err(error) = listener.serve_one(&services, &budget, self) {
|
||||
if self.queued.take().is_some() {
|
||||
self.failed = true;
|
||||
}
|
||||
return Err(error);
|
||||
}
|
||||
if let Some(queued) = self.queued.take() {
|
||||
// serve_one has written/flushed the bounded reply and dropped its
|
||||
// accepted stream. Only now may the original Full process stop.
|
||||
match self.drive(queued) {
|
||||
Ok(()) => self.terminal = true,
|
||||
Err(error) => {
|
||||
self.failed = true;
|
||||
return Err(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
fn require_reader_registry_and_census(&self) -> Result<()> {
|
||||
// This is an explicit source-checkpoint barrier, not a caller boolean
|
||||
// or a known-unit-list substitute. Replace only with the real protected
|
||||
// bootstrap registry + complete live FD/maps census and both locks.
|
||||
anyhow::bail!("UPDATE_READER_CENSUS_NOT_CONFIGURED")
|
||||
}
|
||||
fn enqueue(
|
||||
&mut self,
|
||||
peer: &ParticipantIdentity,
|
||||
grant: Uuid,
|
||||
nonce: Uuid,
|
||||
handoff_sha: &str,
|
||||
) -> Result<()> {
|
||||
ensure!(
|
||||
!self.accepted && self.queued.is_none() && !self.failed && !self.terminal,
|
||||
"UPDATE_ENGINE_NO_RETRY_OR_RESUME"
|
||||
);
|
||||
// Fuse before any fallible original admission. Even an uncertain reply
|
||||
// cannot dispatch this handoff for a second time in this process.
|
||||
self.accepted = true;
|
||||
for file in &self.protected {
|
||||
file.verify()?;
|
||||
}
|
||||
let header = bundle::read_header(grant, nonce, handoff_sha)?;
|
||||
ensure!(
|
||||
peer.role == ParticipantRole::LinuxFullHelper
|
||||
&& *peer == header.delegation.original_helper
|
||||
&& header.handoff.updater_sha256 == self.policy.updater_binary_sha256
|
||||
&& header.handoff.updater_policy_sha256 == self.policy_sha256
|
||||
&& header.handoff.predecessor_record_sha256 == self.installed_sha256,
|
||||
"UPDATE_ENGINE_ORIGINAL_PARTICIPANTS_OR_POLICY"
|
||||
);
|
||||
let finish =
|
||||
chrono::DateTime::from_timestamp(i64::try_from(header.handoff.finish_before)?, 0)
|
||||
.context("UPDATE_ENGINE_FINISH")?;
|
||||
let budget = Budget::new(
|
||||
header.handoff.boot_id,
|
||||
(finish - self.clock.now()?).to_std()?,
|
||||
)?;
|
||||
let services = Systemd::new(self.old_policies.clone())?;
|
||||
verify_original_helper(&services, &header.delegation, &budget)?;
|
||||
self.updater
|
||||
.verify_delegation(&header.delegation, &budget)?;
|
||||
let mut bridge = FullBridge::original(BridgeContext {
|
||||
handoff: &header.handoff,
|
||||
delegation: &header.delegation,
|
||||
services: &services,
|
||||
updater: &self.updater,
|
||||
clock: &self.clock,
|
||||
budget: &budget,
|
||||
health_public_key: self.health_key,
|
||||
generation: Generation::Original,
|
||||
})?;
|
||||
let reply = bridge.call(NativeControlOperation::ReadOriginal)?;
|
||||
let proof = reply.proof.context("UPDATE_ENGINE_ORIGINAL_PROOF")?;
|
||||
let original = Original::verify(
|
||||
&self.binding,
|
||||
&reply
|
||||
.original_start
|
||||
.context("UPDATE_ENGINE_ORIGINAL_START")?,
|
||||
&header.handoff.bytes()?,
|
||||
header.delegation,
|
||||
&self.clock,
|
||||
&budget,
|
||||
)?;
|
||||
let (_, journal) = rmm_domain::agent_update::verify_inflight_proof(&proof, self.health_key)
|
||||
.map_err(anyhow::Error::msg)?;
|
||||
ensure!(
|
||||
journal.phase() == Phase::StopIntent,
|
||||
"UPDATE_ENGINE_NOT_A_FRESH_HANDOFF"
|
||||
);
|
||||
let trust = TrustState::load(&original, &self.binding, &self.clock)?;
|
||||
ensure!(
|
||||
trust.health_public_key() == self.health_key
|
||||
&& original.update().updater.health_key_pin_sha256 == self.health_pin_sha256
|
||||
&& serde_json::to_vec(trust.policy())? == serde_json::to_vec(&self.policy)?,
|
||||
"UPDATE_ENGINE_TRUST_CHANGED"
|
||||
);
|
||||
let witnesses = bundle::read_for_handoff(original.handoff())?;
|
||||
witnesses.files.reopen_stages(original.handoff(), &budget)?;
|
||||
witnesses.retained.verify()?;
|
||||
let agent_startup = BoundAgentLock::bind(&witnesses.retained)?;
|
||||
self.head = Some(proof.head_sha256.clone());
|
||||
self.queued = Some(Queued {
|
||||
agent_startup,
|
||||
original,
|
||||
witnesses,
|
||||
trust,
|
||||
budget,
|
||||
proof,
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
fn drive(&mut self, queued: Queued) -> Result<()> {
|
||||
let Queued {
|
||||
agent_startup,
|
||||
original,
|
||||
witnesses,
|
||||
trust,
|
||||
budget,
|
||||
proof,
|
||||
} = queued;
|
||||
original.check_current(&self.binding, &self.clock, &budget)?;
|
||||
trust.recheck(&original, &self.clock)?;
|
||||
let services = Systemd::new(self.old_policies.clone())?;
|
||||
let old = [Service::Agent, Service::General, Service::Full]
|
||||
.into_iter()
|
||||
.map(|s| services.observe(s, &budget).map(|h| h.proof().clone()))
|
||||
.collect::<Result<Vec<_>>>()?;
|
||||
let mut bridge = FullBridge::new(
|
||||
BridgeContext {
|
||||
handoff: original.handoff(),
|
||||
delegation: original.delegation(),
|
||||
services: &services,
|
||||
updater: &self.updater,
|
||||
clock: &self.clock,
|
||||
budget: &budget,
|
||||
health_public_key: self.health_key,
|
||||
generation: Generation::Original,
|
||||
},
|
||||
proof,
|
||||
)?;
|
||||
let mut claims = Vec::new();
|
||||
for service in [
|
||||
NativeService::Agent,
|
||||
NativeService::General,
|
||||
NativeService::Full,
|
||||
] {
|
||||
let expected_head_sha256 = bridge.head_sha256()?.to_owned();
|
||||
claims.push(
|
||||
bridge
|
||||
.call(NativeControlOperation::ClaimStop {
|
||||
expected_head_sha256,
|
||||
service,
|
||||
})?
|
||||
.claim
|
||||
.context("UPDATE_ENGINE_STOP_CLAIM")?,
|
||||
);
|
||||
}
|
||||
drop(bridge);
|
||||
let mut stop_fence = StopFence {
|
||||
original: &original,
|
||||
binding: &self.binding,
|
||||
clock: &self.clock,
|
||||
budget: &budget,
|
||||
updater: &self.updater,
|
||||
trust: &trust,
|
||||
retained: &witnesses.retained,
|
||||
claims,
|
||||
old,
|
||||
next: 0,
|
||||
pending: false,
|
||||
poisoned: false,
|
||||
};
|
||||
let stopped = services.stop_all(&budget, &mut stop_fence)?;
|
||||
let claims = stop_fence.finish()?;
|
||||
let agent_startup = agent_startup.acquire(&stopped, &budget)?;
|
||||
let os = LedgerGuard::acquire(&stopped, &witnesses.ledger, &budget)?;
|
||||
let mut ledger = OwnedLedger::open(OwnedInputs {
|
||||
os: &os,
|
||||
original: &original,
|
||||
binding: &self.binding,
|
||||
clock: &self.clock,
|
||||
budget: &budget,
|
||||
updater: &self.updater,
|
||||
retained: &witnesses.retained,
|
||||
files: &witnesses.files,
|
||||
stopped: &stopped,
|
||||
trust: &trust,
|
||||
})?;
|
||||
for (claim, old) in claims.iter().zip(stopped.proofs()) {
|
||||
ledger.observe_native(claim, &hash(&serde_json::to_vec(&old)?))?;
|
||||
}
|
||||
ledger.append_observed(Evidence::AllStopped {
|
||||
observation_sha256: hash(&serde_json::to_vec(&stopped.proofs())?),
|
||||
})?;
|
||||
ledger.append_observed(Evidence::UpdaterOwnsLedger {
|
||||
process: Process {
|
||||
pid: self.updater.identity().pid,
|
||||
birth: self.updater.identity().birth,
|
||||
image_sha256: self.updater.identity().image_sha256.clone(),
|
||||
},
|
||||
ledger_identity_sha256: witnesses.ledger.sha256()?,
|
||||
})?;
|
||||
// Do not hold a second connection before all readers really stopped.
|
||||
let swap = (|| -> Result<()> {
|
||||
let stages = witnesses.files.reopen_stages(original.handoff(), &budget)?;
|
||||
let mut fence = LedgerFence::new(&mut ledger)?;
|
||||
for (stage, role) in
|
||||
stages
|
||||
.into_iter()
|
||||
.zip([Role::Agent, Role::Helper, Role::FullConfig, Role::FullPin])
|
||||
{
|
||||
let directory = Directory::open(
|
||||
Path::new(role.target())
|
||||
.parent()
|
||||
.context("UPDATE_ENGINE_TARGET_PARENT")?,
|
||||
0,
|
||||
false,
|
||||
)?;
|
||||
stage.install(&directory, &os, &budget, &mut fence)?;
|
||||
}
|
||||
fence.finish()?;
|
||||
ledger.append_observed(Evidence::PairVerified {
|
||||
pair: original.handoff().target.clone(),
|
||||
retained_state_sha256: original.handoff().retained_state_sha256.clone(),
|
||||
})
|
||||
})();
|
||||
if let Err(error) = swap {
|
||||
// Exactly one best-effort ORIGINAL Unknown CAS while we still own
|
||||
// the real guard. Failure is preserved; no restoration or retry.
|
||||
let _ = ledger.mark_unknown(
|
||||
u64::try_from(self.clock.now()?.timestamp())?,
|
||||
rmm_updater_handoff::UnknownReason::ReplaceUncertain,
|
||||
);
|
||||
return Err(error);
|
||||
}
|
||||
let prepared = ledger.prepare_return_and_close()?;
|
||||
let reservation = prepared.bind(returned::Inputs {
|
||||
original: &original,
|
||||
binding: &self.binding,
|
||||
clock: &self.clock,
|
||||
budget: &budget,
|
||||
updater: &self.updater,
|
||||
retained: &witnesses.retained,
|
||||
files: &witnesses.files,
|
||||
trust: &trust,
|
||||
})?;
|
||||
let target_policies = service_policies(&self.policy, &self.installed, Some(&original))?;
|
||||
let target = Systemd::new(target_policies.clone())?;
|
||||
let observer = Systemd::new(target_policies)?;
|
||||
let mut bridge = FullBridge::new(
|
||||
BridgeContext {
|
||||
handoff: original.handoff(),
|
||||
delegation: original.delegation(),
|
||||
services: &observer,
|
||||
updater: &self.updater,
|
||||
clock: &self.clock,
|
||||
budget: &budget,
|
||||
health_public_key: self.health_key,
|
||||
generation: Generation::Replacement,
|
||||
},
|
||||
reservation.proof().clone(),
|
||||
)?;
|
||||
let mut fence = reservation.start_fence(&observer, &mut bridge);
|
||||
agent_startup.verify()?;
|
||||
os.release(&budget, &mut fence)?;
|
||||
agent_startup.return_after_root_release(&budget)?;
|
||||
let started = stopped.start_once(target, &budget, &mut fence)?;
|
||||
fence.finish()?;
|
||||
bridge.observe_starts(&started)?;
|
||||
loop {
|
||||
original.check_current(&self.binding, &self.clock, &budget)?;
|
||||
self.updater
|
||||
.verify_delegation(original.delegation(), &budget)?;
|
||||
witnesses.retained.verify()?;
|
||||
for service in &started {
|
||||
service.verify(&budget)?;
|
||||
}
|
||||
let reply = bridge.call(NativeControlOperation::ReadOriginal)?;
|
||||
let proof = reply.proof.context("UPDATE_ENGINE_HEALTH_PROOF")?;
|
||||
self.head = Some(proof.head_sha256.clone());
|
||||
let (_, journal) =
|
||||
rmm_domain::agent_update::verify_inflight_proof(&proof, self.health_key)
|
||||
.map_err(anyhow::Error::msg)?;
|
||||
match journal.phase() {
|
||||
Phase::ServicesStarted => std::thread::sleep(Duration::from_millis(100)),
|
||||
Phase::HealthVerified => {
|
||||
bridge.call(NativeControlOperation::Finalize)?;
|
||||
self.head = None;
|
||||
return Ok(());
|
||||
}
|
||||
_ => anyhow::bail!("UPDATE_ENGINE_HEALTH_PREFIX_CHANGED"),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
impl ipc::Engine for Runtime {
|
||||
fn handle(&mut self, peer: &ParticipantIdentity, request: Request) -> Result<Response> {
|
||||
ensure!(!self.failed && !self.terminal, "UPDATE_ENGINE_CLOSED");
|
||||
self.updater
|
||||
.identity()
|
||||
.validate()
|
||||
.then_some(())
|
||||
.context("UPDATE_ENGINE_IDENTITY")?;
|
||||
let state = match request {
|
||||
Request::Describe {} => State::Described,
|
||||
Request::Activate {
|
||||
grant_id,
|
||||
owner_nonce,
|
||||
handoff_sha256,
|
||||
} => {
|
||||
self.enqueue(peer, grant_id, owner_nonce, &handoff_sha256)?;
|
||||
State::Inflight
|
||||
}
|
||||
// Health travels through the existing independently validating
|
||||
// new Fullhelper path. This daemon accepts no duplicate authority.
|
||||
_ => anyhow::bail!("UPDATE_ENGINE_UNSUPPORTED_CONTROL"),
|
||||
};
|
||||
Ok(Response {
|
||||
schema_version: 1,
|
||||
state,
|
||||
ready: false,
|
||||
updater: self.updater.identity().clone(),
|
||||
head_sha256: self.head.clone(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
struct StopFence<'a> {
|
||||
original: &'a Original,
|
||||
binding: &'a Binding,
|
||||
clock: &'a NativeClock,
|
||||
budget: &'a Budget,
|
||||
updater: &'a StableParticipant,
|
||||
trust: &'a TrustState,
|
||||
retained: &'a RetainedSet,
|
||||
claims: Vec<NativeEffectClaim>,
|
||||
old: Vec<ServiceProof>,
|
||||
next: usize,
|
||||
pending: bool,
|
||||
poisoned: bool,
|
||||
}
|
||||
impl StopFence<'_> {
|
||||
fn current(&self) -> Result<()> {
|
||||
self.original
|
||||
.check_current(self.binding, self.clock, self.budget)?;
|
||||
self.updater
|
||||
.verify_delegation(self.original.delegation(), self.budget)?;
|
||||
self.trust.recheck(self.original, self.clock)?;
|
||||
self.retained.verify()
|
||||
}
|
||||
fn finish(self) -> Result<Vec<NativeEffectClaim>> {
|
||||
ensure!(
|
||||
!self.poisoned && !self.pending && self.next == 3,
|
||||
"UPDATE_ENGINE_STOP_INCOMPLETE"
|
||||
);
|
||||
self.current()?;
|
||||
Ok(self.claims)
|
||||
}
|
||||
}
|
||||
impl DurableEffectFence for StopFence<'_> {
|
||||
fn before_effect(&mut self, effect: &Effect) -> Result<()> {
|
||||
ensure!(
|
||||
!self.poisoned && !self.pending && self.next < 3,
|
||||
"UPDATE_ENGINE_STOP_NO_RETRY"
|
||||
);
|
||||
self.poisoned = true;
|
||||
self.current()?;
|
||||
let service = [Service::Agent, Service::General, Service::Full][self.next];
|
||||
let native = [
|
||||
NativeService::Agent,
|
||||
NativeService::General,
|
||||
NativeService::Full,
|
||||
][self.next];
|
||||
let claim = &self.claims[self.next];
|
||||
ensure!(
|
||||
*effect == Effect::StopService { service }
|
||||
&& claim.effect() == &NativeEffect::StopService { service: native }
|
||||
&& claim.grant_id() == self.original.permit().grant_id
|
||||
&& claim.owner_nonce() == self.original.handoff().owner_nonce,
|
||||
"UPDATE_ENGINE_STOP_RESERVATION_CHANGED"
|
||||
);
|
||||
self.pending = true;
|
||||
Ok(())
|
||||
}
|
||||
fn after_effect(&mut self, effect: &Effect, observation: &str) -> Result<()> {
|
||||
ensure!(
|
||||
self.poisoned
|
||||
&& self.pending
|
||||
&& self.next < 3
|
||||
&& *effect
|
||||
== Effect::StopService {
|
||||
service: self.old[self.next].service
|
||||
}
|
||||
&& observation == hash(&serde_json::to_vec(&self.old[self.next])?),
|
||||
"UPDATE_ENGINE_STOP_OBSERVATION_CHANGED"
|
||||
);
|
||||
self.current()?;
|
||||
self.next += 1;
|
||||
self.pending = false;
|
||||
self.poisoned = false;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
fn observation_budget() -> Result<Budget> {
|
||||
Budget::new(
|
||||
std::fs::read_to_string("/proc/sys/kernel/random/boot_id")?
|
||||
.trim()
|
||||
.parse()?,
|
||||
Duration::from_secs(5),
|
||||
)
|
||||
}
|
||||
fn service_policies(
|
||||
policy: &LocalUpdatePolicy,
|
||||
installed: &InstalledReleaseRecord,
|
||||
original: Option<&Original>,
|
||||
) -> Result<Vec<ServicePolicy>> {
|
||||
let release = installed
|
||||
.release_envelope
|
||||
.decode()
|
||||
.map_err(anyhow::Error::msg)?;
|
||||
policy
|
||||
.services
|
||||
.iter()
|
||||
.zip([
|
||||
Service::Agent,
|
||||
Service::General,
|
||||
Service::Full,
|
||||
Service::Apt,
|
||||
])
|
||||
.map(|(pin, service)| {
|
||||
ensure!(pin.unit == service.unit(), "UPDATE_ENGINE_SERVICE_SET");
|
||||
let image_sha256 = match (service, original) {
|
||||
(Service::Agent, Some(o)) => o.handoff().target.agent_sha256.clone(),
|
||||
(Service::General | Service::Full | Service::Apt, Some(o)) => {
|
||||
o.handoff().target.helper_sha256.clone()
|
||||
}
|
||||
(Service::Agent, None) => release.manifest.artifacts[0].sha256.clone(),
|
||||
(_, None) => release.manifest.artifacts[1].sha256.clone(),
|
||||
_ => anyhow::bail!("UPDATE_ENGINE_SERVICE_ROLE"),
|
||||
};
|
||||
Ok(ServicePolicy {
|
||||
service,
|
||||
image_sha256,
|
||||
unit_sha256: pin.unit_sha256.clone(),
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
Reference in New Issue
Block a user