Skip to content

feat(api): serve the CLI's client document on the platform issuer - #3558

Merged
fforootd merged 3 commits into
mainfrom
claude/cli-client-document
Dec 2, 2026
Merged

fforootd merged 3 commits into
mainfrom
claude/cli-client-document

Conversation

@fforootd

@fforootd fforootd commented Dec 2, 2026

Copy link
Copy Markdown
Member

Context

The zitadel CLI has no sign-in: it works from the project secret zitadel setup writes. To sign a person in, the CLI needs an OAuth client the platform issuer knows. A client ID metadata document at an outside host would need a domain decision and a server that can reach that host, which a local or air-gapped server cannot.

Summary

  • The platform project's issuer serves the CLI's client ID metadata document at /oauth/cli-client.json and accepts that URL as a client ID. The CLI builds the URL from the issuer the server's metadata names, so it works against any server, a local one on plain http included.
  • The client directory answers that one exact string from memory (ClientDirectory.ServeCLIClient). Nothing is fetched. Every other URL on the server's own origin, the same URL spelled with :443 included, still names no client, and no fetch of a loopback or private address is opened up.
  • The document goes through the same ParseClientDocument as any outside one: a public client, redirect http://127.0.0.1/callback on any port (RFC 8252), PKCE, the code and refresh grants. It is never first-party, so the person always sees the consent step.
  • It is served only on the platform issuer, and only where oauth.client_documents is on (the default).

Validation

Run by the session that wrote the change, in its cloud container. Its tests show: the directory serves the CLI from memory while the document reader and the policy would refuse it if asked; a caller's mutation does not leak into later answers; the CLI is refused on a customer project's issuer, with client_documents off, and when the admission errors; the platform issuer serves the document at the URL it names; there is no document without a platform project.

Run again when opening this draft, on the commit cherry-picked onto current main:

  • go build ./... in apps/api
  • go test ./internal/oauth/ ./internal/service/ ./internal/domain/
  • go test ./cmd/server/ -run 'CLI|Client|OAuth'
  • node scripts/check-pr-title.mjs --title "…"

Release notes / changeset

  • Changeset: .changeset/cli-client-document.md (@zitadel/server, minor).

Notes

  • Decision taken for review: the CLI is not held to oauth.client_document_hosts. That list names the outside hosts whose documents may be fetched, and nothing is fetched here; holding the CLI to it would refuse the CLI wherever an operator lists hosts, the hosted cloud included. The alternative is to require operators to add their own host to that list. An operator who wants no CLI sign-in turns oauth.client_documents off, which also turns off every other document client.
  • Why not an outside document or a built-in client: see Context. The choice of client is in one place and can change before a release.
  • Conflicts to expect: feat(api)!: name the platform issuer's first-party clients in the server's configuration #3553 (the platform issuer's first-party clients) edits client_directory.go and cmd/server/server.go too. The two do not overlap in behaviour; whichever lands second resolves the text.
  • Not here: the CLI's login, logout and pat commands follow in their own pull request. The server has no token revocation endpoint yet, so a logout can only forget the sign-in on the device.
  • Independent of the personal access token implementation (feat(api): let a person create personal access tokens for agents and CI #3556); the commit was cherry-picked from the writing session's branch, where it sits on top of it.
  • Written in the session https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf; the draft was opened by the coordinating session below.

Generated by Claude Code

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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmS8uCXd1d5jCxWaiSf
(cherry picked from commit 71f5457)
@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:30pm UTC

Request Review

@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

🦋 Changeset detected

Latest commit: 726d62d

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/testing Minor
@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
@zitadel/api 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-qwik-router Minor
@zitadel/sdk-react Minor
@zitadel/sdk-solid Minor
@zitadel/sdk-solid-start Minor
@zitadel/sdk-svelte Minor
@zitadel/sdk-sveltekit Minor
@zitadel/sdk-tanstack-start Minor
@zitadel/sdk-vue Minor
@zitadel/cloud Patch
@zitadel/client-sdk-contract Patch
@zitadel/server-sdk-contract Patch

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

@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:14:16.505423Z 2a732ce 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 document handler bypasses issuer and feature-gate admission checks, while oversized generated client IDs can pass authorization but fail token exchange.

2 open issues
What changed in this PR

Adds the server-side OAuth client identity needed for future CLI sign-in, including local and air-gapped deployments.

Changes:

  • Serves the CLI client document and resolves its exact URL from memory without fetching.
  • Defines a public client with loopback redirects, PKCE, and code/refresh grants.
  • Adds document-serving and client-directory tests plus a release note.
File Description
apps/​api/​internal/​service/​client_directory.go Resolves the CLI client from memory.
apps/​api/​internal/​service/​client_directory_test.go Tests resolution, isolation, and admission boundaries.
apps/​api/​internal/​oauth/​server.go Mounts the CLI document endpoint.
apps/​api/​internal/​oauth/​cli_client.go Builds the client URL and serves its document.
apps/​api/​internal/​oauth/​cli_client_test.go Tests URLs, responses, and platform availability.
apps/​api/​internal/​domain/​cli_client.go Defines the CLI client metadata.
apps/​api/​cmd/​server/​server.go Registers the CLI client during startup.
.changeset/​cli-client-document.md Adds a server minor-release note.

Review effort: Balanced

Comment on lines +110 to +111
if cfg.PlatformEnabled && cfg.PublicBase != nil {
handlers.CLIClient = cliClientDocument(CLIClientID(cfg.PublicBase))
// project's. Its host is not held to the hosts of the auth.client.admit
// policy, which say whose documents may be fetched: nothing is.
func (d *ClientDirectory) ServeCLIClient(clientID string) error {
document, err := domain.ParseClientDocument(clientID, domain.CLIClientDocument(clientID))
main named the platform issuer's first-party clients in the server's
configuration (#3553), in the directory this branch teaches the CLI's
client. Both stay: the CLI's client is answered from memory before the
first-party list is asked, and it is a client with a document, which is
never first-party.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
@fforootd
fforootd enabled auto-merge December 2, 2026 15:28
@fforootd
fforootd added this pull request to the merge queue Dec 2, 2026
Merged via the queue into main with commit baea40c Dec 2, 2026
17 checks passed
@fforootd
fforootd deleted the claude/cli-client-document branch December 2, 2026 15:41
@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 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 holds this branch's bases as squash commits: the personal access token API (#3563), and before it ADR 095 (#3548) and the CLI's client document (#3558). The token API's squash has the tree of its branch's final head, which this branch already holds, so it is recorded as merged and nothing changes.

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

This branch was successfully deployed

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