Skip to content

feat(api): let a person's token read who they are and which projects they can act on - #3559

Merged
fforootd merged 4 commits into
mainfrom
claude/my-reads-person-token
Dec 2, 2026
Merged

fforootd merged 4 commits into
mainfrom
claude/my-reads-person-token

Conversation

@fforootd

@fforootd fforootd commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Context

Summary

  • The gap: an agent signed in to the MCP endpoint as a person could not ask who it acts for or which projects that person can work on. The /users/me reads took only a session cookie, and search was the workaround.

  • The reads: getMyUser, listMyProjects, listMyTeams, getMyUserSchema, listMyPasskeys, listMyIdentityLinks and getMyPasswordState take a token issued for the person, each under the read scope of what it returns:

    Operation Scope
    getMyUser, listMyPasskeys, listMyIdentityLinks, getMyPasswordState user.read
    listMyProjects project.read
    listMyTeams team.read
    getMyUserSchema schema.read

    Without the scope: 403 auth.scope_insufficient, naming it. A token is held to its project as a session is (sess.project_mismatch). All four scopes were already scopes a person's token can use, so the consent screen and the endpoint's metadata do not change.

  • A project secret is no person. On these reads the security handler passes over a secret before it looks at it (ErrSkipServerSecurity), so it is answered exactly as before: 401, as a request without a credential. BearerCredential.Covers keeps their tools from a secret, which could only refuse.

  • The spec says it: x-zitadel-self: true marks the eleven self-service operations (/users/me, /sessions/me). A test holds the gate contract's self-service class and the server's personOwnOperations to the marker. The CLI and the docs read it:

    • @zitadel/api's operation list gets auth: "person", and the CLI, which holds a project secret, refuses those operations with a reason instead of sending its secret and reading the 401 as a bad secret. SKILL.md says so.
    • The docs keep the browser sample for these reads; their bearer branch is a person's token, never ZITADEL_PROJECT_SECRET.
  • MCP: a person's token with the scope is shown the tools. Their project_id (the session-project-id parameter, which holds a browser's cookie to the app's project) is no tool argument: a bearer belongs to one project, so it could only refuse, and an agent would read it as the project to act on. The instructions now say: "Signed in as a person, start with getMyUser, which says who they are, then listMyProjects, the projects they can act on, to learn where their work is."

  • Tool list: 7 tools, 5,142 bytes. listBudget rises from 142,000 to 147,142, by that and no more. A project secret is still shown 79 tools, 141,563 bytes; a person's token with every scope 65 (88,512). All seven land in the list of a credential with every .read scope.

  • Unchanged: updateMyUser, getMySession, revokeMySession, getMySessionCsrfToken, the invitation and claim operations. listMyProjects answers what it answered before; each project's access is §10, step 6.

Validation

