iamops.dev
Argo on X RSS feed
ENEnglish

Labs Practitioner · 20 min

OPA behind AuthZEN: a policy decision point for MCP tool calls

I wrote a Rego policy for MCP tool calls, tested it on OPA 1.22.4 and put an AuthZEN endpoint in front. A $90 payment over a $50 limit is denied with a reason.

Two terminal captures from my OPA lab: an opa eval of one request that returns false with the reason over delegated limit, and the same denial coming back from the AuthZEN endpoint.
TL;DROn 11 November 2026 IndyKite and Obsidian each described the same…
  • On 11 November 2026 IndyKite and Obsidian each described the same shape: the agent or its runtime proposes a call, and a separate decision point answers for each call.
  • I built that shape locally: a Rego policy in OPA 1.22.4, six unit tests, and a small AuthZEN Access Evaluation endpoint in front of OPA. A $90 payment against a $50 limit came back as decision false with the reason over delegated limit.
  • The policy denies by default. An unknown tool, a missing scope, a payment over the limit and an unconfirmed payment were all refused, and I broke one rule on purpose to see a test fail.
  • When I stopped OPA, my shim gave no answer at all, so the enforcement point has to treat a missing decision as a deny.
  • Not run: a real MCP gateway as the enforcement point, AuthZEN conformance tests, the batch and search APIs, and decision logging.
Repeat this lab 8 steps

I wrote this lab so you can run it yourself. Each step has the commands to copy and the output I got, and you can tick it as done. Your ticks stay in this browser only.

Go to the steps

How this works

Copies a ready-made prompt for Claude Code, Cursor, Codex or any coding agent. For test environments only.

Show prompt
I want to run a hands-on lab from iamops.dev, and I would like your help to do it safely.

Lab: OPA behind AuthZEN: a policy decision point for MCP tool calls
Read the whole lab here (Markdown): https://iamops.dev/opa-authzen-mcp-tool-call-policy.md

What the lab needs before the first step:
- Linux on amd64 (for macOS or arm64 take the matching file from the release page), curl, jq and Python 3.13
- Ports 8181 and 8282 free

How I want you to work:
1. Read the lab from start to finish first (each step lists its own prerequisites). Then check that the prerequisites are in place and that the tool versions match what the lab expects. Tell me what is missing before you run anything.
2. Run one step at a time. Before each command, show it to me and say in a sentence what it does.
3. Ask me before anything that costs money, creates cloud resources, touches a real tenant or account, or deletes anything. Wait for my answer.
4. Use the placeholders from the lab. Never paste real secrets, tokens or production identities into a command, a file or this chat. If a value is needed, tell me where to set it myself.
5. After each step, compare the output with the expected output in the lab. If it does not match, stop and tell me what differs. Do not carry on or invent a fix without asking me.
6. At the end, report what passed, what failed and which cleanup you did. Then offer to tick the steps off for me. The lab page keeps ticks only in my browser, so if you cannot do that, list the steps I should tick.

This lab is for test environments only. Do not run it against production, or against a tenant or account that holds real data or real users.

You may answer in my language.

On 11 November 2026 two vendors published the same idea from different sides. IndyKite released its Intent Agent, which turns a prompt into AuthZEN evaluations and, in the words of its developer guide, does not decide anything: the decision stays with the AuthZEN service. Obsidian described a Runtime Policy Decision Engine where an MCP Security Proxy, an agent runtime or a customer gateway pauses a tool call, asks for a decision and applies the answer.

Both split the work the same way. Something that holds the request asks, and something else decides. I wanted to run that split on my own machine with nothing but open-source parts, so I built it: a policy engine (OPA) with a policy for MCP tool calls, and a thin AuthZEN endpoint in front of it.

I wrote a short explainer of AuthZEN, OPA and Cedar.

What the lab builds#

  • A Rego policy that takes an AuthZEN-shaped request (subject, action, resource, context) for an MCP tools/call and returns a boolean plus reasons.
  • Six unit tests that run offline with OPA’s test runner.
  • A small Python endpoint that answers POST /access/v1/evaluation and the PDP metadata document, and forwards the request to OPA as input.
  • Two refusals I wanted to see: a payment over the agent’s delegated limit, and what happens when OPA is not there.

Money is in US cents. The agent may pay up to 5000 cents, which is $50.

