Skip to content

feat(authn): own sessions by the sign-in's sub_id identity - #2497

Merged
ChrisJBurns merged 5 commits into
mainfrom
feat/identitybroker-sign-in-ownership
Oct 26, 2026
Merged

ChrisJBurns merged 5 commits into
mainfrom
feat/identitybroker-sign-in-ownership

Conversation

@ChrisJBurns

@ChrisJBurns ChrisJBurns commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Closes #2487.

With a new opt-in OIDC option, mecak8s accepts only AS-1 access tokens from the TUI or Studio and owns sessions by the company identity in the token's sub_id, so existing owners keep matching without migration when the IdP gives each user the same subject as before.

Design changes (for the design's author)

This PR changes the agent identity design drafts in two places. Please confirm both.

  1. Another user's session returns 404 session_not_found, not 403 not_session_owner. The design (credentials-and-lifecycle.md step (1) check 8 and the failure matrix; implementation.md session binding checks) and Session ownership from the AS-1 sign-in #2487's "Done when" said 403. This PR keeps the server's existing contract instead: another user's session looks exactly like a missing one, so a caller cannot tell which sessions exist, and switching to 403 would change an existing wire behaviour. The drafts are amended to say 404.
  2. "Existing owners keep matching without migration" is qualified. It holds only when the upstream IdP returns the same issuer and sub for each user to AS-1 as it did to mecak8s. IdPs that issue a pairwise subject per registered application (for example Microsoft Entra ID) give AS-1, a new registration, a different sub, so those deployments must remap owners first. The drafts now say so.

What changes

  • New settings, off by default: --oidc-owner-identity and --oidc-accepted-client-ids (Helm oidc.ownerIdentity, oidc.acceptedClientIDs). --oidc-owner-identity is a value flag whose only accepted value today is sub_id (empty is off), so a later owner identity, such as ToolHive's upstream_subject, can be added without a breaking rename. They are registered through the shared OIDC flags, so mecated has them too.

  • With the option on (authn/oidc), after the existing signature, issuer, expiry, and audience checks, a token must:

    • have header typ at+jwt (or application/at+jwt), through toolhive-core's AcceptedTokenTypes; alg is already limited to RS/PS/ES by toolhive-core;
    • carry a client_id from the accepted list;
    • carry an RFC 9493 sub_id with format iss_sub, built through session.PrincipalFromClaims, so iss and sub must be non-empty and NUL-free.

    Any failure is a 401 invalid_token. The owner principal's Issuer and Subject come from sub_id, so PrincipalScopeHash and every stored owner key stay the same for users whose IdP returns the same issuer and subject as before.

  • Misconfiguration fails at startup (mecated and mecak8s, and the Helm chart): the option without client IDs, client IDs without the option, either without --oidc-issuer, an advertised --oidc-client-id missing from the accepted list (clients would enroll and then get 401 on every request), an empty --oidc-accepted-client-ids, an unknown --oidc-owner-identity value, or the option on the Kubernetes token validator. The authn/oidc library also refuses the option without a configured audience or with AllowAnyAudience (RFC 9068 §4). mecak8s also refuses --enable-identity-broker with --oidc-issuer unless the option is on.

  • oidc.Validator stays comparable (the accepted client IDs sit behind a pointer), so the published authn/oidc API keeps its v0.3.0 shape; a compile-time test guards it.

  • 401 challenge: a presented bearer that is rejected now gets WWW-Authenticate: Bearer error="invalid_token" (RFC 6750 §3.1); a request with no bearer keeps the bare Bearer. This applies to every server and to static-token auth.

  • Another user's session stays 404 session_not_found (a foreign delete stays 204 and deletes nothing), so a session's existence is not disclosed. This is a design change; see above.

  • No change needed in identityBrokerOwner: the broker owner is now the company identity, as identitybroker.Owner documents.

  • Docs: caller identity (canonical owner rules, the same-subject precondition, and that storage_management.principals and the execution allowed subjects must name the sub_id identity once the option is on; neither mismatch can be detected at startup), the mecak8s identity page, the HTTP/SSE reference (authentication errors), the CLI reference (generated), and a small correction in deployment-and-hardening.md.

Not in this PR

  • Limiting which issuers sub_id may name (an expected-issuer setting); worth adding only if AS-1 ever federates to more than one IdP.
  • AS-1's own caller identity and client_id are dropped once the owner is built; the audit work adds a separate verified-caller value.
  • Real AS-1 tokens carry sub_id only once Mecatl moves to a ToolHive release that includes Emit sub_id (RFC 9493) with the user's upstream identity in access tokens toolhive#6900 (merged, not yet released). Tests use the offline harness.

Testing

  • authn/oidc: the typ matrix (at+jwt and application/at+jwt pass; JWT and missing fail, and pass with the option off); alg none and HS256 refused; client_id missing, non-string, unlisted, and the second listed ID accepted; every malformed sub_id; the owner from sub_id with the option on and from iss/sub with it off; configuration errors.
  • internal/cliconfig and cmd/mecak8s: flag parsing, misconfiguration through the real constructor stopping startup, and the broker refusal matrix.
  • internal/adapter/server: the challenge for a missing, a rejected, and a static-token bearer; gRPC stays Unauthenticated.
  • mecak8s end to end against the offline harness (cmd/mecak8s/identity_broker_harness_test.go):
    • tokens with typ JWT, no typ, alg none, another client_id, no sub_id, or a malformed sub_id get 401 with the invalid_token challenge;
    • session and broker owners are the company IdP's issuer and the user;
    • Bob gets 404 on Alice's get, events, transcript, and fork, and 204 on delete with her session intact; no response contains her title or prompt (Alice's own reads prove both are present);
    • a session created under the company IdP's identity still belongs to Alice when she arrives through AS-1.
  • Harness: two AS-1 subjects never carry the same company identity.
  • Helm: rendering, defaults unchanged, and each fail message.
  • go test -race on internal/..., cmd/mecak8s, authn/oidc, engine/session, and the chart; task api:check; task docs:server-cli:check; the offline demo. Locally, some tests in packages this PR does not touch fail identically on main (the local shell sandbox: git worktrees, bash, sockets).

