Gate LocalService RemoteSigned admission on a protected Windows profile opt-in
Rust development slice / linux (push) Failing after 6s

This commit is contained in:
2026-11-15 21:47:06 +01:00
parent dffdd401c5
commit fcec400ec6
+103 -5
View File
@@ -39,6 +39,51 @@ struct Config {
// Explicit protected opt-in only; this flag never qualifies a clock or pins.
#[serde(default)]
enable_jobs: bool,
#[serde(
default,
deserialize_with = "rmm_domain::jobs::deserialize_windows_execution_profile"
)]
windows_execution_profile: Option<rmm_domain::jobs::WindowsExecutionProfile>,
}
impl Config {
fn profile_enabled(&self, profile: rmm_domain::jobs::WindowsExecutionProfile) -> bool {
self.enable_jobs
&& self.job_binding_file.is_some()
&& cfg!(feature = "system-helper")
&& self.windows_execution_profile == Some(profile)
}
fn read(path: &Path) -> Result<Self> {
let raw = protected_read(path, 32768)?;
let config: Self = serde_json::from_slice(&raw)?;
if let Some(profile) = config.windows_execution_profile {
ensure!(
config.profile_enabled(profile),
"WINDOWS_PROFILE_REQUIRES_JOB_CONFIGURATION"
);
#[cfg(feature = "system-helper")]
{
use rmm_agent_windows::helper_ipc::PinnedFile;
use std::io::Read;
// Verify the exact bytes used for the opt-in under the existing
// administrator-owned, service-read-only file and directory ACLs.
let readers = [native::service_sid()?];
let mut parent = PinnedFile::open(
path.parent().context("CONFIG_PARENT")?,
true,
&readers,
&[],
false,
)?;
let mut pin = PinnedFile::open(path, false, &readers, &[], false)?;
let mut verified = Vec::new();
(&mut pin.file).take(32769).read_to_end(&mut verified)?;
ensure!(verified == raw, "WINDOWS_PROFILE_CONFIGURATION_CHANGED");
pin.check()?;
parent.check()?;
}
}
Ok(config)
}
}
fn create_private(path: &Path, bytes: &[u8]) -> Result<()> {
use std::io::Write;
@@ -830,6 +875,13 @@ impl Agent {
return false;
}
if rmm_agent_windows::actions::supported(job) {
if let rmm_domain::jobs::Action::RunScript {
windows_execution_profile: Some(profile),
..
} = &job.action
{
return self.binding.is_some() && self.config.profile_enabled(*profile);
}
return true;
}
#[cfg(feature = "system-helper")]
@@ -859,9 +911,12 @@ impl Agent {
{
caps.extend(["rmm.sync.v1", "refresh_inventory"].map(str::to_string));
if rmm_agent_windows::actions::powershell().is_ok() {
// The process_remote_signed profile is implemented but remains
// unpublished until its separate native qualification passes.
caps.extend(["run_script", "script.powershell/1"].map(str::to_string));
if self.config.profile_enabled(
rmm_domain::jobs::WindowsExecutionProfile::PowerShell51RemoteSigned,
) {
caps.push(rmm_agent_windows::actions::REMOTE_SIGNED_PROFILE_CAPABILITY.into());
}
}
}
caps
@@ -1810,7 +1865,7 @@ fn service_run(stop: &'static AtomicBool) -> Result<()> {
);
let path = Path::new(&arguments[2]);
ensure!(path.is_absolute(), "ABSOLUTE_CONFIG_REQUIRED");
let config: Config = serde_json::from_slice(&protected_read(path, 32768)?)?;
let config = Config::read(path)?;
native::require_local_service()?;
ensure!(
config.state_directory.is_absolute(),
@@ -1951,7 +2006,7 @@ pub fn main() -> Result<()> {
args.len() == 3 && args[1] == "--config",
"SERVICE_ARGUMENTS"
);
let config: Config = serde_json::from_slice(&protected_read(Path::new(&args[2]), 32768)?)?;
let config = Config::read(Path::new(&args[2]))?;
// Shared transport reads its one DNS identity. Set it before SCM dispatch
// creates its service thread and before any Tokio/collector threads exist.
unsafe {
@@ -2053,15 +2108,58 @@ mod tests {
}
#[test]
fn old_passive_configuration_cannot_enable_jobs_or_read_the_clock() {
let config:Config=serde_json::from_value(serde_json::json!({"server_name":"example.invalid","connect_address":"127.0.0.1:443","ca_file":"C:/fixture/ca.pem","state_directory":"C:/fixture/state","enrollment_token_file":"C:/fixture/token","transport":"auto"})).unwrap();
let config: Config = serde_json::from_value(passive_test_config()).unwrap();
assert!(!config.enable_jobs);
assert!(config.job_binding_file.is_none());
assert!(config.windows_execution_profile.is_none());
let clock = JobClock::new(config.enable_jobs);
assert_eq!(
clock.now().unwrap_err().to_string(),
"WINDOWS_JOBS_NOT_ENABLED"
);
}
fn passive_test_config() -> serde_json::Value {
serde_json::json!({
"server_name":"example.invalid","connect_address":"127.0.0.1:443",
"ca_file":"C:/fixture/ca.pem","state_directory":"C:/fixture/state",
"enrollment_token_file":"C:/fixture/token","transport":"auto"
})
}
#[test]
fn remote_signed_requires_explicit_profile_jobs_and_binding() {
let profile = rmm_domain::jobs::WindowsExecutionProfile::PowerShell51RemoteSigned;
let mut config: Config = serde_json::from_value(passive_test_config()).unwrap();
config.enable_jobs = true;
config.job_binding_file = Some("C:/fixture/binding.json".into());
assert!(!config.profile_enabled(profile));
config.windows_execution_profile = Some(profile);
assert_eq!(
config.profile_enabled(profile),
cfg!(feature = "system-helper")
);
config.enable_jobs = false;
assert!(!config.profile_enabled(profile));
config.enable_jobs = true;
config.job_binding_file = None;
assert!(!config.profile_enabled(profile));
let mut value = passive_test_config();
value["windows_execution_profile"] = serde_json::json!("powershell_51_remote_signed");
assert_eq!(
serde_json::from_value::<Config>(value.clone())
.unwrap()
.windows_execution_profile,
Some(profile)
);
for invalid in [
serde_json::Value::Null,
serde_json::json!(true),
serde_json::json!("Bypass"),
] {
value["windows_execution_profile"] = invalid;
assert!(serde_json::from_value::<Config>(value.clone()).is_err());
}
}
#[test]
fn legacy_inventory_keeps_original_bytes_until_concrete_core_ack() {
let directory =