Enable per-order privileged scripts on managed devices
This commit is contained in:
@@ -25,7 +25,7 @@ struct SystemPolicy {
|
||||
}
|
||||
#[derive(Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct SystemScope {
|
||||
pub(crate) struct SystemScope {
|
||||
tenant_id: Uuid,
|
||||
asset_id: Uuid,
|
||||
agent_id: Uuid,
|
||||
@@ -76,7 +76,7 @@ fn fixture_service(name: &str) -> bool {
|
||||
.all(|c| c.is_ascii_alphanumeric() || b"_-".contains(&c))
|
||||
}
|
||||
impl SystemScope {
|
||||
fn valid(&self) -> bool {
|
||||
pub(crate) fn valid(&self) -> bool {
|
||||
!self.tenant_id.is_nil()
|
||||
&& !self.asset_id.is_nil()
|
||||
&& !self.agent_id.is_nil()
|
||||
@@ -127,7 +127,7 @@ impl SystemScope {
|
||||
&& rmm_domain::jobs::valid_windows_update_limit(self.windows_update_max_runtime_seconds)
|
||||
&& (1..=120).contains(&self.max_runtime_seconds)
|
||||
}
|
||||
fn permits(
|
||||
pub(crate) fn permits(
|
||||
&self,
|
||||
principal: &str,
|
||||
job: &JobPayload,
|
||||
@@ -293,7 +293,7 @@ fn protected_parent_chain(path: &Path, owner: u32) -> Result<(), Error> {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
fn protected_bytes(path: &Path, owner: u32) -> Result<Vec<u8>, Error> {
|
||||
pub(crate) fn protected_bytes(path: &Path, owner: u32) -> Result<Vec<u8>, Error> {
|
||||
no_symlink_components(path)?;
|
||||
protected_parent_chain(path, owner)?;
|
||||
let before = fs::symlink_metadata(path).map_err(|_| disabled())?;
|
||||
@@ -374,9 +374,12 @@ pub async fn authorize(
|
||||
if matches!(job.action, Action::RunScript { .. }) {
|
||||
crate::permissions::require(tx, principal, "scripts:execute").await?;
|
||||
}
|
||||
let policy = load()?;
|
||||
let caps:serde_json::Value=sqlx::query_scalar("SELECT capabilities FROM agent_installations WHERE tenant_id=$1 AND agent_id=$2 AND asset_id=$3 AND revoked_at IS NULL AND enrollment_generation=$4 AND assignment_version=$5").bind(job.tenant_id).bind(job.agent_id).bind(job.asset_id).bind(i64::try_from(job.enrollment_generation).map_err(|_|Error(StatusCode::CONFLICT,"BINDING_MISMATCH"))?).bind(i64::try_from(job.assignment_version).map_err(|_|Error(StatusCode::CONFLICT,"BINDING_MISMATCH"))?).fetch_optional(&mut **tx).await?.ok_or(Error(StatusCode::CONFLICT,"AUTHORIZATION_REVOKED"))?;
|
||||
let capabilities: Vec<String> = serde_json::from_value(caps)?;
|
||||
if crate::managed_scripts::permits(principal, job, &capabilities)? {
|
||||
return Ok(());
|
||||
}
|
||||
let policy = load()?;
|
||||
if !policy.permits(principal, job, &capabilities, Utc::now()) {
|
||||
return Err(Error(
|
||||
StatusCode::FORBIDDEN,
|
||||
|
||||
Reference in New Issue
Block a user