API compatibility

Assessment: compatible and additive; no major bump. No proto field, engine API (task api:check is clean), or stored-data change; the Principal doc comments in engine/session and harness.proto (and its generated Go, TypeScript, and gRPC reference) now name the sub_id source.

  • New opt-in settings, off by default: existing mecated and mecak8s deployments are unchanged.
  • With the option on, mecatl.v1.Principal.issuer/subject (session owners and event actors) are the sub_id identity, the company IdP's on an AS-1 deployment, rather than the token's own issuer. The owner key is unchanged.
  • 401 challenge: adds the standard error="invalid_token" parameter for a rejected bearer. Status codes, bodies, and gRPC Unauthenticated are unchanged, no Mecatl client or SDK parses the challenge, and RFC 6750 clients must accept the parameter.
  • mecak8s startup: --enable-identity-broker with --oidc-issuer now requires --oidc-owner-identity=sub_id. The broker flag is experimental and not in the chart; a release that sets it through extraArgs with OIDC on will stop starting until the option is set.
  • Cross-user access is unchanged (404, and 204 for delete).

Upgrade implications: to turn the option on, point --oidc-issuer at AS-1, list the TUI and Studio client IDs (including any advertised --oidc-client-id), and make sure AS-1's upstream IdP returns the same issuer and sub for each user as mecak8s saw before; with a pairwise-subject IdP, remap owners first. Otherwise existing data stays with the previous owner identities. Principal lists (storage_management.principals, --execution-allowed-subjects) must name the sub_id identity. Sessions created in an experimental broker setup with AS-1 tokens before this option are owned by AS-1's identity and are not visible once it is on.

Add an opt-in OIDC option, --oidc-owner-from-sub-id with
--oidc-accepted-client-ids (Helm oidc.ownerFromSubID and
oidc.acceptedClientIDs). With it on, a bearer must be an RFC 9068
at+jwt access token from an accepted client_id carrying an RFC 9493
iss_sub sub_id, and the session owner is that sub_id identity, so
owners keyed by the company IdP keep matching without migration.
Off by default for mecated and existing mecak8s deployments.

