Updated 31 October 2026: rewritten around a failure the article's own code reproduces. The earlier Rego policy did not compile (rego_recursion_error), and once that was fixed its rules conflicted at runtime (eval_conflict_error); its ForcedLeak account named the wrong cause, and its policy client crashed instead of failing closed. Everything below has been checked: the policy passes opa check --strict and opa test on OPA 1.22.0, and every Python block runs offline against LangGraph 1.2.18. 30 October 2026: renamed the decision metric to fleet.policy.decisions to match Part 1.
A partner's content domain expires. Security notices and removes it from the egress allowlist, the list of hosts agents may send data to. That allowlist lives in a middleware module that every agent team copied into its own repository, which is the simplest way to enforce one agent policy across many agents. Two teams redeploy the same afternoon, and the third team's release train leaves on Thursday.
I built that fleet in LangGraph to see what happens in the gap, then gave all three agents the same task, the kind an injected instruction in an inbound lead produces: send customer record cust-1042 to cms.partner-old.example.
support-agent policy v2 blockedinvoice-agent policy v2 blockedresearch-agent policy v1 sentleft the fleet: [('research-agent', 'cms.partner-old.example', 'cust-1042')]Two of three agents enforced the revocation. The fleet did not. One record went to a host that the security team had revoked, and no dashboard showed it, because each agent's gate did exactly what its own copy of the rule said.
Agent Policy Enforcement Fails at the Oldest Copy
A common belief holds that guardrails are a per-agent concern, and framework documentation reinforces it: LangChain's guardrails guide, for example, attaches guardrails as middleware to each agent you create. Give every agent a good gate, keep the gates in sync, and the fleet is governed. That plan breaks at the second step, as the run above shows. "Keep the gates in sync" is a deployment process, and a deployment process runs at the speed of its slowest team.
I call this the Oldest-Copy Rule: a policy that ships inside each agent's deploy is enforced at the strength of its oldest copy, however good the newest copy is. Revocation is the most urgent kind of policy change, and it is exactly the change the oldest copy has not received yet.
This rule gives the problem a number. Revocation latency is the time from a policy change to the moment the last enforcement point decides on it. With copied guardrails, revocation latency equals your slowest release train, which in my opening fleet is days; later in this article, the same revocation reaches every agent in 1.7 seconds with a short polling interval, with no agent rebuilt.
My thesis for this part is that a fleet's guardrails are only as strong as its revocation latency, so fleet-wide rules must come from one policy source, evaluated on the one path every tool call takes, while agent-specific rules stay inside the agent. These are two layers with different owners, different change speeds and different failure modes, and I call the pair the Dual-Layer Gate Model. A fleet that has only the agent layer is governed by its oldest deploy. A fleet that pushes everything into the central layer gets a policy service that knows nothing about invoices and blocks the wrong things.
Here is the run, drawn as what each copy allowed:
direction: down
classes: {
fresh: {style: {fill: "#4A90E2"; stroke: "#2C6FB0"; font-color: "#FFFFFF"}}
stale: {style: {fill: "#FFD93D"; stroke: "#C9A800"; font-color: "#2C2C2A"}}
blocked: {style: {fill: "#6BCF7F"; stroke: "#3F9E52"; font-color: "#2C2C2A"}}
leak: {style: {fill: "#E74C3C"; stroke: "#B03A2E"; font-color: "#FFFFFF"}}
}
rev: "Security revokes cms.partner-old.example\n(policy v2)" {
style: {fill: "#7B68EE"; stroke: "#5A4BC4"; font-color: "#FFFFFF"}
}
fleet: "Three agents, three copies of the allowlist" {
label.near: top-center
grid-rows: 2
grid-columns: 3
grid-gap: 20
style: {fill: "#F4F6F6"; stroke: "#95A5A6"}
s: "support-agent\ncopy: v2" {class: fresh}
i: "invoice-agent\ncopy: v2" {class: fresh}
r: "research-agent\ncopy: v1 (Thursday)" {class: stale}
s2: "blocked" {class: blocked}
i2: "blocked" {class: blocked}
r2: "sent cust-1042" {class: leak}
}
host: "cms.partner-old.example\n(revoked, still reachable)" {
style: {fill: "#E74C3C"; stroke: "#B03A2E"; font-color: "#FFFFFF"}
}
rev -> fleet: "redeploys reach 2 of 3"
fleet -> host: "1 record"
In practice the yellow box is the fleet's real policy, and the purple one is only the intent.
Wrong Way: Every Agent Carries Its Own Copy
This is the whole wrong-way fleet, and it is deliberately ordinary: a LangGraph graph with an egress gate node in front of a delivery node, and an allowlist passed in at build time.
from typing import TypedDictfrom langgraph.graph import END, START, StateGraphclass Task(TypedDict): record: dict destination: str # parsed from an untrusted inbound lead outcome: strLEFT_THE_FLEET: list[tuple[str, str, str]] = []def send_record(agent: str, host: str, record: dict) -> None: """Stands in for the HTTP POST. Records what actually left.""" LEFT_THE_FLEET.append((agent, host, record["id"]))def build_agent(name: str, allowed_hosts: frozenset[str]): """Each agent ships with its own copy of the egress allowlist.""" def egress_gate(state: Task) -> dict: ok = state["destination"] in allowed_hosts return {"outcome": "allowed" if ok else "blocked"} def deliver(state: Task) -> dict: send_record(name, state["destination"], state["record"]) return {"outcome": "sent"} def route(state: Task) -> str: return "deliver" if state["outcome"] == "allowed" else END g = StateGraph(Task) g.add_node("egress_gate", egress_gate) g.add_node("deliver", deliver) g.add_edge(START, "egress_gate") g.add_conditional_edges("egress_gate", route, ["deliver", END]) g.add_edge("deliver", END) return g.compile()# Policy v1, copied into every agent's repo.V1 = frozenset({"crm.internal.example", "cms.partner-old.example"})# Policy v2: the partner's domain expired, so security revokes it.V2 = V1 - {"cms.partner-old.example"}fleet = { "support-agent": ("v2", build_agent("support-agent", V2)), "invoice-agent": ("v2", build_agent("invoice-agent", V2)), # This team's release train leaves on Thursday. "research-agent": ("v1", build_agent("research-agent", V1)),}task = { "record": {"id": "cust-1042", "email": "a.rao@example.com"}, "destination": "cms.partner-old.example", "outcome": "",}for name, (version, agent) in fleet.items(): result = agent.invoke(task) print(f"{name:<15} policy {version} {result['outcome']}")print("left the fleet:", LEFT_THE_FLEET)Running it prints the output at the top of this article. Each gate is correct for the rule it was given. What fails is the structure: the rule exists in three places, the fleet cannot tell which version is in force, and the copies leave no record of which one made each decision. Part 1 called the difference between what monitoring captures and what governance needs the Telemetry Surface Gap, and copied policy is that gap on the enforcement side.
A shared library with a version pin is the usual response. That changes where the copy lives, not how many copies there are. A library still reaches each agent only when that agent redeploys.
A better response keeps the check in the agent but loads the allowlist at runtime from a config service or a mounted ConfigMap. That fixes propagation: every agent sees a new allowlist within the config refresh interval, and it can log which revision it used. Two problems remain. Its check still runs in code the agent controls, so an agent that skips it, or a new agent that never had it, skips the policy. And the agent decides on its own claim about who it is. Faster propagation leaves both problems in place, and the gateway later in this article exists to fix them.
What ForcedLeak and SalesBleed Show About Egress Policy
My fleet is a toy, but its failure has a real shape. In September 2025, Noma Security disclosed ForcedLeak, a vulnerability chain in Salesforce Agentforce rated CVSS 9.4. An attacker put instructions into the Description field of a Web-to-Lead form. When an employee later asked Agentforce about the lead, the agent followed those instructions and wrote CRM data into the URL of an image in its reply. Rendering the reply, the employee's browser requested the image from my-salesforce-cms.com, a domain that had expired but was still on Agentforce's Content Security Policy (CSP) allowlist. Noma's researchers bought it for about $5 and read the data in their server logs.
What failed was an egress allowlist entry that nobody owned after the domain lapsed. Salesforce's fix, Trusted URLs Enforcement, shipped on 8 September 2025 and removes URLs that are not on the org's Trusted URLs list, a list configured once in Setup for every agent in the org. That makes it a fleet-level control, the layer this article argues for.
A year later, Zenity Labs showed that the fleet-level control needs the same care as any other code. Their SalesBleed research (September 2026) used the same Web-to-Lead path and got past the Trusted URLs redaction. Its redactor recognized only a fixed set of top-level domains, so a .fun host passed, and it also disagreed with the browser about where a URL ended. Salesforce confirmed fixes in August 2026.
direction: down
classes: {
agent: {style: {fill: "#4A90E2"; stroke: "#2C6FB0"; font-color: "#FFFFFF"}}
bad: {style: {fill: "#E74C3C"; stroke: "#B03A2E"; font-color: "#FFFFFF"}}
input: {style: {fill: "#FFD93D"; stroke: "#C9A800"; font-color: "#2C2C2A"}}
user: {style: {fill: "#98D8C8"; stroke: "#5FA898"; font-color: "#2C2C2A"}}
}
lead: "Web-to-Lead Description field\n(attacker instructions)" {class: input}
agent: "Agentforce agent\nwrites CRM data into\nan image URL in its reply" {
class: agent
}
browser: "Employee's browser\nrenders the reply, requests the image" {class: user}
gate: "Org-wide egress allowlist" {
label.near: top-center
grid-rows: 1
grid-gap: 20
style: {fill: "#F4F6F6"; stroke: "#95A5A6"}
csp: "2025 ForcedLeak:\nexpired domain still\non the CSP allowlist" {class: bad}
tld: "2026 SalesBleed:\nredactor knew a fixed\nTLD list; .fun passed" {class: bad}
}
out: "Attacker-controlled host\nreceives CRM data" {class: bad}
lead -> agent: "1. untrusted text"
agent -> browser: "2. reply with image"
browser -> gate: "3. image request"
gate -> out: "4. allowed"
Both incidents went through the one control that every agent shared. That is the strongest argument for putting egress at the fleet layer, since one fix protected every agent at once. It also shows that the fleet layer is code, and like any other code it needs owners, tests and an expiry process. Simon Willison called ForcedLeak a classic "lethal trifecta" image exfiltration bug: private data, untrusted instructions and a way to send data out, all in one agent. The egress allowlist is the control on that third part.
Look at where the request left from. No tool call was involved. Data left through the user's browser, a path a tool gateway never sees. That limit applies to everything below, so it gets its own section.
The Dual-Layer Gate Model: Tool Gateway Plus OPA
On every axis that matters operationally, the two layers differ.
| Layer 1: fleet decision point | Layer 2: agent gate | |
|---|---|---|
| Question it answers | Is this action permitted anywhere in this fleet? | Should this agent, in this state, take this action? |
| Typical rules | Egress allowlist, agent registry, model allowlist, which agents may write | Invoice amount thresholds, vendor checks, session history rules |
| Owner | Platform or security team | The agent's product team |
| Changes when | Compliance, threat model or a revocation changes | The agent's domain logic changes |
| Ships as | A policy bundle, independent of agent deploys | Part of the agent's own deploy |
| Can see | Authenticated identity, tool, destination | The agent's full state |
What the rebuild changes is where Layer 1 sits. A policy engine that agents call from their own code is still a library each agent must remember to call, and it still trusts the agent to describe its own request honestly. In this version, Layer 1 sits in a tool gateway that holds the only network client and credentials, authenticates the caller, and works out for itself what the request is.
direction: down
classes: {
l2: {style: {fill: "#98D8C8"; stroke: "#5FA898"; font-color: "#2C2C2A"}}
l1: {style: {fill: "#4A90E2"; stroke: "#2C6FB0"; font-color: "#FFFFFF"}}
pdp: {style: {fill: "#7B68EE"; stroke: "#5A4BC4"; font-color: "#FFFFFF"}}
ext: {style: {fill: "#95A5A6"; stroke: "#6C7A7B"; font-color: "#FFFFFF"}}
}
agents: "Layer 2: inside each agent (product teams)" {
label.near: top-center
grid-rows: 1
grid-gap: 20
style: {fill: "#F4F6F6"; stroke: "#95A5A6"}
a: "support-agent\ndomain gate" {class: l2}
b: "invoice-agent\ndomain gate" {class: l2}
c: "research-agent\ndomain gate" {class: l2}
}
gw: "Tool gateway\nauthenticates the caller, owns tools and credentials" {class: l1}
opa: "Layer 1: fleet decision point\nOPA + policy bundle (platform team)" {class: pdp}
net: "CRM, partner hosts, email, webhooks" {class: ext}
agents -> gw: "1. identity, tool, url"
gw -> opa: "2. decide(agent, version, model, action, host)"
opa -> gw: "3. allow / deny / require_human + revision"
gw -> net: "4. only if allowed"
Both layers must pass, and neither can turn the other's deny into an allow. Their order still has one visible effect: an invoice that the agent's own gate stops never reaches the gateway, so it produces no fleet decision record, and for that reason Layer 2 needs its own logging.
OPA Rego Policy for Agent Egress With Default Deny
Fleet policy is written in Rego, OPA's policy language, and shipped as a bundle. Rules live in policy.rego and the allowlists live in data.json beside them, so revoking a host is a one-line data change that a reviewer can read.
{ "fleet": { "egress_allowlist": ["cms.partner-old.example", "crm.internal.example"], "allowed_models": ["model-a-2026-09", "model-b-2026-10"], "agents": { "support-agent": {"actions": ["http_post", "http_get", "read"], "verified_versions": ["3.2.0"]}, "invoice-agent": {"actions": ["http_post", "crm_write", "read"], "verified_versions": ["5.0.1"]}, "research-agent": {"actions": ["http_post", "http_get", "read"], "verified_versions": ["1.9.4"]} } }}Next to them, the bundle directory holds a .manifest file, {"revision": "egress-2026-10-31.1", "roots": ["fleet"]}, which names the revision and the data root the bundle owns.
package fleet.policy
# Fleet-wide rules, owned by platform security and shipped as one bundle.
# The allowlists are data (data.json), so revoking a host is a data change.
# Any request that leaves the fleet. A GET carries data in its URL.
egress_actions := {"http_get", "http_post", "send_email", "webhook"}
write_actions := {"crm_write", "db_write"}
deny contains "destination not on the fleet egress allowlist" if {
input.action in egress_actions
not input.destination in data.fleet.egress_allowlist
}
deny contains "model not on the fleet model allowlist" if {
not input.model in data.fleet.allowed_models
}
# Undefined is not false. If this lookup fails, every rule that reads
# agent.* silently fails with it, so an unknown agent must be denied here.
agent := data.fleet.agents[input.agent]
deny contains "agent not registered with the fleet" if not agent
deny contains "agent not permitted this action" if {
agent
not input.action in agent.actions
}
require_human contains "write from an unverified agent version" if {
input.action in write_actions
not input.agent_version in agent.verified_versions
}
default decision := "deny"
decision := "deny" if count(deny) > 0
decision := "require_human" if {
count(deny) == 0
count(require_human) > 0
}
decision := "allow" if {
count(deny) == 0
count(require_human) == 0
}
default revision := "unbundled"
revision := r if {
some b in data.system.bundles
"fleet" in b.manifest.roots
r := b.manifest.revision
}
result := {
"decision": decision,
"reasons": (deny | require_human),
"revision": revision,
}
Three design choices make this policy safe to change.
First, the reasons are partial sets (deny contains ...). Any number of deny rules can match at once and each one adds its reason, so matching rules never conflict. There is one rule body for each value of decision, and their conditions cannot overlap. A common way to write fleet policy gives each rule its own decision := ... assignment, and that fails in two ways. A catch-all "allow if not denied" rule refers to decision inside its own definition, so OPA refuses to compile it with rego_recursion_error. Without the catch-all, two rules that both match raise eval_conflict_error at runtime.
Second, the code holds no constant for revision; the policy reads it from the bundle manifest, and OPA also records the bundle revision in its decision log entries. Each decision can therefore be traced to the exact policy that made it, which is the evidence Part 6 builds its audit records on.
Third, the default is deny, and the tests cover the cases that matter, including a GET to an unlisted host, because data can leave in a URL as easily as in a body:
package fleet.policy_test
import data.fleet.policy
base := {
"agent": "research-agent",
"agent_version": "1.9.4",
"model": "model-a-2026-09",
"action": "http_post",
"destination": "crm.internal.example",
}
test_allowed_host_is_allowed if {
policy.decision == "allow" with input as base
}
test_unlisted_host_is_denied if {
inp := object.union(base, {"destination": "collector.attacker.example"})
policy.decision == "deny" with input as inp
}
test_get_to_unlisted_host_is_denied if {
inp := object.union(base, {
"action": "http_get",
"destination": "collector.attacker.example",
})
policy.decision == "deny" with input as inp
}
test_unregistered_agent_is_denied if {
inp := object.union(base, {"agent": "shadow-agent"})
policy.decision == "deny" with input as inp
}
test_unverified_write_needs_a_human if {
inp := object.union(base, {
"agent": "invoice-agent",
"agent_version": "5.1.0-rc1",
"action": "crm_write",
})
policy.decision == "require_human" with input as inp
}
test_deny_beats_require_human if {
inp := object.union(base, {
"agent": "invoice-agent",
"agent_version": "5.1.0-rc1",
"action": "crm_write",
"model": "model-z-2024-11",
})
policy.decision == "deny" with input as inp
"write from an unverified agent version" in policy.result.reasons with input as inp
}
$ opa check --strict bundle tests$ opa test bundle testsPASS: 6/6Model names here are placeholders on purpose, because a real model ID in a policy example goes stale within months: gpt-4o-2024-11-20, a common pin in 2025, is scheduled to leave OpenAI's API on 14 January 2027.
Here is the decision flow the tests pin down:
direction: down
classes: {
rule: {style: {fill: "#4A90E2"; stroke: "#2C6FB0"; font-color: "#FFFFFF"}}
set: {style: {fill: "#7B68EE"; stroke: "#5A4BC4"; font-color: "#FFFFFF"}}
deny: {style: {fill: "#E74C3C"; stroke: "#B03A2E"; font-color: "#FFFFFF"}}
human: {style: {fill: "#FFD93D"; stroke: "#C9A800"; font-color: "#2C2C2A"}}
allow: {style: {fill: "#6BCF7F"; stroke: "#3F9E52"; font-color: "#2C2C2A"}}
}
rules: "Rules add reasons; they never assign the decision" {
label.near: top-center
grid-rows: 1
grid-gap: 16
style: {fill: "#F4F6F6"; stroke: "#95A5A6"}
r1: "egress\nallowlist" {class: rule}
r2: "model\nallowlist" {class: rule}
r3: "agent\nregistry" {class: rule}
r4: "unverified\nwrite" {class: rule}
}
sets: "Two sets" {
label.near: top-center
grid-rows: 1
grid-gap: 40
style: {fill: "#F4F6F6"; stroke: "#95A5A6"}
d: "deny = {...}" {class: set}
h: "require_human = {...}" {class: set}
}
out: "One decision" {
label.near: top-center
grid-rows: 1
grid-gap: 16
style: {fill: "#F4F6F6"; stroke: "#95A5A6"}
o1: "deny\nif deny is not empty" {class: deny}
o2: "require_human\nif only require_human" {class: human}
o3: "allow\nif both are empty" {class: allow}
}
rules -> sets
sets -> out
Reading it top to bottom, no rule can force an allow. An allow happens only when every rule stays silent, which is what default-deny means in practice.
Rego Undefined Lookups: How an Unknown Agent Got Allowed
My first draft of this policy failed its own tests, which is why the comment above agent := exists. I had written the registry rule the way most Rego examples write membership checks:
deny contains "agent not registered for this action" if {
not input.action in data.fleet.agents[input.agent].actions
}
For a registered agent this works. For an agent that is not in data.fleet.agents, the lookup is undefined and the rule never fires, because of how OPA compiles the expression: it turns the lookup into its own step, evaluated before the negation, and opa test -v shows it failing there: Fail __local30__ = data.fleet.agents[__local29__].actions. A failed step ends the rule body, so not never runs. Nothing is added to deny, and the registry was the only rule that applied to an unknown agent posting to an allowed host:
$ opa eval -f pretty -b bundle -i shadow-agent.json 'data.fleet.policy.result'{ "decision": "allow", "reasons": [], "revision": "egress-2026-10-31.1"}An agent the fleet had never heard of was allowed to send data out. Because this is valid Rego, opa check --strict passed it, and only test_unregistered_agent_is_denied caught it (PASS: 5/6, FAIL: 1/6). My fix binds the lookup to a rule, agent := ..., and denies with not agent. Negating a whole rule behaves differently: when the rule agent is undefined, not agent is true.
direction: down
classes: {
step: {style: {fill: "#4A90E2"; stroke: "#2C6FB0"; font-color: "#FFFFFF"}}
bad: {style: {fill: "#E74C3C"; stroke: "#B03A2E"; font-color: "#FFFFFF"}}
good: {style: {fill: "#6BCF7F"; stroke: "#3F9E52"; font-color: "#2C2C2A"}}
}
grid-rows: 1
grid-gap: 30
naive: "Lookup inside not (first draft)" {
label.near: top-center
grid-columns: 1
grid-gap: 14
style: {fill: "#F4F6F6"; stroke: "#95A5A6"}
a: "agents[\"shadow-agent\"].actions\nevaluated as its own step" {class: step}
b: "step fails;\nnot never runs" {class: step}
c: "deny stays empty" {class: bad}
d: "decision: allow" {class: bad}
}
fixed: "Negate the whole rule" {
label.near: top-center
grid-columns: 1
grid-gap: 14
style: {fill: "#F4F6F6"; stroke: "#95A5A6"}
a: "rule agent := agents[\"shadow-agent\"]\nis undefined" {class: step}
b: "not agent\nis true" {class: step}
c: "deny = {agent not registered}" {class: good}
d: "decision: deny" {class: good}
}
This lesson applies beyond Rego. A fleet decision point is fail-closed only if every path to "allow" requires evidence, and a rule that silently stops applying when data is missing turns a missing registry entry into permission. Write the test for the agent you have never heard of before any other test.
Agent Tool Gateway: The Only Path to a Side Effect
From an agent, the gateway takes four things: its workload identity, a tool name, a URL and a payload. Everything the policy decides on is derived inside the gateway, from registries in the spirit of deterministic tool registries for a single agent. Agent identity, version and model come from the deploy registry for the authenticated identity, the action class comes from the tool registry, and the destination is the host of the URL the gateway itself is about to request. An agent cannot describe its request more favourably than it is, which is verify every tool call applied at a single chokepoint.
Save this as gateway.py:
from dataclasses import dataclassfrom urllib.parse import urlsplitimport httpxfrom opentelemetry import metrics, tracefrom opentelemetry.metrics import Observation@dataclass(frozen=True)class Workload: agent: str version: str model: str@dataclass(frozen=True)class Tool: action: str # the gateway assigns the action class, never the caller method: str@dataclass(frozen=True)class Decision: decision: str # allow | deny | require_human | allow_unverified reasons: tuple[str, ...] revision: strclass PolicyDenied(Exception): def __init__(self, decision: Decision) -> None: super().__init__(f"{decision.decision}: {', '.join(decision.reasons)}") self.decision = decisionUNKNOWN = Workload("unauthenticated", "none", "none")class ToolGateway: """The only path from an agent to a side effect. Agents send (identity, tool, url, payload). Everything the policy decides on is derived here: who the caller is from its authenticated workload identity, the action class from the tool registry, and the destination from the URL this gateway is about to request. """ def __init__(self, *, opa_url: str, meter: metrics.Meter, workloads: dict[str, Workload], tools: dict[str, Tool], internal_hosts: frozenset[str], egress: httpx.Client) -> None: # httpx applies this timeout to each phase (connect, read, ...). self._opa = httpx.Client(base_url=opa_url, timeout=0.25) self._workloads, self._tools = workloads, tools self._internal = internal_hosts self._egress = egress # holds the network credentials self._revision = "none" self._decisions = meter.create_counter( "fleet.policy.decisions", description="Fleet policy decisions at the tool gateway", ) meter.create_observable_gauge( "fleet.policy.active_revision", callbacks=[lambda _: [Observation( 1, {"fleet.policy.revision": self._revision})]], description="Bundle revision this gateway last decided on", ) def _decide(self, request: dict) -> Decision: try: resp = self._opa.post("/v1/data/fleet/policy/result", json={"input": request}) resp.raise_for_status() body = resp.json()["result"] return Decision(body["decision"], tuple(sorted(body["reasons"])), body["revision"]) except (httpx.HTTPError, KeyError, TypeError, ValueError): internal = request["destination"] in self._internal if request["action"] == "read" and internal: return Decision("allow_unverified", ("policy_unreachable",), "none") return Decision("deny", ("policy_unreachable",), "none") def call(self, *, identity: str, tool: str, url: str, session_id: str, payload: dict | None = None) -> httpx.Response: who = self._workloads.get(identity, UNKNOWN) spec = self._tools[tool] host = urlsplit(url).hostname or "" d = self._decide({"agent": who.agent, "agent_version": who.version, "model": who.model, "action": spec.action, "destination": host}) if d.revision != "none": self._revision = d.revision # Bounded labels: agent and tool come from registries, not callers. self._decisions.add(1, { "gen_ai.agent.name": who.agent, "gen_ai.tool.name": tool, "fleet.policy.action": spec.action, "fleet.policy.decision": d.decision, }) # Per-decision evidence goes on the span (Part 1's rule). span = trace.get_current_span() span.set_attribute("gen_ai.conversation.id", session_id) span.set_attribute("fleet.policy.decision", d.decision) span.set_attribute("fleet.policy.revision", d.revision) span.set_attribute("fleet.policy.reasons", list(d.reasons)) if d.decision not in ("allow", "allow_unverified"): raise PolicyDenied(d) return self._egress.request(spec.method, url, json=payload)One except clause covers every way a decision can fail to arrive: timeout, refused connection, a 5xx status, a response without result (OPA returns {} when the queried rule is undefined), or a body of the wrong shape. Each of these cases returns a decision, and none of them crashes the gateway. Because the timeout applies to each phase of the request, the worst case is a small multiple of 250 ms.
Three things in the example stand in for production parts. Identity is a SPIFFE-style string in a dictionary, while in production the gateway reads it from the client's mTLS certificate, so an agent cannot choose it. To keep the example offline, the gateway runs in the agent's process; in production it is a separate service, and the agent's pod has network policy that allows the gateway and the model provider and nothing else. The credentials the gateway holds should themselves be scoped to the task, not just short-lived. Finally, the egress client uses a mock transport that records every request that leaves.
direction: down
classes: {
agent: {style: {fill: "#98D8C8"; stroke: "#5FA898"; font-color: "#2C2C2A"}}
gw: {style: {fill: "#4A90E2"; stroke: "#2C6FB0"; font-color: "#FFFFFF"}}
pdp: {style: {fill: "#7B68EE"; stroke: "#5A4BC4"; font-color: "#FFFFFF"}}
ok: {style: {fill: "#6BCF7F"; stroke: "#3F9E52"; font-color: "#2C2C2A"}}
no: {style: {fill: "#E74C3C"; stroke: "#B03A2E"; font-color: "#FFFFFF"}}
}
agent: "Agent pod\nno network credentials\negress only to the gateway" {
class: agent
}
gw: "ToolGateway" {
label.near: top-center
grid-rows: 1
grid-gap: 16
style: {fill: "#F4F6F6"; stroke: "#95A5A6"}
who: "1. identity from mTLS\n-> deploy registry" {class: gw}
what: "2. action from tool\nregistry, host from URL" {class: gw}
ask: "3. ask OPA,\ncount, then run" {class: gw}
}
opa: "OPA\nfleet bundle" {class: pdp}
tool: "Network client\n(credentials live here)" {class: ok}
blocked: "Direct call from the agent\nhas no route out" {class: no}
agent -> gw: "identity, tool, url"
gw -> opa: "decide"
gw -> tool: "allow"
agent -> blocked: "bypass attempt"
Both of the next two runs share a fleet setup made of the deploy registry, the tool registry and the recording network. Save it as fleet.py:
import httpxfrom opentelemetry import metricsfrom gateway import Tool, ToolGateway, Workload# Deploy registry: what is running under each authenticated workload# identity. In production the gateway gets the identity from mTLS.WORKLOADS = { "spiffe://fleet.example/support-agent": Workload("support-agent", "3.2.0", "model-a-2026-09"), "spiffe://fleet.example/invoice-agent": Workload("invoice-agent", "5.0.1", "model-a-2026-09"), "spiffe://fleet.example/invoice-agent-canary": Workload("invoice-agent", "5.1.0-rc1", "model-a-2026-09"), "spiffe://fleet.example/research-agent": Workload("research-agent", "1.9.4", "model-b-2026-10"),}TOOLS = { "post_record": Tool(action="http_post", method="POST"), "fetch_page": Tool(action="http_get", method="GET"), "crm_upsert": Tool(action="crm_write", method="POST"), "crm_lookup": Tool(action="read", method="GET"),}INTERNAL_HOSTS = frozenset({"crm.internal.example"})LEFT_THE_FLEET: list[tuple[str, str]] = []def _network(request: httpx.Request) -> httpx.Response: """Stands in for the real network. Records every request that left.""" LEFT_THE_FLEET.append((request.method, request.url.host)) return httpx.Response(200)def make_gateway(opa_url: str, meter: metrics.Meter, gateway_cls: type[ToolGateway] = ToolGateway, **options) -> ToolGateway: return gateway_cls( opa_url=opa_url, meter=meter, workloads=WORKLOADS, tools=TOOLS, internal_hosts=INTERNAL_HOSTS, egress=httpx.Client(transport=httpx.MockTransport(_network)), **options, )Measuring Revocation Latency Without Redeploying Agents
This run repeats the opening scenario through the gateway, against an OPA that pulls its policy from a bundle server, the way it would in production. A local HTTP server stands in for the bundle server, and OPA polls it every one to two seconds:
services: policy: url: http://127.0.0.1:8282bundles: fleet: service: policy resource: bundle.tar.gz polling: min_delay_seconds: 1 max_delay_seconds: 2status: prometheus: true # bundle health on /metrics, used by the staleness guard$ opa build -b bundle -r egress-2026-10-31.1 -o serve/bundle.tar.gz$ (cd serve && python -m http.server 8282 --bind 127.0.0.1) &$ opa run -s -c opa-config.yaml --addr 127.0.0.1:8181 &My script builds the three agents once, runs them on revision .1, then publishes revision .2 with the revoked host removed and runs the same compiled agents again:
import jsonimport subprocessimport timefrom typing import TypedDictimport httpxfrom langgraph.graph import END, START, StateGraphfrom opentelemetry.sdk.metrics import MeterProviderfrom opentelemetry.sdk.metrics.export import InMemoryMetricReaderfrom fleet import LEFT_THE_FLEET, make_gatewayfrom gateway import PolicyDenied, ToolGatewayOPA = "http://127.0.0.1:8181"class Task(TypedDict): record: dict destination: str session_id: str outcome: strdef build_agent(identity: str, gateway: ToolGateway): """No allowlist in the agent. It holds no network client either.""" def deliver(state: Task) -> dict: try: gateway.call(identity=identity, tool="post_record", url=f"https://{state['destination']}/ingest", payload=state["record"], session_id=state["session_id"]) except PolicyDenied as exc: return {"outcome": f"denied: {', '.join(exc.decision.reasons)}"} return {"outcome": "sent"} g = StateGraph(Task) g.add_node("deliver", deliver) g.add_edge(START, "deliver") g.add_edge("deliver", END) return g.compile()def publish(revision: str, allowlist: set[str]) -> None: """Stands in for the policy repo's CI: change data, build the bundle.""" with open("bundle/data.json") as f: data = json.load(f) data["fleet"]["egress_allowlist"] = sorted(allowlist) with open("bundle/data.json", "w") as f: json.dump(data, f, indent=2) subprocess.run(["opa", "build", "-b", "bundle", "-r", revision, "-o", "serve/bundle.tar.gz"], check=True)def publish_and_wait(revision: str, allowlist: set[str]) -> float: """Publish a revision, then wait until the decision point serves it.""" started = time.monotonic() publish(revision, allowlist) url = f"{OPA}/v1/data/fleet/policy/revision" while httpx.post(url, json={}).json().get("result") != revision: time.sleep(0.1) return time.monotonic() - startedreader = InMemoryMetricReader()gateway = make_gateway(OPA, MeterProvider(metric_readers=[reader]) .get_meter("fleet.gateway"))names = ["support-agent", "invoice-agent", "research-agent"]agents = {n: build_agent(f"spiffe://fleet.example/{n}", gateway) for n in names}def run_fleet(label: str) -> None: for name, agent in agents.items(): out = agent.invoke({ "record": {"id": "cust-1042", "email": "a.rao@example.com"}, "destination": "cms.partner-old.example", "session_id": f"sess-{label}-{name}", "outcome": "", }) print(f"{label:<7}{name:<15} {out['outcome']}")publish_and_wait("egress-2026-10-31.1", {"crm.internal.example", "cms.partner-old.example"})run_fleet("before")sent_before = len(LEFT_THE_FLEET)# The partner's domain expired. Security revokes it in the policy repo.took = publish_and_wait("egress-2026-10-31.2", {"crm.internal.example"})print(f"revision .2 serving after {took:.1f} s; no agent rebuilt")run_fleet("after")print(f"left the fleet: {sent_before} before, " f"{len(LEFT_THE_FLEET) - sent_before} after")for m in reader.get_metrics_data().resource_metrics[0].scope_metrics[0].metrics: for p in m.data.data_points: a = p.attributes label = a.get("fleet.policy.revision") or ( f"{a['gen_ai.agent.name']} {a['fleet.policy.decision']}") print(f"{m.name:<29} {label:<22} {p.value}")before support-agent sentbefore invoice-agent sentbefore research-agent sentrevision .2 serving after 1.7 s; no agent rebuiltafter support-agent denied: destination not on the fleet egress allowlistafter invoice-agent denied: destination not on the fleet egress allowlistafter research-agent denied: destination not on the fleet egress allowlistleft the fleet: 3 before, 0 afterfleet.policy.decisions support-agent allow 1fleet.policy.decisions invoice-agent allow 1fleet.policy.decisions research-agent allow 1fleet.policy.decisions support-agent deny 1fleet.policy.decisions invoice-agent deny 1fleet.policy.decisions research-agent deny 1fleet.policy.active_revision egress-2026-10-31.2 1Nothing about the research agent changed; it is the same build that leaked in the opening run. Revocation latency was 1.7 seconds in this run and between 1.5 and 2.1 seconds across three others, and its bound is the polling interval plus the bundle build, with no team's release train anywhere in it. All the revocation took was one line of data and one new bundle revision.
Layer 2: Per-Agent Gate Rules Stay in the Agent
Nothing at the fleet layer can know that this invoice team wants finance to review anything above 50,000, or which vendors are in its master list. Those rules belong to the invoice team, deploy with the invoice agent, and run inside its graph, as the Gated Execution pattern describes, while the tool call that follows still goes through the gateway.
from typing import TypedDictfrom langgraph.graph import END, START, StateGraphfrom opentelemetry.sdk.metrics import MeterProviderfrom fleet import make_gatewayfrom gateway import PolicyDenied, ToolGatewayVENDOR_MASTER = {"V-118", "V-204"} # owned by the invoice teamREVIEW_ABOVE = 50_000 # owned by the invoice teamCRM = "https://crm.internal.example/invoices"class Invoice(TypedDict): invoice_id: str vendor_id: str amount: float session_id: str outcome: strdef build_invoice_agent(identity: str, gateway: ToolGateway): def domain_gate(state: Invoice) -> dict: # Layer 2: rules only this agent's team can write. if state["vendor_id"] not in VENDOR_MASTER: return {"outcome": "blocked: unknown vendor"} if state["amount"] > REVIEW_ABOVE: return {"outcome": "held: amount needs finance review"} return {"outcome": "domain ok"} def write_crm(state: Invoice) -> dict: # Layer 1: the fleet decides at the gateway, on every call. try: gateway.call(identity=identity, tool="crm_upsert", url=CRM, payload={"id": state["invoice_id"]}, session_id=state["session_id"]) except PolicyDenied as exc: return {"outcome": f"fleet {exc.decision.decision}: " f"{', '.join(exc.decision.reasons)}"} return {"outcome": "written"} def route(state: Invoice) -> str: return "write_crm" if state["outcome"] == "domain ok" else END g = StateGraph(Invoice) g.add_node("domain_gate", domain_gate) g.add_node("write_crm", write_crm) g.add_edge(START, "domain_gate") g.add_conditional_edges("domain_gate", route, ["write_crm", END]) g.add_edge("write_crm", END) return g.compile()meter = MeterProvider().get_meter("fleet.gateway")live = make_gateway("http://127.0.0.1:8181", meter)stable = "spiffe://fleet.example/invoice-agent"canary = "spiffe://fleet.example/invoice-agent-canary"cases = [ (stable, {"invoice_id": "INV-7731", "vendor_id": "V-118", "amount": 1_200}), (stable, {"invoice_id": "INV-7732", "vendor_id": "V-118", "amount": 82_000}), (stable, {"invoice_id": "INV-7733", "vendor_id": "V-999", "amount": 300}), (canary, {"invoice_id": "INV-7734", "vendor_id": "V-204", "amount": 900}),]for identity, inv in cases: agent = build_invoice_agent(identity, live) out = agent.invoke({**inv, "session_id": "sess-inv-01", "outcome": ""}) print(f"{inv['invoice_id']} {identity.rsplit('/', 1)[1]:<20} {out['outcome']}")def attempt(gateway: ToolGateway, label: str, identity: str, tool: str, url: str) -> None: try: gateway.call(identity=identity, tool=tool, url=url, session_id="sess-inv-02") print(f"{label:<24} proceeded") except PolicyDenied as exc: d = exc.decision more = f" (+{len(d.reasons) - 1} more)" if len(d.reasons) > 1 else "" print(f"{label:<24} {d.decision}: {d.reasons[0]}{more}")# A workload the deploy registry has never seen, naming itself.attempt(live, "unknown identity, read", "spiffe://fleet.example/x", "crm_lookup", CRM)# The decision point goes away: nothing listens on this port.down = make_gateway("http://127.0.0.1:8999", meter)attempt(down, "OPA down, CRM write", stable, "crm_upsert", CRM)attempt(down, "OPA down, CRM read", stable, "crm_lookup", CRM)attempt(down, "OPA down, external read", stable, "fetch_page", "https://cms.partner-old.example/page")INV-7731 invoice-agent writtenINV-7732 invoice-agent held: amount needs finance reviewINV-7733 invoice-agent blocked: unknown vendorINV-7734 invoice-agent-canary fleet require_human: write from an unverified agent versionunknown identity, read deny: agent not registered with the fleet (+1 more)OPA down, CRM write deny: policy_unreachableOPA down, CRM read proceededOPA down, external read deny: policy_unreachableEach invoice stops at the layer that owns its rule:
grid-rows: 4
grid-columns: 3
grid-gap: 14
classes: {
id: {style: {fill: "#95A5A6"; stroke: "#6C7A7B"; font-color: "#FFFFFF"}}
l2: {style: {fill: "#98D8C8"; stroke: "#5FA898"; font-color: "#2C2C2A"}}
l1: {style: {fill: "#7B68EE"; stroke: "#5A4BC4"; font-color: "#FFFFFF"}}
pass: {style: {fill: "#6BCF7F"; stroke: "#3F9E52"; font-color: "#2C2C2A"}}
stop: {style: {fill: "#FFD93D"; stroke: "#C9A800"; font-color: "#2C2C2A"}}
}
a1: "INV-7731\n1,200, known vendor" {class: id}
a2: "Layer 2: pass" {class: pass}
a3: "Layer 1: allow -> written" {class: pass}
b1: "INV-7732\n82,000" {class: id}
b2: "Layer 2: held for\nfinance review" {class: stop}
b3: "Layer 1: never asked" {class: l2}
c1: "INV-7733\nvendor V-999" {class: id}
c2: "Layer 2: blocked,\nunknown vendor" {class: stop}
c3: "Layer 1: never asked" {class: l2}
d1: "INV-7734\ncanary 5.1.0-rc1" {class: id}
d2: "Layer 2: pass" {class: pass}
d3: "Layer 1: require_human,\nunverified version" {class: l1}
INV-7734 is the case teams usually get wrong. By every domain rule the invoice is fine, but the agent build is a release candidate that the fleet has not verified for writes. Only the fleet layer knows which builds are verified, and only the invoice team knows its vendors. Neither layer can do the other's job, which is the Dual-Layer Gate Model in four rows. A require_human decision needs somewhere to go: the approval queue from Gated Execution is that place, and the gateway simply refuses until an approval arrives.
An unknown identity is denied even when it asks only for a read. Nor could the canary pass itself off as the stable build, because the gateway looked up its version in the deploy registry.
Fail Closed or Fail Open: Decide Per Action Class
In that output, the last three lines are the most important decision in this design. "If the policy service is unreachable, deny" sounds like the only safe answer, yet OPA's own Kubernetes admission controller disagrees. Gatekeeper ships with failurePolicy: Ignore, which is fail-open, and its docs explain why: with fail-closed, the availability of the Kubernetes control plane becomes subject to the availability of the webhook. Audit is expected to catch what slips through. Envoy's external authorization filter makes the opposite default choice: its failure_mode_allow is false, so requests are rejected when the authorization service fails, and CVE-2023-27488 is a privilege escalation in deployments that turned fail-open on.
Both projects are right for their traffic. Which answer fits depends on what a wrong allow costs compared with a wrong deny, so the gateway decides per action class, and two details matter. Its class comes from the tool registry, so an agent cannot label a write as a read. And a read fails open only when its destination is an internal host, because a GET to an outside host can carry data in its URL:
grid-rows: 3
grid-columns: 3
grid-gap: 14
classes: {
head: {style: {fill: "#95A5A6"; stroke: "#6C7A7B"; font-color: "#FFFFFF"}}
closed: {style: {fill: "#E74C3C"; stroke: "#B03A2E"; font-color: "#FFFFFF"}}
open: {style: {fill: "#FFD93D"; stroke: "#C9A800"; font-color: "#2C2C2A"}}
}
h1: "Action class" {class: head}
h2: "When OPA is down" {class: head}
h3: "Why" {class: head}
w1: "Writes, sends, and\nany external request" {class: closed}
w2: "deny\npolicy_unreachable" {class: closed}
w3: "A wrong allow can leak\nor destroy data; a wrong\ndeny costs a retry" {class: closed}
r1: "Reads of\ninternal hosts" {class: open}
r2: "proceed as\nallow_unverified" {class: open}
r3: "A wrong deny stops the\nfleet; every unverified\nread is counted" {class: open}
Fail-open without a counter is a hole. Fail-open with a counter is a measured trade. Here allow_unverified has its own value on fleet.policy.decisions and is also stamped on the span, so the audit trail records decisions OPA never made.
Agent Egress Paths a Tool Gateway Does Not See
ForcedLeak is the reminder that a tool gateway covers tool calls and nothing else, and a chokepoint is only as complete as the list of paths that go around it. These are the paths I check in every fleet, with what closes each:
grid-rows: 5
grid-columns: 2
grid-gap: 14
classes: {
path: {style: {fill: "#E74C3C"; stroke: "#B03A2E"; font-color: "#FFFFFF"}}
fix: {style: {fill: "#4A90E2"; stroke: "#2C6FB0"; font-color: "#FFFFFF"}}
}
p1: "Rendered output\nimages and links in replies" {class: path}
f1: "Sanitize output and set CSP\nfrom the same allowlist data" {class: fix}
p2: "Provider-hosted tools\nweb fetch, code interpreter" {class: path}
f2: "Disable them, or restrict their\ndomains at the provider" {class: fix}
p3: "MCP servers the agent\nconnects to directly" {class: path}
f3: "Route MCP traffic through\nthe gateway or an MCP proxy" {class: fix}
p4: "Code sandboxes\nwith network access" {class: path}
f4: "Sandbox egress only via\nthe gateway, or none" {class: fix}
p5: "The model API call itself" {class: path}
f5: "Allow only the provider host,\nor route it via an LLM proxy" {class: fix}
Most fleets miss the first row, and the third is close behind: MCP servers carry their own context-injection and exfiltration risks, so route them through the gateway too. An agent's reply is output, and a browser that renders it makes requests on the agent's behalf. To fix it, drive the output sanitizer and the CSP header from the same egress_allowlist data the gateway uses, so that one allowlist governs both paths and one revocation closes both.
OPA Sidecar vs Central Service for Agent Policy
A common recommendation is to run OPA as one dedicated central service rather than as sidecars. For per-request decisions, OPA's own deployment guidance says the opposite: the decision point is "best located as close as possible" to the enforcement point, and a central service has higher latency and is a "failure point if not highly available". Its guidance lists large data volumes, serverless and batch jobs as the uses for a central deployment.
If every gateway host runs its own OPA, the fleet has N copies of the policy again, and the Oldest-Copy Rule should apply. It does, in a weaker form. Sidecar OPAs pull the same bundle from one bundle server, a revocation reaches all of them within the polling interval without any agent redeploying, and every decision carries the revision, so skew between copies is measurable. By default OPA polls every 60 to 120 seconds, set by min_delay_seconds and max_delay_seconds; lower it, or use long polling, if revocation latency matters to you.
One hard case remains in the weak form: an OPA that loses its bundle server. It gets its own section below, because the fix is the least obvious part of this design.
direction: down
classes: {
src: {style: {fill: "#7B68EE"; stroke: "#5A4BC4"; font-color: "#FFFFFF"}}
host: {style: {fill: "#4A90E2"; stroke: "#2C6FB0"; font-color: "#FFFFFF"}}
note: {style: {fill: "#98D8C8"; stroke: "#5FA898"; font-color: "#2C2C2A"}}
}
git: "Policy repo\nrego + data.json, reviewed by security" {class: src}
bs: "Bundle server\nsigned bundle, revision egress-2026-10-31.2" {class: src}
hosts: "Gateway hosts, each with a local OPA" {
label.near: top-center
grid-rows: 1
grid-gap: 18
style: {fill: "#F4F6F6"; stroke: "#95A5A6"}
h1: "gateway + OPA\nrev .2" {class: host}
h2: "gateway + OPA\nrev .2" {class: host}
h3: "gateway + OPA\nrev .2" {class: host}
}
mon: "Active revision per gateway:\nmore than one for too long = skew alert" {
class: note
}
git -> bs: "1. CI builds and signs"
bs -> hosts: "2. each OPA polls"
hosts -> mon: "3. active revision gauge"
Latency is the other reason to stay local. I measured the decision call against the local OPA used above, timing 2,000 POST /v1/data/fleet/policy/result calls from one reused httpx.Client after 200 warm-up calls. On a Windows laptop over loopback, the median was 0.8 ms, the 99th percentile was 2.3 ms, and the slowest single call took 47 ms. OPA publishes no official local-versus-remote benchmark, so measure your own path and set the gateway timeout from the tail latency.
Sign your bundles and keep OPA current: version 1.21.3 fixed a bundle signature verification flaw (GHSA-g2pf-6v5v-qcc8), which matters once signed bundles are your revocation channel. To keep the setup short, the demo above serves an unsigned bundle.
When the Decision Point Itself Goes Stale
An OPA that cannot reach its bundle server does not fail. It keeps deciding on the last bundle it activated, for as long as it runs, and every answer looks normal. That is the Oldest-Copy Rule again, this time inside the decision point: the copy is OPA's cached bundle, and the revocation it has not received is whatever security published after the connection broke. The active-revision alert cannot see this case if every OPA lost the same server at the same time, because all of them still agree.
The fix is to bound the age of the policy, not only its availability. With status: prometheus: true in its configuration, OPA exposes last_success_bundle_request on /metrics, the time it last reached its bundle server. The guard below is a subclass of the gateway from earlier. It reads that gauge before each decision and, past a maximum age, treats the policy as stale: side effects are denied with policy_stale, and reads of internal hosts proceed as a counted allow_unverified, exactly like policy_unreachable.
Stop the bundle server from the previous run first. This script starts its own, so that it can take it away:
import subprocessimport sysimport timeimport httpxfrom opentelemetry.sdk.metrics import MeterProviderfrom fleet import make_gatewayfrom gateway import Decision, PolicyDenied, ToolGatewayAGE_METRIC = 'last_success_bundle_request{name="fleet"}'class FreshPolicyGateway(ToolGateway): """Refuses side effects when OPA has lost touch with its bundle server. An OPA that cannot reach the bundle server keeps deciding on its last bundle forever. Bound that: past max_age_s, treat the policy as stale. """ def __init__(self, *, max_age_s: float, **kwargs) -> None: super().__init__(**kwargs) self._max_age_s = max_age_s def bundle_age_s(self) -> float: # Exposed by OPA's status plugin with `prometheus: true`, in ns. for line in self._opa.get("/metrics").text.splitlines(): if line.startswith(AGE_METRIC): return time.time() - float(line.split()[-1]) / 1e9 return float("inf") def _decide(self, request: dict) -> Decision: try: age = self.bundle_age_s() except httpx.HTTPError: return super()._decide(request) # unreachable: parent handles it if age <= self._max_age_s: return super()._decide(request) internal = request["destination"] in self._internal if request["action"] == "read" and internal: return Decision("allow_unverified", ("policy_stale",), "none") return Decision("deny", ("policy_stale",), "none")meter = MeterProvider().get_meter("fleet.gateway")gateway = make_gateway("http://127.0.0.1:8181", meter, FreshPolicyGateway, max_age_s=6)unguarded = make_gateway("http://127.0.0.1:8181", meter)support = "spiffe://fleet.example/support-agent"def attempt(label: str, tool: str, url: str, via: ToolGateway = gateway) -> None: try: via.call(identity=support, tool=tool, url=url, session_id="sess-stale-01") print(f"{label:<34} proceeded") except PolicyDenied as exc: print(f"{label:<34} {exc}")POST = "https://crm.internal.example/ingest"server = subprocess.Popen( [sys.executable, "-m", "http.server", "8282", "--bind", "127.0.0.1"], cwd="serve", stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)time.sleep(3) # let OPA complete a poll against the fresh serverattempt("bundle server up: post", "post_record", POST)server.terminate()server.wait()lost = time.monotonic()time.sleep(2)attempt("down 2 s (inside 6 s bound): post", "post_record", POST)time.sleep(6)attempt("down 8 s (past 6 s bound): post", "post_record", POST)attempt("down 8 s, no guard: post", "post_record", POST, via=unguarded)attempt("down 8 s: internal read", "crm_lookup", "https://crm.internal.example/invoices")print(f"bundle age when refused: {gateway.bundle_age_s():.0f} s " f"(server gone {time.monotonic() - lost:.0f} s)")bundle server up: post proceededdown 2 s (inside 6 s bound): post proceededdown 8 s (past 6 s bound): post deny: policy_staledown 8 s, no guard: post proceededdown 8 s: internal read proceededbundle age when refused: 9 s (server gone 8 s)The fourth line is the failure this section exists for. Eight seconds after the bundle server disappeared, a gateway without the guard still allowed the post, on a policy it could no longer refresh. The guarded gateway refused it two seconds after its six-second bound ran out, and the internal read went through. Reading /metrics on every call keeps the demo short; a production gateway would cache the age for a second or two.
grid-rows: 1
grid-gap: 16
classes: {
ok: {style: {fill: "#6BCF7F"; stroke: "#3F9E52"; font-color: "#2C2C2A"}}
warn: {style: {fill: "#FFD93D"; stroke: "#C9A800"; font-color: "#2C2C2A"}}
stop: {style: {fill: "#E74C3C"; stroke: "#B03A2E"; font-color: "#FFFFFF"}}
}
t0: "t = 0\nbundle server up\npost: proceeded" {class: ok}
t1: "server killed\nOPA keeps its\nlast bundle" {class: warn}
t2: "down 2 s\ninside the 6 s bound\npost: proceeded" {class: warn}
t3: "down 8 s, guarded\npost: policy_stale\nread: proceeded" {class: ok}
t4: "down 8 s, no guard\npost: proceeded\n(stale policy)" {class: stop}
Choose the bound from the polling interval, not from a feeling. With OPA's defaults of 60 to 120 seconds, a bound of three or four polling delays, six to eight minutes, tolerates a few missed polls without hiding a dead bundle server. That bound is also the honest worst case for revocation latency when the bundle server fails: your fleet's real revocation latency is the polling interval while things work, and the staleness bound when they do not.
Choosing the Engine: OPA, Cedar in AgentCore, or a Gateway
The Dual-Layer Gate Model decides where policy is evaluated. Which engine evaluates it mostly follows where your agents already run.
grid-rows: 3
grid-columns: 2
grid-gap: 22
classes: {
q: {style: {fill: "#7B68EE"; stroke: "#5A4BC4"; font-color: "#FFFFFF"}}
a: {style: {fill: "#4A90E2"; stroke: "#2C6FB0"; font-color: "#FFFFFF"}}
}
q1: "1. Agents run on Amazon Bedrock\nAgentCore with its Gateway?" {class: q}
a1: "AgentCore Policy:\nCedar, default-deny, forbid-wins,\nenforce or log-only" {class: a}
q2: "2. Tools are mostly MCP servers\nbehind one proxy?" {class: q}
a2: "Gateway-native rules, e.g.\nagentgateway mcpAuthorization (CEL)" {class: a}
q3: "3. Mixed runtimes, your own\ngateway, existing OPA skills?" {class: q}
a3: "OPA + signed bundles\n(this article's code)" {class: a}
q1 -> q2: "no"
q2 -> q3: "no"
AgentCore Policy became generally available on 3 March 2026. Its gateway intercepts agent-to-tool traffic and evaluates each request against Cedar policies. AWS's documentation states default-deny and forbid-wins semantics, and policies in a policy engine apply to every gateway associated with it, which makes it the fleet layer as a managed service. Its log-only mode is a good way to roll out a new rule: watch what it would deny before it denies anything.
agentgateway, an open-source proxy for agent traffic, has an mcpAuthorization policy that evaluates CEL rules in the context of each MCP request and hides tools a caller may not use. Check its documentation for your version before you rely on rules over tool arguments; the versions I read disagreed on that point.
OPA is a CNCF graduated project. Choose it when agents run on mixed runtimes and you already operate a gateway, or when the same policy language also governs Kubernetes admission and service-to-service calls.
Whichever engine you choose, the rule enforces only when it sits on the path the traffic cannot avoid. One different approach is worth knowing about: Chen et al. (arXiv 2603.27299) propose compiling one declarative policy source into every enforcement layer, from the inference gateway to the agent gate, with verification across layers. That removes copy drift without a runtime network hop, but it moves the trust to the compiler and the deploy pipeline, and the Oldest-Copy Rule still applies to whatever the pipeline has not yet delivered.
What Each Layer Catches in the OWASP Agentic Top 10
OWASP released the OWASP Top 10 for Agentic Applications for 2026 in December 2025. Titles below are the ones OWASP uses on its own pages, including its Q3 2026 exploit roundup, while the "layer" column is my own mapping. For a worked mapping of a real incident to all ten, see the Hugging Face breach postmortem.
| Risk | Primary layer | What that layer does about it |
|---|---|---|
| ASI01 Agent Goal Hijack | Agent gate | Treats retrieved and inbound text as data, not instructions; the fleet egress rule limits what a hijacked agent can send |
| ASI02 Tool Misuse and Exploitation | Split | Agent gate validates arguments; fleet layer owns the tool and destination allowlists |
| ASI03 Identity and Privilege Abuse | Fleet | Authenticated workload identity, per-agent action lists, credentials held only by the gateway |
| ASI04 Agentic Supply Chain Vulnerabilities | Fleet | Model and tool allowlists, signed policy bundles |
| ASI05 Unexpected Code Execution | Split | Sandbox per runtime; fleet layer decides which agents may request execution at all |
| ASI06 Memory & Context Poisoning | Agent gate | Validates what the agent writes to its own memory and state |
| ASI07 Insecure Inter-Agent Communication | Fleet | Which identity may call which agent, if agent-to-agent traffic also goes through the gateway |
| ASI08 Cascading Failures | Neither alone | Propagation across a pipeline; the subject of Part 3 |
| ASI09 Human-Agent Trust Exploitation | Agent gate | What the agent shows a human; fleet require_human decides when a human must approve |
| ASI10 Rogue Agents | Fleet | Unregistered agents are denied; a compromised agent is stopped by removing its registration |
Counted from the table: four risks sit primarily at the fleet layer (ASI03, ASI04, ASI07, ASI10), three at the agent gate (ASI01, ASI06, ASI09), two are split (ASI02, ASI05), and one needs pipeline-level handling (ASI08). A fleet with only agent gates leaves the four fleet-layer risks to whichever copy deployed last. OWASP's own Q1 2026 roundup recommends validating "tool and identity usage through policy engines" for tool and identity abuse, a fleet-layer control even for a risk whose argument checks live in the agent.
Policy Decisions Close Part 1's Telemetry Surface Gap
Part 1 set two rules for this series: metrics carry only bounded attributes, and the session goes on the span. It put its custom agent metrics under fleet.agent.*, and policy metrics follow the same rule under fleet.policy.*. The counter leaves out agent version on purpose: version and model are inputs to the decision, recorded on the span, and the reasons already say when a version was the cause. OpenTelemetry's GenAI conventions define gen_ai.tool.name but have no attributes for policy or guardrail decisions yet; a proposal for guardrail spans was closed in May 2026 without merging.
Both rules are applied in the gateway. fleet.policy.decisions is labeled by agent, tool, action and decision, and the gateway takes all four from its registries, so a caller cannot invent a new label value. Revision is kept off the counter, because every new revision would add a full set of series that stay until the process restarts. It goes on the span with the reasons instead, and the fleet.policy.active_revision gauge reports one value per gateway.
Three queries, in Prometheus naming, cover the failure modes this article reproduced:
# 1. Reads are failing open. increase() misses a series born at 1,
# so also catch series that did not exist five minutes ago.
sum(increase(
fleet_policy_decisions_total{fleet_policy_decision="allow_unverified"}[5m]
)) > 0
or
sum(
fleet_policy_decisions_total{fleet_policy_decision="allow_unverified"}
unless
fleet_policy_decisions_total{fleet_policy_decision="allow_unverified"} offset 5m
) > 0
# 2. Gateways disagree on the revision. Alert with for: 5m, longer
# than the maximum polling delay, so a normal rollout does not fire.
count(count by (fleet_policy_revision) (fleet_policy_active_revision)) > 1
# 3. Dashboard: deny rate by agent, to compare before and after a rollout.
sum by (gen_ai_agent_name) (
rate(fleet_policy_decisions_total{fleet_policy_decision="deny"}[15m])
)
direction: down
classes: {
src: {style: {fill: "#4A90E2"; stroke: "#2C6FB0"; font-color: "#FFFFFF"}}
metric: {style: {fill: "#98D8C8"; stroke: "#5FA898"; font-color: "#2C2C2A"}}
span: {style: {fill: "#FFA07A"; stroke: "#D9785A"; font-color: "#2C2C2A"}}
alert: {style: {fill: "#E74C3C"; stroke: "#B03A2E"; font-color: "#FFFFFF"}}
}
d: "One gateway decision" {class: src}
m: "fleet.policy.decisions\nagent, tool, action,\ndecision + gauge\nactive_revision" {
class: metric
}
s: "Span attributes\nconversation id, decision,\nrevision, reasons" {class: span}
alerts: "Queries on the metrics" {
label.near: top-center
grid-rows: 1
grid-gap: 16
style: {fill: "#F4F6F6"; stroke: "#95A5A6"}
a1: "1. allow_unverified > 0" {class: alert}
a2: "2. revisions > 1 for 5m" {class: alert}
a3: "3. deny rate by agent" {class: alert}
}
d -> m: "bounded labels"
d -> s: "per-decision evidence"
m -> alerts
Query 2 is the Oldest-Copy Rule turned into an alert. With copied middleware it is impossible to write, because the copies record nothing.
Revocation Latency Is the Number to Own
One record leaked from the opening fleet because a rule lived in three deploys. Fixing it meant moving the fleet's rules to one policy source, evaluated at the one place every tool call has to pass, where the gateway itself decides identity and action for each call. Agent-specific rules stayed in the agents, owned by the teams that understand them.
That split is the Dual-Layer Gate Model, and it gives a platform team one number it can own. With copied guardrails, revocation latency is your slowest release train. With a policy bundle on an unavoidable path, it is the polling interval: 1.7 seconds in the run above with a 1-2 second poll, 60-120 seconds at OPA's defaults, and when the bundle server fails, it is the staleness bound (6 seconds in the demo above). If you cannot say what your fleet's revocation latency is, it is the age of your oldest deploy.
grid-rows: 1
grid-gap: 30
classes: {
slow: {style: {fill: "#E74C3C"; stroke: "#B03A2E"; font-color: "#FFFFFF"}}
fast: {style: {fill: "#6BCF7F"; stroke: "#3F9E52"; font-color: "#2C2C2A"}}
step: {style: {fill: "#95A5A6"; stroke: "#6C7A7B"; font-color: "#FFFFFF"}}
}
copied: "Copied guardrails" {
label.near: top-center
grid-columns: 1
grid-gap: 12
style: {fill: "#F4F6F6"; stroke: "#95A5A6"}
a: "change merged" {class: step}
b: "each team redeploys\non its own schedule" {class: step}
c: "revocation latency =\nslowest release train (days)" {class: slow}
}
bundle: "One policy source at the gateway" {
label.near: top-center
grid-columns: 1
grid-gap: 12
style: {fill: "#F4F6F6"; stroke: "#95A5A6"}
a: "change merged" {class: step}
b: "bundle built; every OPA\npolls the bundle server" {class: step}
c: "revocation latency =\npolling + build (1.7 s here)" {class: fast}
}
Agent Policy Enforcement Checklist
Fleet decision point (platform or security team):
- Every tool call with a side effect passes through a gateway that holds the network client and credentials; agent pods can reach the gateway and the model provider and nothing else
- The gateway authenticates the caller (mTLS or a signed workload token) and takes agent, version and model from the deploy registry, never from the request
- The gateway takes the action class from its tool registry and the destination from the URL it requests
- Fleet rules (egress allowlist, agent registry, model allowlist, verified versions for writes) live in one policy bundle, with allowlists as data
- Rules add reasons to partial sets; one rule body per decision value; default deny; GETs count as egress
-
opa check --strictandopa testrun in CI, including a test for an unregistered agent and a test that deny beatsrequire_human - Bundles are signed and carry a revision; OPA runs 1.21.3 or later; the polling interval matches the revocation latency you promise
- A gateway whose OPA has not reached its bundle server within a set bound (
last_success_bundle_requeston/metrics) denies side effects withpolicy_stale - Side effects deny on
policy_unreachable; only reads of internal hosts proceed, as a countedallow_unverified - Egress allowlist entries have an owner and an expiry check, so a lapsed domain is removed before someone else buys it
- The paths around the gateway are closed: rendered output (CSP from the same allowlist), provider-hosted tools, direct MCP connections, sandboxes, the model API call
Agent gate (each product team):
- Domain rules (amounts, vendors, session rules) live in the agent's graph and deploy with the agent, and log their own decisions
- The agent carries no copy of any fleet rule, so redeploying it cannot change fleet policy
- Tests include a case where the fleet returns deny or
require_human, and the agent surfaces it without retrying around it
Cross-layer:
-
fleet.policy.decisionscarries agent, tool, action and decision; revision and reasons go on the span; one active-revision gauge per gateway - Alerts on any
allow_unverifiedand on more than one active revision for longer than the polling delay - Quarterly review: domain rules that every agent now copies are candidates to move into the fleet bundle
What Comes Next
The Dual-Layer Gate Model decides whether a single action may happen, and it says nothing about what the rest of a pipeline should do when the answer is no. Part 3, Multi-Agent Pipeline Orchestration and Failure Propagation, picks up from there: how a policy denial in one agent halts the agents downstream of it, and how failure signals move through a multi-agent graph without cascading timeouts or silent partial completions.
References
- OWASP GenAI Security Project. (December 2025). OWASP Top 10 for Agentic Applications for 2026. https://genai.owasp.org/resource/owasp-top-10-for-agentic-applications-for-2026/
- OWASP GenAI Security Project. (October 2026). GenAI and Agentic AI Exploit Roundup Q3 2026. https://genai.owasp.org/2026/10/08/genai-and-agentic-ai-exploit-roundup-q3-2026/
- OWASP GenAI Security Project. (April 2026). OWASP GenAI Exploit Round-up Report Q1 2026. https://genai.owasp.org/2026/04/14/owasp-genai-exploit-round-up-report-q1-2026/
- Levi, S. (September 2025). ForcedLeak: AI Agent Risks Exposed in Salesforce Agentforce. Noma Security. https://noma.security/blog/forcedleak-agent-risks-exposed-in-salesforce-agentforce/
- Salesforce. Update & Action Required: Changes to Default Allowlist for Agentforce. https://help.salesforce.com/s/articleView?id=005135034&type=1
- Willison, S. (September 2025). Note on ForcedLeak. https://simonwillison.net/2025/Sep/26/agentforce/
- LangChain. Guardrails. https://docs.langchain.com/oss/python/langchain/guardrails
- Zenity Labs. (September 2026). SalesBleed: 0-Click Data Exfiltration on Agentforce. https://labs.zenity.io/post/salesbleed-0-click-data-exfiltration-on-agentforce
- Open Policy Agent. Policy Language. https://www.openpolicyagent.org/docs/policy-language
- Open Policy Agent. Policy Testing. https://www.openpolicyagent.org/docs/policy-testing
- Open Policy Agent. Deploying OPA. https://www.openpolicyagent.org/docs/deploy
- Open Policy Agent. Bundles. https://www.openpolicyagent.org/docs/management-bundles
- Open Policy Agent. Configuration (bundle polling defaults). https://www.openpolicyagent.org/docs/configuration
- Open Policy Agent. Status. https://www.openpolicyagent.org/docs/management-status
- Open Policy Agent. Decision Logs. https://www.openpolicyagent.org/docs/management-decision-logs
- Open Policy Agent. v1.22.0 release. https://github.com/open-policy-agent/opa/releases/tag/v1.22.0
- Open Policy Agent. GHSA-g2pf-6v5v-qcc8. https://github.com/open-policy-agent/opa/security/advisories/GHSA-g2pf-6v5v-qcc8
- OPA Gatekeeper. Failing Closed. https://open-policy-agent.github.io/gatekeeper/website/docs/failing-closed
- Envoy. External Authorization filter (failure_mode_allow). https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/filters/http/ext_authz/v3/ext_authz.proto
- NIST NVD. CVE-2023-27488. https://nvd.nist.gov/vuln/detail/CVE-2023-27488
- Amazon Web Services. (March 2026). Policy in Amazon Bedrock AgentCore is now generally available. https://aws.amazon.com/about-aws/whats-new/2026/03/policy-amazon-bedrock-agentcore-generally-available/
- Amazon Web Services. Policy in AgentCore: core concepts. https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/policy-core-concepts.html
- Common Expression Language (CEL). https://cel.dev/
- SPIFFE. SPIFFE concepts. https://spiffe.io/docs/latest/spiffe-about/spiffe-concepts/
- agentgateway. MCP authorization. https://agentgateway.dev/docs/standalone/latest/configuration/security/mcp-authz/
- OpenTelemetry. Semantic conventions for generative AI. https://github.com/open-telemetry/semantic-conventions-genai
- OpenTelemetry. gen-ai: add security guardian (apply_guardrail) span (closed proposal). https://github.com/open-telemetry/semantic-conventions/pull/3233
- OpenAI. Deprecations. https://developers.openai.com/api/docs/deprecations
- Chen, H., Liu, X., He, B., Liu, X. (March 2026). From Inference Routing to Agent Orchestration: Declarative Policy Compilation with Cross-Layer Verification. arXiv:2603.27299. https://arxiv.org/abs/2603.27299
- LangGraph. Releases. https://github.com/langchain-ai/langgraph/releases
- Ranjan Kumar. Agent Fleet Observability: Why Dashboards Miss Running Loops (AI Control Plane, Part 1). https://ranjankumar.in/ai-control-plane-unified-observability-agent-fleet
- Ranjan Kumar. Hugging Face Breach: 17,000 Actions to OWASP ASI01-ASI10. https://ranjankumar.in/hugging-face-agent-breach-owasp-asi-mapping
- Ranjan Kumar. Gated Execution: Why Your Agent Should Never Act Without Permission. https://ranjankumar.in/harness-engineering-gated-execution-llm-agents-policy-safety
- Ranjan Kumar. Deterministic Constraint Systems: Building Tool Registries That Keep Agents in Scope. https://ranjankumar.in/harness-engineering-deterministic-constraint-systems-tool-registry-agents
Related Articles
- Agent Fleet Observability: Why Dashboards Miss Running Loops
- Agent Versioning and Deployment Strategies: Shipping Agent Updates Without Breaking Running Pipelines
- Cost Governance and Budget Allocation Across Agent Types: Token Spend Is Infrastructure Spend






