Skip to content

fix(identitybroker): follow-ups from reviewing #2946 - #2960

Merged
jhrozek merged 4 commits into
feat/identitybroker-gateway-entriesfrom
fix/identitybroker-gateway-entries-followups
Nov 23, 2026
Merged

jhrozek merged 4 commits into
feat/identitybroker-gateway-entriesfrom
fix/identitybroker-gateway-entries-followups

Conversation

@jhrozek

@jhrozek jhrozek commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Follow-ups from reviewing #2946, stacked on feat/identitybroker-gateway-entries. Merge this into #2946's branch before #2946 merges. Chris is away, so these are separate commits for him to review when he's back.

  • Refuse embedded-gateway signing keys the gateway can't use. mcp.broker.signing_key_file and fallback_key_files were documented as RSA, ECDSA, or Ed25519. ToolHive's authorization server signs with an Ed25519 key as EdDSA, but ToolHive's token validator accepts only RSA and ECDSA, so every gateway token would get a 401 after a clean start (Embedded auth server signs with an Ed25519 key, but ToolHive's token validator refuses EdDSA tokens toolhive#7250). A P-224 key passed Mecatl's checks and was refused by ToolHive later in startup. Startup now refuses both and accepts RSA and ECDSA on P-256, P-384, or P-521.
  • Refuse a signing key listed twice. The signing key repeated as a fallback, or the same fallback twice, published one key ID twice in AS-2's key set.
  • Check the keys AS-2 actually loaded. Startup read the key files to compare them with the identity broker's keys, and ToolHive read them again. If a file changed in between, the check approved different bytes. After the build, the MCP broker now compares the public keys AS-2 loaded with the identity broker's keys too. The comparison refuses a key type it can't compare instead of skipping it.
  • Name the differing field when the built AS-2 isn't the entry's, as the startup check already does.
  • Tests.
    • The server-name rule that rebasing onto feat(identitybroker): limit each agent's gateway calls to its definition's tools #2937 brought to gateway entries now has core and loader tests, and its doc comments describe it.
    • TestHostedAS1IssuesTheGatewaysIDJAGs again pins the outcome: CodeInternal after one retry, so two ID-JAGs and two redemptions.
    • In the Helm render tests, the "no embedded gateway" case expected an empty message, so any failure passed. It now asserts the rule it actually hits. Five refusals that had no test now have one.
  • Docs. The operator guide said turning the identity broker on or off changes the MCP gateway's token audience. The gateway entry decides it now. The guide and values.yaml also say every broker client key must be P-256, and the chart example uses the chart's value names.

Issue relationship

Relates to #2538

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe): tests

Test plan

Baseline checks

  • Linting: golangci-lint run on ./internal/adapter/mcpbroker/..., ./internal/app/, ./internal/identitybroker/..., ./internal/adapter/permconfig/, and deploy/helm/mecak8s, 0 issues
  • Focused tests: go test on ./internal/adapter/mcpbroker/, ./internal/identitybroker/..., the gateway, broker, and key tests in ./internal/app/, and deploy/helm/mecak8s pass
  • Fast offline test suite (task test): left to CI
  • Pre-review race suite (task test:race): left to CI
  • Markdown changed: task docs link check, 0 broken links, anchors, or orphans
  • task docs:configref regenerated configuration.md and the settings skeleton

New tests:

  • TestSigningPublicKeysRefusesKeysTheVMCPCannotVerify: Ed25519 and P-224 refused as signing key or fallback; RSA and P-384 accepted.
  • TestSigningPublicKeysRefusesAKeyListedTwice
  • TestBuildMCPBrokerRefusesAS2SigningWithABrokerKey: the check after the build refuses a key AS-2 loaded that is a broker key.
  • TestCheckAS2KeysAreNotBrokerKeysFailsClosed
  • TestAS2SigningKeyRotation also checks that AS-2 reports the keys it loaded.

User-facing change

An embedded-gateway signing key that is Ed25519, on an ECDSA curve other than P-256, P-384, or P-521, or listed twice now stops startup with an error naming the file. Before this, such a key either started and then failed every gateway call, or failed later in startup. The operator guide now says the gateway entry, not the identity broker setting, decides when users must enroll protected MCP servers again.

