Add reviewed Windows scope completion and idle certificate renewal; deploy completion API
Rust development slice / linux (push) Failing after 7s
Rust development slice / linux (push) Failing after 7s
This commit is contained in:
@@ -0,0 +1,154 @@
|
||||
//! Operator-provisioned native qualification intersected with a live authenticated helper.
|
||||
//! A source build or a permissive policy by itself cannot publish SYSTEM capabilities.
|
||||
use crate::{
|
||||
helper_ipc::{self as ipc, Pin, PinnedFile},
|
||||
helper_system,
|
||||
};
|
||||
use anyhow::{Result, ensure};
|
||||
use serde::Deserialize;
|
||||
use std::{collections::BTreeSet, io::Read, path::Path};
|
||||
use uuid::Uuid;
|
||||
|
||||
pub const PATH: &str = r"C:\ProgramData\RustDiscoverySystem\system-qualification.json";
|
||||
pub const RESULT_PATH: &str = r"C:\ProgramData\RustDiscoverySystem\system-native-result.json";
|
||||
#[derive(Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct Qualification {
|
||||
schema_version: u32,
|
||||
tenant_id: Uuid,
|
||||
asset_id: Uuid,
|
||||
agent_id: Uuid,
|
||||
enrollment_generation: u64,
|
||||
assignment_version: u64,
|
||||
agent_binary_sha256: String,
|
||||
helper_binary_sha256: String,
|
||||
policy_sha256: String,
|
||||
native_result_sha256: String,
|
||||
qualification_reference: Uuid,
|
||||
actions: Vec<String>,
|
||||
}
|
||||
pub fn qualified(pin: &Pin, clock_qualified: bool) -> Result<Vec<String>> {
|
||||
if !clock_qualified || !Path::new(PATH).try_exists()? {
|
||||
return Ok(vec![]);
|
||||
}
|
||||
let readers = [
|
||||
ipc::service_sid(crate::SERVICE_NAME)?,
|
||||
ipc::service_sid(ipc::HELPER_SERVICE)?,
|
||||
];
|
||||
let root = Path::new(PATH)
|
||||
.parent()
|
||||
.expect("fixed qualification parent");
|
||||
let mut dir = PinnedFile::open_read_shared(root, true, &readers, &[])?;
|
||||
let mut file = PinnedFile::open(Path::new(PATH), false, &readers, &[], false)?;
|
||||
let mut bytes = vec![];
|
||||
(&mut file.file).take(16385).read_to_end(&mut bytes)?;
|
||||
ensure!(bytes.len() <= 16384, "system qualification size");
|
||||
file.check()?;
|
||||
dir.check()?;
|
||||
let q: Qualification = serde_json::from_slice(&bytes)?;
|
||||
ensure!(
|
||||
q.schema_version == 1
|
||||
&& (
|
||||
q.tenant_id,
|
||||
q.asset_id,
|
||||
q.agent_id,
|
||||
q.enrollment_generation,
|
||||
q.assignment_version
|
||||
) == (
|
||||
pin.binding.tenant_id,
|
||||
pin.binding.asset_id,
|
||||
pin.binding.agent_id,
|
||||
pin.binding.enrollment_generation,
|
||||
pin.binding.assignment_version
|
||||
)
|
||||
&& q.agent_binary_sha256 == pin.agent.binary_sha256
|
||||
&& q.helper_binary_sha256 == pin.helper.binary_sha256
|
||||
&& q.policy_sha256 == pin.policy_sha256
|
||||
&& ipc::digest(&q.native_result_sha256)
|
||||
&& !q.qualification_reference.is_nil()
|
||||
&& !q.actions.is_empty()
|
||||
&& q.actions.len() <= 3
|
||||
&& q.actions.iter().collect::<BTreeSet<_>>().len() == q.actions.len()
|
||||
&& q.actions.iter().all(|a| matches!(
|
||||
a.as_str(),
|
||||
"run_script" | "set_service_state" | "ensure_package"
|
||||
)),
|
||||
"system qualification binding"
|
||||
);
|
||||
let mut result = PinnedFile::open(Path::new(RESULT_PATH), false, &readers, &[], false)?;
|
||||
let mut result_bytes = vec![];
|
||||
(&mut result.file)
|
||||
.take(65537)
|
||||
.read_to_end(&mut result_bytes)?;
|
||||
ensure!(
|
||||
result_bytes.len() <= 65536
|
||||
&& rmm_domain::jobs::hash(&result_bytes) == q.native_result_sha256,
|
||||
"system native qualification evidence hash"
|
||||
);
|
||||
result.check()?;
|
||||
let evidence: serde_json::Value = serde_json::from_slice(&result_bytes)?;
|
||||
ensure!(
|
||||
evidence["schema_version"] == 1
|
||||
&& evidence["platform"] == "windows-x86_64"
|
||||
&& evidence["qualification_reference"] == q.qualification_reference.to_string()
|
||||
&& evidence["helper_binary_sha256"] == q.helper_binary_sha256
|
||||
&& evidence["validated_actions"] == serde_json::to_value(&q.actions)?
|
||||
&& evidence["status"] == "passed",
|
||||
"system native qualification evidence profile"
|
||||
);
|
||||
let (settings, _handles) = helper_system::read_settings()?;
|
||||
ensure!(
|
||||
serde_json::to_vec(&settings.pin()?)? == serde_json::to_vec(pin)?
|
||||
&& settings.enable_effects,
|
||||
"system qualification effective policy"
|
||||
);
|
||||
let mut caps = vec![
|
||||
"helper.system.v1".into(),
|
||||
format!("helper.binary.sha256:{}", pin.helper.binary_sha256),
|
||||
format!("helper.policy.sha256:{}", pin.policy_sha256),
|
||||
];
|
||||
for action in q.actions {
|
||||
match action.as_str() {
|
||||
"run_script" => {
|
||||
ensure!(
|
||||
settings.schema_version == 3
|
||||
&& settings.allowed_script_profiles.as_deref()
|
||||
== Some(&[
|
||||
rmm_domain::jobs::PrivilegedScriptProfile::FullMaintenanceV1
|
||||
])
|
||||
&& crate::actions::powershell().is_ok(),
|
||||
"system script qualification policy"
|
||||
);
|
||||
caps.extend(["system:run_script", "script.full_maintenance/1"].map(str::to_string));
|
||||
}
|
||||
"set_service_state" => {
|
||||
ensure!(
|
||||
!settings.allowed_services.is_empty(),
|
||||
"system SCM qualification policy"
|
||||
);
|
||||
caps.extend(["set_service_state", "system:set_service_state"].map(str::to_string));
|
||||
}
|
||||
"ensure_package" => {
|
||||
ensure!(
|
||||
settings.schema_version >= 2
|
||||
&& settings
|
||||
.allowed_msi_recipe_sha256
|
||||
.as_ref()
|
||||
.is_some_and(|v| !v.is_empty())
|
||||
&& crate::msi_cache::stage_configured(),
|
||||
"system MSI qualification policy"
|
||||
);
|
||||
caps.extend(
|
||||
[
|
||||
"ensure_package",
|
||||
"system:ensure_package",
|
||||
rmm_domain::windows_execution::MSI_CAPABILITY,
|
||||
]
|
||||
.map(str::to_string),
|
||||
);
|
||||
}
|
||||
_ => unreachable!("validated qualification action"),
|
||||
}
|
||||
}
|
||||
Ok(caps)
|
||||
}
|
||||
Reference in New Issue
Block a user