Skip to content

feat(api): let a person create personal access tokens for agents and CI - #3556

Closed
fforootd wants to merge 20 commits into
claude/personal-access-tokens-adrfrom
claude/personal-access-tokens
Closed

fforootd wants to merge 20 commits into
claude/personal-access-tokens-adrfrom
claude/personal-access-tokens

Conversation

@fforootd

@fforootd fforootd commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Superseded

This draft showed the writing session's whole working branch (claude/personal-access-tokens), which grew to hold four separate changes. That branch is finished, and it was cut into one pull request per change. The cut loses nothing: the top of the new stack has exactly this branch's final tree (609f1eef1), checked with git diff.

CI's full-pr was green on this branch's last head. Review and merge the four above instead; this one is closed without merging.

https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U


Generated by Claude Code

A person homed in the platform project creates a PAT with
createMyPersonalAccessToken (POST /users/me/personal_access_tokens), lists
and revokes their own with listMyPersonalAccessTokens and
revokeMyPersonalAccessToken, from a Console session, an access token issued
for them, or (to list and revoke) a PAT (ADR 095).

A PAT reads zpat_<id>_<secret><checksum>: a 256-bit random secret whose
SHA-256 the tokens record keeps, found by the record id and compared in
constant time; a wrong checksum is refused before any read. The API and the
MCP endpoint take it on the operations an access token issued for a person
reaches, through the same gate: its owner is the principal, its scopes a
ceiling on the owner's grants at each call, and a refusal names the scope.
It expires within 90 days and stops while its owner is not active.

Creating one with an access token needs personal_access_token.create, which
consent never preselects; the PAT holds no scope that token lacks and records
its client. A PAT never creates one. Events of a PAT's calls name the owner
as a human actor, the PAT as token_id and pat_shared as delegation_type.

tokens gains name, secret_hash and client_id in the three dialects. The MCP
tool list budget is raised by the three tools' 3,700 bytes until the change
that makes room in it lands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf
Creating a PAT is a marked call with a scope of its own, so ADR 094 §5's
rule fits it: the scope is the gate, and the MCP endpoint asks where the
client can answer once it asks about marked calls at all.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf
@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 9:23am UTC

Request Review

@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

🦋 Changeset detected

Latest commit: 609f1ee

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/cli Minor
@zitadel/api Minor
@zitadel/testing 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/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 CLI signs in to the platform issuer with "<issuer>/cli-client.json" as
its client ID. The issuer serves that document, and the client directory
answers that one URL from memory instead of fetching it, so the CLI signs
in to a local or self-hosted server with no outside host. The document is
read like any client's: a public client with a loopback redirect and PKCE,
never first-party, so the person sees the consent step. It is served on
the platform issuer only, where oauth.client_documents is on, and is not
held to oauth.client_document_hosts, which names whose documents may be
fetched. Every other URL on the server's own origin still names no client.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf
… from the API mock

The mock answers createMyPersonalAccessToken, listMyPersonalAccessTokens and
revokeMyPersonalAccessToken for the bearer that sent them, as the server
answers a person's own, and refuses what the server refuses: no credential,
a PAT creating a PAT, the create scope, an expiry past 90 days. It also
serves the MCP endpoint's protected-resource metadata and the platform
issuer's metadata, which `zitadel login` reads to find where to sign in.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf
`zitadel login` signs a person in to a server's platform issuer in their
browser: the authorization code flow with PKCE and a loopback redirect, as
the client whose document the issuer serves at <issuer>/cli-client.json. The
person consents on the server's own page, where only reads start ticked.
The link is printed for an agent to hand on, and a browser opens unless
--no-open. The sign-in is kept per server in the CLI's config directory,
mode 0600, and refreshed under a lock so no two runs present one refresh
token.

`zitadel pat create|list|revoke` act as the signed-in person: create holds
the token to the scopes the sign-in holds and to 90 days, and prints it
once. `zitadel logout` forgets the sign-in; the server has no endpoint that
ends the grant yet, so it says so.

The sign-in's OAuth requests go through one file, which the no-raw-fetch
rule allows: they are no operation of the API and carry none of its
credentials.

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

A first-party client is asked no consent, so it would be granted
personal_access_token.create unasked, and with it a credential that
outlives its grant. The scope is now granted only on the consent step,
whoever the client is.

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

PATs were served wherever the platform project is, outside oauth.enabled,
so a server that took no person's bearer before would take a PAT after.
personal_access_tokens.enabled (NEXTGEN_PERSONAL_ACCESS_TOKENS_ENABLED) now
switches them on, off by default as oauth.enabled is. Off, the three
operations answer not_implemented and a zpat_ bearer is refused as an
unknown one.

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

A credential that is only ever added to is one nobody reviews. Creating a
51st live PAT is refused with tkn.pat_invalid until the person revokes one.
Expired rows stay until a purge, which is a follow-up, and are not counted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf
A PAT leaves the audience of the token that created it: a token issued for
the MCP endpoint creates one through the endpoint, and the PAT then
answers on the API directly, where the endpoint's questions do not reach.
createMyPersonalAccessToken is now marked x-zitadel-asks: the endpoint asks
the person where the client can ask them, and sends the call where it
cannot, its own scope, ticked on purpose, being the gate (ADR 094 §5). The
tool says so, at 84 bytes, which the list budget's raise now counts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf
The endpoint now asks before createMyPersonalAccessToken where the client
can ask, so the agent's client in the integration test answers as its
person would, and the test holds that the person was asked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf
A project secret's scopes cover the three operations on a person's own
PATs, so the MCP endpoint listed them as tools that could only be refused.
No secret is anyone's person: Covers now passes them over for a secret.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf
PATs are off until personal_access_tokens.enabled switches them on, since
they do open a bearer path a server without OAuth did not have, and §7 no
longer says otherwise. The create scope is never granted without the
consent step, and the MCP endpoint asks before a PAT is created where the
client can. A person holds at most 50 live PATs. The risks now name the
audience a PAT leaves and the Console session that outlives recovery,
with the options and a recommendation for the latter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf
A PAT is persisted only with its secret's hash, and the Postgres dialect's
own token test still created one without it, which the Postgres lane
refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf
The API reference shows the command behind each operation, and the CLI's
coverage test holds every operation to a command that calls it: the three
personal access token operations now name pat create, pat list and pat
revoke, which call them through the person's own sign-in.

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

The CLI names a command's noun after the collection the API lists, and
answers to its plural: the list operation returns personal_access_tokens,
so the commands are personal-access-token create, list and revoke, and
answer to personal-access-tokens too. The topic gets its description in
root help, which the longer noun widens.

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

This branch was successfully deployed

1 active deployment
Preview — 609f1eef 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.

2 participants