Repository navigation
feat(server): open the identity broker session before any change - #2606
Merged
Merged
Conversation
mecak8s now opens the identity broker session, which converts the user's AS-1 access token, before a request changes anything: create, fork, and clear open before saving (clear before cancelling the source run), prompt before its repair saves, and MCP authorization cancel and recheck before touching the MCP broker. A request presents its token at most once, and a stream drops it at its first response. A broker session opened for a successor that is never saved is closed by ID. Broker refusals reach clients from the design's error reasons: token_used and subject_invalid as bearer_rejected (401, invalid_token challenge), revoked sign-ins as sign_in_required (mecatui asks to sign in again), and pairing refusals as identity_broker_session_refused (403). The authenticator's REST 401 now carries the bearer_rejected code too. app.Config.IdentityBrokerAS1 is exported for #2490. Closes #2492. Co-authored-by: Mecatl <[email protected]>
A request's first broker open now takes the access token whether or not it presents it, so a later open in the same request can never present a token an earlier request already converted and return a tagged 401 after a write. The broker's reasons map to the new client errors only for the session open; registration keeps its mapping (#2552). An explicit-ID create whose ID another owner's broker session holds gets the same answer as a plain ID collision. Adds a lost-create-race test with a shared broker. Co-authored-by: Mecatl <[email protected]>
This was referenced Oct 29, 2026
jhrozek
reviewed
Oct 29, 2026
jhrozek
left a comment
Contributor
There was a problem hiding this comment.
Review of 80b4cac. The retained-token fix (the first open now takes the token whether or not it presents it) closes the race I had been checking: a prompt that reuses a broker session which already holds a refresh token can no longer present the token at a later open after the request saved something. The shared-broker lost-create-race test also covers close-by-ID.
Still open, as inline comments:
- The two MCP broker-state-loss branches settle the authorization without any open (mcp_authorization.go).
- Test gaps: the MCP refusal test cannot see event-log changes, no test sends a user token into a scheduled session, fork's close of an unsaved broker session is untested, and one assertion accepts any untagged error. One test leaks its observer goroutine when it fails early.
- Two follow-ups on structure: open-before-change is enforced by hand at six call sites, and clear's cleanup depends on a return-value convention.
- Docs wording in caller-identity.md.
Two points that have no diff line to anchor to:
user-docs/reference/http-sse-api.mddoes not describebearer_rejected,sign_in_requiredandidentity_broker_session_refused, or what a client should do for each.- The "Older clients" bullet in the PR description is milder than what happens. Older mecatui maps
sign_in_requiredto its rejected-credential path (cmd/mecatui/ui/connect.go:138,:294). It tells the user to check issuer, audience and CA settings and disables re-login from the connect panel. The user has to runmecatui loginby hand or upgrade. That is still not a break, but the note should say so.
I read the code and did not run tests.
The MCP recheck and cancel branches that settle an authorization after the MCP broker lost its state now open the identity broker session first, like every other path that changes state. A guard at the three late opens (prompt run start and both MCP continuations) fails loudly if a path changed state before its early open. Client-visible broker refusals use fixed text; the reason stays in diagnostics. Tests: event log in the MCP refusal fixture, the broker-state-loss branches, fork closing an unsaved successor's broker session, the guard, fixed error text, and tighter assertions. Docs: authentication error codes in the HTTP/SSE reference and the caller identity page. Co-authored-by: Mecatl <[email protected]>
jbeda
added a commit
that referenced
this pull request
Oct 29, 2026
Co-authored-by: Mecatl <[email protected]> * origin/main: ci: add a stable omnibus CI gate (#2611) feat(server): open the identity broker session before any change (#2606) fix(learning): fit manual synchronous reflection to request budgets (#2600)
This was referenced Oct 29, 2026
This was referenced Nov 11, 2026
Merged
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Server side of #2492 (the broker side merged in #2593 and #2601): mecak8s opens the identity broker session, which converts the user's AS-1 access token, before a request changes anything, and maps the broker's refusals to client outcomes from the design's error-reasons table.
Open before any change, on every path.
A token is presented at most once per request. The first open that presents it takes it from the request, so later opens carry none, and a stream drops it at its first response. A conversion lost to a closed session in the same request becomes the tagged 401 only before anything changed.
Create, fork, and clear open before saving instead of rolling back (the ticket's fallback). Rollback cannot be made safe: deleting a session may be unsupported or fail, its title event has already reached live watchers, and a cleared run cannot be restored. A broker session opened for a successor that is never saved is closed by its broker ID, so a lost create race never closes the winner's session. Registration errors after the save are logged and retried at run entry, not returned, so a client retry cannot create a duplicate.
Error mapping:
token_used,subject_invalidbearer_rejected, 401 withinvalid_tokenchallenge; mecatui refreshes and resends oncesigned_out,upstream_revoked,owner_action_requiredsign_in_required, 401 with the challenge; mecatui opens Reauthenticateowner_mismatch,session_ownedidentity_broker_session_refused, 403 (was 500)identity_broker_unavailable, 503 (unchanged)The authenticator's own REST 401 now carries the
bearer_rejectedproblem code, so the code means the same on gRPC and REST.app.Config.IdentityBrokerAS1is exported, without a flag, soTestIdentityBrokerAgainstOfflineHarnessruns through real startup. Host AS-1 in mecak8s #2490 fills it from operator configuration.Guard against a forgotten early open: the three late opens (prompt run start and both MCP continuations) fail with an internal error if the request still holds a token that would be presented, so a path that changes state before opening fails loudly in tests. Client-visible refusal text is fixed per error; the broker's reason stays in diagnostics.
Docs: the caller identity page (
user-docs/features/security-and-execution/caller-identity.md) and the HTTP/SSE reference's authentication errors table (user-docs/reference/http-sse-api.md, now with eachcodeand what to do); SDK error list and generated references updated.Known edge, documented in code: a create whose host session ID already has a broker session for another incarnation (a cross-replica race only) skips the early open, and the open after the save then only logs a refusal.
Issue relationship
Closes #2492
API compatibility
bearer_rejected,sign_in_required,identity_broker_session_refused.bearer_rejectedkeeps its contract. It now also comes from handlers, but only before the request changed anything, and each request presents its token at most once, so clients' existing refresh-and-retry stays correct.internaltobearer_rejected, for a missing as well as a rejected bearer. Status andWWW-Authenticateare unchanged, and gRPC already carriedbearer_rejected. Codes are open strings and 401s were always distinguishable by status.internalto 403. Still a failure for any client.sign_in_requiredas a rejected credential.mecatuibefore this change shows "The server rejected this credential. Re-login is disabled for this target; check issuer, audience, and CA settings." and offers no sign-in from the connect panel, which points the user at configuration instead. They must runmecatui login <target>by hand or upgrade. Not a break (the request still fails safely), but a worse experience until they upgrade.--enable-identity-broker, and token conversion needsConfig.IdentityBrokerAS1, which no deployment sets until Host AS-1 in mecak8s #2490. Under the flag, a create, fork, or clear carrying a token now fails with a retryable 503 when the broker is unreachable, saving nothing (before, it succeeded and the run failed), and a clear whose token is refused no longer cancels the source's run.MECATL_ERROR_CODES(the SDK'sAuthenticationErrordoes not exposecodeyet; follow-up). REST clients should key on theinvalid_tokenchallenge or thebearer_rejectedcode for refresh-and-retry.Test plan
go test -raceoninternal/adapter/server,internal/identitybroker/...,internal/app,cmd/mecak8s,cmd/mecatui/...: only failures that also occur on unmodifiedmainon this machinetask lint: clean except the pre-existing gosec finding inenvironment/microvm/launch_ownership_darwin.gomatlatl check user-docs --strict: no new findingstask site:build: not run locally (pnpm toolchain); CI covers it