Recheck the submitting principal and protect stored log output

This commit is contained in:
2026-11-18 10:10:06 +01:00
parent db2f5b407d
commit 0f15f91f65
16 changed files with 788 additions and 209 deletions
+50 -17
View File
@@ -85,6 +85,15 @@ fn parse_log_units(raw: Option<&str>) -> Result<Option<Vec<String>>, Error> {
}
Ok(Some(units))
}
fn configured_sensitive_units() -> Result<Option<Vec<String>>, Error> {
match std::env::var("RMM_ROOT_SENSITIVE_LOG_UNITS") {
Ok(raw) => parse_log_units(Some(&raw)),
Err(std::env::VarError::NotPresent) => Ok(None),
Err(std::env::VarError::NotUnicode(_)) => {
Err(Error(StatusCode::CONFLICT, "ROOT_LOG_ALLOWLIST_INVALID"))
}
}
}
impl RootLogPolicy {
fn valid(&self) -> bool {
self.schema_version == 1
@@ -92,17 +101,45 @@ impl RootLogPolicy {
&& valid_log_units(&self.sensitive_units)
}
}
impl RootPolicy {
fn sensitive_log_unit(&self, job: &JobPayload, unit: &str, extra: Option<&[String]>) -> bool {
matches!(unit, "ssh.service" | "sshd.service" | "auditd.service" | "systemd-logind.service")
|| (unit.starts_with("sshd@") && unit.ends_with(".service"))
|| extra.is_some_and(|units| units.iter().any(|u| u == unit))
// Classification is shared across matching target scopes, not just
// the first scope/actor that grants a unit. Another scope cannot
// silently declassify a sensitive source.
|| self.scopes.iter().any(|scope| scope.matches_target(job)
&& scope.root_logs.as_ref().is_some_and(|logs| logs.sensitive_units.iter().any(|u| u == unit)))
}
fn sensitive_log_unit(
policy: Option<&RootPolicy>,
job: &JobPayload,
unit: &str,
extra: Option<&[String]>,
) -> bool {
matches!(unit, "ssh.service" | "sshd.service" | "auditd.service" | "systemd-logind.service")
|| (unit.starts_with("sshd@") && unit.ends_with(".service"))
|| extra.is_some_and(|units| units.iter().any(|u| u == unit))
// Any matching scope can classify the source, regardless of principal.
|| policy.is_some_and(|p| p.scopes.iter().any(|scope| scope.matches_target(job)
&& scope.root_logs.as_ref().is_some_and(|logs| logs.sensitive_units.iter().any(|u| u == unit))))
}
/// Record the source classification alongside the grant. Readers in a separate
/// API profile cannot reconstruct an expired or replaced gateway policy.
pub(crate) fn stored_log_sensitivity(job: &JobPayload) -> Option<bool> {
let Action::QueryLogs { unit, .. } = &job.action else {
return None;
};
let Ok(extra) = configured_sensitive_units() else {
return Some(true);
};
let policy = if std::env::var_os("RMM_DEV_ROOT_POLICY_FILE").is_some()
|| std::env::var("RMM_DEV_ROOT_ENABLED").as_deref() == Ok("true")
{
let Ok(policy) = load() else {
return Some(true);
};
Some(policy)
} else {
None
};
Some(sensitive_log_unit(
policy.as_ref(),
job,
unit,
extra.as_deref(),
))
}
fn required_permissions(job: &JobPayload, sensitive_log: bool) -> Vec<&'static str> {
let mut permissions = vec!["root:execute"];
@@ -350,12 +387,8 @@ pub async fn authorize(
None
};
if let Action::QueryLogs { unit, .. } = &job.action {
let sensitive_units = parse_log_units(
std::env::var("RMM_ROOT_SENSITIVE_LOG_UNITS")
.ok()
.as_deref(),
)?;
if policy.sensitive_log_unit(job, unit, sensitive_units.as_deref()) {
let sensitive_units = configured_sensitive_units()?;
if sensitive_log_unit(Some(&policy), job, unit, sensitive_units.as_deref()) {
// Re-read current membership on every planning/approval/start call.
// No policy flag, viewer role, capability or test profile grants it.
crate::permissions::require(tx, principal, "logs:read_sensitive").await?;