Persist the exact Windows echo scope across recovery and process restarts
Rust development slice / linux (push) Failing after 6s

This commit is contained in:
2026-11-15 23:52:02 +01:00
parent 1b8acf06ea
commit b0b7e4e2f7
7 changed files with 550 additions and 38 deletions
+66 -5
View File
@@ -39,6 +39,10 @@ struct Config {
// Explicit protected opt-in only; this flag never qualifies a clock or pins.
#[serde(default)]
enable_jobs: bool,
#[serde(default)]
windows_echo_probe_only: bool,
#[serde(skip)]
echo_scope: Option<rmm_domain::windows_echo_probe::ProbeScope>,
#[serde(
default,
deserialize_with = "rmm_domain::jobs::deserialize_windows_execution_profile"
@@ -55,6 +59,15 @@ impl Config {
fn read(path: &Path) -> Result<Self> {
let raw = protected_read(path, 32768)?;
let config: Self = serde_json::from_slice(&raw)?;
if config.windows_echo_probe_only {
ensure!(
config.profile_enabled(
rmm_domain::jobs::WindowsExecutionProfile::PowerShell51RemoteSigned
) && config.server_name == "discovery.ease-technologies.de"
&& config.state_directory == Path::new(r"C:\ProgramData\RustDiscovery\state"),
"WINDOWS_ECHO_CONFIGURATION"
);
}
if let Some(profile) = config.windows_execution_profile {
ensure!(
config.profile_enabled(profile),
@@ -876,6 +889,15 @@ impl Agent {
})
}
fn supported_job(&self, job: &rmm_domain::jobs::JobPayload) -> bool {
if self.config.windows_echo_probe_only
&& !self
.config
.echo_scope
.as_ref()
.is_some_and(|s| s.matches_job(job))
{
return false;
}
if native::require_local_service().is_err() {
return false;
}
@@ -906,15 +928,28 @@ impl Agent {
false
}
}
fn scope_permits(&self, offer: &JobOffer, job: &rmm_domain::jobs::JobPayload) -> bool {
!self.config.windows_echo_probe_only
|| self.config.echo_scope.as_ref().is_some_and(|scope| {
rmm_agent_windows::echo_probe::permits_offer(scope, offer, job)
})
}
fn capabilities(&self) -> Vec<String> {
let mut caps: Vec<String> = CAPABILITIES.iter().map(|c| c.to_string()).collect();
caps.push("agent.update/1".into());
if self.config.windows_echo_probe_only {
caps.push("windows.echo-probe/1".into());
} else {
caps.push("agent.update/1".into());
}
if self.config.enable_jobs
&& cfg!(feature = "system-helper")
&& self.binding.is_some()
&& native::require_local_service().is_ok()
{
caps.extend(["rmm.sync.v1", "refresh_inventory"].map(str::to_string));
caps.push("rmm.sync.v1".into());
if !self.config.windows_echo_probe_only {
caps.push("refresh_inventory".into());
}
if rmm_agent_windows::actions::powershell().is_ok() {
caps.extend(["run_script", "script.powershell/1"].map(str::to_string));
if self.config.profile_enabled(
@@ -1290,7 +1325,10 @@ impl Agent {
return Ok(());
}
let (job, grant) = verified_window(&binding, &request, &self.clock)?;
ensure!(self.supported_job(&job), "UNSUPPORTED_CAPABILITY");
ensure!(
self.supported_job(&job) && self.scope_permits(&offer, &job),
"UNSUPPORTED_CAPABILITY"
);
let system = job.execution_identity == "system";
ensure!(
self.ready_identity(generation, system),
@@ -1486,6 +1524,7 @@ impl Agent {
let work_offer = offer.clone();
let work_grant = grant.clone();
let original_boot = Uuid::parse_str(&self.boot)?;
let echo_scope = self.config.echo_scope.clone();
let worker = tokio::task::spawn_blocking(move || {
let mut outcome = (|| -> Result<Outcome> {
if !fence.allows(generation, &clock)
@@ -1496,6 +1535,12 @@ impl Agent {
"START_WINDOW_OR_CLOCK_INVALID_BEFORE_EFFECT",
));
}
if let Some(scope) = &echo_scope {
ensure!(
rmm_agent_windows::echo_probe::permits_offer(scope, &work_offer, &job),
"WINDOWS_ECHO_DISPATCH_SCOPE"
);
}
let prepared = match rmm_agent_windows::actions::PreparedAction::prepare(
&job,
&directory,
@@ -1736,6 +1781,7 @@ impl Agent {
let now=self.clock.now()?;
if let Some(offer)=jobs::next_at(self.journal.connection(),now)? {
let job=self.binding.as_ref().context("JOB_BINDING_REQUIRED")?.job(&offer.payload_bytes)?;
ensure!(self.scope_permits(&offer,&job),"WINDOWS_ECHO_OFFER_OUT_OF_SCOPE");
if now>=job.start_before {self.record(generation,&offer,"",jobs::no_start("expired","START_DEADLINE_EXPIRED"))?;needs_sync=true;}
else if now-chrono::Duration::seconds(2)>=job.not_before && self.ready_identity(generation,job.execution_identity=="system") {
jobs::reserve_request(self.journal.connection(),&offer)?;
@@ -1760,7 +1806,8 @@ impl Agent {
ensure!(self.config.enable_jobs,"UNSUPPORTED_EXECUTION_CAPABILITY");
let binding=self.binding.as_ref().context("JOB_BINDING_REQUIRED")?.clone();
let accepted=self.envelope(generation,Payload::JobAccepted(JobAccepted{job_id:offer.job_id.clone(),attempt_id:offer.attempt_id.clone(),job_payload_hash:offer.job_payload_hash.clone(),journal_proof:rmm_domain::jobs::hash(&offer.encode_to_vec())}))?;
let supported=self.supported_job(&binding.job(&offer.payload_bytes)?);
let job=binding.job(&offer.payload_bytes)?;
let supported=self.supported_job(&job) && self.scope_permits(&offer,&job);
let tx=self.journal.connection_mut().transaction()?;
let fresh=jobs::accept(&tx,&binding,&offer,|_|supported)?;
jobs::event(&tx,&accepted)?;tx.commit()?;needs_sync|=fresh;
@@ -1935,7 +1982,21 @@ fn service_run(stop: &'static AtomicBool) -> Result<()> {
for child in fs::read_dir(&config.state_directory)? { let child=child?;native::private_path(&child.path(),child.file_type()?.is_dir())?; }
let (ledger,ledger_file)=match &binding {Some(binding)=>{let (db,file)=open_ledger(&config.state_directory,binding)?;(Some(db),Some(file))},None=>(None,None)};
let clock=JobClock::new(config.enable_jobs);
let sync=if config.enable_jobs {binding.clone().map(|binding|reconcile::ClientSync::new(binding).with_helper_identity(reconcile::HelperIdentity::System))} else {None};
let mut config=config;
if config.enable_jobs {
config.echo_scope=rmm_agent_windows::echo_probe::installed(journal.connection(),binding.as_ref().context("JOB_BINDING_REQUIRED")?)?;
}
if config.enable_jobs && config.echo_scope.is_some() {ensure!(config.windows_echo_probe_only, "WINDOWS_ECHO_PROFILE_REQUIRED");}
if config.windows_echo_probe_only {
ensure!(identity.agent_id==rmm_domain::windows_echo_probe::AGENT.to_string()
&& identity.asset_id==rmm_domain::windows_echo_probe::ASSET.to_string()
&& boot==rmm_agent_core::windows_sync_history::BOOT,"WINDOWS_ECHO_DEVICE");
#[cfg(feature="system-helper")]
if let Some(scope)=&config.echo_scope {
ensure!(rmm_agent_windows::echo_probe::protected_scope()? == *scope, "WINDOWS_ECHO_CONFIGURATION_CHANGED");
}
}
let sync=if config.enable_jobs && (!config.windows_echo_probe_only || config.echo_scope.is_some()) {binding.clone().map(|binding|reconcile::ClientSync::new(binding).with_helper_identity(reconcile::HelperIdentity::System))} else {None};
let (completed_tx,completed_rx)=tokio::sync::mpsc::channel(1);
let mut agent = Agent {
config,