Guide · Agent security

MCP authorization on Kubernetes

Andrey Lesnikov · 2026-11-30 · sources checked 2026-11-30

Authorize MCP tool calls for AI agents on Kubernetes: OAuth 2.1, ServiceAccounts, NetworkPolicy, secrets, and fail-closed admission before execution.

On this page

Transport auth and tool authorization are easy to confuse. The Model Context Protocol authorization specification covers how an HTTP MCP client obtains and presents an OAuth 2.1 access token to an MCP server acting as a resource server. That is necessary. It is not enough: a valid token still must not mean every tool runs. On Kubernetes, identity, network path, secret handling and a fail-closed capability gate decide whether a concrete tool call executes.

This guide is the authorization slice. For the broader hardening checklist (egress, sandboxing, catalog pinning), see MCP security checklist for Kubernetes. The design stance — no valid capability, no tool call — is written up in the fail-closed authorization preprint (DOI 10.5281/zenodo.24075886) and collected under the Agent and MCP security hub.

OAuth to the server, then a fail-closed capability gate before the tool runs. Client OAuth 2.1 Capability gate no capability → BLOCK Tool + audit
OAuth to the server, then a fail-closed capability gate before the tool runs.

What the MCP authorization spec covers

Per the MCP authorization specification (HTTP transports), when authorization is supported:

  • Authorization servers implement OAuth 2.1 for confidential and public clients.
  • An MCP server acts as an OAuth 2.1 resource server and must expose OAuth 2.0 Protected Resource Metadata (RFC 9728), including authorization_servers.
  • Clients discover the authorization server from that metadata (and from WWW-Authenticate on 401), then obtain tokens for that resource.
  • Servers must not accept tokens that were not issued for them. Token passthrough to downstream APIs breaks audience binding, rate limits and audit boundaries.

STDIO transports are out of that OAuth flow: credentials come from the environment instead. On Kubernetes that usually means a Secret mounted into the agent or MCP pod — still not a substitute for per-call tool authorization.

Fail-closed tool authorization

OAuth answers "is this client allowed to call this MCP server?". Tool authorization answers "is this exact tool name and argument set allowed for this agent, under this policy version?".

The rule I design for is blunt: if the capability check cannot affirmatively ALLOW (or REQUIRE_APPROVAL), the call does not execute. That includes missing policy, digest mismatch on the tool catalog, undeclared tools, enforcement timeouts and adapter errors. The Agent Security Contract implements that pattern as a pre-execution gate with ALLOW / BLOCK / REQUIRE_APPROVAL and an integrity-checked evidence envelope. Its measured results apply only on its own scenario corpus — not as a general safety claim.

Map the gate to Kubernetes so it cannot be skipped:

  • Put the decision in the execution path (sidecar, gateway ext_authz, or an admission-style hook before the tool runner), not in prompt instructions.
  • Prefer fail-closed client behaviour when the gate is unreachable (failure_mode_allow: false in the ASC external-auth example).
  • Bind approvals to exact arguments and consume them atomically; a flipped parameter needs a new approval.

Kubernetes primitives that carry authorization

ServiceAccounts and workload identity

Give each agent and each MCP server its own ServiceAccount. Do not share default. Disable automountServiceAccountToken unless the pod must call the Kubernetes API. The MCP server's OAuth client credentials and any downstream API tokens belong in Secrets referenced by that ServiceAccount's pods — not in the agent container's environment "for convenience".

apiVersion: v1
kind: ServiceAccount
metadata:
  name: mcp-tools
  namespace: agents
automountServiceAccountToken: false

NetworkPolicy as a hard path

Default-deny egress (and, where useful, ingress) for agent and MCP pods. Allow DNS and the named destinations the tools need. Core NetworkPolicy matches pods, namespaces and CIDRs, not hostnames — for FQDN allowlists use an egress proxy or a CNI/mesh that supports them. East-west traffic between agent, gate and MCP server should use workload identity and mutual TLS; the zero-trust service mesh case covers that pattern.

Secrets handling

  • Mount OAuth client secrets and API tokens as projected volumes or env-from Secret, with the secret scoped to the MCP server's namespace.
  • Prefer short-lived tokens over long-lived personal access tokens, matching the MCP spec's least-privilege guidance on scopes.
  • Keep tool-runner pods from mounting cluster-admin kubeconfigs or cloud metadata paths; NetworkPolicy should already block link-local metadata ranges.

Admission and policy-as-code

Use admission (Pod Security, ValidatingAdmissionPolicy, or a policy engine) so agent/MCP Deployments cannot opt out of the gate sidecar, the non-root security context, or the required ServiceAccount. Policy-as-code guardrails is the companion case for CI and admission contracts. Admission does not evaluate MCP tool arguments; it keeps the runtime shape that makes the capability gate unavoidable.

A minimal authorization loop

  1. Client obtains an audience-bound OAuth access token for the MCP server (Protected Resource Metadata + authorization server).
  2. Request hits the MCP server (or a fronting gateway) with that token; invalid or wrong-audience tokens are rejected.
  3. Before any tool side effect, a capability gate evaluates agent identity, pinned catalog digest, tool name, arguments, rate limits and approvals.
  4. Missing capability → BLOCK. Allowed call runs under the MCP server's ServiceAccount and NetworkPolicy. Every decision should leave an audit record — see AI agent audit trail.

Sources

Related

Cases

Related cases.

Case 27 · Flagship

Agent Security Contract

  • CLI
  • Action
  • Policy

Agent and MCP stacks expand the attack surface beyond prompt text: tool misuse, poisoned tool descriptions, argument injection, and unapproved high-impact actions run without a pre-execution gate

0 false-ALLOW · 0 false-BLOCK on this corpus

Case 23

Zero Trust Service Mesh

  • Identity
  • mTLS
  • AuthZ

Internal traffic is often trusted by default, making lateral movement and policy gaps hard to see

East-west mTLS by default

Case 15 · Pattern

Policy as Code Guardrails

  • OPA
  • Feedback
  • Promote

Security and platform rules are often discovered only after deployment or during reviews

Standards enforced in CI, not slides

Available for meaningful infrastructure conversations

Build systems that stay calm under pressure.

Available for conversations

Talk infrastructure

Book a working session

Meet ↗

Evidence first

For deep dives

Explore the systems

All cases ↗