Skip to content

feat(listener): authenticate MCP callers with a token file - #171

Open
karauda wants to merge 9 commits into
mainfrom
feat/s30-listener-authenticator
Open

karauda wants to merge 9 commits into
mainfrom
feat/s30-listener-authenticator

Conversation

@karauda

@karauda karauda commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

What changed, and why

An MCP HTTP listener can now name the principal of each call from a bearer token, so a principal stop or pause matches one caller instead of every call of the plane. listener.authenticator.kind stays none by default. With token_file, listener.authenticator.token_file names a listener-tokens/v1alpha1 file holding, per line, a token's SHA-256 digest, a principal id and an expiry. The authenticator is experimental.

  • The plane reads the file once at start. It must be owned by the plane's account and readable by no other account. Its line count and size are bounded. A digest given twice, the empty token's digest and a line naming listener.principal.id are refused; for the last, the start and doctor's listener.authenticator line name the line and say to give that caller another principal id.
  • Every line is compared, whatever matches first. An expired line never authenticates. No token or digest is printed.
  • The listener answers 401 unless a request carries exactly one valid bearer token, and 503 when it cannot judge one.
  • token_file is refused on stdio, on the enforcement API and under approvals.authority: signed.
  • Under token_file, a stop or pause of the configured principal, or of a principal no unexpired line names, matches no call. A pause of the configured principal now refuses the start and fails doctor's pause line, as a stop of it already did. Doctor and /healthz report such a stop as unheld and such a pause as covering none, with the reason. A stop or pause of a principal the file names is held and covers some calls, never all.
  • /healthz reports listener.principal_source: configured, authenticated or none (the enforcement API).
  • The gateway takes exactly one principal source per adapter kind: configured, authenticated (an adapter that authenticates its callers) or unauthenticated (an adapter whose callers carry no principal, as the enforcement adapter says). Any other pairing refuses the plane.

Breaking, on the enforcement API (listener.kind: enforce_api): that API authenticates no caller, so its calls carry no principal for stops and pauses. While any principal stop of the plane's tenant is active, every call is blocked INDETERMINATE with STOP_STATE_UNAVAILABLE. Before, a stop of the configured principal gave DENY with AGENT_OR_PRINCIPAL_STOPPED and a stop of another principal let calls run. A principal pause of any principal now pauses every call. The CHANGELOG says to lift a stop or remove a pause meant for one principal.

Invariant or record

Implements ADR-0090, now accepted and amended for the pause refusal, the enforcement API's principal source, the refusal under signed approvals, the refused token lines, and one limit: principal ids are compared byte for byte, not normalised. ADR-0083 gets a pointer for the enforcement API.

Invariants: INDETERMINATE is not ALLOW (an unknown stop state blocks); fail closed (an authenticator that cannot judge answers 503); security behaviour has adversarial tests.

Stated limits, not changed here: the token file's parent directory is not judged; no ACLs are read beyond mode bits; policy rules keyed on the configured principal id still read it under token_file.

How it was tested

  • Three rounds: the build, then two rounds of fixes after security reviews and a code review, and a final security re-check. Each fix had a failing line on its base first. Under token_file, a pause of the configured principal let a call reach the upstream while /healthz said the pause covered all. An enforcement API call ran under a stop of another principal. A pause of a principal no token line names was reported as covering some. A token line naming the configured principal, and one holding the empty token's digest, were accepted.
  • Mutation runs in every round, each mutant run with a filter naming the tests meant to kill it: 10 of 10 killed in the first round, 16 of 16 in the second, 29 of 29 in the third.
  • The final security re-check found no fail-open path: no call reached an upstream without a valid token or as another principal, and every fail-closed state it tried held. An end-to-end test through the real MCP HTTP listener shows a stop of alice blocking alice's call while bob's call runs.
  • On macOS at the final code: internal/listenerauth (35 tests), internal/gateway (1394), adapters/enforce (463), internal/hookbridge (143) and cmd/guardana-gateway (947, 3 skipped) passed. adapters/mcp (571) passed on Linux at the final code. internal/gatewayconfig (660, 1 skipped), internal/gateway/e2e (132) and bench (16) passed in the second round and were not re-run locally after the third; CI runs them.
  • On the last head: make vet, vetting with twoaccounts, linting on macOS and Linux, formatting, check-sizes, check-brand and docs-check passed.
  • Not verified here: on Linux, the tests that need the Go toolchain, go.mod, root or ACLs in the test container failed for that reason only, the same list as on the base. No gateway binary was run live; the listener, /healthz and doctor ran in-process. No race run and no local quality run. CI's quality run is the gate.