Sequence diagram: a caller sends an AuthZEN evaluation for an MCP tools/call to a small endpoint, which forwards it to OPA 1.22.4. A 9000-cent payment against a 5000-cent limit is denied with the reason over delegated limit, 4500 cents is allowed, other bad calls are denied with reasons, and a stopped OPA returns no HTTP answer.
The decision. The request names the agent, the tools/call, the tool, the amount and the confirmation. 9000 cents against a 5000-cent limit comes back as decision false with the reason over delegated limit. 4500 cents with confirmation is allowed. Missing scope, no confirmation or an unknown tool are denied with reasons. If OPA is stopped, the endpoint gives no HTTP answer at all.

Setup#

OPA 1.22.4 is a single static binary from the release page. The endpoint is a file of under 40 lines of Python 3.13 standard library. You also need curl and jq. There is no Docker, no database and no account. The lab opens ports 8181 for OPA and 8282 for the endpoint, both on localhost.

The policy#

The request is the one an enforcement point would build from an MCP tools/call. The subject is the agent with its scopes and limit, the resource is the tool, and the context carries the amount and whether the user confirmed.

The policy has a tool catalog that says which scope each tool needs and whether it moves money. decision is false unless a rule makes it true. Reading tools need their scope. A tool that moves money needs the scope, an amount at or under the limit, and a confirmation:

plaintext
decision if {
	input.subject.type == "agent"
	input.action.name == "tools/call"
	tool.scope in input.subject.properties.scopes
	tool.moves_money
	input.context.amount_cents <= input.subject.properties.limit_cents
	input.context.user_confirmed
}

A second set, reasons, explains denials. The full files are in the lab steps below.

Tests first#

The opa test runner finds test_ rules in _test.rego files. I wrote six: a read is allowed, a write without the scope is denied, a confirmed payment within the limit is allowed, a payment over the limit is denied with the right reason, an unconfirmed payment is denied, and an unknown tool is denied. opa check --strict and opa fmt passed before the tests ran.

Terminal output of OPA 1.22.4: version information, fmt and strict check passing, and six unit tests listed as PASS with a summary of 6 out of 6.
Checks and tests. The format check, the strict check and all six tests pass on OPA 1.22.4.

To see that the tests can fail, I deleted the user_confirmed line from the second rule in a copy. Five tests still passed and test_payment_needs_confirmation failed. That is the test doing its job.

One request, offline#

opa eval takes the policy and one request file without starting a server. The request is the agent support-bot with both scopes and a 5000-cent limit, calling send_payment for 9000 cents with the user’s confirmation.

Terminal output of two opa eval commands: the decision is false and the reasons set contains over delegated limit.
A $90 payment against a $50 limit. The decision is false and the reason is "over delegated limit".

The AuthZEN endpoint#

OPA runs as a server on port 8181, and the endpoint on port 8282 sits in front of it. The AuthZEN spec defines the request as subject, action, resource and context, and the response as a required boolean decision with an optional context. It leaves the content of that context to the implementation. I put the denial reasons under reason_admin, which is the key its non-normative example uses. The metadata document lives at /.well-known/authzen-configuration.

Terminal output: the PDP metadata document with two URLs, a denial with decision false and the reason over delegated limit, and an allow with decision true after the amount is changed to 4500 cents.
The same request through AuthZEN. 9000 cents is denied with a reason. Changing only the amount to 4500 cents returns decision true.

The endpoint is a teaching shim. It does not authenticate callers, does not validate input, and has no batch or search API, so it is not a conformant PDP.

Other refusals, and OPA going away#

I sent three more requests through a small shell function called ask. With only the read scope, the payment was denied for a missing scope, and for the limit too, because the amount was still 9000. With a 4500-cent amount and user_confirmed set to false, it was denied for the missing confirmation. A tool named delete_account was denied as unknown.

Terminal output of three denied requests with reasons missing scope and over delegated limit, user did not confirm, and unknown tool, followed by a request after OPA was stopped that returns HTTP status 000.
Three more denials. Each comes with its reasons. After OPA is stopped, the request gets no HTTP answer at all, shown by curl as 000.

Then I stopped OPA and sent the 4500-cent request again. The shim raised an exception and dropped the connection, so curl printed 000. There was no decision: false to enforce. A gateway that waits for a true can treat that as a deny. A gateway that only blocks on an explicit false would let the call through. I did not test a real gateway, so this is a reason to check yours, not a finding about any product.