mecak8s refuses to start the identity broker with OIDC on but the
option off. A presented-and-rejected bearer now gets
WWW-Authenticate: Bearer error="invalid_token"; a missing bearer keeps
the bare Bearer challenge. Another user's session stays a 404, and the
design drafts now say so.

Closes #2487.

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

With --oidc-owner-from-sub-id on, refuse startup when --oidc-client-id
(advertised in protected-resource metadata) is not in
--oidc-accepted-client-ids; otherwise clients enroll and every request
gets 401. The Helm chart refuses the same combination.

Hold the accepted client IDs behind a pointer so oidc.Validator stays
comparable, as it was in authn/oidc v0.3.0.

Document that existing owners keep matching only when the upstream IdP
returns the same issuer and sub for each user (not a pairwise subject
per application), and that storage_management.principals and the
execution allowed subjects must name the sub_id identity.

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

@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. These are follow-ups found during an automated review; none blocks merging, and they can be fixed in a later PR.

Two points have no line in this diff:

  • The proto description of Principal is now wrong. contracts/proto/mecatl/v1/harness.proto:1148-1150 still says issuer is "the IdP that minted the token (the canonical iss claim)" and subject is "the sub claim". With --oidc-owner-from-sub-id on, both come from sub_id. The PR fixed the same comment in engine/session/principal.go but not here, and the proto is what API clients read (it is generated into user-docs/reference/grpc-schema.md and the TypeScript SDK). Copy the principal.go wording into the proto and run task generate.
  • A few tests don't cover what they look like they cover.
    • The alg: none and HS256 tests (and the harness alg: none case) would still pass with this PR's code removed, because toolhive-core already rejects those algorithms.
    • No test uses a different case, such as AT+JWT.
    • No test has a non-string sub_id.sub or sub_id.format. The code already handles both safely.
    • No test changes the caller's AcceptedClientIDs slice after NewValidator to prove the slices.Clone matters.

Comment thread authn/oidc/oidc.go
if identity == nil {
return nil, subIDRejection("sub_id claim is missing or not a well-formed iss_sub identifier")
}
out.Issuer, out.Subject = identity.Issuer, identity.Subject

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.

The execution allowlist no longer pins the issuer. ownerAllowed (cmd/mecak8s/flags.go:727-731) matches --execution-allowed-subjects against p.Subject only. Before this PR the issuer was always --oidc-issuer, so a subject named one person. With the option on, the issuer is whatever AS-1 writes into sub_id.iss, and this line accepts any non-empty, NUL-free value.

Example: AS-1 signs in users from both the company IdP and a partner IdP. A partner user whose sub is alice-204 matches the allowlist entry meant for the company's alice-204, and can list and bind execution templates. This goes against the Principal doc comment ("never Subject alone"). storage_management.principals compares issuer and subject together, so it is not affected.

It needs AS-1 to issue such a token, so it isn't exploitable today. Possible fixes: match the (issuer, subject) pair, refuse --execution-enabled while the option is on, or add the expected-issuer setting the PR description defers. user-docs/features/security-and-execution/caller-identity.md:153-154 should then stop presenting the subject-only match as enough.

Separately, this line drops AS-1's own iss, sub and client_id. The audit design (audit.md, credentials-and-lifecycle.md:211) expects mecak8s to record the AS-1 subject, so Validate will need to return it once request auditing lands. The description already defers this; a note in implementation.md would keep it from being lost.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, both points are valid.

  • Execution allowlist: agreed, with the option on the issuer is no longer pinned, so --execution-allowed-subjects matching the subject alone is not enough. Not fixed in this PR yet: we are choosing between refusing --execution-enabled while --oidc-owner-identity=sub_id is on (nothing uses that combination today) and making the allowlist match issuer and subject. I'll follow up here once decided.
  • AS-1's own iss, sub and client_id: implementation.md now records that mecak8s keeps only the sub_id identity for now and that the audit work must also record AS-1's subject and client_id (afc5565).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Decided: the allowlist will match issuer and subject together, like storage_management.principals, tracked in #2521 (blocked by #2487, under the sign-in slice so it lands before the real AS-1 is hosted). Subject-only entries keep working while --oidc-owner-identity is off and are refused with it on.

Comment thread authn/oidc/oidc.go Outdated

// validateOwnerFromSubID requires a non-empty, well-formed client list exactly
// when OwnerFromSubID is on, so neither half is a silent no-op.
func validateOwnerFromSubID(cfg Config) error {

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.

validateOwnerFromSubID doesn't check AllowAnyAudience. A program using this published module could set AllowAnyAudience: true and OwnerFromSubID: true. It would then accept an AS-1 at+jwt minted for a different resource server and give that token the company user's identity. client_id doesn't help here, because it names the client that asked for the token, not the server it was meant for. RFC 9068 §4 says the token MUST be rejected if aud doesn't name the current resource server.

mecak8s and mecated never set AllowAnyAudience, so they aren't affected. Rejecting the combination here, with a constructor test, would close it for other users of the library.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 34c5b65: authn/oidc now refuses the owner option without a configured audience, and with AllowAnyAudience, with constructor tests for both.

{{- if or (eq (trim $scope) "") (not (regexMatch "^[!-~]+$" $scope)) (contains "," $scope) (contains "\"" $scope) (contains "\\" $scope) -}}{{ fail (printf "oidc.scopes entry %q is invalid" $scope) }}{{- end -}}
{{- end -}}
{{- end -}}
{{- if .Values.oidc.ownerFromSubID -}}

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.

The chart doesn't check the new startup rule in cmd/mecak8s/flags.go:670-674. Take a release with extraArgs: [--enable-identity-broker], oidc.enabled: true and ownerFromSubID: false. helm upgrade succeeds, then the new pod exits with --enable-identity-broker with --oidc-issuer requires --oidc-owner-from-sub-id and goes into CrashLoopBackOff, and the rollout stalls on the old pods.

validatePermissionMode already scans extraArgs for --posture and similar flags. The same scan for --enable-identity-broker (and --enable-identity-broker=...) would fail at render time instead. It needs a chart_test case, and a line in the ownerFromSubID comment in values.yaml.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in b4f39de: the chart now fails at render time when extraArgs enables the identity broker (--enable-identity-broker, -enable-identity-broker, =true, =1) with OIDC on and no oidc.ownerIdentity=sub_id; =false, the option set, and OIDC off still render. Chart tests cover each case, and the values.yaml comment mentions the rule.

fs.Func("oidc-accepted-client-ids",
"comma-separated OAuth client IDs whose access tokens --oidc-owner-from-sub-id accepts",
func(raw string) error {
c.AcceptedClientIDs = nil

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.

Passing --oidc-accepted-client-ids more than once keeps only the last value, because this line resets the list on each call. --oidc-accepted-client-ids=tui --oidc-accepted-client-ids=studio accepts only studio, and TUI users get 401s. That's the safe direction to fail, but it is surprising. Either append here or say "last value wins" in the help text.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'd keep last-wins here: it's the standard Go flag behaviour and matches the other list flags (--oidc-scopes, --execution-allowed-subjects), so appending only for this flag would be the surprising one. Related gap fixed in 34c5b65, though: an empty value (--oidc-accepted-client-ids= or ,,) used to become an empty list silently and is now refused at startup, like --oidc-scopes=.

in `--oidc-accepted-client-ids`, and its `sub_id` claim has format `iss_sub`
with a non-empty `iss` and `sub`. The owner is that `iss` and `sub`. When
`--oidc-client-id` is set, the server refuses to start unless that client ID is
also listed in `--oidc-accepted-client-ids`.

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.

This paragraph names only one startup refusal. The server also refuses to start when:

  • --oidc-owner-from-sub-id is set without --oidc-accepted-client-ids (authn/oidc/oidc.go:185),
  • --oidc-accepted-client-ids is set without the owner flag (oidc.go:180),
  • either flag is set without --oidc-issuer (internal/cliconfig/oidc.go:306-307).

Suggested sentence: "The server refuses to start if either flag is set without the other, or without --oidc-issuer."

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 34c5b65: the paragraph is now a list of every startup refusal (either flag without --oidc-issuer, each flag without the other, an advertised --oidc-client-id not in the accepted list, an empty client list, and the mecak8s broker rule). afc5565 added an unknown --oidc-owner-identity value to the list.

**Failures.** Checks 1–7 return HTTP 401 with `WWW-Authenticate: Bearer error="invalid_token"` (RFC 6750 §3.1). The client refreshes its access token and retries once; a second failure is shown to the user. Check 8 returns 404 with the Mecatl API's `session_not_found` error body, the same response as for a session that does not exist, and is not retryable. A 403 would confirm that another user's session exists, so an ownership failure is deliberately indistinguishable from absence; for the same reason, deleting another user's session succeeds and deletes nothing.

**Why.** An `id_token` is not accepted here: its audience is the client, not the API. Session ownership is keyed by the company identity in `sub_id`, not by AS-1's own `(iss, sub)`, so existing owners keep matching without migration and the owner stays Alice's stable human identity.
**Why.** An `id_token` is not accepted here: its audience is the client, not the API. Session ownership is keyed by the company identity in `sub_id`, not by AS-1's own `(iss, sub)`, so existing owners keep matching without migration and the owner stays Alice's stable human identity. That holds only when the IdP gives the same subject across application registrations: an IdP with pairwise subjects per application (for example Microsoft Entra ID) gives AS-1 a different `sub`, so owners must be remapped.

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.

Suggest "the same issuer and subject" rather than "the same subject". Owners match on both values byte for byte, so a differently written issuer also orphans every owner (for example an Entra v1 versus v2 issuer, or a trailing slash). caller-identity.md already says issuer and subject.

Related: implementation.md:13 says two AS-1 subjects never carry the same company identity. Only AS-1 can guarantee that, so it reads better as a requirement on AS-1 than as something mecak8s tests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed: both drafts now say "the same issuer and subject" (34c5b65), and implementation.md states it as a requirement on AS-1: "AS-1 must never issue the same company identity to two of its subjects" (afc5565).

@jhrozek

jhrozek commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

One more thought before this merges, about the setting's name.

stacklok/toolhive#6908 added a second claim next to sub_id: https://toolhive.dev/upstream_subject, shaped {"iss", "claim", "value"}. With an Entra upstream and subject_claim: oid, value is the user's oid. That stays the same across app registrations, while sub_id.sub changes with each one. On Okta, Google and Keycloak, claim is "sub" and value equals sub_id.sub, so keying on it gives the same owner key as this PR does.

On Entra, keying owners on upstream_subject would mean:

  • re-registering AS-1 doesn't orphan every owner;
  • the AS-1/AS-2 consistency check compares the same value for the same person.

Moving owners from mecak8s's own registration still needs a one-time remap, but only once.

Switching would need three things:

  • an allowlist of (iss, claim) pairs, one claim per issuer, defaulting to sub, so that email/upn are never used as owner keys;
  • the same key in AS-1's owner_mismatch check and the AS-2 check (credentials-and-lifecycle.md:788);
  • one claim per deployment, never "whichever is present".

That can be a follow-up. The part that can't wait: --oidc-owner-from-sub-id and oidc.ownerFromSubID become public settings when this ships. Could we give them a neutral name now, for example --oidc-owner-from-upstream-identity, so the follow-up doesn't need a breaking rename?

…empty client list

Address review follow-ups on the sub_id owner option:

- authn/oidc refuses OwnerFromSubID without a configured audience, or
  with AllowAnyAudience, as RFC 9068 section 4 requires.
- --oidc-accepted-client-ids refuses a value with no client IDs, as
  --oidc-scopes already does.
- The Principal proto comments name the sub_id source, matching
  engine/session; regenerated Go, TypeScript, and the gRPC reference.
- Caller identity docs list every startup refusal; the design drafts say
  the same issuer and subject.
- Tests cover a mixed-case typ, non-string sub_id members, and that the
  validator keeps its own copy of the accepted client IDs.

Co-authored-by: Mecatl <[email protected]>
…ntity=sub_id

Replace the unreleased boolean --oidc-owner-from-sub-id (Helm
oidc.ownerFromSubID) with --oidc-owner-identity (Helm
oidc.ownerIdentity), whose only accepted value is sub_id; empty keeps
today's behaviour. A later owner identity, such as ToolHive's
upstream_subject, can then be added as a new value without a breaking
rename. Unknown values fail at startup and in the chart.

Also note in the design drafts that the audit work must record AS-1's
own subject and client_id, state that AS-1 must never issue one company
identity to two subjects, and say that the alg tests pin toolhive-core's
algorithm allowlist.

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

mecak8s refuses --enable-identity-broker with OIDC on unless
--oidc-owner-identity=sub_id is set. The chart now fails at render time
for that combination instead of rendering a pod that crash-loops.

Also document that, with a pairwise-subject IdP, replacing the
authorization server's application registration loses users' access to
their sessions.

Co-authored-by: Mecatl <[email protected]>
@ChrisJBurns

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Fixes for the summary points:

  • Proto Principal description: harness.proto now matches engine/session/principal.go (the token's iss/sub, or those inside an accepted sub_id), with the generated Go, TypeScript, and gRPC reference regenerated (34c5b65). Comment-only.
  • Tests:
    • alg: none / HS256: agreed they only pin toolhive-core's fixed algorithm allowlist; they now say so in a comment (afc5565) rather than claiming to cover this package's code.
    • Added a mixed-case typ (AT+JWT, accepted), non-string sub_id.sub and sub_id.format (rejected), and a test that changes the caller's AcceptedClientIDs after NewValidator and checks the validator kept its own copy (34c5b65).

On the naming comment: done in afc5565. The option is now a value flag, --oidc-owner-identity=sub_id (Helm oidc.ownerIdentity), whose only accepted value is sub_id (empty is off, unknown values are refused), so another identity such as upstream_subject can be added later without a breaking rename. As agreed on Slack, owners stay keyed on sub_id; the docs now say that with a pairwise-subject IdP such as Entra, replacing the authorization server's app registration loses users' access to their sessions (b4f39de).

One point where I read the design differently: credentials-and-lifecycle.md:788 is AS-1's owner_mismatch row, not an AS-2 check, and the current design has AS-2 resolve users by the AS-1 sub (embedded) or a consent link (external), never by upstream identity (credentials-and-lifecycle.md:622, mcp-gateway-modes.md). So keying Mecatl owners on upstream_subject would not by itself make AS-1 and AS-2 compare the same value. I understand you'll change step (8) to key the AS-1/AS-2 user links on upstream_subject in a separate design PR; nothing in this PR depends on that, and the gateway-call work will follow it.

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

Re-approving at b4f39de.

Checked the six earlier inline comments against the new commits:

  • Audience with the owner option: fixed in 34c5b65 (AllowAnyAudience and an empty audience are now refused).
  • Helm broker-in-extraArgs crash loop: fixed in b4f39de (fails at render time).
  • Startup-refusal docs and "issuer and subject" wording: fixed.
  • Repeated --oidc-accepted-client-ids: last-wins kept, consistent with the other list flags. Fine by me.
  • Execution allowlist matching subject only: still open, tracked in #2521. Please make sure it lands before the real AS-1 is hosted.

The stale Principal comment in harness.proto is also updated.

@ChrisJBurns
ChrisJBurns merged commit 5591b76 into main Oct 26, 2026
45 checks passed
@ChrisJBurns
ChrisJBurns deleted the feat/identitybroker-sign-in-ownership branch October 26, 2026 15:00
@toolhive-release-app toolhive-release-app Bot mentioned this pull request Oct 26, 2026
2 tasks
jhrozek added a commit that referenced this pull request Oct 26, 2026
Define how a delegated client such as Mecatl's broker uses a user's
existing gateway connections: what AS-1 issues, how AS-2 decides which
local user and whether the client may act for them, and what the gateway
reads. The ToolHive side is tracked in stacklok/toolhive#6886 (issuing),

AS-1 (credentials-and-lifecycle.md, steps 4 and 7)
- AS-1 confirms the acting agent through ToolHive's pluggable actor-token
  validator (stacklok/toolhive#6899). Mecatl's implementation runs in the
  broker against its instance registry and returns the agent's ag_
  identifier; AS-1 puts it in act.sub and caps the ID-JAG's exp at the
  SVID's. Why: AS-1 is ToolHive's server and cannot read Mecatl's
  registry, and the SVID carries only the claims JWT-SVID requires.
- "Does not prove" now says the agent check is the broker checking its
  own registry. A built-in JWT-SVID validator with a session claim stays
  later work, for an AS-1 that runs apart from the broker.
- The agent-instance issuer and the broker client each keep their own
  key, as "one key per role" already requires. Where SPIFFE client
  authentication is enabled, no client's SPIFFE ID may fall in the agent
  trust domain, or an SVID could pass as a client assertion.

AS-2 (credentials-and-lifecycle.md step 8, mcp-gateway-modes.md)
- Redemption maps the source user to a local user and checks approval:
  implicit in embedded mode; in external mode the local user is the one
  whose shared-login identity is the ID-JAG's upstream_subject, trusted
  only because the approval compared it with AS-2's own login (ID-JAG
  section 9.5).
- An approval is one row per (gateway, local user, client, actor_iss),
  required actor_iss, no stored copy of AS-1's subject. Why: storing the
  source subject per approval allowed two rows to map one source user to
  different local users.
- The actor rule: only the top-level act counts; an act without iss uses
  the token's iss; no act means no actor.
- The embedded AS-2 accepts each ID-JAG from AS-1 once, and external
  gateways are recommended to do the same. It costs nothing because the
  broker never re-submits, and a stolen ID-JAG redeemed first by a holder
  of the broker key shows up as a failure of the broker's own redemption.
  ToolHive's general default (re-submission until exp for new issuers) is
  unchanged. Single-use leftovers in README, gateway modes, audit and the
  failure matrix are corrected.
- V from an approved redemption carries the delegated-access marker
  (stacklok/toolhive#6404), is terminal as subject and actor token, and is
  the only thing that reaches the user-keyed read; a missing tsid or an
  act claim never stands in for it.
- The vMCP binds a session to iss, sub, client_id, act.iss, act.sub and
  the marker, consistently in step 9 and "Sessions at the vMCP".

Approval link (implementation.md "External consent link")
- AS-2 refuses an unapproved ID-JAG with consent_required and an
  error_uri to a pending approval, under a profile AS-2 advertises in its
  metadata. Mecatl shows AS-2's own link; it adds no callback, state or
  PKCE, and resumes by redeeming a new ID-JAG.
- On approval AS-2 compares the company IdP identity the user signed in
  with against the ID-JAG's, activates on a match and discards the
  pending approval on a mismatch. Why: this stops link swapping without
  a browser, so it also covers CLI and cross-device use, while a Mecatl
  callback needed a web session Mecatl does not have and did not stop a
  forwarded link anyway.
- AS-2 offers user approval only for issuers that share its company IdP;
  otherwise plain invalid_grant and no link, leaving administrator
  pre-approval. The broker shows an error_uri only from a gateway that
  advertises the profile, on AS-2's https origin.

Ledger and tests (implementation.md)
- The ToolHive work list links the posted issues instead of "no issue
  covers it": #6887, #6404, #6407, #6885, #6888, #6892 and the #6886
  sub-issues (#6893-#6900); #6894 and #6900 are marked done.
- Tests cover the approval comparison, the marker, re-submission policy,
  the actor rule and the validator.
- Removed: issue triage pinned to a commit, a costs paragraph that
  repeated the table, and duplicated explanations.

Identifying claim (credentials-and-lifecycle.md "Identifying claim")
- Two claims identify a user and answer different questions. Session
  ownership stays on sub_id, as merged in #2497: only AS-1's application
  registration is involved, so a per-application sub is enough. The
  gateway uses upstream_subject, configured per company IdP as ToolHive's
  subject claim at AS-1 and AS-2 (oid for Entra, sub where it is the same
  across applications), because AS-1 and AS-2 are different registrations.
- On Entra, replacing AS-1's registration orphans sessions until owners
  are remapped; the section says so, and moving ownership to
  upstream_subject is listed as later work.

threat-model.md and audit.md follow the same terms.

Terminology: new text calls the stored record an "approval" (it can come
from the user or an administrator). Existing lines that say "consent link"
are left unchanged to keep this diff reviewable; a mechanical rename can
follow separately.

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

This branch was successfully deployed

1 active deployment
Preview — b4f39de5 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Session ownership from the AS-1 sign-in

2 participants