Run by the session that wrote the change, in its cloud container:

  • go test ./internal/api/ ./internal/mcp/: new TestAPersonsTokenReadsWhatIsTheirOwn, TestASecretIsNoPersonOnAPersonsOwnRead, TestPersonOwnOperationsAreSelfService, TestNoToolTakesTheSessionsProject; TestSelfServiceHoldsTheSessionToItsProject now also holds a token to its project.
  • go test -tags sqlite_integration ./internal/api/integration_test/ ./internal/api/integration_test/helpers/ ./internal/bootstrap/platform/: passes. New TestAccessTokenReadsWhatIsThePersonsOwn (each read, over HTTP: with the scope the token answers what the cookie answers; without it auth.scope_insufficient naming it; another project sess.project_mismatch; a project secret answers what a request with no credential answers) and MCP subtests (a person's token is shown and calls the tools; a secret is shown none and is refused). Without the server change, getMyUser and all three MCP claims fail.
  • go test ./... in apps/api passes (with the Console built for cmd/server).
  • turbo run lint --filter=@zitadel/server passes (check-generate, Redocly, Go lint). turbo run format flags internal/flowengine/sso_test.go, which this does not touch: the container's gofmt formats it differently than main's.
  • pnpm run check-openapi-rules, turbo run test --filter=@zitadel/api-mock and turbo run typecheck --filter=@zitadel/docs (compiles every SDK sample) pass.
  • CLI: npx vitest run in apps/cli on this branch and on clean main, failures diffed. The same 98 terminal, spinner and local-runtime tests fail on both in that container. The one this change broke, tests/integration/api.spec.ts pinning getMyUser's old reason, is fixed in the second commit; the other two differences pass when run alone.
  • Not run there: the docs' Playwright lanes and the Postgres and Spanner lanes. CI's full-pr runs Postgres. The Spanner lane (spanner.yml, Spanner Omni) is not one of a pull request's checks: it runs weekly on main and on dispatch, and has not run on this branch.
  • After CI's first run: the docs' pages.spec.ts keeps its own copy of the rule for which operations the CLI calls and expected a zitadel api getMyUser sample. It now reads x-zitadel-self, as the docs' samples do; verified against a built docs site and in CI.

Checked when opening this draft: node scripts/check-pr-title.mjs --title "…" passes, and I read the security handler's change. I did not rerun the suites.

Release notes / changeset

  • Changeset: .changeset/api-person-token.md (pending, unreleased), extended: a person's own reads take such a token; the MCP endpoint's instructions; Breaking for the Go client: the 403 of the seven reads is now an error with a Code (GetMyUserForbidden and so on, or ErrorDetails) in place of SessProjectMismatch.

Notes

  • Decisions taken for review, each built as recommended with the alternative small:
    • x-zitadel-self marks a person's own operations in the spec. Alternative: a separate security scheme for a person's token, which would touch the generated server and every reader of oauth2.
    • A project secret is answered as before (401, as without a credential). Alternative: a 403 that says a secret is no person, a change for existing secret callers.
    • listBudget grows by the seven tools' weight. That raise is dropped when feat(api): let an MCP client choose tool sets, and reads only, by its URL #3555 (tool sets by URL) lands, which replaces the budget; under its numbers the read list stays well below 80,000 bytes.
  • Go client: the 403 type of these reads changes (above). The wire body is unchanged.
  • Written in the session https://claude.ai/code/session_0137eGmTvJjKuUM2VnUUGH9Y; the draft was opened by the coordinating session below.

https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U


Generated by Claude Code

…they can act on

An agent signed in to the MCP endpoint as a person could not ask who it
acts for or which projects that person can work on: the /users/me reads
took only a session cookie (ADR 094 §6, step 1 of §12).

- getMyUser, listMyProjects, listMyTeams, getMyUserSchema,
  listMyPasskeys, listMyIdentityLinks and getMyPasswordState take a
  token issued for the person, each under the read scope of what it
  returns (user.read, project.read, team.read, schema.read). Without it
  the token is refused with 403 auth.scope_insufficient naming the scope.
  The token is held to its project as a session is (sess.project_mismatch).
- A project secret is no person: on these reads the API passes over it
  before looking at it, so it is answered exactly as before, as a request
  without a credential, and the MCP endpoint shows it none of their tools.
- The spec marks a person's own operations x-zitadel-self. The CLI, which
  holds a project secret, refuses them with a reason, and the docs' sample
  for their bearer branch is a person's token, never a project secret.
- Their tools take no project_id: that parameter holds a browser's session
  to the project of the app that sends the cookie, which a bearer never
  needs, and an agent would read it as the project to act on.
- The endpoint's instructions tell an agent signed in as a person to start
  with getMyUser, then listMyProjects.
- The tool list's budget grows by the seven tools' 5,142 bytes. A project
  secret is still shown 79 tools (141,563 bytes); a person's token with
  every scope 65 (88,512).
- The 403 of the seven is now an error with a code in the Go client, in
  place of SessProjectMismatch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmTvJjKuUM2VnUUGH9Y
getMyUser now takes a person's token as well as their session, so the
CLI refuses it as an operation that reads the person who calls it; the
session-cookie-only case is pinned on updateMyUser.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmTvJjKuUM2VnUUGH9Y
@vercel

vercel Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cloud Ready Ready Preview Dec 2, 2026 3:19pm UTC

Request Review

@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

🦋 Changeset detected

Latest commit: a694ee2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 27 packages
Name Type
@zitadel/server Minor
@zitadel/api Minor
@zitadel/cli Minor
@zitadel/components Minor
@zitadel/config Minor
@zitadel/sdk-angular Minor
@zitadel/sdk-core Minor
@zitadel/sdk-next Minor
@zitadel/sdk-nuxt Minor
@zitadel/sdk-qwik Minor
@zitadel/sdk-react Minor
@zitadel/sdk-solid Minor
@zitadel/sdk-svelte Minor
@zitadel/sdk-tanstack-start Minor
@zitadel/sdk-vue Minor
@zitadel/testing Minor
@zitadel/cloud Patch
@zitadel/client-sdk-contract Patch
@zitadel/sdk-qwik-router Minor
@zitadel/sdk-solid-start Minor
@zitadel/sdk-sveltekit Minor
@zitadel/server-sdk-contract Patch
@zitadel/server-darwin-arm64 Minor
@zitadel/server-darwin-x64 Minor
@zitadel/server-linux-arm64 Minor
@zitadel/server-linux-x64 Minor
@zitadel/server-win32-x64 Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

The page test keeps its own rule for which operations the CLI calls:
one that names no bearer scheme is a session's. A person's own read now
names one, for a person's token, but takes no project secret, which the
CLI holds, so the test reads x-zitadel-self as the docs' samples do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmTvJjKuUM2VnUUGH9Y
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ✅ Completed 2026-12-02T14:13:57.682067Z ca9d675 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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

The breaking-change instructions omit additional Go client response-type replacements that can cause existing type switches and assertions to stop compiling.

1 open issue
What changed in this PR

Enables scoped personal tokens to read the caller’s identity and accessible projects through the API and MCP, while preserving project boundaries and rejecting project secrets on these reads.

Changes:

  • Adds personal-token authentication to seven self-service reads.
  • Updates MCP discovery, CLI refusals, documentation samples, and contract tests.
  • Regenerates OpenAPI and Go bindings, including changed error response types.
File Description
packages/​go/​api/​oas_security_gen.go Adds self-read scope mappings.
packages/​go/​api/​oas_schemas_gen.go Updates generated error types.
packages/​go/​api/​oas_response_decoders_gen.go Decodes updated response types.
packages/​go/​api/​oas_json_gen.go Adds error serialization support.
packages/​go/​api/​oas_client_gen.go Adds OAuth authentication alternatives.
packages/​api/​scripts/​operations.ts Classifies personal authentication.
docs/​design/​api/​system-permission-catalog.md Documents self-read scope boundaries.
docs/​adrs/​094-project-permission-model.md Records implemented personal reads.
docs/​adrs/​092-mcp-server.md Updates tool eligibility and budgets.
apps/​docs/​tests/​pages.spec.ts Adjusts CLI sample expectations.
apps/​docs/​lib/​sdk-sample.ts Generates personal-token samples.
apps/​cli/​tests/​unit/​lib/​backend/​services/​operation.test.ts Tests personal-operation refusals.
apps/​cli/​tests/​integration/​api.spec.ts Verifies CLI refusal envelopes.
apps/​cli/​src/​lib/​backend/​services/​operation.ts Explains personal-operation refusals.
apps/​cli/​skills/​zitadel-cli/​SKILL.md Documents CLI restrictions.
apps/​api/​internal/​mcp/​handler.go Adds identity-discovery guidance.
apps/​api/​internal/​mcp/​catalog.go Offers bearer tools without session-project arguments.
apps/​api/​internal/​mcp/​catalog_test.go Tests tool schemas and budget.
apps/​api/​internal/​api/​security.go Accepts personal tokens and skips secrets on self-reads.
apps/​api/​internal/​api/​security_access_token_test.go Tests credential and scope boundaries.
apps/​api/​internal/​api/​integration_test/​user_test.go Updates error-type assertions.
apps/​api/​internal/​api/​integration_test/​mcp_test.go Verifies project-secret tool exclusions.
apps/​api/​internal/​api/​integration_test/​access_token_test.go Tests personal reads over HTTP and MCP.
apps/​api/​internal/​api/​generated/​oas_unimplemented_gen.go Refreshes generated operation comments.
apps/​api/​internal/​api/​generated/​oas_server_gen.go Refreshes handler interface comments.
apps/​api/​internal/​api/​generated/​oas_security_gen.go Adds server scope mappings.
apps/​api/​internal/​api/​generated/​oas_router_gen.go Allows Authorization headers on self-reads.
apps/​api/​internal/​api/​generated/​oas_response_encoders_gen.go Encodes updated error response types.
apps/​api/​internal/​api/​generated/​oas_json_gen.go Adds generated error serialization.
apps/​api/​internal/​api/​generated/​oas_handlers_gen.go Adds OAuth security checks.
apps/​api/​internal/​api/​authz_ungated_contract_internal_test.go Tests self-service markers and project boundaries.
apps/​api/​internal/​api/​authz_contract_internal_test.go Reads self-service markers in contract tests.
apps/​api/​api/​openapi/​endpoints/​users/​me/​teams/​methods.yaml Adds scoped personal team reads.
apps/​api/​api/​openapi/​endpoints/​users/​me/​teams/​listMyTeams-error-response.yaml Adds insufficient-scope errors.
apps/​api/​api/​openapi/​endpoints/​users/​me/​schema/​methods.yaml Adds scoped personal schema reads.
apps/​api/​api/​openapi/​endpoints/​users/​me/​schema/​getMyUserSchema-error-response.yaml Adds insufficient-scope errors.
apps/​api/​api/​openapi/​endpoints/​users/​me/​projects/​methods.yaml Adds scoped personal project discovery.
apps/​api/​api/​openapi/​endpoints/​users/​me/​projects/​listMyProjects-error-response.yaml Adds insufficient-scope errors.
apps/​api/​api/​openapi/​endpoints/​users/​me/​password/​methods.yaml Adds scoped password-state reads.
apps/​api/​api/​openapi/​endpoints/​users/​me/​password/​getMyPasswordState-error-response.yaml Adds insufficient-scope errors.
apps/​api/​api/​openapi/​endpoints/​users/​me/​passkeys/​methods.yaml Adds scoped personal passkey reads.
apps/​api/​api/​openapi/​endpoints/​users/​me/​passkeys/​listMyPasskeys-error-response.yaml Adds insufficient-scope errors.
apps/​api/​api/​openapi/​endpoints/​users/​me/​methods.yaml Adds personal user reads and self-service markers.
apps/​api/​api/​openapi/​endpoints/​users/​me/​identity_links/​methods.yaml Adds scoped identity-link reads.
apps/​api/​api/​openapi/​endpoints/​users/​me/​identity_links/​listMyIdentityLinks-error-response.yaml Adds insufficient-scope errors.
apps/​api/​api/​openapi/​endpoints/​users/​me/​getMyUser-error-response.yaml Adds insufficient-scope errors.
apps/​api/​api/​openapi/​endpoints/​sessions/​me/​methods.yaml Marks session operations as self-service.
apps/​api/​api/​openapi/​endpoints/​sessions/​me/​csrf/​methods.yaml Marks CSRF retrieval as self-service.
apps/​api/​api/​openapi/​bundled/​openapi.json Refreshes the bundled contract.
apps/​api/​api/​openapi/​AGENTS.md Documents self-service marker conventions.
.changeset/​api-person-token.md Adds release notes and Go migration guidance.

Review effort: Balanced

With `oauth.enabled`, the management API takes an access token the platform project's issuer signed for a person, as a bearer. The person acts with the grants their Console session has, on the operations a Console session may call, and the token's scopes are a ceiling on them: an operation that names a scope the token was not issued with answers `403` with the new error code `auth.scope_insufficient`, which those operations now list. The token ends when the person's session does. The platform project's issuer signs such a token for an authorization request that names the API with `resource` (RFC 8707), by the API's URL or the MCP endpoint's, with the scopes of the API it asks for: a resource the issuer has no API for answers `invalid_target`, and a scope the API does not define `invalid_scope`. `project.read` on such a token covers the reads of the project that name `project.write`. Through `search` it finds only the types whose read scope it also carries, such as `user.read` for users, and is refused with `auth.scope_insufficient` on any other. The invitation operations name the grant scopes in place of `project.write`, since an invitation ends in a grant: `grant.create` to create one, `grant.read` to read and `grant.delete` to cancel, with `user.read` for `expand=inviter`, and a replace with `replaces_invitation_id` needs `grant.delete` as well, plus `grant.read` when it sends no `metadata`; a project secret is unaffected, as its `project.write` covers every scope. An `expand` that reads another resource needs that resource's scope on such a token: `user.read` for a grant's `principal`, an invitation's `inviter` and a schema's `in_use`, `schema.read` for a flow definition's `user_schema`. The MCP endpoint shows such a token the tools its scopes cover, takes a token issued for the endpoint itself, which the API takes on the endpoint's calls only, and serves its protected-resource metadata (RFC 9728) at `/.well-known/oauth-protected-resource/api/v1/mcp`, named in the challenge of a `401`.
With `oauth.enabled`, the management API takes an access token the platform project's issuer signed for a person, as a bearer. The person acts with the grants their Console session has, on the operations a Console session may call, and the token's scopes are a ceiling on them: an operation that names a scope the token was not issued with answers `403` with the new error code `auth.scope_insufficient`, which those operations now list. The token ends when the person's session does. The platform project's issuer signs such a token for an authorization request that names the API with `resource` (RFC 8707), by the API's URL or the MCP endpoint's, with the scopes of the API it asks for: a resource the issuer has no API for answers `invalid_target`, and a scope the API does not define `invalid_scope`. `project.read` on such a token covers the reads of the project that name `project.write`. Through `search` it finds only the types whose read scope it also carries, such as `user.read` for users, and is refused with `auth.scope_insufficient` on any other. The invitation operations name the grant scopes in place of `project.write`, since an invitation ends in a grant: `grant.create` to create one, `grant.read` to read and `grant.delete` to cancel, with `user.read` for `expand=inviter`, and a replace with `replaces_invitation_id` needs `grant.delete` as well, plus `grant.read` when it sends no `metadata`; a project secret is unaffected, as its `project.write` covers every scope. An `expand` that reads another resource needs that resource's scope on such a token: `user.read` for a grant's `principal`, an invitation's `inviter` and a schema's `in_use`, `schema.read` for a flow definition's `user_schema`. A person's own reads take such a token too, each under the read scope of what it returns: `GET /users/me` and its `password`, `passkeys` and `identity_links` with `user.read`, `/users/me/projects` with `project.read`, `/users/me/teams` with `team.read` and `/users/me/schema` with `schema.read`; a project secret is answered on them as before. The MCP endpoint shows such a token the tools its scopes cover, takes a token issued for the endpoint itself, which the API takes on the endpoint's calls only, and serves its protected-resource metadata (RFC 9728) at `/.well-known/oauth-protected-resource/api/v1/mcp`, named in the challenge of a `401`. Its instructions tell an agent signed in as a person to start with `getMyUser`, then `listMyProjects`.

**Breaking:** in the Go client, the `403` of those seven `/users/me` reads is now an error with a `Code`, `sess.project_mismatch` or `auth.scope_insufficient` (`GetMyUserForbidden`, `ListMyProjectsForbidden` and so on, or `ErrorDetails`), in place of `SessProjectMismatch`. Switch on its `Code`.
fforootd pushed a commit that referenced this pull request Dec 2, 2026
…o the policy work

A remembered consent holds the person's answer for every scope offered,
yes or no, so a client that asks for everything skips the step once the
person answered, and is issued the scopes answered yes. A scope that is
never remembered no longer forces the step: a skip does not issue it.
A declined scope is asked for again with prompt=consent after the API's
auth.scope_insufficient refusal. How long a consent lasts, and whether
use renews it, is left open for the policy work; the me operations
become two tools once #3559 lands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmUEzNb3SNs7Rj5USYf
main replaced the one budget on the whole tool list with three checks
(#3555), so the raise this branch made to that budget goes. A person's
own reads fit them: 86 tools on a plain URL, and 50 tools, 66,412 bytes,
on the list a default consent yields. The tool-set tests expect the own
reads in the users set, and ADR 092's measured figures say so.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
@fforootd
fforootd enabled auto-merge December 2, 2026 15:16
@fforootd
fforootd added this pull request to the merge queue Dec 2, 2026
fforootd pushed a commit that referenced this pull request Dec 2, 2026
The Enable OAuth guide says which clients are asked once and which every
time, and how a person lists and revokes a consent. ADR 082's amendment
says the me operations take the session cookie until #3559 lets them
take a person's token. The changeset covers the three code pieces.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmUEzNb3SNs7Rj5USYf
Merged via the queue into main with commit 01a93a7 Dec 2, 2026
17 checks passed
@fforootd
fforootd deleted the claude/my-reads-person-token branch December 2, 2026 15:34
@github-project-automation github-project-automation Bot moved this from Inbox to Done in Engineering Kanban Dec 2, 2026
fforootd pushed a commit that referenced this pull request Dec 2, 2026
main holds this branch's base as one squash commit (#3559). Its tree is the base's final head merged with the main before it, which this branch already holds, so the squash is recorded as merged and nothing changes.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
fforootd pushed a commit that referenced this pull request Dec 2, 2026
main gained a person's own reads (#3559), the client secret's rotation (#3561), the session type (#3551) and the CLI's client document (#3558). The personal access token migrations move behind the session type's (Postgres 64, Spanner 68, SQLite 51). A secret is refused on a person's own reads and on their personal access tokens alike, and the server's code is generated again from the merged spec. The tool-set tests expect the three token tools in the users set.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
fforootd pushed a commit that referenced this pull request Dec 2, 2026
main renumbered the migrations (#3551) and marks a person's own
operations x-zitadel-self (#3559, #3560). listMyConsents takes the mark
and a person's token with user.read; revokeMyConsent takes the mark and
stays with the session cookie, as revokeMySession does. Generated files
regenerated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmUEzNb3SNs7Rj5USYf

This branch was successfully deployed

1 active deployment
Preview — a694ee2e Deployed Dec 2, 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

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants