Separate SYSTEM policy and verify thirteen policy guards on cloud Linux
Rust development slice / linux (push) Failing after 7s

This commit is contained in:
2026-11-14 04:41:09 +01:00
parent b046209ba3
commit 5a6d0b0c3a
15 changed files with 914 additions and 20 deletions
+21 -4
View File
@@ -317,9 +317,9 @@ pub async fn permit(
if !payload.action.validate() {
return Ok(denied("APT_MANIFEST_REQUIRED"));
}
if payload.execution_identity == "root" {
if crate::root_policy::needs_helper(&payload.execution_identity) {
let helper_ready: bool = sqlx::query_scalar(
"SELECT helper_sync_ready FROM agent_installations WHERE agent_id=$1",
"SELECT i.helper_sync_ready AND EXISTS(SELECT 1 FROM agent_sync_state s WHERE s.tenant_id=i.tenant_id AND s.agent_id=i.agent_id AND s.helper_journal_id IS NOT NULL) FROM agent_installations i WHERE i.agent_id=$1",
)
.bind(agent)
.fetch_one(&mut *tx)
@@ -332,7 +332,11 @@ pub async fn permit(
.await
.is_err()
{
return Ok(denied("ROOT_SCOPE_OR_HELPER_SYNC_REQUIRED"));
return Ok(denied(if payload.execution_identity == "system" {
"SYSTEM_SCOPE_OR_HELPER_SYNC_REQUIRED"
} else {
"ROOT_SCOPE_OR_HELPER_SYNC_REQUIRED"
}));
}
}
let sync: (bool, bool) = sqlx::query_as(
@@ -497,7 +501,7 @@ pub async fn next(
if let Some(r)=sqlx::query("SELECT job_id,attempt_id FROM jobs WHERE agent_id=$1 AND cancel_requested AND state IN ('accepted','running','verifying','awaiting_reboot') ORDER BY job_id LIMIT 1").bind(agent).fetch_optional(&mut *tx).await?{
tx.commit().await?;return Ok(Some(Payload::CancelRequest(CancelRequest{job_id:r.get::<Uuid,_>("job_id").to_string(),attempt_id:r.get::<Uuid,_>("attempt_id").to_string(),reason:"operator_cancel_requested".into()})))
}
let row=sqlx::query("SELECT j.job_id,j.attempt_id,j.payload,j.payload_hash,a.authorization_id,p.plan_hash,i.capabilities FROM outbox b JOIN jobs j USING(tenant_id,job_id,attempt_id) JOIN operations o ON o.tenant_id=j.tenant_id AND o.operation_id=j.operation_id JOIN authorizations a ON a.tenant_id=o.tenant_id AND a.authorization_id=o.authorization_id JOIN approval_requests r ON r.tenant_id=j.tenant_id AND r.operation_id=j.operation_id JOIN operation_plans p ON p.tenant_id=j.tenant_id AND p.plan_id=r.plan_id JOIN tenants t ON t.tenant_id=j.tenant_id JOIN agent_installations i ON i.tenant_id=j.tenant_id AND i.agent_id=j.agent_id WHERE j.agent_id=$1 AND j.state='queued' AND NOT j.cancel_requested AND NOT t.changes_stopped AND a.revoked_at IS NULL AND r.approval_state='approved' AND p.expires_at>now() AND b.acknowledged_at IS NULL AND (b.lease_until IS NULL OR b.lease_until<now()) ORDER BY j.job_id FOR UPDATE OF b SKIP LOCKED LIMIT 1").bind(agent).fetch_optional(&mut *tx).await?;
let row=sqlx::query("SELECT j.job_id,j.attempt_id,j.payload,j.payload_hash,a.authorization_id,a.principal AS approver,p.plan_hash,p.payload AS plan_payload,i.capabilities FROM outbox b JOIN jobs j USING(tenant_id,job_id,attempt_id) JOIN operations o ON o.tenant_id=j.tenant_id AND o.operation_id=j.operation_id JOIN authorizations a ON a.tenant_id=o.tenant_id AND a.authorization_id=o.authorization_id JOIN approval_requests r ON r.tenant_id=j.tenant_id AND r.operation_id=j.operation_id JOIN operation_plans p ON p.tenant_id=j.tenant_id AND p.plan_id=r.plan_id JOIN tenants t ON t.tenant_id=j.tenant_id JOIN agent_installations i ON i.tenant_id=j.tenant_id AND i.agent_id=j.agent_id WHERE j.agent_id=$1 AND j.state='queued' AND NOT j.cancel_requested AND NOT t.changes_stopped AND a.revoked_at IS NULL AND r.approval_state='approved' AND p.expires_at>now() AND b.acknowledged_at IS NULL AND (b.lease_until IS NULL OR b.lease_until<now()) ORDER BY j.job_id FOR UPDATE OF b SKIP LOCKED LIMIT 1").bind(agent).fetch_optional(&mut *tx).await?;
let Some(row) = row else {
tx.commit().await?;
return Ok(None);
@@ -511,6 +515,19 @@ pub async fn next(
tx.commit().await?;
return Ok(None);
}
if crate::root_policy::needs_helper(&payload.execution_identity) {
let plan: PlanPayload = serde_json::from_slice(&row.get::<Vec<u8>, _>("plan_payload"))?;
if crate::root_policy::authorize(&mut tx, &plan.principal, &payload)
.await
.is_err()
|| crate::root_policy::authorize(&mut tx, &row.get::<String, _>("approver"), &payload)
.await
.is_err()
{
tx.commit().await?;
return Ok(None);
}
}
sqlx::query("UPDATE outbox SET lease_until=now()+interval '30 seconds' WHERE job_id=$1")
.bind(row.get::<Uuid, _>("job_id"))
.execute(&mut *tx)