Integrate strict Windows MSI manifests tenant catalog and SYSTEM package policy
Rust development slice / linux (push) Failing after 7s
Rust development slice / linux (push) Failing after 7s
This commit is contained in:
@@ -48,6 +48,17 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Missing preserves Linux codecs; explicit null/nonobject is never a manifest.
|
||||
pub fn deserialize_windows_msi_manifest<'de, D>(
|
||||
deserializer: D,
|
||||
) -> Result<Option<Box<crate::windows_execution::ResolvedWindowsMsi>>, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
crate::windows_execution::ResolvedWindowsMsi::deserialize(deserializer)
|
||||
.map(|m| Some(Box::new(m)))
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, schemars::JsonSchema)]
|
||||
#[serde(tag = "action", rename_all = "snake_case", deny_unknown_fields)]
|
||||
pub enum Action {
|
||||
@@ -88,6 +99,13 @@ pub enum Action {
|
||||
recipe_id: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
apt_manifest: Option<crate::apt_transaction::AptExecutionManifest>,
|
||||
#[serde(
|
||||
default,
|
||||
deserialize_with = "deserialize_windows_msi_manifest",
|
||||
skip_serializing_if = "Option::is_none"
|
||||
)]
|
||||
#[schemars(with = "crate::windows_execution::ResolvedWindowsMsi")]
|
||||
windows_msi_manifest: Option<Box<crate::windows_execution::ResolvedWindowsMsi>>,
|
||||
},
|
||||
ApplyUpdates {
|
||||
provider: String,
|
||||
@@ -185,6 +203,28 @@ impl Action {
|
||||
installation_context,
|
||||
recipe_id,
|
||||
apt_manifest,
|
||||
windows_msi_manifest: Some(m),
|
||||
} => {
|
||||
m.validate()
|
||||
&& provider == "msi"
|
||||
&& package == crate::windows_execution::MSI_PACKAGE_ID
|
||||
&& version == &m.recipe.postcondition.product_version
|
||||
&& architecture == "x64"
|
||||
&& installation_context == "machine"
|
||||
&& recipe_version == &m.recipe.recipe_version
|
||||
&& recipe_id.as_ref() == Some(&m.recipe.recipe_id)
|
||||
&& apt_manifest.is_none()
|
||||
}
|
||||
Self::EnsurePackage {
|
||||
provider,
|
||||
package,
|
||||
version,
|
||||
architecture,
|
||||
recipe_version,
|
||||
installation_context,
|
||||
recipe_id,
|
||||
apt_manifest,
|
||||
windows_msi_manifest: None,
|
||||
} => {
|
||||
provider == "apt"
|
||||
&& unit(package)
|
||||
@@ -243,6 +283,20 @@ impl Action {
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn windows_msi(&self) -> Option<&crate::windows_execution::ResolvedWindowsMsi> {
|
||||
match self {
|
||||
Self::EnsurePackage {
|
||||
windows_msi_manifest: Some(m),
|
||||
..
|
||||
} => Some(m.as_ref()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
pub fn valid_helper_denial_shape(&self, identity: &str) -> bool {
|
||||
(matches!(self,Self::SetServiceState{state,..} if matches!(state.as_str(),"running"|"stopped"))
|
||||
&& self.validate())
|
||||
|| (identity == "system" && self.windows_msi().is_some() && self.validate())
|
||||
}
|
||||
pub fn is_windows_event_log_fixture(&self) -> bool {
|
||||
matches!(self, Self::QueryLogs { unit, .. } if unit == WINDOWS_EVENT_LOG_FIXTURE_SOURCE)
|
||||
}
|
||||
@@ -250,6 +304,9 @@ impl Action {
|
||||
/// its inner Event Log calls retain their own cooperative <=5s deadline.
|
||||
pub fn valid_job_limits(&self, runtime_seconds: u32, output_bytes: u32) -> bool {
|
||||
(1..=3600).contains(&runtime_seconds)
|
||||
&& (self.windows_msi().is_none()
|
||||
|| ((10..=120).contains(&runtime_seconds)
|
||||
&& (1024..=65536).contains(&output_bytes)))
|
||||
&& (1..=262144).contains(&output_bytes)
|
||||
&& (!self.is_windows_event_log_fixture()
|
||||
|| ((10..=120).contains(&runtime_seconds)
|
||||
@@ -268,7 +325,7 @@ impl Action {
|
||||
}
|
||||
/// Shared plan/revalidation/start gate. Passive Windows never implies job support.
|
||||
pub fn available_for(&self, identity: &str, capabilities: &[String]) -> bool {
|
||||
if identity == "system" && !matches!(self, Self::SetServiceState { .. }) {
|
||||
if identity == "system" && !self.valid_helper_denial_shape(identity) {
|
||||
return false;
|
||||
}
|
||||
let has = |cap: &str| capabilities.iter().any(|c| c == cap);
|
||||
@@ -304,6 +361,17 @@ impl Action {
|
||||
&& !(has("linux.base/1") && has("windows.base/1"))
|
||||
&& (scope != "windows.base" || has("rmm.sync.v1"))
|
||||
}
|
||||
Self::EnsurePackage { .. } if self.windows_msi().is_some() || has("windows.base/1") => {
|
||||
self.windows_msi().is_some()
|
||||
&& self.validate()
|
||||
&& identity == "system"
|
||||
&& has("windows.base/1")
|
||||
&& !has("linux.base/1")
|
||||
&& has("rmm.sync.v1")
|
||||
&& has("helper.system.v1")
|
||||
&& has("system:ensure_package")
|
||||
&& has(crate::windows_execution::MSI_CAPABILITY)
|
||||
}
|
||||
Self::QueryLogs { unit, .. }
|
||||
if unit == WINDOWS_EVENT_LOG_FIXTURE_SOURCE || has("windows.base/1") =>
|
||||
{
|
||||
@@ -349,6 +417,7 @@ impl Action {
|
||||
installation_context,
|
||||
recipe_id: None,
|
||||
apt_manifest: None,
|
||||
windows_msi_manifest: None,
|
||||
} => {
|
||||
provider == "apt"
|
||||
&& !package.is_empty()
|
||||
|
||||
@@ -4,6 +4,7 @@ pub mod checkpoint_repair;
|
||||
pub mod inventory_document;
|
||||
pub mod jobs;
|
||||
pub mod reconciliation;
|
||||
pub mod windows_execution;
|
||||
|
||||
pub const TENANT_A: &str = "11111111-1111-4111-8111-111111111111";
|
||||
pub const TENANT_B: &str = "22222222-2222-4222-8222-222222222222";
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
//! Unexported Windows MSI fixture contract. No legacy Linux codec is changed.
|
||||
//! Windows MSI fixture contract. No legacy Linux codec is changed.
|
||||
//! Fixed1.0 first installation/noop and separate1.0→1.1 major-upgrade/noop
|
||||
//! recipes only. No implicit REINSTALL, repair, downgrade or fresh1.1 mode.
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sha2::{Digest, Sha256};
|
||||
use uuid::Uuid;
|
||||
|
||||
pub const MSI_PACKAGE_ID: &str = "rmm-windows-msi-fixture";
|
||||
pub const MSI_CAPABILITY: &str = "package.msi.fixture/1";
|
||||
pub const MSI_RECIPE_ID: &str = "rmm-windows-msi-fixture-install-1.0";
|
||||
pub const MSI_PRODUCT_CODE: &str = "{3F070B4B-9C08-4D65-BD41-13D81B884AEC}";
|
||||
pub const MSI_UPGRADE_CODE: &str = "{C9BF1FB8-E31D-4BD7-BA0D-AB46539BBBAA}";
|
||||
@@ -21,29 +23,62 @@ pub const MSI_PAYLOAD_11_SHA256: &str =
|
||||
pub const MSI_OLD_PRODUCTS: &str = "RMM_OLD_PRODUCTS";
|
||||
pub const MSI_ALL_PRODUCTS: &str = "RMM_ALL_PRODUCTS";
|
||||
pub const MSI_UPGRADE_CONDITION: &str = "Installed OR (RMM_OLD_PRODUCTS = \"{3F070B4B-9C08-4D65-BD41-13D81B884AEC}\" AND RMM_ALL_PRODUCTS = \"{3F070B4B-9C08-4D65-BD41-13D81B884AEC}\")";
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, schemars::JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum Architecture {
|
||||
X64,
|
||||
}
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, schemars::JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum InstallContext {
|
||||
Machine,
|
||||
}
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, schemars::JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum MsiCommandProfile {
|
||||
FixtureQuietNoRebootV1,
|
||||
}
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
impl<'de> Deserialize<'de> for Architecture {
|
||||
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
|
||||
let value = String::deserialize(deserializer)?;
|
||||
if value == "x64" {
|
||||
Ok(Self::X64)
|
||||
} else {
|
||||
Err(serde::de::Error::unknown_variant(&value, &["x64"]))
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<'de> Deserialize<'de> for InstallContext {
|
||||
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
|
||||
let value = String::deserialize(deserializer)?;
|
||||
if value == "machine" {
|
||||
Ok(Self::Machine)
|
||||
} else {
|
||||
Err(serde::de::Error::unknown_variant(&value, &["machine"]))
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<'de> Deserialize<'de> for MsiCommandProfile {
|
||||
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
|
||||
let value = String::deserialize(deserializer)?;
|
||||
if value == "fixture_quiet_no_reboot_v1" {
|
||||
Ok(Self::FixtureQuietNoRebootV1)
|
||||
} else {
|
||||
Err(serde::de::Error::unknown_variant(
|
||||
&value,
|
||||
&["fixture_quiet_no_reboot_v1"],
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, schemars::JsonSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct MsiArtifact {
|
||||
pub artifact_id: Uuid,
|
||||
pub sha256: String,
|
||||
pub bytes: u64,
|
||||
}
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, schemars::JsonSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct MsiPostcondition {
|
||||
pub product_code: String,
|
||||
@@ -52,7 +87,7 @@ pub struct MsiPostcondition {
|
||||
pub payload_sha256: String,
|
||||
pub payload_bytes: u64,
|
||||
}
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, schemars::JsonSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct WindowsMsiRecipe {
|
||||
pub schema_version: u32,
|
||||
@@ -72,7 +107,7 @@ pub struct WindowsMsiRecipe {
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub predecessor: Option<MsiPostcondition>,
|
||||
}
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, schemars::JsonSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct ResolvedWindowsMsi {
|
||||
pub recipe: WindowsMsiRecipe,
|
||||
@@ -174,6 +209,107 @@ mod tests {
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn ensure_msi_action_is_strict_opt_in_and_system_windows_only_without_linux_byte_changes() {
|
||||
use crate::jobs::{Action, encode};
|
||||
let old=br#"{"action":"ensure_package","provider":"apt","package":"rmm-test","version":"1.0","architecture":"amd64","recipe_version":"1","installation_context":"system"}"#;
|
||||
let legacy: Action = serde_json::from_slice(old).unwrap();
|
||||
assert!(legacy.validate_plan_shape());
|
||||
assert!(legacy.windows_msi().is_none());
|
||||
assert_eq!(encode(&legacy).unwrap(), old);
|
||||
let recipe = recipe();
|
||||
let m = ResolvedWindowsMsi {
|
||||
recipe_sha256: recipe.sha256().unwrap(),
|
||||
recipe,
|
||||
};
|
||||
let action = Action::EnsurePackage {
|
||||
provider: "msi".into(),
|
||||
package: MSI_PACKAGE_ID.into(),
|
||||
version: MSI_VERSION.into(),
|
||||
architecture: "x64".into(),
|
||||
recipe_version: "1".into(),
|
||||
installation_context: "machine".into(),
|
||||
recipe_id: Some(MSI_RECIPE_ID.into()),
|
||||
apt_manifest: None,
|
||||
windows_msi_manifest: Some(Box::new(m)),
|
||||
};
|
||||
assert!(action.validate());
|
||||
assert!(action.valid_helper_denial_shape("system"));
|
||||
assert!(!action.valid_helper_denial_shape("root"));
|
||||
let caps: Vec<String> = [
|
||||
"ensure_package",
|
||||
"windows.base/1",
|
||||
"rmm.sync.v1",
|
||||
"helper.system.v1",
|
||||
"system:ensure_package",
|
||||
MSI_CAPABILITY,
|
||||
]
|
||||
.into_iter()
|
||||
.map(str::to_owned)
|
||||
.collect();
|
||||
assert!(action.available_for("system", &caps));
|
||||
for identity in ["root", "agent_service"] {
|
||||
assert!(!action.available_for(identity, &caps));
|
||||
}
|
||||
for i in 0..caps.len() {
|
||||
let mut short = caps.clone();
|
||||
short.remove(i);
|
||||
assert!(!action.available_for("system", &short));
|
||||
}
|
||||
let mut mixed = caps;
|
||||
mixed.push("linux.base/1".into());
|
||||
assert!(!action.available_for("system", &mixed));
|
||||
for (key, value) in [
|
||||
("provider", serde_json::json!("apt")),
|
||||
("architecture", serde_json::json!("amd64")),
|
||||
("installation_context", serde_json::json!("system")),
|
||||
("version", serde_json::json!("1.1.0")),
|
||||
] {
|
||||
let mut bad = serde_json::to_value(&action).unwrap();
|
||||
bad[key] = value;
|
||||
assert!(!serde_json::from_value::<Action>(bad).unwrap().validate());
|
||||
}
|
||||
for value in [
|
||||
serde_json::Value::Null,
|
||||
serde_json::json!(false),
|
||||
serde_json::json!(1),
|
||||
serde_json::json!([]),
|
||||
serde_json::json!({}),
|
||||
] {
|
||||
let mut bad = serde_json::to_value(&action).unwrap();
|
||||
bad["windows_msi_manifest"] = value;
|
||||
assert!(serde_json::from_value::<Action>(bad).is_err());
|
||||
}
|
||||
for (key, value) in [
|
||||
("architecture", "x64"),
|
||||
("context", "machine"),
|
||||
("command_profile", "fixture_quiet_no_reboot_v1"),
|
||||
] {
|
||||
let mut bad = serde_json::to_value(&action).unwrap();
|
||||
bad["windows_msi_manifest"]["recipe"][key] = serde_json::json!({value:null});
|
||||
assert!(serde_json::from_value::<Action>(bad).is_err());
|
||||
}
|
||||
for (runtime, bytes) in [(9, 4096), (121, 4096), (10, 1023), (10, 65537)] {
|
||||
assert!(!action.valid_job_limits(runtime, bytes));
|
||||
}
|
||||
let schema = schemars::schema_for!(Action).to_value();
|
||||
let pkg = schema["oneOf"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.find(|v| v["properties"].get("windows_msi_manifest").is_some())
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
pkg["properties"]["windows_msi_manifest"],
|
||||
serde_json::json!({"$ref":"#/$defs/ResolvedWindowsMsi"})
|
||||
);
|
||||
assert!(
|
||||
!pkg["required"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.contains(&serde_json::json!("windows_msi_manifest"))
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn major_upgrade_requires_explicit_exact_predecessor_new_package_and_same_family() {
|
||||
let old = recipe();
|
||||
let old_bytes = serde_json::to_vec(&old).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user