Skip to content

Rate-limit the embedded gateway's authorization server routes #2772

Open

Description

@ChrisJBurns

Mecatl change in the MCP broker's HTTP surface (mecak8s and mecated). No ToolHive dependency.

Problem

The embedded gateway's authorization server is reachable without signing in: its token, authorize, consent, callback, discovery, and key-set routes. mecak8s and mecated mount the MCP broker's routes with no rate limit and no cap on the request body or query (HandlerBundle.Mount, internal/adapter/mcpbroker/handlers.go; mountBrokerHandlers, cmd/mecak8s/serve.go; cmd/mecated/main.go). Anyone who can reach the server can flood them or send oversized requests.

AS-1's routes on the same mux already have both: global rate limits, with the token endpoint and the sign-in routes in separate buckets, plus query and body caps (limitAS1, cmd/mecak8s/serve.go).

This predates the identity broker, since gateway logins already used these routes. #2738 makes it matter more: with the identity broker on, the same server is AS-2, and its token endpoint also redeems ID-JAGs for gateway tokens.

Design

Requirements

  • Rate-limit the embedded authorization server's routes with global limits, the token endpoint in its own bucket, and cap the query and request body, as limitAS1 does for AS-1. Apply them wherever the MCP broker's routes are mounted, in mecak8s and mecated.
  • The broker's own calls. While the identity broker shares the process, it reaches AS-2's token endpoint in process through mcpbroker.AS2.Handler() (Wire the embedded gateway's authorization server into startup as AS-2 #2738), not through the mux. Apply the same body and query caps on that path, so it skips no check the network route makes.
  • Decide whether the broker's ID-JAG redemptions share the public token bucket. If they do, a flood of anonymous token requests refuses users' gateway calls; consider a separate budget for the in-process path.
  • Decide whether the limits are fixed, like AS-1's, or operator settings (Keys and gateway entries for the identity broker #2538).

Done when

  • Requests beyond the token endpoint's budget get 429, oversized queries get 414, and oversized bodies are refused, on the mounted routes in mecak8s and mecated.
  • Flooding the sign-in routes doesn't exhaust the token endpoint's budget.
  • The in-process path to AS-2 applies the same caps.
  • With no protected MCP route, nothing changes.

Activity

  1. ChrisJBurns commented on Nov 13, 2026

    @ChrisJBurns
    ContributorAuthor

    Moved from phase 1 (#2455) to phase 2 (#2558): this is hardening, and phase 1 doesn't need it. A phase 1 attempt (#2781) was closed so this can be redone from scratch after #2560.

    When picking this up, also decide:

    • The broker's own budget. After Identity broker RPC contract and transport #2560 the identity broker reaches AS-2's token endpoint over the network, so its ID-JAG redemptions land in the public token bucket. A flood of anonymous token requests then refuses users' gateway calls. Options: a broker-only route or listener (with a NetworkPolicy), or per-client buckets once Configure the embedded gateway's authorization server as AS-2 #2533 adds client authentication. The in-process requirement in this issue goes away with AS2.Handler().
    • The MCP broker's own token calls. The broker Runtime's code exchange and refresh also reach the token endpoint over the network, through the same bucket.
    • AS-1's in-process calls. as1server.InProcessClient skips the caps mountAS1 applies. implementation.md ("Modulith constraints") says in-process calls get the same checks and limits. Decide whether that means size caps only, not the public rate buckets, and update the wording.
    • Settings. Rates as operator settings, 0 meaning disabled, on by default, covering AS-1 and AS-2 together (Keys and gateway entries for the identity broker #2538). Size caps stay fixed and always on. ToolHive v0.63.0 already caps every auth-server body at 64 KiB.
    • Ingress. In-code limits are a global backstop. Per-client limits belong at the ingress, which can see client addresses.
    • Multi-replica (phase 3). Limiters are per process, so the total budget grows with the replica count. Size the limits per replica or share the limiter.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions