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:
@@ -62,7 +62,7 @@ pub fn observation(report: Report, collected_at: DateTime<Utc>) -> serde_json::V
|
||||
"error_code":error,"data":report})
|
||||
}
|
||||
struct Pending {
|
||||
receiver: oneshot::Receiver<Report>,
|
||||
receiver: oneshot::Receiver<(Report, Option<ReleaseEnvelope>)>,
|
||||
task: tokio::task::JoinHandle<()>,
|
||||
}
|
||||
impl Drop for Pending {
|
||||
@@ -73,10 +73,21 @@ impl Drop for Pending {
|
||||
#[derive(Default)]
|
||||
pub struct Checker {
|
||||
report: Option<Report>,
|
||||
release: Option<ReleaseEnvelope>,
|
||||
started: Option<Instant>,
|
||||
pending: Option<Pending>,
|
||||
}
|
||||
impl Checker {
|
||||
/// Exact authenticated envelope, for the independent read-only Full
|
||||
/// verifier. This cache never confers admission or a capability itself.
|
||||
pub fn candidate_envelope(&self, now: DateTime<Utc>) -> Option<(ReleaseEnvelope, u64)> {
|
||||
let report = self.cached(now)?;
|
||||
let candidate = report.candidate?;
|
||||
let envelope = self.release.as_ref()?;
|
||||
let decoded = envelope.decode().ok()?;
|
||||
(hash(&decoded.payload_bytes) == candidate.manifest_sha256)
|
||||
.then(|| (envelope.clone(), candidate.keyring_generation))
|
||||
}
|
||||
pub fn cached(&self, now: DateTime<Utc>) -> Option<Report> {
|
||||
self.report
|
||||
.as_ref()
|
||||
@@ -90,17 +101,20 @@ impl Checker {
|
||||
binding: Option<&Binding>,
|
||||
clock: TrustedClock,
|
||||
address: SocketAddr,
|
||||
guarded: Option<crate::agent_update_apply::GuardedRecord>,
|
||||
client: impl FnOnce() -> Result<reqwest::Client>,
|
||||
) -> Report {
|
||||
if let Some(pending) = &mut self.pending {
|
||||
match pending.receiver.try_recv() {
|
||||
Ok(report) => {
|
||||
Ok((report, release)) => {
|
||||
self.report = Some(report);
|
||||
self.release = release;
|
||||
self.pending.take();
|
||||
}
|
||||
Err(oneshot::error::TryRecvError::Empty) => {}
|
||||
Err(oneshot::error::TryRecvError::Closed) => {
|
||||
self.report = Some(empty(Status::Unavailable));
|
||||
self.release = None;
|
||||
self.pending.take();
|
||||
}
|
||||
}
|
||||
@@ -123,6 +137,7 @@ impl Checker {
|
||||
Path::new(POLICY),
|
||||
Path::new(KEYRING),
|
||||
Path::new(RECORD),
|
||||
guarded.as_ref(),
|
||||
)
|
||||
})
|
||||
.transpose();
|
||||
@@ -148,7 +163,7 @@ impl Checker {
|
||||
let report = result
|
||||
.ok()
|
||||
.and_then(Result::ok)
|
||||
.unwrap_or_else(|| empty(Status::Unavailable));
|
||||
.unwrap_or_else(|| (empty(Status::Unavailable), None));
|
||||
let _ = sender.send(report);
|
||||
});
|
||||
self.pending = Some(Pending { receiver, task });
|
||||
@@ -254,7 +269,13 @@ struct Trust {
|
||||
generation: u64,
|
||||
}
|
||||
impl Trust {
|
||||
fn load(binding: &Binding, policy: &Path, keys: &Path, record: &Path) -> Result<Option<Self>> {
|
||||
fn load(
|
||||
binding: &Binding,
|
||||
policy: &Path,
|
||||
keys: &Path,
|
||||
record: &Path,
|
||||
guarded: Option<&crate::agent_update_apply::GuardedRecord>,
|
||||
) -> Result<Option<Self>> {
|
||||
let result = (|| -> Result<Self> {
|
||||
let policy = Protected::read(policy, 65536)?;
|
||||
let (local, _) =
|
||||
@@ -264,12 +285,22 @@ impl Trust {
|
||||
"UPDATE_CATALOG_FIXED_ANCHOR_PATHS"
|
||||
);
|
||||
let keys = Protected::read(keys, 16384)?;
|
||||
let record = Protected::read(record, 32768)?;
|
||||
let result = Self::verify(binding, &policy.raw, &keys.raw, &record.raw)?;
|
||||
Ok(Self {
|
||||
files: vec![policy, keys, record],
|
||||
..result
|
||||
})
|
||||
if let Some(guarded) = guarded {
|
||||
let raw = guarded.bytes(&policy.raw, &keys.raw)?;
|
||||
let result =
|
||||
Self::verify_guarded(binding, &policy.raw, &keys.raw, raw, Some(guarded))?;
|
||||
Ok(Self {
|
||||
files: vec![policy, keys],
|
||||
..result
|
||||
})
|
||||
} else {
|
||||
let record = Protected::read(record, 32768)?;
|
||||
let result = Self::verify(binding, &policy.raw, &keys.raw, &record.raw)?;
|
||||
Ok(Self {
|
||||
files: vec![policy, keys, record],
|
||||
..result
|
||||
})
|
||||
}
|
||||
})();
|
||||
match result {
|
||||
Ok(value) => Ok(Some(value)),
|
||||
@@ -288,6 +319,15 @@ impl Trust {
|
||||
policy_raw: &[u8],
|
||||
keys_raw: &[u8],
|
||||
record_raw: &[u8],
|
||||
) -> Result<Self> {
|
||||
Self::verify_guarded(binding, policy_raw, keys_raw, record_raw, None)
|
||||
}
|
||||
fn verify_guarded(
|
||||
binding: &Binding,
|
||||
policy_raw: &[u8],
|
||||
keys_raw: &[u8],
|
||||
record_raw: &[u8],
|
||||
guarded: Option<&crate::agent_update_apply::GuardedRecord>,
|
||||
) -> Result<Self> {
|
||||
let (policy, _) = LocalUpdatePolicy::from_bytes(policy_raw).map_err(anyhow::Error::msg)?;
|
||||
ensure!(
|
||||
@@ -322,14 +362,23 @@ impl Trust {
|
||||
.initial_baseline
|
||||
.decode()
|
||||
.map_err(anyhow::Error::msg)?;
|
||||
// Only the independently signed bootstrap can currently authenticate
|
||||
// the floor here. Later Updated records require the separate guarded
|
||||
// Full history observer; do not guess a floor from parsed root JSON.
|
||||
ensure!(
|
||||
baseline.payload_bytes == record_raw
|
||||
&& hash(record_raw) == policy.initial_record_sha256,
|
||||
"UPDATE_CATALOG_GUARDED_HISTORY_REQUIRED"
|
||||
hash(&baseline.payload_bytes) == policy.initial_record_sha256,
|
||||
"UPDATE_CATALOG_BASELINE_BYTES"
|
||||
);
|
||||
if let Some(guarded) = guarded {
|
||||
ensure!(
|
||||
guarded.bytes(policy_raw, keys_raw)? == record_raw,
|
||||
"UPDATE_CATALOG_GUARDED_HISTORY_REQUIRED"
|
||||
);
|
||||
} else {
|
||||
ensure!(
|
||||
baseline.payload_bytes == record_raw,
|
||||
"UPDATE_CATALOG_GUARDED_HISTORY_REQUIRED"
|
||||
);
|
||||
}
|
||||
let installed =
|
||||
InstalledReleaseRecord::from_bytes(record_raw).map_err(anyhow::Error::msg)?;
|
||||
let signer = keys
|
||||
.keys
|
||||
.iter()
|
||||
@@ -347,8 +396,7 @@ impl Trust {
|
||||
Verifier::new_without_digest(&public)?.verify_oneshot(&baseline.signature, &signed)?,
|
||||
"UPDATE_CATALOG_BASELINE_SIGNATURE"
|
||||
);
|
||||
let decoded = baseline
|
||||
.record
|
||||
let decoded = installed
|
||||
.release_envelope
|
||||
.decode()
|
||||
.map_err(anyhow::Error::msg)?;
|
||||
@@ -358,7 +406,7 @@ impl Trust {
|
||||
protocol: decoded.manifest.protocol_major,
|
||||
state: decoded.manifest.state_schema,
|
||||
generation: keys.generation,
|
||||
record: baseline.record,
|
||||
record: installed,
|
||||
};
|
||||
result.release(&result.record.release_envelope, result.record.activated_at)?;
|
||||
Ok(result)
|
||||
@@ -458,14 +506,17 @@ async fn request(
|
||||
address: SocketAddr,
|
||||
trust: &Trust,
|
||||
clock: &TrustedClock,
|
||||
) -> Result<Report> {
|
||||
) -> Result<(Report, Option<ReleaseEnvelope>)> {
|
||||
ensure!(clock.trusted(), "UPDATE_CATALOG_CLOCK_UNTRUSTED");
|
||||
let bytes = fetch(client, address).await?;
|
||||
ensure!(clock.trusted(), "UPDATE_CATALOG_CLOCK_UNTRUSTED");
|
||||
for file in &trust.files {
|
||||
file.recheck()?;
|
||||
}
|
||||
trust.response(&bytes, Utc::now())
|
||||
let report = trust.response(&bytes, Utc::now())?;
|
||||
let response: CatalogResponse = serde_json::from_slice(&bytes)?;
|
||||
let release = response.release.map(|r| r.release_envelope);
|
||||
Ok((report, release))
|
||||
}
|
||||
|
||||
async fn fetch(client: &reqwest::Client, address: SocketAddr) -> Result<Vec<u8>> {
|
||||
@@ -750,6 +801,7 @@ mod tests {
|
||||
None,
|
||||
TrustedClock::new(),
|
||||
"127.0.0.1:1".parse().unwrap(),
|
||||
None,
|
||||
|| panic!("missing anchor must not load device TLS keys"),
|
||||
);
|
||||
assert_eq!(report.status, Status::NotConfigured);
|
||||
@@ -757,6 +809,7 @@ mod tests {
|
||||
None,
|
||||
TrustedClock::new(),
|
||||
"127.0.0.1:1".parse().unwrap(),
|
||||
None,
|
||||
|| panic!("cadence must not create client"),
|
||||
);
|
||||
assert_eq!(report.checked_at, again.checked_at);
|
||||
|
||||
Reference in New Issue
Block a user