OPA policies reference

Complete reference for OPA policy configuration in the Agent Gateway: the Policy canvas element, policy scopes, and the full input object available to Rego rules.

This page is the lookup reference for writing OPA (Rego) policies on the Agent Gateway. It covers two things:

  • The Policy element: which canvas slots accept a policy and how to configure the element on a surface.
  • Policy input reference: every field the gateway populates in the input object that Rego rules read at evaluation time.

If you are new to OPA policies on the Agent Gateway, read the OPA policies concept overview first.

The Policy element

The Policy element runs an OPA (Rego) policy against the request or response and denies it when the policy returns false. Policies run in-process via Regorus. No external OPA daemon is required. Multiple Policy elements can coexist on a surface, one per slot.

The slot the element fills is determined by the edge you drop it on.

Drop positionSlotWhen it evaluates
Caller → Access Point (request)Inbound policyBefore the request reaches the Managed Agent.
Managed Agent → Target (request)Target policyJust before the upstream call.
Target → Managed Agent (response)Response policyOn the response before it is forwarded back to the caller.
On a Transit PointTransit Point policyPer-hop, before dispatch to that destination.

Fields

FieldTypeRequiredDefaultDescription
Policy DefinitionselectYesID of the OPA policy definition in the policy store. Evaluated against the PolicyInput struct at runtime.
Enrich policy input with agent contextboolNofalseWhen on, the pipeline fetches the target’s agent card and queries the trust registry before evaluation, populating input.agent in the OPA input. Adds latency. Enable only when the policy uses input.agent. Not available for response policies.

Policy input reference

The gateway serialises request context into a structured input object before evaluating any Rego policy. Policy rules read fields from input to make access decisions. Use this reference when writing Rego rules to understand which fields are available, how authentication data appears in input.source_auth, and which fields are populated at each evaluation point.

Policy scopes and input structs

Two distinct input shapes exist. Use the correct package declaration and field paths for the scope you are writing.

ScopePackage declarationQuery pathInput struct
Gatewaypackage gateway.policydata.gateway.policy.allowPolicyInput
Surface (inbound, outbound, response)package surface.policydata.surface.policy.allowPolicyInput
MCP toolpackage surface.policydata.surface.policy.allowMcpPolicyContext

Gateway and surface policies share the same PolicyInput struct and field namespace. MCP tool policies use a different struct (McpPolicyContext) with a different field layout; see MCP tool policy input.

Gateway and surface policy input (PolicyInput)

Full example

A fully-populated PolicyInput for an inbound MCP request with JWT authentication and trust registry data:

{
  "http": {
    "method": "POST",
    "path": "/v1/surfaces/my-surface/mcp",
    "headers": {
      "content-type": "application/json",
      "x-request-id": "req-abc123"
    }
  },
  "gateway": {
    "direction": "inbound"
  },
  "channel": {
    "config_id": "surface-abc123",
    "name": "my-surface"
  },
  "source_auth": {
    "method": "jwt_bearer",
    "subject": "user@example.com",
    "claims": {
      "role": "admin",
      "org": "acme-corp",
      "aud": "https://gateway.example.com"
    }
  },
  "mcp": {
    "method": "tools/call",
    "tool_name": "search",
    "params": { "query": "hello" }
  },
  "agent": {
    "did": "did:web:example.com:agent-1",
    "trust_verification": true,
    "source_trust_verification": true,
    "agent_dna": {
      "uai": "urn:uai:example.com:agent-1:v1",
      "birthEvent": { "scid": "...", "timestamp": "..." },
      "genesis": { "codeHash": "...", "genesisHash": "..." },
      "behavioral": { "behavioralHash": "..." },
      "operational": {},
      "attestations": {}
    }
  }
}

Not all fields are present on every request. See Input availability by evaluation path for when each field is populated.

input.http

Always present. Sensitive headers (authorization, cookie, any header containing token) are stripped before policy evaluation. Policies cannot read credential values from headers.

