Repository navigation
feat(api): serve the CLI's client document on the platform issuer - #3558
Conversation
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)
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 726d62d The changes in this PR will be included in the next version bump. This PR includes changesets to release 27 packages
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 |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
🟡 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
| 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
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
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

Context
zitadel login.The
zitadelCLI has no sign-in: it works from the project secretzitadel setupwrites. 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
/oauth/cli-client.jsonand 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.ClientDirectory.ServeCLIClient). Nothing is fetched. Every other URL on the server's own origin, the same URL spelled with:443included, still names no client, and no fetch of a loopback or private address is opened up.ParseClientDocumentas any outside one: a public client, redirecthttp://127.0.0.1/callbackon any port (RFC 8252), PKCE, the code and refresh grants. It is never first-party, so the person always sees the consent step.oauth.client_documentsis 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_documentsoff, 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 ./...inapps/apigo 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/cli-client-document.md(@zitadel/server, minor).Notes
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 turnsoauth.client_documentsoff, which also turns off every other document client.client_directory.goandcmd/server/server.gotoo. The two do not overlap in behaviour; whichever lands second resolves the text.login,logoutandpatcommands 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.Generated by Claude Code