Connect passive signed release checks to compatible Linux inventory
Rust development slice / linux (push) Failing after 6s
Rust development slice / linux (push) Failing after 6s
This commit is contained in:
@@ -780,3 +780,63 @@ pub fn job_health_public_key(job: &crate::jobs::JobPayload) -> Result<[u8; 32],
|
||||
.try_into()
|
||||
.map_err(|_| "UPDATE_HEALTH_KEY")
|
||||
}
|
||||
|
||||
/// Diagnostic catalog metadata inside the existing linux.base observations
|
||||
/// vector. This is never an AgentUpdateObservation/CandidatePreview or authority.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, schemars::JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum CatalogCheckStatus {
|
||||
NotConfigured,
|
||||
Unavailable,
|
||||
Available,
|
||||
Current,
|
||||
}
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, schemars::JsonSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct CatalogCandidate {
|
||||
pub release_id: Uuid,
|
||||
pub release_sequence: u64,
|
||||
pub version: String,
|
||||
pub manifest_sha256: String,
|
||||
pub keyring_generation: u64,
|
||||
}
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, schemars::JsonSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct CatalogCheckReport {
|
||||
pub schema_version: u32,
|
||||
pub source_id: String,
|
||||
/// Actual authenticated check, not the later cache/inventory collection.
|
||||
pub checked_at: chrono::DateTime<chrono::Utc>,
|
||||
pub status: CatalogCheckStatus,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub candidate: Option<CatalogCandidate>,
|
||||
}
|
||||
impl CatalogCheckReport {
|
||||
pub fn validate(
|
||||
&self,
|
||||
collected_at: chrono::DateTime<chrono::Utc>,
|
||||
now: chrono::DateTime<chrono::Utc>,
|
||||
) -> bool {
|
||||
self.schema_version == 1
|
||||
&& self.source_id == "mtls:release-catalog-v1"
|
||||
&& self.checked_at <= collected_at + chrono::Duration::seconds(1)
|
||||
&& self.checked_at <= now + chrono::Duration::seconds(45)
|
||||
&& self.checked_at >= now - chrono::Duration::hours(72)
|
||||
&& match (&self.status, &self.candidate) {
|
||||
(CatalogCheckStatus::Available | CatalogCheckStatus::Current, Some(candidate)) => {
|
||||
!candidate.release_id.is_nil()
|
||||
&& candidate.release_sequence > 0
|
||||
&& candidate.keyring_generation > 0
|
||||
&& digest(&candidate.manifest_sha256)
|
||||
&& !candidate.version.is_empty()
|
||||
&& candidate.version.len() <= 64
|
||||
&& candidate
|
||||
.version
|
||||
.bytes()
|
||||
.all(|b| b.is_ascii_alphanumeric() || b".-+_".contains(&b))
|
||||
}
|
||||
(CatalogCheckStatus::NotConfigured | CatalogCheckStatus::Unavailable, None) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,6 +150,26 @@ pub fn validate_for_scope(
|
||||
.data
|
||||
.get("host_reboot_required")
|
||||
.is_some_and(|v| !v.is_boolean());
|
||||
if o.scope == "linux.agent_update.catalog" {
|
||||
let report: crate::agent_update::CatalogCheckReport =
|
||||
serde_json::from_value(o.data.clone())
|
||||
.map_err(|_| "INVALID_AGENT_UPDATE_CATALOG_REPORT")?;
|
||||
let quality = match report.status {
|
||||
crate::agent_update::CatalogCheckStatus::Available
|
||||
| crate::agent_update::CatalogCheckStatus::Current => "valid",
|
||||
crate::agent_update::CatalogCheckStatus::NotConfigured => "unknown",
|
||||
crate::agent_update::CatalogCheckStatus::Unavailable => "error",
|
||||
};
|
||||
if scope != "linux.base"
|
||||
|| o.source_id != "agent:cached-release-catalog-v1"
|
||||
|| o.quality != quality
|
||||
|| o.completeness != "complete"
|
||||
|| o.truncated
|
||||
|| !report.validate(o.observed_at, now)
|
||||
{
|
||||
return Err("INVALID_AGENT_UPDATE_CATALOG_REPORT");
|
||||
}
|
||||
}
|
||||
if !o.scope.starts_with(prefix)
|
||||
|| o.scope.len() > 64
|
||||
|| !(o
|
||||
|
||||
Reference in New Issue
Block a user