Documentation

New guide: docs/guides/authenticate-mcp-callers.md. docs/status.md gains the experimental listener-authenticator row, and its gateway and run-stop passages changed.

Also changed: the listener token file in contracts, the generated configuration reference, the reaction, signed reaction, runs and MCP coverage references, the threat model, enforcement modes, privacy, control and supervision and where-it-fits pages, the run-the-gateway, troubleshoot, container, two-tasks and existing-setup guides, the backlog, and the site.

CHANGELOG has an Added entry and a Breaking entry under Changed. Of the 37 paths docs-impact flags, 17 changed; the other 20 were read and still hold. Five pages it does not flag changed as well.

The listener authenticator port and its token_file kind: a
listener-tokens/v1alpha1 file read at start, every line's digest compared
with no early exit, an expired line never authenticating. The
listener.authenticator.kind and listener.authenticator.token_file keys,
refused on stdio and on the enforcement API (ADR-0090).

Signed-off-by: Konrad Karauda <konrad@karauda.com>
…ncipal

The pipeline takes a call's principal from one source, set when it is
built: the listener's configured principal, or the principal an
authenticating adapter names for the call. An unset source, or one that
disagrees with whether the adapter authenticates, refuses the pipeline.

Under the authenticated source a principal stop and a principal pause
match the principal the MCP listener authenticated. A call that carries
no authenticated principal reads an active principal stop as unknown, so
it is blocked STOP_STATE_UNAVAILABLE rather than let through. Under the
configured source nothing changes.

Signed-off-by: Konrad Karauda <konrad@karauda.com>
listener.authenticator.kind token_file makes an MCP HTTP listener answer
401 to a request without exactly one bearer Authorization header whose
token a line of the token file holds and has not expired, before any
upstream is reached; the principal of that line is the call's principal.

A plane whose stop list holds an active principal stop of
listener.principal.id refuses to start under token_file, naming the stop
and how to lift it: such a stop would match no authenticated call, so
carrying it would let it lapse unseen. Doctor reports the authenticator,
the principals its file names and fails on the same stop; /healthz gives
the kind, the principals and the requests refused. No token or digest is
printed. scripts/ports.txt lists the listener-authenticator port.

The token_file kind is refused under the signed authority: the file the
plane's account owns would decide which principal an operator's stop or
pause matches.

Signed-off-by: Konrad Karauda <konrad@karauda.com>
The exported constants' comments open with their names, the zero-width
character in a test id is spelled as an escape, and the fuzz target and
the listener's 401 test hand their checks to helpers to stay within the
complexity bound.

Signed-off-by: Konrad Karauda <konrad@karauda.com>
…heir principal

The enforcement API authenticates nobody, so its calls now carry no
principal for a stop or a pause: an active principal stop of the plane's
tenant reads as unknown for every call (STOP_STATE_UNAVAILABLE,
INDETERMINATE) and a principal pause of anyone pauses it, as ADR-0090
says. A stop of the configured principal moves from DENY to
INDETERMINATE there; both block.

Under a token file, a pause entry naming listener.principal.id refuses
the start and fails doctor's pause line, as a stop of it already did.
/healthz and doctor judge a principal stop or pause by the calls that
carry its principal: another principal's is held and covers some calls,
the configured one's is unheld and covers none, with the reason, and on
the enforcement API it covers every call. /healthz names the listener's
principal source.

Signed-off-by: Konrad Karauda <konrad@karauda.com>
A token file may no longer name listener.principal.id, and refuses a line
holding the digest of the empty token. Under a token file, the health answer
and doctor report a principal stop or pause as matching no call when no
unexpired line names the principal, and as unknown where the file was not
read. The core now ties the unauthenticated principal source to an adapter
whose calls carry no caller the plane can name, which the enforcement
adapter declares.

Signed-off-by: Konrad Karauda <konrad@karauda.com>
…judged

Signed-off-by: Konrad Karauda <konrad@karauda.com>
A how-to for the token file, ADR-0090 amended and accepted, the status
row and its details, the token file's contract, the changelog entries,
and the pages whose claims the authenticator and the enforcement API's
missing principal change. configuration.md and the site regenerated.

Signed-off-by: Konrad Karauda <konrad@karauda.com>
Signed-off-by: Konrad Karauda <konrad@karauda.com>
@karauda
karauda requested a review from a team November 30, 2026 14:50
@karauda
karauda requested a review from a team as a code owner November 30, 2026 14:50
@cloudflare-workers-and-pages

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Failed ❌

View logs ↗
2c8b860 2026-11-30T13:58:21.614Z View logs ↗

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant