feat: add approval bound full maintenance script console and executors
Rust development slice / linux (push) Failing after 6s
Rust development slice / linux (push) Failing after 6s
This commit is contained in:
@@ -69,6 +69,18 @@ pub struct Policy {
|
||||
pub allowed_services: Vec<String>,
|
||||
pub allow_root_scripts: bool,
|
||||
pub allow_reboot: bool,
|
||||
#[serde(
|
||||
default,
|
||||
skip_serializing_if = "Option::is_none",
|
||||
deserialize_with = "rmm_domain::jobs::deserialize_script_profiles"
|
||||
)]
|
||||
pub allowed_script_profiles: Option<Vec<rmm_domain::jobs::PrivilegedScriptProfile>>,
|
||||
#[serde(
|
||||
default,
|
||||
skip_serializing_if = "Option::is_none",
|
||||
deserialize_with = "rmm_domain::jobs::deserialize_optional_sha256"
|
||||
)]
|
||||
pub helper_binary_sha256: Option<String>,
|
||||
}
|
||||
impl Policy {
|
||||
pub fn sha256(&self) -> Result<String> {
|
||||
@@ -90,6 +102,12 @@ pub struct Response {
|
||||
pub ledger_inode: u64,
|
||||
pub lock_device: u64,
|
||||
pub lock_inode: u64,
|
||||
#[serde(
|
||||
default,
|
||||
skip_serializing_if = "Option::is_none",
|
||||
deserialize_with = "rmm_domain::jobs::deserialize_optional_sha256"
|
||||
)]
|
||||
pub helper_binary_sha256: Option<String>,
|
||||
}
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
@@ -98,6 +116,12 @@ pub struct GeneralPin {
|
||||
pub profile: String,
|
||||
pub identity: Identity,
|
||||
pub policy_sha256: String,
|
||||
#[serde(
|
||||
default,
|
||||
skip_serializing_if = "Option::is_none",
|
||||
deserialize_with = "rmm_domain::jobs::deserialize_optional_sha256"
|
||||
)]
|
||||
pub helper_binary_sha256: Option<String>,
|
||||
}
|
||||
impl GeneralPin {
|
||||
pub fn read(path: &Path, binding: &Binding) -> Result<Self> {
|
||||
@@ -105,8 +129,12 @@ impl GeneralPin {
|
||||
ensure!(fs::metadata(path)?.len() <= 8192, "POLICY_PIN_LIMIT");
|
||||
let pin: Self = serde_json::from_slice(&fs::read(path)?)?;
|
||||
ensure!(
|
||||
pin.schema_version == 1
|
||||
((pin.schema_version == 1
|
||||
&& pin.profile == "general"
|
||||
&& pin.helper_binary_sha256.is_none())
|
||||
|| (pin.schema_version == 2
|
||||
&& pin.profile == "full_maintenance_v1"
|
||||
&& pin.helper_binary_sha256.as_ref().is_some_and(|h| digest(h))))
|
||||
&& pin.identity == Identity::from_binding(binding)?
|
||||
&& digest(&pin.policy_sha256),
|
||||
"POLICY_PIN_BINDING"
|
||||
@@ -199,9 +227,20 @@ pub fn validate_response(request: &Request, response: &Response, binding: &Bindi
|
||||
&& response.challenge == challenge
|
||||
&& &response.identity == identity
|
||||
&& response.identity == Identity::from_binding(binding)?
|
||||
&& matches!(response.profile.as_str(), "general" | "apt_only")
|
||||
&& matches!(
|
||||
response.profile.as_str(),
|
||||
"general" | "apt_only" | "full_maintenance_v1"
|
||||
)
|
||||
&& response.ledger_inode != 0
|
||||
&& response.lock_inode != 0,
|
||||
&& response.lock_inode != 0
|
||||
&& if response.profile == "full_maintenance_v1" {
|
||||
response
|
||||
.helper_binary_sha256
|
||||
.as_ref()
|
||||
.is_some_and(|h| digest(h))
|
||||
} else {
|
||||
response.helper_binary_sha256.is_none()
|
||||
},
|
||||
"HELPER_CONTROL_RESPONSE_BINDING"
|
||||
);
|
||||
Ok(())
|
||||
@@ -214,8 +253,23 @@ pub fn general_probe(socket: &Path, binding: &Binding, pin: &GeneralPin) -> Resu
|
||||
let response = call(socket, binding, &request)?;
|
||||
let policy = response.policy.as_ref().context("GENERAL_POLICY_MISSING")?;
|
||||
ensure!(
|
||||
response.profile == "general"
|
||||
&& policy.profile == "general"
|
||||
response.profile == pin.profile
|
||||
&& policy.profile == pin.profile
|
||||
&& ((policy.schema_version == 1
|
||||
&& policy.profile == "general"
|
||||
&& policy.allowed_script_profiles.is_none()
|
||||
&& policy.helper_binary_sha256.is_none()
|
||||
&& pin.helper_binary_sha256.is_none())
|
||||
|| (policy.schema_version == 2
|
||||
&& policy.profile == "full_maintenance_v1"
|
||||
&& policy.allowed_script_profiles.as_deref()
|
||||
== Some(&[rmm_domain::jobs::PrivilegedScriptProfile::FullMaintenanceV1])
|
||||
&& policy.helper_binary_sha256 == pin.helper_binary_sha256
|
||||
&& response.helper_binary_sha256 == pin.helper_binary_sha256
|
||||
&& pin.helper_binary_sha256.is_some()
|
||||
&& policy.allow_root_scripts
|
||||
&& !policy.allow_reboot
|
||||
&& policy.allowed_services.is_empty()))
|
||||
&& response.policy_sha256 == pin.policy_sha256
|
||||
&& policy.sha256()? == pin.policy_sha256
|
||||
&& policy.identity == pin.identity,
|
||||
@@ -264,8 +318,21 @@ mod tests {
|
||||
ledger_inode: 2,
|
||||
lock_device: 1,
|
||||
lock_inode: 3,
|
||||
helper_binary_sha256: None,
|
||||
};
|
||||
validate_response(&q, &r, &b).unwrap();
|
||||
let legacy = serde_json::to_value(&r).unwrap();
|
||||
assert!(legacy.get("helper_binary_sha256").is_none());
|
||||
let mut null = legacy.clone();
|
||||
null["helper_binary_sha256"] = serde_json::Value::Null;
|
||||
assert!(serde_json::from_value::<Response>(null).is_err());
|
||||
r.profile = "full_maintenance_v1".into();
|
||||
assert!(validate_response(&q, &r, &b).is_err());
|
||||
r.helper_binary_sha256 = Some("ab".repeat(32));
|
||||
validate_response(&q, &r, &b).unwrap();
|
||||
r.profile = "general".into();
|
||||
assert!(validate_response(&q, &r, &b).is_err());
|
||||
r.helper_binary_sha256 = None;
|
||||
r.challenge = Uuid::new_v4();
|
||||
assert!(validate_response(&q, &r, &b).is_err());
|
||||
r.challenge = challenge;
|
||||
@@ -313,6 +380,8 @@ mod tests {
|
||||
allowed_services: vec!["rmm-acceptance.service".into()],
|
||||
allow_root_scripts: false,
|
||||
allow_reboot: false,
|
||||
allowed_script_profiles: None,
|
||||
helper_binary_sha256: None,
|
||||
};
|
||||
let old = p.sha256().unwrap();
|
||||
let mut changed = p.clone();
|
||||
|
||||
Reference in New Issue
Block a user