FieldTypeDescription
methodstringHTTP method: "POST", "GET", etc.
pathstringRequest path, for example /v1/surfaces/my-surface/mcp.
headersobjectNon-sensitive request headers as a flat string-to-string map. Empty {} on outbound requests.

input.gateway

Always present. Describes the traffic direction and the identity participants.

FieldTypeDescription
directionstring"inbound" when traffic arrives at this gateway. "outbound" when the managed agent sends a request through a transit point.
source_idstring or nullOn outbound requests, the resolved DID of the managed agent acting as the protected caller. null on inbound requests.
target_idstring or nullOn outbound requests: the target endpoint URL or remote gateway DID. null on inbound requests.

input.channel

Always present. Identifies the surface handling the request.

FieldTypeDescription
config_idstring or nullInternal surface ID. Stable identifier across renames.
namestring or nullHuman-readable surface name as configured in the dashboard.
variant_aliasstring or nullVariant alias from the request URL (/route$alias/...). null when the request targets the default variant.

input.source_auth

Present when the caller is authenticated. Absent when the surface has no Caller Context element or when the request carries no credentials.

The method field indicates the authentication method and determines the shape of the object:

JWT bearer

Callers authenticated with a validated JWT.

{
  "method": "jwt_bearer",
  "subject": "user@example.com",
  "claims": {
    "role": "admin",
    "org": "acme-corp"
  }
}
FieldDescription
subjectThe sub claim from the validated token.
claimsAll claims from the token payload as a JSON object. Access individual claims as input.source_auth.claims.<claim_name>.
API key

Callers authenticated with a surface-scoped API key.

{
  "method": "api_key",
  "key_name": "my-client-id"
}
FieldDescription
key_nameThe Client ID associated with the API key.
DID auth

Callers authenticated with a DID-based credential.

{
  "method": "did_auth",
  "did": "did:web:example.com:caller"
}
FieldDescription
didThe caller’s DID.
mTLS

Callers authenticated with a mutual TLS client certificate.

{
  "method": "mtls",
  "principal": "CN=my-service,O=Example Corp",
  "fingerprint": "sha256:abc123...",
  "subject_dn": "CN=my-service,O=Example Corp",
  "issuer_dn": "CN=Example CA,O=Example Corp",
  "sans": {
    "dns": ["my-service.example.com"],
    "uri": ["spiffe://example.com/my-service"]
  }
}
FieldDescription
principalThe matched principal string (fingerprint, subject CN, DNS SAN, URI SAN, or RDN), depending on the configured identity binding.
fingerprintSHA-256 fingerprint of the client certificate in hex.
subject_dnFull subject Distinguished Name.
issuer_dnFull issuer Distinguished Name.
sans.dnsDNS Subject Alternative Names. Absent when none.
sans.uriURI Subject Alternative Names (for example SPIFFE IDs). Absent when none.
sans.emailEmail Subject Alternative Names. Absent when none.
sans.ipIP address Subject Alternative Names. Absent when none.

input.mcp

Present on inbound MCP protocol requests only. Absent on outbound requests and non-MCP protocols.

FieldTypeDescription
methodstringThe MCP JSON-RPC method, for example "tools/call", "tools/list", "resources/read".
tool_namestring or nullTool name from a tools/call request. null for other MCP methods.
resource_uristring or nullResource URI from a resources/read request. null for other methods.
prompt_namestring or nullPrompt name from a prompts/get request. null for other methods.
paramsobject or nullFull parsed params from the JSON-RPC request body.

input.a2a

Present on A2A and AP2 protocol requests. It is built from the original request body before identity injection and reflects what the caller actually sent.

FieldTypeDescription
methodstring or nullThe A2A JSON-RPC method, for example "message/send".
messageobject or nullThe A2A message object (params.message or top-level message). Contains role, parts, metadata, and messageId when present.

input.agent

Present when Extract Trust Registry Data is enabled on the surface and data was retrieved. Also present with did populated after the caller DID is resolved. Absent when neither condition applies.

FieldTypeDescription
didstring or nullThe agent’s effective DID.
trust_verificationboolean or nulltrue when all configured trust registry recognition queries pass. false when any query returns untrusted. null when no queries ran.
source_trust_verificationboolean or nullCaller-leg trust verification result when the surface is configured in Both mode.
target_trust_verificationboolean or nullTarget-leg trust verification result when the surface is configured in Both mode.
agent_dnaobject or nullAgent DNA fingerprint from the agent card. Contains uai and nested fingerprint objects. Absent when the agent card does not include an agentDNA field.
trust_registry_didstring or nullThe trust registry DID from the agent’s trust-registry extension.
provider_didstring or nullThe department or provider DID from the agent’s trust-registry extension.
authority_didstring or nullThe authority DID from the trust-registry extension.

input.extension_identity

Present when a verified Verifiable Presentation (VP) was included in the request body. Absent otherwise.

FieldTypeDescription
didstring or nullThe agent DID from the VP holder/subject.
identity_hashstring or nullA hash of the identity payload for correlation.

input.payment

Present on inbound requests where an x402 payment was verified. Absent otherwise.

FieldTypeDescription
verifiedbooleantrue when the payment was cryptographically verified.
response_headerstring or nullThe raw payment receipt header value.

input.identity_binding

Present when a verified VP from an upstream gateway was processed. Absent otherwise.

FieldTypeDescription
verifiedbooleanWhether the VP signature was cryptographically verified.
agent_didstringThe agent DID (VP holder/subject).
gateway_didstringThe DID of the upstream gateway that issued the VP.
identity_fieldsobjectIdentity fields extracted from the Verifiable Credential inside the VP.

input.trust_check_results

Present when Trust Check elements are configured on the surface and at least one ran. Absent when no Trust Check elements are configured for the leg.

{
  "trust_check_results": {
    "caller": [
      {
        "id": "tc-caller-1",
        "trust_registry_id": "tr-main",
        "query_type": "recognition",
        "ok": true,
        "error": null,
        "name": "Verify caller department",
        "authority_id": "did:web:authority.example.com",
        "entity_id": "did:web:caller.example.com",
        "action": "is",
        "resource": "ownedAgent",
        "query_resolved": true
      }
    ],
    "target": []
  }
}
FieldTypeDescription
callerarrayResults for the caller leg. Empty array [] when no caller-leg checks ran. Never null.
targetarrayResults for the target leg. Empty array [] when no target-leg checks ran. Never null.

Each result in the array shares the same shape as the Trust Check result fields. For the complete list of error.code values and their categories, see Trust Check error codes.

input.metadata

Present when Metadata Injection rules have added metadata to the request. A flat key-value map with string keys and arbitrary JSON values.

Input availability by evaluation path

Use this table when a policy condition behaves unexpectedly. The field you are checking may simply not be populated on that evaluation path.

The four columns correspond to these evaluation paths:

  • Inbound direct: a caller connects to an Access Point on this gateway.
  • Inbound G2G (fabric send): the call arrives through a gateway-to-gateway Fabric tunnel, with this gateway acting as the receiving end.
  • Inbound GW2 (connection point): this gateway acts as a connection point receiving a call forwarded from an upstream gateway.
  • Outbound: the Managed Agent sends a request through a Transit Point to an upstream target.

Condition shorthand used in this table:

  • If authenticated: the surface has a Caller Context element and the request carries valid credentials.
  • If TR enabled: Extract Trust Registry Data is enabled on the surface.
  • If TC elements configured: at least one Trust Check element is configured for this leg.
  • If VP present: a verified Verifiable Presentation was included in the request body.
  • If binding VP present: a verified VP from an upstream gateway was processed at the connection point.
  • If x402 verified: an x402 payment was cryptographically verified on the request.

= present when the stated condition is met. = never present on this path.

FieldInbound directInbound G2G (fabric send)Inbound GW2 (connection point)Outbound
input.http
input.http.headersFilteredFilteredFilteredEmpty {}
input.gateway
input.gateway.direction"inbound""outbound""inbound""outbound"
input.gateway.source_idnullnullCaller DIDManaged agent DID
input.gateway.target_idnullRemote gateway DIDnullTarget endpoint URL
input.channel
input.source_authIf authenticatedIf authenticatedIf authenticated
input.mcpIf MCP protocol
input.a2aIf A2A / AP2If A2A / AP2If A2A / AP2
input.agentIf TR enabledIf TR enabledIf TR enabledIf TR enabled
input.extension_identityIf VP presentIf VP present
input.paymentIf x402 verifiedIf x402 verified
input.identity_bindingIf binding VP present
input.trust_check_resultsIf TC elements configuredIf TC elements configuredIf TC elements configuredIf TC elements configured

MCP tool policy input

MCP tool policies share the same package declaration (package surface.policy) and query path (data.surface.policy.allow) as surface policies, but use a different input struct (McpPolicyContext) with different field paths.

Full example

{
  "mcp": {
    "method": "search",
    "params": { "query": "hello" },
    "protocol": "json-rpc-2.0"
  },
  "jwt": {
    "role": "admin",
    "org": "acme-corp",
    "sub": "user@example.com"
  },
  "channel": {
    "name": "my-mcp-surface",
    "id": "surface-abc123",
    "protocol": "mcp"
  },
  "request": {
    "source_ip": "203.0.113.42",
    "method": "POST",
    "path": "/v1/surfaces/my-mcp-surface/mcp"
  }
}

Fields

FieldTypeDescription
input.mcp.methodstringThe tool name from the tools/call request: the value the policy should gate on.
input.mcp.paramsobject or nullFull parsed params from the tools/call body.
input.mcp.protocolstringAlways "json-rpc-2.0".
input.jwtobjectFlat JWT claims map when the caller used JWT bearer auth. Absent from the input entirely when the caller used a different authentication method. Referencing input.jwt.* without JWT auth evaluates to undefined and silently denies. Access claims directly: input.jwt.role, input.jwt.sub.
input.channel.namestringSurface name.
input.channel.idstring or nullSurface ID.
input.channel.protocolstringAlways "mcp" for MCP tool policies.
input.request.methodstringHTTP method of the request.
input.request.pathstringHTTP request path.
input.request.source_ipstringSource IP address of the caller.

Field name mapping from PolicyInput to McpPolicyContext

In gateway / surface policyIn MCP tool policyNotes
input.source_auth.claims.*input.jwt.*JWT claims are a flat map in McpPolicyContext.
input.mcp.tool_nameinput.mcp.methodTool name is in method in McpPolicyContext.
input.http.methodinput.request.method
input.http.pathinput.request.path
input.channel.config_idinput.channel.id
Not availableinput.request.source_ipSource IP only available in MCP tool policies.

Absent fields and Rego behaviour

Fields that are not populated are omitted entirely from the JSON input. They are not set to null unless explicitly nullable in the schema above. In Rego, referencing an absent field evaluates to undefined.

A rule block where any condition is undefined does not contribute to the allow decision. When default allow = false, a rule that silently becomes undefined causes a deny.

# This rule silently denies when input.mcp is absent (non-MCP request)
allow if {
  input.mcp.tool_name == "search"
}

To write rules that handle both present and absent fields safely, use object.get or check for field existence first:

allow if {
  input.source_auth.method == "jwt_bearer"
  object.get(input.source_auth, "claims", {}).role == "admin"
}

Stripped headers

input.http.headers never contains headers whose names include authorization, cookie, or token, matched case-insensitively. These are stripped at policy input construction time. Policies cannot read bearer tokens, API key header values, or session cookies from input.http.headers. Use input.source_auth for authenticated identity information instead.