Integrate signed agent catalog, tenant enrollment and HTTPS installers

This commit is contained in:
2026-11-17 15:56:18 +01:00
parent 689f326460
commit 7fd17272d5
70 changed files with 12982 additions and 327 deletions
+262 -1
View File
@@ -113,6 +113,65 @@ pub struct RoleQualification {
pub binary_sha256: String,
pub qualification_sha256: String,
}
/// Separately protected stable-updater clock profile. It never loads a helper
/// calibration/qualification as its own image or process evidence.
#[derive(Debug, serde::Deserialize, serde::Serialize)]
#[serde(deny_unknown_fields)]
pub struct UpdaterConfiguration {
pub schema_version: u32,
pub key_generation: u64,
pub server_instance: Uuid,
pub binding: rmm_agent_core::auth::Binding,
pub public_keys_hex: std::collections::BTreeMap<String, String>,
pub updater_policy_sha256: String,
pub updater_service_configuration_sha256: String,
pub trusted_os_active_guest: TrustedOsActiveGuest,
}
impl UpdaterConfiguration {
#[cfg(any(windows, test))]
fn validate(&self, image: &str) -> Result<()> {
let profile = &self.trusted_os_active_guest;
ensure!(
self.schema_version == 3
&& self.key_generation > 0
&& !self.server_instance.is_nil()
&& !self.binding.agent_id.is_nil()
&& !self.binding.asset_id.is_nil()
&& !self.binding.tenant_id.is_nil()
&& self.binding.enrollment_generation > 0
&& self.binding.assignment_version > 0
&& digest(&self.updater_policy_sha256)
&& digest(&self.updater_service_configuration_sha256)
&& matches!(
profile.operating_assumption,
ActiveGuestOperation::NoPauseSaveRestoreSnapshotMigrationHostSuspend
)
&& matches!(profile.platform, TrustedPlatform::KvmQemuHypervClock)
&& digest(&profile.platform_provenance_sha256)
&& profile.qualifications.len() == 1
&& profile.qualifications[0].role == rmm_time_attestation::Role::Updater
&& profile.qualifications[0].binary_sha256 == image
&& digest(&profile.qualifications[0].qualification_sha256),
"TIME_UPDATER_OWN_PROFILE"
);
ensure!(
!self.public_keys_hex.is_empty() && self.public_keys_hex.len() <= 8,
"TIME_UPDATER_KEYS"
);
for (id, public) in &self.public_keys_hex {
ensure!(
!id.is_empty()
&& id.len() <= 64
&& id
.bytes()
.all(|b| b.is_ascii_alphanumeric() || b"_-".contains(&b)),
"TIME_UPDATER_KEY_ID"
);
independent_time_key(public, &self.binding.public_key_hex)?;
}
Ok(())
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum CaptureMode {
Physical { base_error_ns: u64 },
@@ -159,6 +218,10 @@ impl Configuration {
helper_image: &str,
) -> Result<CaptureMode> {
use rmm_time_attestation::Role;
ensure!(
own_role != Role::Updater,
"TIME_UPDATER_OWN_PROFILE_REQUIRED"
);
ensure!(self.key_generation() > 0, "TIME_NATIVE_CONFIG_PROFILE");
let images = [
(Role::Agent, agent_image),
@@ -663,6 +726,8 @@ mod installed {
};
pub const CONFIG_PATH: &str = r"C:\ProgramData\RustDiscoverySystem\time-attestation.json";
pub const UPDATER_CONFIG_PATH: &str =
r"C:\ProgramData\RustDiscoveryUpdater\time-attestation.json";
const PUBLIC_ROOT: &str = r"C:\ProgramData\RustDiscoverySystem";
const MAX_CONFIG_BYTES: usize = 16_384;
const MAX_REPLY_BYTES: usize = 16_384;
@@ -728,12 +793,16 @@ mod installed {
capture_mode: CaptureMode,
pending: Option<Pending>,
latest: Option<HeldEvidence>,
own_updater_configuration: Option<(ipc::PeerPin, String)>,
}
impl SignedClock {
/// Connection generation is later confirmed by the independently
/// signed server response. It is never itself a ready/sync flag.
pub async fn open(role: Role, connection_generation: u64) -> Result<Self> {
ensure!(connection_generation > 0, "TIME_NATIVE_CONNECTION");
if role == Role::Updater {
return Self::open_updater(connection_generation).await;
}
let mut failure_fence = ConstructorFailureFence { armed: true };
let (settings, mut files) = crate::helper_system::read_settings()?;
let own_pin = match role {
@@ -830,6 +899,127 @@ mod installed {
capture_mode,
pending: None,
latest: None,
own_updater_configuration: None,
};
value.recheck()?;
process()
.lock()
.map_err(|_| anyhow::anyhow!("TIME_NATIVE_STATE_POISONED"))?
.accept_connection(connection_generation)?;
observed(boot_id, capture_mode)?;
failure_fence.armed = false;
Ok(value)
}
/// Stable-updater-only process proof and separately protected profile.
/// It uses its OWN current SCM process/image/token and challenge.
pub async fn open_updater(connection_generation: u64) -> Result<Self> {
ensure!(connection_generation > 0, "TIME_NATIVE_CONNECTION");
let mut failure_fence = ConstructorFailureFence { armed: true };
let readers = vec![
ipc::service_sid(crate::update_ipc::SERVICE)?,
ipc::service_sid(crate::SERVICE_NAME)?,
ipc::service_sid(ipc::HELPER_SERVICE)?,
];
let root = PinnedFile::open_read_shared(
Path::new(r"C:\ProgramData\RustDiscoveryUpdater"),
true,
&readers,
&[],
)?;
let mut policy_file = PinnedFile::open(
Path::new(r"C:\ProgramData\RustDiscoveryUpdater\policy.json"),
false,
&readers,
&[],
false,
)?;
ensure!(
policy_file.file.metadata()?.len() <= 65536,
"TIME_UPDATER_POLICY_SIZE"
);
let mut policy_raw = Vec::new();
(&mut policy_file.file)
.take(65537)
.read_to_end(&mut policy_raw)?;
let (policy, policy_hash) =
rmm_domain::agent_update_provisioning::LocalUpdatePolicy::from_bytes(&policy_raw)
.map_err(anyhow::Error::msg)?;
let own_pin = crate::update_native::services::updater_pin(&policy)?;
ipc::require_self(&own_pin)?;
let own_process = PeerProof::for_service(&own_pin, unsafe {
windows_sys::Win32::System::Threading::GetCurrentProcessId()
})?;
let service_hash =
crate::update_native::services::updater_configuration_sha256(&own_pin)?;
ensure!(
service_hash == policy.updater_service.unit_sha256,
"TIME_UPDATER_SCM_POLICY"
);
let mut config_file =
PinnedFile::open(Path::new(UPDATER_CONFIG_PATH), false, &readers, &[], false)?;
ensure!(
config_file.file.metadata()?.len() <= MAX_CONFIG_BYTES as u64,
"TIME_NATIVE_CONFIG_SIZE"
);
let mut raw = Vec::new();
(&mut config_file.file)
.take(MAX_CONFIG_BYTES as u64 + 1)
.read_to_end(&mut raw)?;
ensure!(raw.len() <= MAX_CONFIG_BYTES, "TIME_NATIVE_CONFIG_SIZE");
let config: UpdaterConfiguration = serde_json::from_slice(&raw)?;
config.validate(&own_pin.binary_sha256)?;
ensure!(
config.updater_policy_sha256 == policy_hash
&& config.updater_service_configuration_sha256 == service_hash
&& config.binding.tenant_id == policy.tenant_id
&& config.binding.asset_id == policy.asset_id
&& config.binding.agent_id == policy.agent_id
&& config.binding.enrollment_generation == policy.enrollment_generation
&& config.binding.assignment_version == policy.assignment_version,
"TIME_UPDATER_POLICY_BINDING"
);
let keys = config
.public_keys_hex
.iter()
.map(|(id, key)| {
Ok((
id.clone(),
independent_time_key(key, &config.binding.public_key_hex)?,
))
})
.collect::<Result<BTreeMap<_, _>>>()?;
let pins = Pins::new(config.key_generation, config.server_instance, keys)?;
process()
.lock()
.map_err(|_| anyhow::anyhow!("TIME_NATIVE_STATE_POISONED"))?
.accept_configuration(config.key_generation, &hash(&raw))?;
let boot_id = Uuid::parse_str(&crate::native::boot_id().await?)?;
let context = Context {
tenant_id: config.binding.tenant_id,
asset_id: config.binding.asset_id,
agent_id: config.binding.agent_id,
enrollment_generation: config.binding.enrollment_generation,
assignment_generation: config.binding.assignment_version,
connection_generation,
windows_boot_id: boot_id,
verifier_incarnation: *INCARNATION.get_or_init(Uuid::new_v4),
role: Role::Updater,
helper_image_sha256: None,
binding_schema: 2,
updater_image_sha256: Some(own_pin.binary_sha256.clone()),
};
let capture_mode = CaptureMode::TrustedOsActiveGuest;
let mut value = Self {
verifier: Verifier::new(context, pins)?,
own_process,
files: vec![root, policy_file, config_file],
config_sha256: hash(&raw),
boot_id,
connection_generation,
capture_mode,
pending: None,
latest: None,
own_updater_configuration: Some((own_pin, service_hash)),
};
value.recheck()?;
process()
@@ -843,6 +1033,13 @@ mod installed {
fn recheck(&mut self) -> Result<()> {
let result = (|| {
self.own_process.check()?;
if let Some((pin, expected)) = &self.own_updater_configuration {
ensure!(
crate::update_native::services::updater_configuration_sha256(pin)?
== *expected,
"TIME_UPDATER_SCM_CHANGED"
);
}
for file in &mut self.files {
file.check()?;
}
@@ -1127,6 +1324,22 @@ mod installed {
fn now(&self) -> Result<chrono::DateTime<chrono::Utc>> {
Ok(self.reading()?.own_wall)
}
fn bounds(&self) -> Result<(chrono::DateTime<chrono::Utc>, chrono::DateTime<chrono::Utc>)> {
ensure!(self.generation > 0, "TIME_RUNTIME_NO_CONNECTION");
let mut state = self
.source
.state
.lock()
.map_err(|_| anyhow::anyhow!("TIME_RUNTIME_POISONED"))?;
let (held, clock) = state.as_mut().context("TIME_RUNTIME_NO_EVIDENCE")?;
ensure!(*held == self.generation, "TIME_RUNTIME_CONNECTION_CHANGED");
clock.with_current_comparison(|value| {
Ok((
chrono::DateTime::from_timestamp_nanos(value.interval().lower_utc_ns()),
chrono::DateTime::from_timestamp_nanos(value.interval().upper_utc_ns()),
))
})
}
fn reading(&self) -> Result<rmm_agent_core::reconcile::ClockReading> {
ensure!(self.generation > 0, "TIME_RUNTIME_NO_CONNECTION");
let mut state = self
@@ -1163,12 +1376,60 @@ mod installed {
}
}
#[cfg(all(windows, feature = "system-helper"))]
pub use installed::{BoundClock, CONFIG_PATH, Comparison, RuntimeClock, SignedClock};
pub use installed::{
BoundClock, CONFIG_PATH, Comparison, RuntimeClock, SignedClock, UPDATER_CONFIG_PATH,
};
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn updater_profile_binds_only_its_own_image_and_explicit_active_guest_assumption() {
use serde_json::json;
let job = ed25519_dalek::SigningKey::from_bytes(&[71; 32])
.verifying_key()
.to_bytes();
let time = ed25519_dalek::SigningKey::from_bytes(&[72; 32])
.verifying_key()
.to_bytes();
let hex = |raw: [u8; 32]| raw.iter().map(|b| format!("{b:02x}")).collect::<String>();
let value = json!({"schema_version":3,"key_generation":1,"server_instance":Uuid::new_v4(),
"binding":{"tenant_id":Uuid::new_v4(),"asset_id":Uuid::new_v4(),"agent_id":Uuid::new_v4(),"enrollment_generation":1,"assignment_version":1,"public_key_hex":hex(job)},
"public_keys_hex":{"updater-time":hex(time)},"updater_policy_sha256":"12".repeat(32),"updater_service_configuration_sha256":"13".repeat(32),
"trusted_os_active_guest":{"operating_assumption":"active_guest_no_pause_save_restore_snapshot_migration_host_suspend","platform":"kvm_qemu_hypervclock","platform_provenance_sha256":"14".repeat(32),
"qualifications":[{"role":"updater","binary_sha256":"15".repeat(32),"qualification_sha256":"16".repeat(32)}]}});
let config: UpdaterConfiguration = serde_json::from_value(value.clone()).unwrap();
config.validate(&"15".repeat(32)).unwrap();
assert!(config.validate(&"17".repeat(32)).is_err());
for mutation in ["helper", "second", "policy", "assumption"] {
let mut bad = value.clone();
match mutation {
"helper" => {
bad["trusted_os_active_guest"]["qualifications"][0]["role"] =
json!("system_helper")
}
"second" => {
let q = bad["trusted_os_active_guest"]["qualifications"][0].clone();
bad["trusted_os_active_guest"]["qualifications"]
.as_array_mut()
.unwrap()
.push(q);
}
"policy" => bad["updater_policy_sha256"] = json!("bad"),
_ => bad["trusted_os_active_guest"]["operating_assumption"] = json!(true),
}
let result = serde_json::from_value::<UpdaterConfiguration>(bad);
assert!(
match result {
Err(_) => true,
Ok(c) => c.validate(&"15".repeat(32)).is_err(),
},
"mutation {mutation}"
);
}
}
#[test]
fn passive_sampling_requires_a_profile_and_uses_heartbeat_cadence() {
let dir = std::env::temp_dir().join(Uuid::new_v4().to_string());