Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

feat(security): scope approval.list_pending and approval.decide to an agent (#7032)

oxoxDevefd5baa70bde
diff --git a/crates/openhuman-core/src/security/approval/rpc.rs b/crates/openhuman-core/src/security/approval/rpc.rs
index f5f50a65e2..401674d190 100644
--- a/crates/openhuman-core/src/security/approval/rpc.rs
+++ b/crates/openhuman-core/src/security/approval/rpc.rs
@@ -48,13 +48,24 @@ pub async fn approval_get_gate_state() -> anyhow::Result<Outcome<ApprovalGateBoo
/// Returns an empty list (not an error) when the gate is not
/// installed — supervised mode may be disabled, in which case there
/// is nothing pending by definition.
-pub async fn approval_list_pending() -> anyhow::Result<Outcome<Vec<PendingApproval>>> {
- tracing::debug!("[rpc:approval_list_pending] entry");
+///
+/// `agent_id` narrows the list to the rows one embedded agent parked.
+pub async fn approval_list_pending(
+ agent_id: Option<&str>,
+) -> anyhow::Result<Outcome<Vec<PendingApproval>>> {
+ tracing::debug!(
+ agent_id = agent_id.unwrap_or("<all>"),
+ "[rpc:approval_list_pending] entry"
+ );
let Some(gate) = ApprovalGate::try_global() else {
tracing::debug!("[rpc:approval_list_pending] gate not installed, returning empty");
return Ok(Outcome::new(Vec::new(), vec![]));
};
- let rows = match gate.list_pending() {
+ let listed = match agent_id {
+ Some(agent) => gate.list_pending_for_agent(Some(agent)),
+ None => gate.list_pending(),
+ };
+ let rows = match listed {
Ok(rows) => rows,
Err(err) => {
tracing::error!(error = %err, "[rpc:approval_list_pending] store error");
@@ -188,14 +199,17 @@ pub async fn approval_preauthorize_flow(
}
/// Apply a decision to a pending row. Errors when the request id is
-/// unknown / already decided / belongs to a different session.
+/// unknown / already decided / belongs to a different session. With
+/// `agent_id`, also errors when the request belongs to another agent.
pub async fn approval_decide(
request_id: &str,
decision: ApprovalDecision,
+ agent_id: Option<&str>,
) -> anyhow::Result<Outcome<PendingApproval>> {
tracing::debug!(
request_id = request_id,
decision = decision.as_str(),
+ agent_id = agent_id.unwrap_or("<any>"),
"[rpc:approval_decide] entry"
);
let gate = ApprovalGate::try_global().ok_or_else(|| {
@@ -205,7 +219,11 @@ pub async fn approval_decide(
);
anyhow!("approval gate is not installed; supervised mode disabled")
})?;
- let decided = match gate.decide(request_id, decision) {
+ let decided = match agent_id {
+ Some(agent) => gate.decide_for_agent(agent, request_id, decision),
+ None => gate.decide(request_id, decision),
+ };
+ let decided = match decided {
Ok(row) => row,
Err(err) => {
tracing::error!(
@@ -263,7 +281,17 @@ pub async fn approval_decide(
// `gate.decide` already resolved the current call, so a persistence failure
// must not fail the RPC. It degrades safely — the tool simply prompts again
// next time rather than being silently auto-approved.
- if decision == ApprovalDecision::ApproveAlwaysForTool {
+ if decision == ApprovalDecision::ApproveAlwaysForTool && row.agent_id.is_some() {
+ tracing::info!(
+ tool = row.tool_name.as_str(),
+ agent_id = row.agent_id.as_deref().unwrap_or(""),
+ "[rpc:approval_decide] agent request approved once; the process allowlist is not widened"
+ );
+ logs.push(format!(
+ "[approval] '{}' approved; an agent's 'Always allow' comes from its own access",
+ row.tool_name
+ ));
+ } else if decision == ApprovalDecision::ApproveAlwaysForTool {
match crate::config::ops::add_auto_approve_tool(&row.tool_name).await {
Ok(()) => {
tracing::info!(
diff --git a/crates/openhuman-core/src/security/approval/schemas.rs b/crates/openhuman-core/src/security/approval/schemas.rs
index d300611c03..b040ecafc5 100644
--- a/crates/openhuman-core/src/security/approval/schemas.rs
+++ b/crates/openhuman-core/src/security/approval/schemas.rs
@@ -54,7 +54,12 @@ pub fn schemas(function: &str) -> ControllerSchema {
function: "list_pending",
description:
"List pending approval requests awaiting a user decision in the current session.",
- inputs: vec![],
+ inputs: vec![FieldSchema {
+ name: "agent_id",
+ ty: TypeSchema::Option(Box::new(TypeSchema::String)),
+ comment: "Only the requests this embedded agent parked. Omit to list every request.",
+ required: false,
+ }],
outputs: vec![FieldSchema {
name: "pending",
ty: TypeSchema::Array(Box::new(TypeSchema::Ref("PendingApproval"))),
@@ -113,6 +118,13 @@ pub fn schemas(function: &str) -> ControllerSchema {
source_context names a flow), or \"deny\".",
required: true,
},
+ FieldSchema {
+ name: "agent_id",
+ ty: TypeSchema::Option(Box::new(TypeSchema::String)),
+ comment: "Decide as this embedded agent; refused when the request belongs to \
+ another agent.",
+ required: false,
+ },
],
outputs: vec![FieldSchema {
name: "decided",
@@ -167,9 +179,10 @@ pub fn schemas(function: &str) -> ControllerSchema {
}
}
-fn handle_list_pending(_params: Map<String, Value>) -> ControllerFuture {
+fn handle_list_pending(params: Map<String, Value>) -> ControllerFuture {
Box::pin(async move {
- let outcome = approval_rpc::approval_list_pending()
+ let agent_id = read_optional_string(&params, "agent_id")?;
+ let outcome = approval_rpc::approval_list_pending(agent_id.as_deref())
.await
.map_err(|e| e.to_string())?;
to_json(outcome)
@@ -205,9 +218,11 @@ fn handle_decide(params: Map<String, Value>) -> ControllerFuture {
approve_once|approve_always_for_tool|approve_always_for_flow|deny, got '{decision_str}'"
)
})?;
- let outcome = approval_rpc::approval_decide(request_id.trim(), decision)
- .await
- .map_err(|e| e.to_string())?;
+ let agent_id = read_optional_string(&params, "agent_id")?;
+ let outcome =
+ approval_rpc::approval_decide(request_id.trim(), decision, agent_id.as_deref())
+ .await
+ .map_err(|e| e.to_string())?;
to_json(outcome)
})
}
@@ -255,6 +270,17 @@ fn read_optional_u64(params: &Map<String, Value>, key: &str) -> Result<Option<u6
}
}
+fn read_optional_string(params: &Map<String, Value>, key: &str) -> Result<Option<String>, String> {
+ match params.get(key) {
+ Some(Value::String(s)) if !s.trim().is_empty() => Ok(Some(s.trim().to_string())),
+ Some(Value::String(_)) | Some(Value::Null) | None => Ok(None),
+ Some(other) => Err(format!(
+ "invalid '{key}': expected string, got {}",
+ type_name(other)
+ )),
+ }
+}
+
fn read_required_string(params: &Map<String, Value>, key: &str) -> Result<String, String> {
match params.get(key) {
Some(Value::String(s)) => Ok(s.clone()),
diff --git a/crates/openhuman-core/src/security/approval/schemas_tests.rs b/crates/openhuman-core/src/security/approval/schemas_tests.rs
index 8b1686ec95..c8942e90f0 100644
--- a/crates/openhuman-core/src/security/approval/schemas_tests.rs
+++ b/crates/openhuman-core/src/security/approval/schemas_tests.rs
@@ -2,11 +2,13 @@ use super::*;
use serde_json::json;
#[test]
-fn schemas_list_pending_has_no_inputs() {
+fn schemas_list_pending_takes_only_an_optional_agent() {
let s = schemas("list_pending");
assert_eq!(s.namespace, "approval");
assert_eq!(s.function, "list_pending");
- assert!(s.inputs.is_empty());
+ assert_eq!(s.inputs.len(), 1);
+ assert_eq!(s.inputs[0].name, "agent_id");
+ assert!(!s.inputs[0].required);
}
#[test]
@@ -15,7 +17,11 @@ fn schemas_decide_requires_request_id_and_decision() {
let names: Vec<_> = s.inputs.iter().map(|f| f.name).collect();
assert!(names.contains(&"request_id"));
assert!(names.contains(&"decision"));
- assert!(s.inputs.iter().all(|f| f.required));
+ assert!(s
+ .inputs
+ .iter()
+ .all(|f| f.required == (f.name != "agent_id")));
+ assert!(names.contains(&"agent_id"));
}
#[test]