Build the Agent Permission Gate Before Plugging In Tools
Without a permission gate, any prompt injection or model error can turn a read-only search into a delete once tools are connected. This demo gives a concrete least-privilege and human-in-the-loop pattern that is easy to copy, and it warns about a logging pitfall that would silently break your audit trail.
The threat model rating for agent permissions-cum-proxy starts low only because the demo has no tool calling. Once RAG or an agent can query records, modify them, or send email, that risk jumps to critical. The fix is to install a permission framework before writing the first real tool integration: each tool declares its minimum role and a sensitive flag, all calls funnel through one execute_guarded() entry, and sensitive operations require human approval with a timeout that defaults to deny.
The demo covers five scenarios that exercise the permission matrix and HITL branches: a read-only tool passes, an over-permission write is denied, a sensitive write with operator role waits for confirmation and then executes on approval, an insufficient role is denied, and an admin-level sensitive call is terminated when a human denies it. Seven unit tests pass, covering the role matrix, unknown tools, repeated confirmations failing, and denial states; the full regression suite is 128 passing.
A real pitfall appears in the audit log: the structured formatter's field whitelist drops tool, role, and approver, leaving only event and request_id. That makes security auditing of "who did what to which tool" impossible without fixing the whitelist. The article also draws a clear boundary between a permission framework and a sandbox: the former decides whether a tool may be called, the latter where it runs. Production needs both, and the framework is a prerequisite, not a replacement.
Writing permissions declaratively in tool definitions makes security a design-time decision, so adding a tool forces a conscious grant of authority rather than a guess later.
Treating a denied request as a non-event is a common mistake; logging denials as structured events gives security operations a signal for attack detection.
The logging field-whitelist bug is a reminder that audit completeness is a schema problem, not just a capture problem; you must explicitly choose which fields survive.
A very solid production-grade breakdown! The points about "permissions being enforced by the system, not by the model's good conscience" and unifying everything through execute_guarded(), with undeclared tools rejected by default, are especially critical. The pitfall in section 3.3 where the audit log whitelist dropped the tool/approver fields is painfully real. At Spark Workshop, when organizing Agent Skills, we increasingly emphasize marking read-only/write boundaries and human-confirmation nodes directly in the tool definitions, rather than relying on prompt-based caution to enforce safety boundaries.