Repository navigation
feat(identitybroker): declare gateways and the embedded gateway's signing key - #2946
ChrisJBurns wants to merge 2 commits into
Conversation
…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
left a comment
There was a problem hiding this comment.
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 underinternal/identitybroker/with file access in thebrokerconfigadapter; at most oneembeddedentry,externalrefused 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;
BindGatewayAS2refuses 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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 -}} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>
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
gateways: [{kind, as2_issuer, token_endpoint, resource, servers}]. The core accepts at most one entry, of kindembedded, and refusesexternal(External gateway: Gateway implementation, operator setup, and end-to-end test #2812 lifts that).token_endpointis AS-2's advertised endpoint, never a dial address.mecatlregistration.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.internal/appinto the broker's configuration loader.mcp.broker.signing_key_fileandmcp.broker.fallback_key_files, absolute paths likesecret_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.IdentityBrokerGatewayServerstest seam,deriveGatewayIDJAGTarget, and the startup-derived ID-JAG target.ListLimitsmarkers 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#2560markers 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).identityBroker.gatewaysandmcp.broker.signingKey(a read-only Secret mount, with fallbacks). The render-time refusals mirror startup. The Kind profile declares no entry and is unchanged.Choices made in this PR
keys.broker_clientin the broker's file, since AS-2 registers the broker client from it.signing_key_fileis refused in global MCP mode, and in broker mode with no OAuth route, the same waycallback_urlis.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 themecatlclient at its authorization server, which nothing outside mecak8s used. No major or feature change.Testing
task lint: 0 issues.go test -race ./...: passes exceptcmd/mecatui/ui(TestConnectMouse*goldens),deploy/helm/mecatl-execution, anddeploy/mecatl-execution-kind, which fail the same way onmain.helm unittest --strict deploy/helm/mecak8s: 97 pass.task docs:configrefandtask docs:check: pass.invalid_targetfor an unconfigured audience or resource;