Qualify tenant-scoped bootstrap rotation and fresh Windows scripting
This commit is contained in:
@@ -176,6 +176,7 @@ impl UpdaterConfiguration {
|
||||
enum CaptureMode {
|
||||
Physical { base_error_ns: u64 },
|
||||
TrustedOsActiveGuest,
|
||||
EnrolledLocalService,
|
||||
}
|
||||
fn digest(value: &str) -> bool {
|
||||
value.len() == 64
|
||||
@@ -476,7 +477,9 @@ fn bracket_sample(
|
||||
// This is a software bracket in trusted nominal OS units, not a
|
||||
// physical accuracy bound. Checked multiplication by100 is exact, so
|
||||
// there is no conversion rounding remainder or invented base constant.
|
||||
CaptureMode::TrustedOsActiveGuest => width.max(unbiased_width),
|
||||
CaptureMode::TrustedOsActiveGuest | CaptureMode::EnrolledLocalService => {
|
||||
width.max(unbiased_width)
|
||||
}
|
||||
};
|
||||
ensure!(
|
||||
capture_error_ns <= rmm_time_attestation::MAX_CAPTURE_ERROR_NS,
|
||||
@@ -778,14 +781,58 @@ mod installed {
|
||||
challenge: Challenge,
|
||||
}
|
||||
struct HeldEvidence {
|
||||
received_ticks: Sample,
|
||||
evidence: VerifiedEvidence,
|
||||
epoch: u64,
|
||||
}
|
||||
/// Own-process role proof, protected held configuration, private challenge
|
||||
/// and native timers. No constructor accepts agent-reported helper times.
|
||||
enum ClockOwner {
|
||||
Service(Box<PeerProof>),
|
||||
EnrolledLocalService,
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct LocalPolicy {
|
||||
schema_version: u32,
|
||||
key_generation: u64,
|
||||
server_instance: Uuid,
|
||||
public_keys_hex: BTreeMap<String, String>,
|
||||
tenant_id: Uuid,
|
||||
job_signing_public_key_hex: String,
|
||||
}
|
||||
pub fn enrolled_binding(
|
||||
policy: &Path,
|
||||
registration: &rmm_protocol::EnrollmentResponse,
|
||||
) -> Result<rmm_agent_core::auth::Binding> {
|
||||
crate::job_binding::check_admin_readonly(policy)?;
|
||||
ensure!(
|
||||
std::fs::metadata(policy)?.len() <= MAX_CONFIG_BYTES as u64,
|
||||
"TIME_NATIVE_CONFIG_SIZE"
|
||||
);
|
||||
let p: LocalPolicy = serde_json::from_slice(&std::fs::read(policy)?)?;
|
||||
ensure!(
|
||||
p.schema_version == 1 && !p.tenant_id.is_nil() && digest(&p.job_signing_public_key_hex),
|
||||
"INSTALLED_JOB_TRUST"
|
||||
);
|
||||
let binding = rmm_agent_core::auth::Binding {
|
||||
tenant_id: p.tenant_id,
|
||||
agent_id: Uuid::parse_str(®istration.agent_id)?,
|
||||
asset_id: Uuid::parse_str(®istration.asset_id)?,
|
||||
enrollment_generation: 1,
|
||||
assignment_version: 1,
|
||||
public_key_hex: p.job_signing_public_key_hex,
|
||||
};
|
||||
ensure!(
|
||||
!binding.agent_id.is_nil() && !binding.asset_id.is_nil(),
|
||||
"INSTALLED_DEVICE_IDENTITY"
|
||||
);
|
||||
Ok(binding)
|
||||
}
|
||||
pub struct SignedClock {
|
||||
verifier: Verifier,
|
||||
own_process: PeerProof,
|
||||
owner: ClockOwner,
|
||||
files: Vec<PinnedFile>,
|
||||
config_sha256: String,
|
||||
boot_id: Uuid,
|
||||
@@ -891,7 +938,7 @@ mod installed {
|
||||
files.push(config_file);
|
||||
let mut value = Self {
|
||||
verifier: Verifier::new(context, pins)?,
|
||||
own_process,
|
||||
owner: ClockOwner::Service(Box::new(own_process)),
|
||||
files,
|
||||
config_sha256: hash(&raw),
|
||||
boot_id,
|
||||
@@ -910,6 +957,88 @@ mod installed {
|
||||
failure_fence.armed = false;
|
||||
Ok(value)
|
||||
}
|
||||
/// An enrolled LocalService never supplies time evidence for a helper.
|
||||
/// Its public broker pins and job binding are installed by the HTTPS
|
||||
/// bootstrap; every usable reading still needs a current signed challenge.
|
||||
async fn open_local_service(
|
||||
generation: u64,
|
||||
binding: &rmm_agent_core::auth::Binding,
|
||||
policy_file: &Path,
|
||||
) -> Result<Self> {
|
||||
let mut failure_fence = ConstructorFailureFence { armed: true };
|
||||
crate::native::require_local_service()?;
|
||||
let readers = [crate::native::service_sid()?];
|
||||
let parent = PinnedFile::open(
|
||||
policy_file.parent().context("TIME_POLICY_PARENT")?,
|
||||
true,
|
||||
&readers,
|
||||
&[],
|
||||
false,
|
||||
)?;
|
||||
let mut config_file = PinnedFile::open(policy_file, false, &readers, &[], false)?;
|
||||
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 p: LocalPolicy = serde_json::from_slice(&raw)?;
|
||||
ensure!(
|
||||
p.schema_version == 1
|
||||
&& !p.public_keys_hex.is_empty()
|
||||
&& p.public_keys_hex.len() <= 8,
|
||||
"TIME_LOCAL_SERVICE_POLICY"
|
||||
);
|
||||
let keys = p
|
||||
.public_keys_hex
|
||||
.into_iter()
|
||||
.map(|(id, key)| Ok((id, independent_time_key(&key, &binding.public_key_hex)?)))
|
||||
.collect::<Result<BTreeMap<_, _>>>()?;
|
||||
ensure!(
|
||||
p.tenant_id == binding.tenant_id
|
||||
&& p.job_signing_public_key_hex == binding.public_key_hex,
|
||||
"TIME_POLICY_BINDING"
|
||||
);
|
||||
let pins = Pins::new(p.key_generation, p.server_instance, keys)?;
|
||||
let boot_id = Uuid::parse_str(&crate::native::boot_id().await?)?;
|
||||
let context = Context {
|
||||
tenant_id: binding.tenant_id,
|
||||
asset_id: binding.asset_id,
|
||||
agent_id: binding.agent_id,
|
||||
enrollment_generation: binding.enrollment_generation,
|
||||
assignment_generation: binding.assignment_version,
|
||||
connection_generation: generation,
|
||||
windows_boot_id: boot_id,
|
||||
verifier_incarnation: *INCARNATION.get_or_init(Uuid::new_v4),
|
||||
role: Role::Agent,
|
||||
binding_schema: 1,
|
||||
helper_image_sha256: None,
|
||||
updater_image_sha256: None,
|
||||
};
|
||||
let hash = hash(&raw);
|
||||
let mut clock = Self {
|
||||
verifier: Verifier::new(context, pins)?,
|
||||
owner: ClockOwner::EnrolledLocalService,
|
||||
files: vec![parent, config_file],
|
||||
config_sha256: hash.clone(),
|
||||
boot_id,
|
||||
connection_generation: generation,
|
||||
capture_mode: CaptureMode::EnrolledLocalService,
|
||||
pending: None,
|
||||
latest: None,
|
||||
own_updater_configuration: None,
|
||||
};
|
||||
clock.recheck()?;
|
||||
{
|
||||
let mut state = process()
|
||||
.lock()
|
||||
.map_err(|_| anyhow::anyhow!("TIME_NATIVE_STATE_POISONED"))?;
|
||||
state.accept_configuration(p.key_generation, &hash)?;
|
||||
state.accept_connection(generation)?;
|
||||
}
|
||||
observed(boot_id, clock.capture_mode)?;
|
||||
failure_fence.armed = false;
|
||||
Ok(clock)
|
||||
}
|
||||
/// 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> {
|
||||
@@ -1011,7 +1140,7 @@ mod installed {
|
||||
let capture_mode = CaptureMode::TrustedOsActiveGuest;
|
||||
let mut value = Self {
|
||||
verifier: Verifier::new(context, pins)?,
|
||||
own_process,
|
||||
owner: ClockOwner::Service(Box::new(own_process)),
|
||||
files: vec![root, policy_file, config_file],
|
||||
config_sha256: hash(&raw),
|
||||
boot_id,
|
||||
@@ -1032,7 +1161,10 @@ mod installed {
|
||||
}
|
||||
fn recheck(&mut self) -> Result<()> {
|
||||
let result = (|| {
|
||||
self.own_process.check()?;
|
||||
match &mut self.owner {
|
||||
ClockOwner::Service(process) => process.check()?,
|
||||
ClockOwner::EnrolledLocalService => crate::native::require_local_service()?,
|
||||
}
|
||||
if let Some((pin, expected)) = &self.own_updater_configuration {
|
||||
ensure!(
|
||||
crate::update_native::services::updater_configuration_sha256(pin)?
|
||||
@@ -1141,6 +1273,7 @@ mod installed {
|
||||
state.active = None;
|
||||
self.latest = Some(HeldEvidence {
|
||||
evidence,
|
||||
received_ticks: received,
|
||||
epoch: pending.epoch,
|
||||
});
|
||||
let comparison = Comparison {
|
||||
@@ -1179,6 +1312,25 @@ mod installed {
|
||||
self.recheck()?;
|
||||
let (sample, current_epoch) = observed(self.boot_id, self.capture_mode)?;
|
||||
ensure!(epoch == current_epoch, "TIME_NATIVE_EVIDENCE_INVALIDATED");
|
||||
if self.capture_mode == CaptureMode::EnrolledLocalService {
|
||||
let previous = self
|
||||
.latest
|
||||
.as_ref()
|
||||
.context("TIME_NATIVE_NO_EVIDENCE")?
|
||||
.received_ticks;
|
||||
let wall = sample
|
||||
.interrupt_ns
|
||||
.checked_sub(previous.interrupt_ns)
|
||||
.context("TIME_INTERRUPT_RESET")?;
|
||||
let awake = sample
|
||||
.unbiased_ns
|
||||
.checked_sub(previous.unbiased_ns)
|
||||
.context("TIME_AWAKE_RESET")?;
|
||||
ensure!(
|
||||
wall <= 15 * SECOND_NS && wall.abs_diff(awake) <= 10_000_000,
|
||||
"TIME_LOCAL_SERVICE_STALE_OR_SUSPENDED"
|
||||
);
|
||||
}
|
||||
let state = process()
|
||||
.lock()
|
||||
.map_err(|_| anyhow::anyhow!("TIME_NATIVE_STATE_POISONED"))?;
|
||||
@@ -1233,6 +1385,7 @@ mod installed {
|
||||
#[derive(Clone)]
|
||||
pub struct RuntimeClock {
|
||||
role: Role,
|
||||
local_policy: Option<(rmm_agent_core::auth::Binding, std::path::PathBuf)>,
|
||||
state: Arc<Mutex<Option<(u64, SignedClock)>>>,
|
||||
}
|
||||
#[derive(Clone)]
|
||||
@@ -1244,9 +1397,18 @@ mod installed {
|
||||
pub fn new(role: Role) -> Self {
|
||||
Self {
|
||||
role,
|
||||
local_policy: None,
|
||||
state: Arc::new(Mutex::new(None)),
|
||||
}
|
||||
}
|
||||
pub fn enrolled_local_service(
|
||||
binding: rmm_agent_core::auth::Binding,
|
||||
policy: std::path::PathBuf,
|
||||
) -> Self {
|
||||
let mut value = Self::new(Role::Agent);
|
||||
value.local_policy = Some((binding, policy));
|
||||
value
|
||||
}
|
||||
pub fn for_generation(&self, generation: u64) -> BoundClock {
|
||||
BoundClock {
|
||||
source: self.clone(),
|
||||
@@ -1261,7 +1423,12 @@ mod installed {
|
||||
pub async fn open_connection(&self, generation: u64) -> Result<()> {
|
||||
ensure!(generation > 0, "TIME_RUNTIME_GENERATION");
|
||||
self.close()?;
|
||||
let clock = SignedClock::open(self.role, generation).await?;
|
||||
let clock = match &self.local_policy {
|
||||
Some((binding, policy)) => {
|
||||
SignedClock::open_local_service(generation, binding, policy).await?
|
||||
}
|
||||
None => SignedClock::open(self.role, generation).await?,
|
||||
};
|
||||
let mut state = self
|
||||
.state
|
||||
.lock()
|
||||
@@ -1378,6 +1545,7 @@ mod installed {
|
||||
#[cfg(all(windows, feature = "system-helper"))]
|
||||
pub use installed::{
|
||||
BoundClock, CONFIG_PATH, Comparison, RuntimeClock, SignedClock, UPDATER_CONFIG_PATH,
|
||||
enrolled_binding,
|
||||
};
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user