Skip to main content

Deploy the gateway PEP

Goal: run one shared enforcement point in front of a fleet of agents you control, instead of one sidecar per agent process. The gateway makes the same decisions as the sidecar, because it runs the sidecar's own enforce() unmodified. It's simpler to operate at fleet scale, at the cost of a single point every call passes through. Enforcement point tradeoffs compares the options.

1. Install​

pip install 'authzai[server]' # or run the image: ghcr.io/xinweiiiii/agentic-auth

2. Write the gateway config​

gateway.yaml
pdp_url: https://control-plane.internal # the control plane's decision and token endpoints
listen_addr: 0.0.0.0:8080
decision_deadline_ms: 2000 # past this, the call is refused, never retried
route_table:
# "<agent>|<prefix>": an entry for one agent. "|<prefix>": any agent.
"|/kb":
url: https://kb.internal
target: mcp://kb.internal/search
data_class: kb.internal
"balance-agent|/accounts":
url: https://accounts.internal
target: mcp://accounts.internal/read_balance
data_class: account.read

Routing. The longest prefix wins, and an entry for a specific agent beats the any-agent entry for the same prefix. Which agent is calling comes from the token it presents, never from a header. A forged agent name only picks a different target, which the control plane then refuses, so lying gets a deny, never an allow.

Target and data class. Each route pins its own, or an SDK-aware agent sends X-Agentic-Target / X-Agentic-Data-Class per call. If neither supplies them, the call is refused, because guessing a data class would be inventing consent.

The gateway refuses to start with an empty route table, which would block everything, and with agent_name / identity_key_path. A gateway holds no agent's signing key: one component holding every agent's key could impersonate all of them. Each agent sends its own Agent-Identity and Actor-Token headers, and the gateway relays them.

You can also set every key as AGENTIC_AUTH_GATEWAY_* environment variables instead of using a file.

3. Run it​

agentic-auth-gateway gateway.yaml

A bad config exits non-zero before the port is bound. A gateway that started but couldn't enforce would look healthy while forwarding everything.

The gateway is stateless, so you can run several instances behind a load balancer. Each serves:

  • GET /v1/gateway/healthz: liveness
  • GET /v1/gateway/routes: the route table it loaded, so you can check what it will do
  • GET /metrics: Prometheus decision, deadline and route-miss counters

4. Point the fleet's egress at it​

Each agent sends its tool calls to the gateway, https://gateway.internal/kb/..., with its hop token as Authorization: Bearer .... The gateway decides, exchanges the token for one narrowed to that call, and forwards it to the upstream. A refusal comes back as a structured 403 naming the reason.

Failing closed​

The gateway is the one path for many agents, so it must not fail open. If the control plane is unreachable, or doesn't decide within decision_deadline_ms, the call is refused.

To roll out without blocking anything, set observe_mode: true. Every call is still decided and recorded, and calls policy would refuse are forwarded and marked as forwarded. Switch it off once the decision log shows what you expect.