Skip to content

feat(identitybroker): declare gateways and the embedded gateway's signing key - #2946

Open
ChrisJBurns wants to merge 2 commits into
mainfrom
feat/identitybroker-gateway-entries
Open

ChrisJBurns wants to merge 2 commits into
mainfrom
feat/identitybroker-gateway-entries

Conversation

@ChrisJBurns

Copy link
Copy Markdown
Contributor

Closes #2538 (the second of its two PRs; the first was #2875).

Summary

The identity broker's configuration file now declares gateways, and the embedded gateway's authorization server (AS-2) signs with an operator key instead of one generated at startup.

Changes

  • Gateway entries. The broker's configuration file takes gateways: [{kind, as2_issuer, token_endpoint, resource, servers}]. The core accepts at most one entry, of kind embedded, and refuses external (External gateway: Gateway implementation, operator setup, and end-to-end test #2812 lifts that). token_endpoint is AS-2's advertised endpoint, never a dial address.
  • The entry is optional.
    • No entry: with the identity broker on, the MCP broker builds exactly as with it off. There is no AS-2 role and no mecatl registration.
    • An entry with no servers: it is validated and gives AS-2 its role and operator key, but it creates no broker gateway and no AS-1 ID-JAG target.
    • An entry with servers: refused until AS-2 trusts AS-1 (Configure the embedded gateway's authorization server as AS-2 #2533). Tests enable it through the existing AS-2 trust seam. The entry's servers then become the broker's gateway (check 6, by server), AS-1's ID-JAG target and actor profile, and the MCP broker's gateway routes, all from the one entry.
  • The entry must match the embedded gateway. Before AS-1 is built, startup refuses an embedded entry whose AS-2 issuer, token endpoint, or resource differs byte for byte from what mecak8s derives from mcp.broker.callback_url, or whose servers are not OAuth routes of the MCP broker. It also refuses an embedded entry when no embedded gateway runs. After the build, the built AS-2 must equal the entry, and the broker refuses to bind any other AS-2.
  • Same-issuer check for every gateway. An entry whose AS-2 issuer is AS-1's issuer is refused. The comparison includes the path, as corrected in docs(agent-identity): compare AS-2 and AS-1 issuers including the path #2945. The check moved from internal/app into the broker's configuration loader.
  • AS-2's signing key. New operator-tier settings mcp.broker.signing_key_file and mcp.broker.fallback_key_files, absolute paths like secret_file. They are required when the identity broker is on and the file has an embedded entry, and refused otherwise for now (MCP broker: logins to protected MCP servers survive a mecak8s restart #2869 will allow them with the broker off). The identity broker never holds this key. Startup refuses it if its public key matches any of the broker's keys.
  • Removed. The IdentityBrokerGatewayServers test seam, deriveGatewayIDJAGTarget, and the startup-derived ID-JAG target.
  • Shortcut markers. Check 6's marker is deleted, since the design now checks by server. The one-gateway and ListLimits markers point to External gateway: Gateway implementation, operator setup, and end-to-end test #2812, the production-routes-nothing markers to Configure the embedded gateway's authorization server as AS-2 #2533, and the #2560 markers to Broker over gRPC, authenticated as the mecak8s workload #2559. AS-2's key marker is narrowed to its HMAC secret (MCP broker: logins to protected MCP servers survive a mecak8s restart #2869).
  • Helm. New values identityBroker.gateways and mcp.broker.signingKey (a read-only Secret mount, with fallbacks). The render-time refusals mirror startup. The Kind profile declares no entry and is unchanged.
  • Docs. The operator guide covers declaring the embedded gateway and its signing key. The generated configuration reference adds the two settings.

Choices made in this PR

  • An entry requires keys.broker_client in the broker's file, since AS-2 registers the broker client from it.
  • An entry with servers but no AS-1 is refused.
  • signing_key_file is refused in global MCP mode, and in broker mode with no OAuth route, the same way callback_url is.
  • The chart refuses servers in an entry at render time, matching the Configure the embedded gateway's authorization server as AS-2 #2533 refusal at startup.

API compatibility

Assessment: no remote-observable API change. The configuration file, settings.yaml (two new optional operator-tier keys), and Helm values change. The gRPC and HTTP APIs, session events, and model-visible tool results do not. With the identity broker on and no gateway entry, the MCP broker no longer registers the mecatl client at its authorization server, which nothing outside mecak8s used. No major or feature change.

Testing

  • task lint: 0 issues.
  • go test -race ./...: passes except cmd/mecatui/ui (TestConnectMouse* goldens), deploy/helm/mecatl-execution, and deploy/mecatl-execution-kind, which fail the same way on main.
  • helm unittest --strict deploy/helm/mecak8s: 97 pass. task docs:configref and task docs:check: pass.
  • New tests cover:
    • entry parsing and every refusal, including path-aware shared issuers;
    • building with no entry, with an entry without servers, and with servers but without trust (refused, naming Configure the embedded gateway's authorization server as AS-2 #2533);
    • building with servers and test trust: the gateway, the AS-1 target, gateway calls, and invalid_target for an unconfigured audience or resource;
    • entries that disagree with the embedded gateway;
    • the AS-2 key rules, including a key shared with the broker;
    • AS-2 key persistence across a rebuild, and rotation: a gateway token signed with the previous key verifies at the vMCP while that key is a fallback, and is refused once it is dropped;
    • the Helm render.

…ning key

The broker's configuration file declares gateway entries. An embedded entry
must match the gateway mecak8s runs and must not share AS-1's issuer; with
no servers it is inert until AS-2 trusts AS-1 (#2533), and with servers it
drives check 6, AS-1's ID-JAG target, and the MCP broker's gateway routes.
The embedded gateway's authorization server signs with an operator key from
mcp.broker.signing_key_file, and takes its AS-2 role only with an entry.
Closes #2538.

Co-authored-by: Mecatl <noreply@mecatl.dev>

@rdimitrov rdimitrov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked against #2538, the design (credentials-and-lifecycle.md: Configuration, Credential roles, step (6) check 6), #2868/#2945, and the follow-ups it hands work to (#2533, #2812, #2869, #2559). It lines up:

  • Gateway entries are a list of {kind, as2_issuer, token_endpoint, resource, servers}, validated by the broker under internal/identitybroker/ with file access in the brokerconfig adapter; at most one embedded entry, external refused naming #2812.
  • Optional entry behaves as the issue specifies in all three cases (none / no servers / servers refused until #2533), and AS-1 gets an ID-JAG target and actor profile only from an entry that routes servers.
  • Startup refuses an entry that disagrees with the derived AS-2 issuer, token endpoint, resource, or OAuth routes, and the built AS-2 is re-checked against the entry; BindGatewayAS2 refuses another issuer/resource.
  • Same-issuer check moved to the loader, path-aware per #2945, and still holds transitively for the built AS-2.
  • AS-2 key is MCP-broker operator settings, never held by the identity broker, refused without an entry (#2869 shortcut marked), and cross-checked against the broker's keys using ToolHive's own loader.
  • Check 6 by server, shortcut markers re-pointed correctly, Kind profile untouched, flag-off path unchanged.

Focused tests pass locally (internal/identitybroker/..., mcpbroker, permconfig, cliconfig, mcpauthority, internal/app identity/gateway tests). The k8s e2e (kind) failure is a k8s lease API timeout in the learning failover spec, unrelated to this change.

Two non-blocking comments inline. Approving.

var set JWKSet
if json.Unmarshal(k.BrokerClientKeySet, &set) == nil {
for _, key := range set.Keys {
if pub, ok := p256JWKKey(key); ok {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: the cross-role check now also guards the AS-2 key, which can be RSA or Ed25519, but this loop only collects the key set's EC P-256 entries (and JWK can't represent n/e/OKP). An operator who put AS-2's public key into the broker client key set as an RSA/OKP JWK would pass checkGatewayEntry, and AS-2 would then accept client assertions signed with its own signing key as mecatl.

Operator error, so low severity, but the simplest close is to refuse non-P-256 keys in the broker client key set at load (checkClientKeySet), since the broker client key must be P-256 anyway. Then PublicKeys really is every key a server accepts for that role.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in bda0d58. checkClientKeySet now refuses any key in the broker client key set that is not ECDSA P-256, naming its kid, so PublicKeys covers every key a server accepts for mecatl. New TestKeysValidateRefuses cases cover RSA, Ed25519, and P-384 entries.

{{- range $field, $want := dict "as2Issuer" $issuer "tokenEndpoint" (printf "%s/oauth/token" $issuer) "resource" (printf "%s/mcp" $issuer) -}}
{{- if ne (get $entry $field) $want -}}{{ fail (printf "identityBroker.gateways[0].%s must be %s, which the embedded gateway derives from mcp.broker.callbackURL" $field $want) }}{{- end -}}
{{- end -}}
{{- if and $broker.as1.issuer (eq (trimSuffix "/" (lower $broker.as1.issuer)) (lower $issuer)) -}}{{ fail "identityBroker.gateways[0].as2Issuer must differ from identityBroker.as1.issuer: the broker client authenticates to both with one key" }}{{- end -}}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this differs from mecak8s's sameIssuer: it lowercases the path (mecak8s compares paths case-sensitively) and doesn't normalize a default port. So as1.issuer: https://mecatl.example.com:443/v1/mcp/broker renders here and then crash-loops at startup. Since the point of the render-time refusals is to avoid crash loops, worth either stripping :443 before comparing or noting that startup is authoritative.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in bda0d58. A new mecak8s.issuerKey helper normalizes as sameIssuer does: scheme and host lowercased, :443 and :80 dropped for their schemes, and the path compared case-sensitively without a trailing slash. Its comment notes that the startup check is authoritative. Tests cover https://MECATL.example.com:443/v1/mcp/broker/ (refused) and a path differing only in case (renders).

…cak8s's issuer comparison in Helm

The broker client key set now refuses any key that is not ECDSA P-256, so
the cross-role check covers every key a server accepts as mecatl's. The
chart compares AS-1's and AS-2's issuers as mecak8s does: scheme and host
lowercased, a default port dropped, the path compared case-sensitively
without a trailing slash.

Co-authored-by: Mecatl <noreply@mecatl.dev>

This branch was successfully deployed

1 active (outdated) deployment
Preview — a024b662 Deployed Nov 21, 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.

Keys and gateway entries for the identity broker

2 participants