TOOL WIKI · SECURITY & IDENTITY

Open Policy Agent

Evaluates application policies using structured input and policy definitions.

Download example files Code + setup + checks in a ZIP
Jump to a section 10 sections

EXAMPLE USE CASE

Authorize a same-tenant read while denying other actions

An agent application needs independently enforced input, identity, data or action checks before exposing a protected capability.

Input
Trusted principal/resource attributes and the orders:read action.
Expected output
A true or false policy decision from the Rego rule.
  • Success check: The same-tenant read evaluates to true. A write, different tenant, or missing role evaluates to false.
  • Try a failure: Change action to write, remove the role or change tenant; each should deny.

Example scope: Actual local policy evaluation; the application must supply verified identity and resource ownership.

Official reference · Open Policy Agent

WHAT IT ISPolicy engine
WHERE IT FITSSecurity & identity
SEE HOW THE SYSTEM FITS TOGETHERSELECT A COMPONENT
inputprocessresultcheckoutputRequest or workloadVerified application inputOpen Policy AgentPolicy engineApplicationenforcementInterpret and enforceAllowed operationScoped service callAuthoritative outcomeSuccess or explicit errorAudit + reviewEvidence of the decision
  1. Identify the actor, operation, resource, and relevant evidence.

  2. Centralizing decisions about allowed resources and operations. The calling service must enforce the returned policy decision.

  3. Consume the identity, policy result, credential, or detection from this component. Fail according to an explicit application policy.

  4. The business service still checks permission for the actual target resource.

  5. Record the result without leaking unnecessary credentials or sensitive content.

  6. Retain actor, policy version, operation identifier, and result with deliberate redaction.

    Result or stopping point
Open Policy Agent

Centralizing decisions about allowed resources and operations. The calling service must enforce the returned policy decision.

Follow the arrows, then select a component to inspect its responsibility. On mobile, downward arrows connect the next step; bent arrows identify branches and return paths. Select a destination to jump to that component.

When to consider it

  • Centralizing decisions about allowed resources and operations.

A design decision to make

  • The calling service must enforce the returned policy decision.

Prerequisites and setup

  • Docker. Save the two files before running the policy query.
Shell
mkdir -p opa-demo

Try a small integration

opa-demo/policy.rego

Rego · opa-demo/policy.rego
package agent
import rego.v1

default allow := false
allow if {
  input.action == "orders:read"
  input.principal.role == "support"
  input.principal.tenant == input.resource.tenant
}

opa-demo/input.json

JSON · opa-demo/input.json
{"action":"orders:read","principal":{"role":"support","tenant":"a"},"resource":{"tenant":"a","id":"A104"}}

Run and check the result

Shell
docker run --rm -v "$PWD/opa-demo:/work:ro" openpolicyagent/opa:1 \
  eval --format=pretty -d /work/policy.rego -i /work/input.json data.agent.allow
  • The same-tenant read evaluates to true. A write, different tenant, or missing role evaluates to false.
  • The principal/resource in this local fixture stand in for trusted authentication and database state.

Common failures

  • Do not continue a protected operation when the policy response is missing, invalid or unavailable.
  • A successful test on one fixture is not a complete security evaluation; include bypass attempts and legitimate requests.

Production decisions

  • Enforce decisions in application/service code before an operation. A detector score or valid schema is not user authorization.
  • Test allowed, denied, malformed, timeout and unavailable outcomes; record redacted decision reasons and default to a safe failure state.
  • Sign/version policy bundles and monitor decision latency and policy rollout. Never let the model self-assert the principal role.

Keep exploring

A human approval boundary for agent actionsA governed tool layer with MCP

Explore the same layer

Guardrails AINeMo GuardrailsLlama GuardPresidio

Compare candidates on your own workload. This entry describes a product’s role; it is not a claim that products in the category are interchangeable.