Skip to content

fix(mcpbroker): rate-limit the embedded authorization server's routes - #2781

Closed
ChrisJBurns wants to merge 1 commit into
mainfrom
fix/2772-rate-limit-as2-routes
Closed

ChrisJBurns wants to merge 1 commit into
mainfrom
fix/2772-rate-limit-as2-routes

Conversation

@ChrisJBurns

Copy link
Copy Markdown
Contributor

Closes #2772.

What

The MCP broker's embedded authorization server (AS-2 when the identity broker is on) served its anonymous OAuth routes with no rate limit and no query cap. They now get the same bounds as AS-1:

  • global rate limits: 50 req/s, burst 200, /oauth/token in its own bucket, the other auth-server routes (authorize, consent, upstream callback, discovery, JWKS, protected-resource metadata) in a separate sign-in bucket. Past a budget: 429.
  • queries over 8 KiB: 414; bodies capped at 64 KiB.

The limits are applied where the handlers are built (internal/adapter/mcpbroker/toolhive_process.go), so every mount gets them: mecak8s, mecated, and internal/app. The vMCP endpoint and a callback-only bundle (no protected MCP route) are unchanged.

AS-1's limitAS1 moved into a shared package, internal/adapter/authserverlimit, which both servers now use. AS-1's behaviour and values are unchanged.

Decisions

  • In-process AS-2 path (mcpbroker.AS2.Handler(), used by the identity broker's ID-JAG redemptions): gets the query and body caps but not the public token bucket, so an anonymous flood cannot refuse users' gateway calls. Identity broker RPC contract and transport #2560 deletes this path; whether the broker gets its own budget over the network is decided there.
  • Fixed limits, like AS-1's. Operator settings stay with Keys and gateway entries for the identity broker #2538.
  • Threat model: unchanged. threat-model.md already has the "Anonymous traffic at the embedded AS-2" bullet from docs(agent-identity): record AS-1 in-process calls, AS-2's anonymous routes, and distinct issuers #2773, which matches this.
  • Accepted trade-off, same as AS-1: the limits are global because Mecatl does not trust forwarded headers. One client can use up a budget for everyone, including the broker Runtime's own code exchange and refresh, which reach the token endpoint over the network. The docs recommend a per-client limit at the ingress.
  • ToolHive v0.63.0 already caps every auth-server body at 64 KiB. We keep our own cap for parity with AS-1; the authserverlimit unit test proves it.

API compatibility

Not a wire API change. The new 429 and 414 responses come from the embedded ToolHive OAuth routes, not the versioned gRPC or HTTP/SSE API. No major or feature changes.

Testing

  • New: TestLimitAndCaps, TestEmbeddedAuthServerRoutesAreRateLimited (sign-in flood leaves token serving and vMCP unlimited; token flood), TestEmbeddedAuthServerRoutesRefuseAnOversizedQuery, TestAS2InProcessHandlerIsCappedButNotPublicRateLimited, TestCallbackOnlyBundleIsNotRateLimited, plus mounted-route probes in mecak8s and mecated.
  • Mutation-checked: shared bucket, dropped limiters, Caps removed from AS-2, public bucket on AS-2, limiter on vMCP.
  • task test:race: passes except three tests that fail locally for sandbox reasons in packages this PR doesn't touch (TestMecatedCLICompositionValidatesMicroVMDefaultAfterReadiness, unix socket bind; TestRunInDirUsesDescriptorAndPassesArgumentsOpaquely, no bash; TestRepositoryGuestAuthenticationRejectsCompetingConnectorBeforeDisclosure, timing).
  • Lint: 0 issues in the touched modules. task lint stops on a pre-existing gosec finding in environment/microvm/launch_ownership_darwin.go.
  • task site:build passes. Offline demo shows tool call, permission ask and approval, and result.

@ChrisJBurns

Copy link
Copy Markdown
Contributor Author

Closing: rate limiting for the embedded gateway's routes moves to phase 2 (#2558). It will be redone from scratch then.

This branch was successfully deployed

1 active deployment
Preview — fb64416a Deployed Nov 13, 2026 by vercel[bot]
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.

Rate-limit the embedded gateway's authorization server routes

1 participant