Gotchas#

  • Unknown tools need no rule. When the tool is not in the catalog, tool is undefined, so every decision rule is undefined and the default false applies. A test pins that down.
  • Reasons can stack. reasons is a set, and the request with only the read scope returned two at once.
  • The policy trusts the context. user_confirmed is only as good as the enforcement point that sets it. A model must never be able to fill it in. IndyKite’s guide makes a similar point for the subject: it comes from the caller’s verified identity, never from the prompt text.
  • Default deny is a choice. Obsidian’s post says tool calls that match no policy proceed. Mine are refused. Neither is wrong, but decide on purpose.

What I would do with this#

  1. Put the enforcement point at the gateway or proxy that sees every tools/call, not inside the agent.
  2. Build the subject from the verified token and the delegation record, not from anything the model wrote.
  3. Keep the policy in a repository with its tests, and run opa test in CI.
  4. Make the enforcement point fail closed, and test that by stopping the decision point.

What was not run#

I did not run a real MCP gateway as the enforcement point. I did not run AuthZEN conformance tests, the batch evaluations API, the search APIs or any other AuthZEN decision point. I did not test OPA bundles, decision logs or policy performance. There is no recording for this lab. The lab uses no credentials or tokens.

Terminal images were rendered from the saved output of the run on 20 November 2026.

Repeat this lab#

This lab needs Linux on amd64, curl, jq and Python 3.13. Plan for about 20 minutes. Open each step, copy the blocks and compare the output with mine.

Every value in angle brackets is a placeholder for your own test environment. Nothing on this page is a real identifier or secret.

Set your variables once

bash · env.sh
# Paste into every terminal you use for this lab. No secrets are involved.
export OPA_VERSION="1.22.4"
export OPA_URL="http://localhost:8181"
export PDP_URL="http://localhost:8282"
Step 1Download OPA

Goal. Fetch the single static OPA binary at a pinned version and print its version.

Prerequisites

  • Linux on amd64 (for macOS or arm64 take the matching file from the release page), curl, jq and Python 3.13
  • Ports 8181 and 8282 free
bash · get-opa.sh
curl -sSL -o opa "https://github.com/open-policy-agent/opa/releases/download/v$OPA_VERSION/opa_linux_amd64_static"
chmod +x opa
./opa version | head -1

Expected output

output
Version: 1.22.4
Step 2Write the policy

Goal. Create the Rego policy: a tool catalog, a default of false, two decision rules and a set of denial reasons.

Prerequisites

  • Step 1 done, in the same folder
bash · write-policy.sh
cat > mcp_tools.rego <<'EOF'
# Which MCP tools may an agent call? The input has the shape of an
# AuthZEN Access Evaluation request: subject, action, resource, context.
package mcp.tools

default decision := false

# Tool catalog: the scope each tool needs and whether it moves money.
catalog := {
	"get_balance": {"scope": "payments.read", "moves_money": false},
	"list_transactions": {"scope": "payments.read", "moves_money": false},
	"send_payment": {"scope": "payments.write", "moves_money": true},
}

tool := catalog[input.resource.id]

decision if {
	input.subject.type == "agent"
	input.action.name == "tools/call"
	tool.scope in input.subject.properties.scopes
	not tool.moves_money
}

decision if {
	input.subject.type == "agent"
	input.action.name == "tools/call"
	tool.scope in input.subject.properties.scopes
	tool.moves_money
	input.context.amount_cents <= input.subject.properties.limit_cents
	input.context.user_confirmed
}

# Explain denials, the way a PDP would put reasons in the AuthZEN context.
reasons contains "unknown tool" if not catalog[input.resource.id]

reasons contains "missing scope" if {
	tool
	not tool.scope in input.subject.properties.scopes
}

reasons contains "over delegated limit" if {
	tool.moves_money
	input.context.amount_cents > input.subject.properties.limit_cents
}

reasons contains "user did not confirm" if {
	tool.moves_money
	not input.context.user_confirmed
}
EOF
head -3 mcp_tools.rego

Expected output

output
# Which MCP tools may an agent call? The input has the shape of an
# AuthZEN Access Evaluation request: subject, action, resource, context.
package mcp.tools
Step 3Write the tests and run them

Goal. Write six unit tests, then run the formatter, the strict checker and the test runner. All of them should pass.

Prerequisites

  • The policy file from the previous step
