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:
@@ -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