API compatibility

This PR adds no remote-observable change. It does change the assessment for #2946, whose description doesn't mention this: for a deployment with the identity broker, AS-1, and a protected MCP server, the MCP gateway's token audience was <issuer>/mcp before #2946. After upgrading without a gateway entry it is <issuer>, and users must enroll their protected MCP servers again. Adding the entry later moves it back to <issuer>/mcp, which means enrolling again. The token audience is visible to clients, so this belongs in #2946's release notes.

Special notes for reviewers

🤖 Generated with Claude Code

jhrozek and others added 4 commits November 23, 2026 16:38
…check the keys AS-2 loaded

The embedded gateway's signing key settings now refuse:

- an Ed25519 key, or an ECDSA curve other than P-256, P-384, or P-521.
  ToolHive's authorization server signs with Ed25519 as EdDSA, but its
  token validator accepts only RSA and ECDSA, so every gateway token
  would get a 401.
- a key listed twice, the signing key repeated as a fallback included,
  which would publish one key ID twice.

Startup read the key files once for the check against the identity
broker's keys, and ToolHive read them again. After the build, the MCP
broker now checks the public keys AS-2 actually loaded against the
identity broker's keys too, and refuses, failing closed, a key it
cannot compare. A built AS-2 other than the entry's now names the
field that differs.

Co-Authored-By: mecatl <[email protected]>
…e hosted AS-1 retry

Rebasing onto #2937 made a gateway entry's servers follow the stricter
server-name rule (letters, digits, and single underscores). The doc
comments on ValidateGatewayEntries and WithGateway now say so, and the
core and loader tests refuse a dotted server and a double underscore.

TestHostedAS1IssuesTheGatewaysIDJAGs again pins the outcome: the
broker retries the reasonless invalid_grant once, so the call fails
with CodeInternal after two ID-JAGs and two redemptions.

Co-Authored-By: mecatl <[email protected]>
…essages

The "no embedded gateway" case expected an empty message, so any render
failure passed; it actually stopped at the empty callback URL rule, and
now asserts that rule's message. New cases cover a signing key with no
Secret and a Secret with no key, fallbacks without a signing key, a
fallback that is a broker key, and a gateway entry with the identity
broker off. An entry without a broker client key is not covered here:
without AS-1 the production profile first needs a full OIDC client.

Co-Authored-By: mecatl <[email protected]>
…audience

The operator guide said turning the identity broker on or off changes
the audience of the MCP gateway's tokens. Since #2946 the embedded
gateway entry decides it: without an entry the audience is the gateway's
issuer, with one it is the entry's resource, so adding or removing the
entry is what makes users enroll protected MCP servers again.

The guide and values.yaml also say that every key in the broker
client's key set must be EC P-256, that the key is registered at the
MCP gateway only with a gateway entry, and that an entry requires it.
The "Declare the embedded gateway" section now shows the chart values,
whose names (as2Issuer, tokenEndpoint) differ from the file's.

Co-Authored-By: mecatl <[email protected]>

@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.

LGTM. These changes should go into #2946's branch before #2946 merges.

  • Refusing Ed25519 is correct: ToolHive signs with EdDSA, but its validator accepts only RSA and ECDSA (stacklok/toolhive#7250), so every gateway token would have been refused. Accepting only P-256, P-384, and P-521 moves ToolHive's late refusal to startup, where the error names the file.
  • Running the broker-key comparison again on the keys AS-2 actually loaded (KeyProvider().PublicKeys) closes the window where the file changes between the two reads. Failing closed on a key type that can't be compared is the right default.
  • The duplicate-key refusal, the named field in the post-build mismatch error, and the fixed Helm assertions (the "no embedded gateway" case used to pass on any failure) are all real fixes.
  • I agree with the note that the same-issuer check lives only in the loader. #2559 and #2812 will need to repeat it when they add a second source of entries.

@jhrozek
jhrozek merged commit a13d09f into feat/identitybroker-gateway-entries Nov 23, 2026
45 checks passed
@jhrozek
jhrozek deleted the fix/identitybroker-gateway-entries-followups branch November 23, 2026 16:23

This branch was successfully deployed

1 active deployment
Preview — 391e9f0e Deployed Nov 23, 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.

2 participants