bash · unit-tests.sh
cat > mcp_tools_test.rego <<'EOF'
package mcp.tools_test

import data.mcp.tools

agent(scopes, limit) := {"type": "agent", "id": "support-bot", "properties": {"scopes": scopes, "limit_cents": limit}}

call(subject, tool, ctx) := {"subject": subject, "action": {"name": "tools/call"}, "resource": {"type": "mcp_tool", "id": tool}, "context": ctx}

test_read_allowed if {
	tools.decision with input as call(agent(["payments.read"], 0), "get_balance", {})
}

test_write_needs_scope if {
	not tools.decision with input as call(agent(["payments.read"], 50000), "send_payment", {"amount_cents": 100, "user_confirmed": true})
}

test_payment_within_limit_confirmed if {
	tools.decision with input as call(agent(["payments.write"], 5000), "send_payment", {"amount_cents": 4500, "user_confirmed": true})
}

test_payment_over_limit_denied if {
	r := tools.reasons with input as call(agent(["payments.write"], 5000), "send_payment", {"amount_cents": 9000, "user_confirmed": true})
	"over delegated limit" in r
}

test_payment_needs_confirmation if {
	not tools.decision with input as call(agent(["payments.write"], 5000), "send_payment", {"amount_cents": 4500, "user_confirmed": false})
}

test_unknown_tool_denied if {
	not tools.decision with input as call(agent(["payments.write"], 5000), "delete_account", {})
}
EOF
./opa fmt --list --fail . && ./opa check --strict . && echo "fmt + strict check: OK"
./opa test . -v

Expected output

output
fmt + strict check: OK
mcp_tools_test.rego:30:
data.mcp.tools_test.test_unknown_tool_denied: PASS (970.514µs)
mcp_tools_test.rego:17:
data.mcp.tools_test.test_payment_within_limit_confirmed: PASS (984.282µs)
mcp_tools_test.rego:26:
data.mcp.tools_test.test_payment_needs_confirmation: PASS (1.131509ms)
mcp_tools_test.rego:21:
data.mcp.tools_test.test_payment_over_limit_denied: PASS (1.197352ms)
mcp_tools_test.rego:13:
data.mcp.tools_test.test_write_needs_scope: PASS (1.433506ms)
mcp_tools_test.rego:9:
data.mcp.tools_test.test_read_allowed: PASS (1.255784ms)
--------------------------------------------------------------------------------
PASS: 6/6
Step 4Evaluate one request offline

Goal. Write an AuthZEN-shaped request for a $90 payment against a $50 limit and evaluate it with opa eval, without a server.

Prerequisites

  • Amounts are in cents: 9000 is $90 and 5000 is $50
bash · eval-offline.sh
cat > request.json <<'EOF'
{
  "subject": { "type": "agent", "id": "support-bot",
               "properties": { "scopes": ["payments.read", "payments.write"], "limit_cents": 5000 } },
  "action": { "name": "tools/call" },
  "resource": { "type": "mcp_tool", "id": "send_payment" },
  "context": { "amount_cents": 9000, "user_confirmed": true }
}
EOF
./opa eval -d mcp_tools.rego -i request.json 'data.mcp.tools.decision' --format pretty
./opa eval -d mcp_tools.rego -i request.json 'data.mcp.tools.reasons' --format pretty

Expected output

output
false
[
  "over delegated limit"
]
Step 5Run OPA as a server and add the AuthZEN endpoint

Goal. Serve the policy from OPA on port 8181, check its own decision API, then start the small Python endpoint on port 8282 and read its metadata document.

Prerequisites

  • Steps 2 to 4 done
  • The endpoint is a teaching shim, not a conformant AuthZEN PDP; keep it on localhost
bash · serve-opa.sh
./opa run --server --addr localhost:8181 mcp_tools.rego > opa-server.log 2>&1 &
sleep 2
curl -s $OPA_URL/health
curl -s $OPA_URL/v1/data/mcp/tools/decision -d '{"input":'"$(cat request.json)"'}'
bash · start-endpoint.sh
cat > authzen_pdp.py <<'EOF'
"""A minimal AuthZEN Access Evaluation endpoint in front of OPA.
Standard library only (Python 3.10+). OPA runs on :8181 with mcp_tools.rego loaded.
This is a teaching shim, not a conformant AuthZEN PDP."""
import json
import urllib.request
from http.server import BaseHTTPRequestHandler, HTTPServer

OPA = "http://localhost:8181/v1/data/mcp/tools"


class PDP(BaseHTTPRequestHandler):
    def _send(self, code, body):
        data = json.dumps(body).encode()
        self.send_response(code)
        self.send_header("content-type", "application/json")
        self.end_headers()
        self.wfile.write(data)

    def do_GET(self):
        if self.path == "/.well-known/authzen-configuration":
            base = f"http://{self.headers['host']}"
            return self._send(200, {"policy_decision_point": base,
                                    "access_evaluation_endpoint": f"{base}/access/v1/evaluation"})
        self._send(404, {})

    def do_POST(self):
        if self.path != "/access/v1/evaluation":
            return self._send(404, {})
        request = json.loads(self.rfile.read(int(self.headers["content-length"])))
        opa_req = urllib.request.Request(OPA, data=json.dumps({"input": request}).encode(),
                                         headers={"content-type": "application/json"})
        result = json.load(urllib.request.urlopen(opa_req)).get("result", {})
        body = {"decision": bool(result.get("decision"))}
        if not body["decision"]:
            body["context"] = {"reason_admin": {"403": ", ".join(sorted(result.get("reasons", [])))}}
        self._send(200, body)


HTTPServer(("127.0.0.1", 8282), PDP).serve_forever()
EOF
python3 authzen_pdp.py > pdp.log 2>&1 &
sleep 1
curl -s $PDP_URL/.well-known/authzen-configuration | jq .

Expected output

output
{}
{"result":false}
{
  "policy_decision_point": "http://localhost:8282",
  "access_evaluation_endpoint": "http://localhost:8282/access/v1/evaluation"
}
Step 6Ask for a decision: $90, then $45

Goal. Send the request to the AuthZEN evaluation endpoint. It should deny with a reason. Then change only the amount to 4500 cents and ask again.

Prerequisites

  • OPA and the endpoint are running
bash · evaluate.sh
curl -s $PDP_URL/access/v1/evaluation -H 'content-type: application/json' -d @request.json | jq .
jq '.context.amount_cents=4500' request.json \
  | curl -s $PDP_URL/access/v1/evaluation -H 'content-type: application/json' -d @- | jq .

Expected output

output
{
  "decision": false,
  "context": {
    "reason_admin": {
      "403": "over delegated limit"
    }
  }
}
{
  "decision": true
}
Step 7Try more denials, then stop OPA

Goal. Send three more requests: a missing scope, an unconfirmed payment and an unknown tool. Then stop OPA and ask again to see that no decision comes back.

Prerequisites

  • The endpoint is running
bash · denials.sh
ask() { curl -s $PDP_URL/access/v1/evaluation -H 'content-type: application/json' -d @- | jq -c .; }
jq '.subject.properties.scopes=["payments.read"]' request.json | ask
jq '.context.user_confirmed=false | .context.amount_cents=4500' request.json | ask
jq '.resource.id="delete_account"' request.json | ask
# Now stop OPA and ask again: no decision comes back
pkill -f "opa run --server"
sleep 1
curl -s -o /dev/null -w "%{http_code}\n" -m 5 $PDP_URL/access/v1/evaluation -H 'content-type: application/json' -d @request.json

Expected output

output
{"decision":false,"context":{"reason_admin":{"403":"missing scope, over delegated limit"}}}
{"decision":false,"context":{"reason_admin":{"403":"user did not confirm"}}}
{"decision":false,"context":{"reason_admin":{"403":"unknown tool"}}}
000
Step 8Clean up

Goal. Stop both processes and delete the files the lab created.

Prerequisites

  • Nothing else uses ports 8181 and 8282
bash · cleanup.sh
pkill -f "opa run --server" || true
pkill -f authzen_pdp.py || true
rm -f opa mcp_tools.rego mcp_tools_test.rego request.json authzen_pdp.py opa-server.log pdp.log
unset -f ask
# check: nothing listens on ports 8181 and 8282 any more
curl -s -o /dev/null -w "%{http_code}\n" "$OPA_URL/health"
curl -s -o /dev/null -w "%{http_code}\n" "$PDP_URL/"

Expected output

output
000
000

Sources#

Discuss this on X or LinkedIn

Follow on X

New posts by email

One email a week with new posts and labs. Unsubscribe anytime.

Your address is stored with Kit, which sends the emails. Details

Related posts and labs