Skip to content

feat(identitybroker): carry the request's AS-1 token to broker session open - #2522

Merged
ChrisJBurns merged 5 commits into
mainfrom
feat/identitybroker-carry-as1-token
Oct 26, 2026
Merged

ChrisJBurns merged 5 commits into
mainfrom
feat/identitybroker-carry-as1-token

Conversation

@ChrisJBurns

@ChrisJBurns ChrisJBurns commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Closes #2488.

When a user request opens an identity broker session, the server now passes along the AS-1 access token that authenticated that request. Requests that don't come from a user (scheduler fires, server-owned plan continuations) carry no token.

What changes

  • Sign-in check (authn.go): after a bearer passes identity verification, on the gRPC unary and stream interceptors and the HTTP middleware, it is wrapped in identitybroker.Token (authGRPC returns it as that type, so it can't be swapped with the static token) and stored in a request-scoped holder on the context. The holder is emptied when the request returns, so a context that outlives the request (detached with context.WithoutCancel, or kept by a run) no longer yields the token. The bearer is never re-read from metadata or headers, and the static server token is never carried.
  • Server-owned work (service.go): detachedControlContext, the auto-approve continuation, and saved exact-approval contexts strip the token. They act without a user request.
  • Broker open (identity_broker.go): openIdentityBrokerSession reads the token once and sets OpenSessionRequest.AccessToken. This covers every open path: create, fork, clear, run entry (which also covers restore, since loading doesn't reopen), and team root. A scheduled session never takes the token, even when a user's fire-now request creates it inside that request: its authority comes from the schedule. The in-process broker ignores the field for now.
  • New file: internal/adapter/server/access_token.go.

Scope against #2492

#2488 said putting the token into the open request belongs to #2492. Setting the field here is what lets the tests prove the token reaches every open. The exchange, and the decision about when a token is spent (the open loop can call OpenSession twice in one request, and AS-1 accepts each token only once), stay with #2492.

Testing

  • Over real gRPC and HTTP, create, fork, clear, a prompt that reopens a closed broker session, and a team run each give the broker the request's exact bearer.
  • Scheduled creates, Service calls with only a principal, and contexts kept after a unary, stream, or HTTP request returned all open with a zero token. The kept contexts still hold the principal, which shows the holder was emptied and the principal kept.
  • A scheduled session created inside a verified unary, stream, or HTTP request (as fire-now does) opens with a zero token; this test fails without the fix.
  • Static-token auth carries no token; identity auth inside the same handler does (positive control). A rejected bearer creates no session and opens no broker session.
  • The bearer appears in none of: diagnostics (service and authenticator, all arguments rendered), the caller's error with the broker down, saved session snapshots, the event log, or model requests. Each search also checks there was something to search.
  • Internal tests cover the holder's lifetime and the server-owned strip. When the holder was changed so it kept the token, these tests failed.
  • go test -race on the focused server tests; cmd/mecak8s, internal/identitybroker, and internal/app broker tests pass.
  • Known failures, not from this change: TestACPUsesHostGovernanceRootAndClosesRejectedBinding and TestLoadACPSessionOwnsExactBindingUntilOverrideLifecycleEnds fail the same way on main in the local sandbox ("cwd does not match the configured session placement"). Lint reports a staticcheck SA5011 at service.go:3256, on a line this PR doesn't touch.
  • Not covered: audit records (no audit sink is on these paths, so the token cannot reach one today), and the auto-approve continuation's strip has no direct test.
  • Not yet run: the full task lint && task test:race gate.

API compatibility

Assessment: compatible; no wire change and no major bump. No proto, HTTP body, status, or engine API change. The token goes only to the in-process identity broker, which ignores it for now. Nothing about it is visible to clients.

Upgrade implications: none.

…n open

The authenticator attaches the bearer that verified the caller to the
request context in a holder emptied when the request returns, on gRPC
and HTTP. Server-owned work (plan continuations, auto-approve, retained
approval contexts) has no token. The broker session open reads it once
and passes it in OpenSessionRequest.AccessToken; the exchange is #2492.

Refs #2488

Co-authored-by: Mecatl <[email protected]>
@ChrisJBurns
ChrisJBurns marked this pull request as ready for review October 26, 2026 15:20
ChrisJBurns and others added 2 commits October 26, 2026 15:37
authGRPC returned the static token and the identity bearer as adjacent
strings, so swapping them would compile and could hand the static
server token to the broker. The access token now has its own type.

Co-authored-by: Mecatl <[email protected]>
… token

A fire-now request creates the scheduled fire session inside the user's
request, so its broker open read the user's AS-1 token. A scheduled
session's authority comes from its schedule, not the user's sign-in.

Refs #2488

Co-authored-by: Mecatl <[email protected]>
@ChrisJBurns
ChrisJBurns merged commit 62d056c into main Oct 26, 2026
41 checks passed
@ChrisJBurns
ChrisJBurns deleted the feat/identitybroker-carry-as1-token branch October 26, 2026 20:42

@jhrozek jhrozek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approving. The token reaches every open made for a user request. Scheduled sessions and server-owned work get no token. The token never appears in logs, errors, snapshots, events, or model requests.

Non-blocking, fine as a follow-up:

  • No test covers the strip in autoApproveContinuation (service.go:8690). If you delete it, the suite stays green. The goroutine starts with the live request context (service.go:8636). So while a Converse stream is open, if the broker session had closed, the continuation would pass the user's bearer to OpenSession. A small internal test would close this gap: call autoApproveContinuation with a token in the context, and check that the broker open gets a zero token.

For #2492:

  • After session_closed, the retry loop in openIdentityBrokerSession sends the same token to a second, new broker session. AS-1 will answer token_used there.
  • The comment at access_token.go:12-13 ("nothing else may read it") will need to change once schedule setup also needs the token.

This branch was successfully deployed

1 active deployment
Preview — 72a0bc75 Deployed Oct 26, 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.

Carry the user's AS-1 token to session open

2 participants