Skip to content

agentHost: forward the authentication ID token and learn the tenant - #350464

Merged
TylerLeonhardt merged 4 commits into
mainfrom
tyleonha/agent-host-authenticate-id-token
Nov 26, 2026
Merged

TylerLeonhardt merged 4 commits into
mainfrom
tyleonha/agent-host-authenticate-id-token

Conversation

@TylerLeonhardt

@TylerLeonhardt TylerLeonhardt commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Problem

The Copilot agent host knows the signed-in Microsoft account only by the opaque authenticate.accountId. An upcoming Copilot SDK contract (github/copilot-agent-runtime#34048) requires the host to also return the account's Entra tenant when the runtime asks for its identity. The host has no way to learn it: the access token is opaque to it, and accountId must not be parsed.

Changes

This uses the optional AuthenticateParams.idToken added in microsoft/agent-host-protocol#631, so no private metadata is involved.

  • Client: forwards the authentication session's ID token on authenticate whenever the session has one. On relayed connections (Web PubSub and Mission Control) only token is sealed, so the ID token crosses the relay in clear. That is deliberate: the relay already carries the session's content in clear, the ID token grants no access, and an optional field omitted on one kind of connection would be hard to notice.
  • Host: rejects an empty idToken, keeps it with the accepted credential, replays it to providers, and exposes it on getAuthCredential.
  • Logs: the AHP JSONL logger redacts idToken. It needs its own check because the relay transport pre-redacts token, which made the logger skip the entry.
  • Entra bridge: reads the unverified tid claim from the first ID token sent with a discovery credential and keeps it with the account. A later credential without an ID token does not lose it, and a different tid for the same account does not replace it.
  • Protocol copy: idToken is synced as a targeted backport on the current pin (1928cd4e), recorded in common/state/AGENTS.md. A full sync to AHP main brings unrelated protocol changes that need their own adoption.

Not in this PR

The tenant is not handed to the runtime. The current SDK (2.0.3) has no tenantId on the identity result, so the return that carries it is a commented line under a TODO in resolveEntraIdentity. Adopting it also means updating the identity expectations in the Entra and Copilot agent tests, whose fixtures send no ID token.

Once that line is live, a client that sends no ID token will not be able to sign in to the Microsoft path. Until then, behaviour without an ID token is unchanged.

How to test

  • ./scripts/test.sh --reporter dot --run src/vs/platform/agentHost/test/electron-browser/agentHostProtocolClient.test.ts --run src/vs/platform/agentHost/test/node/copilotEntraAuthentication.test.ts --run src/vs/platform/agentHost/test/node/copilotAccountService.test.ts --run src/vs/platform/agentHost/test/common/ahpJsonlLogger.test.ts --run src/vs/platform/agentHost/test/node/agentHostAuthenticationScope.test.ts --run src/vs/workbench/contrib/chat/test/browser/agentSessions/copilotEntraAuthentication.test.ts --run src/vs/workbench/contrib/chat/test/browser/agentSessions/agentHostAuth.test.ts — passed, 767 tests.
  • ./scripts/test.sh --reporter dot --run src/vs/platform/agentHost/test/node/copilotAgent.test.ts --grep "Microsoft|Entra" — passed, 31 tests.
  • pnpm run typecheck-client — passed.
  • pnpm run oxlint on the changed TypeScript files — passed.

Live check on a source build of this branch (SDK 2.0.3) with chat.agentHost.copilot.m365.enabled on: after "Continue with Microsoft", sign-in completed and the host listed its models. Logpoints in the agent host showed the discovery authenticate request carrying an ID token, the bridge reading its tid, and the stored account holding that tenant each time the runtime asked for the identity. A later discovery credential for the same account kept the tenant.

An earlier run of the first commit, on SDK 2.0.2, captured the tenant the same way, but sign-in then failed in service discovery with "The runtime returned an unsupported Microsoft service choice". That did not reproduce on this branch. I did not isolate the cause.

Not checked live: a relayed (Mission Control) connection.

Not run: the full unit, integration and smoke suites.

Forward the Microsoft session's ID token on authenticate, using the optional idToken field from microsoft/agent-host-protocol#631. The host keeps it with the accepted credential, replays it, and redacts it from AHP logs.

The Entra bridge reads the unverified tid claim from the first ID token sent for the account and keeps it with the account. Nothing is handed to the runtime yet: the identity result that carries the tenant is left as a TODO until the SDK accepts it.

Sync the protocol copy with idToken as a targeted backport on the current pin.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 25, 2026 22:28

Copilot AI 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.

🟡 Changes recommended

ID tokens remain exposed to relays on sealed connections, while credential caching and lookup can prevent newly available identity claims from reaching or updating the host.

3 open issues
What changed in this PR

Extends Agent Host authentication to carry optional ID tokens and retain the Microsoft account’s tenant for future SDK support. The tenant is not yet returned to the runtime.

Changes:

  • Adds client forwarding and host validation, storage, and replay of ID tokens.
  • Reads and retains the first usable tenant claim for the selected account.
  • Updates log redaction, regression tests, and protocol-backport documentation.
File Description
src/​vs/​workbench/​contrib/​chat/​test/​browser/​agentSessions/​copilotEntraAuthentication.test.ts Tests ID-token forwarding from authentication sessions.
src/​vs/​workbench/​contrib/​chat/​browser/​agentSessions/​agentHost/​agentHostAuth.ts Adds ID tokens to client authentication requests.
src/​vs/​platform/​agentHost/​test/​node/​copilotEntraAuthentication.test.ts Tests validation, storage, replay, and tenant retention.
src/​vs/​platform/​agentHost/​test/​common/​ahpJsonlLogger.test.ts Tests ID-token redaction with pre-redacted access tokens.
src/​vs/​platform/​agentHost/​node/​copilot/​copilotEntraAuthentication.ts Learns and retains the account’s tenant claim.
src/​vs/​platform/​agentHost/​node/​agentHostAuthenticationService.ts Validates, stores, and replays ID tokens.
src/​vs/​platform/​agentHost/​common/​state/​protocol/​common/​commands.ts Adds the optional protocol idToken field.
src/​vs/​platform/​agentHost/​common/​state/​AGENTS.md Documents the targeted protocol backport.
src/​vs/​platform/​agentHost/​common/​ahpJsonlLogger.ts Redacts ID tokens independently of access tokens.
src/​vs/​platform/​agentHost/​common/​agent.ts Extends the internal authentication contract.
src/​vs/​platform/​agentHost/​AGENTS.md Documents ID-token handling and tenant retention.

Review effort: Balanced

TylerLeonhardt and others added 3 commits November 25, 2026 14:47
…epted credential

Drop the ID token wherever the access token is sealed, since only the token can be sealed and a relay would otherwise read its claims.

Learn the tenant from the discovery credential that was just accepted, not from an older credential stored under the advertised scopes.

Include the ID token in the client's forwarded-credential key, so one that becomes available for an unchanged access token still reaches the host.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Stop dropping the ID token where the access token is sealed. An optional field that is silently omitted on one kind of connection is hard to notice, and the relay already carries the session's content in clear; the ID token is identity, not access.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Move authenticate redaction into one function so the log replacer does not grow, share the nonempty-string check between accountId and idToken, and store the ID token the same way as the account ID.

Stop storing the ID token on host execution credentials, where nothing can read it, and keep the authority type private to the bridge.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@TylerLeonhardt
TylerLeonhardt marked this pull request as ready for review November 26, 2026 00:21
@TylerLeonhardt
TylerLeonhardt added this pull request to the merge queue Nov 26, 2026
Merged via the queue into main with commit b06e940 Nov 26, 2026
53 checks passed
@TylerLeonhardt
TylerLeonhardt deleted the tyleonha/agent-host-authenticate-id-token branch November 26, 2026 01:07
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.

4 participants