Repository navigation
feat: serve the API under /api/v1 and deprecate the root paths - #2358
Conversation
Checking the proposal against the code showed that more moves than the mount and the client base URL. The project secret, the SDKs' session-cookie handling, the dev proxies the CLI writes and the production proxies the docs describe all decide by exact path; so do the session no-store rule and the audit's route fallback in the server. The amendment keeps the probes in the spec and at the root for good, gives the root alias a Deprecation header and a measure of its traffic, has every path check accept both spellings until 1.0.0 (with a doctor --fix migration for scaffolded proxies), and orders the rollout so every mix of versions keeps working. The design docs say the prefix is accepted but not shipped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ADR 077 moves the resource API under /api/v1, and until 1.0.0 the server answers both spellings. Every check that decides by path now accepts both, so apps keep signing in on any mix of versions once their packages call the prefix: - @zitadel/sdk-core: the project-secret gate (POST /sessions/exchange) and the shared-session handling of the session probe, sign-in and sign-out trim the prefix before they compare. All six server SDKs go through it. - The dev proxies zitadel setup writes for SPAs (Vite and Angular) move to zitadel:proxy:v3, whose bearer hook knows both exchange paths. A separate convenience edit migrates the v2 hook, matched formatter-insensitively in vite.config.*: zitadel doctor warns until zitadel doctor --fix applies it, since a v2 proxy keeps working until the packages call the prefix. - The credential-policy check now accepts only the exact guard (POST, one or both exchange paths, no overwrite), so a guard an `|| true` widens is flagged for manual review. - @zitadel/api exports API_PREFIX; the SDK proxy docs tell a hand-written SPA production proxy to accept both paths. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The server mounts the resource API under /api/v1 (ADR 077): the spec's servers URL, a generated server with WithPathPrefix at /api/v1/ and at the bare prefix, so it gets ADR 076's not-found instead of a redirect. The health probes answer at the root for good, from a server of their own. Until 1.0.0 a root alias answers every operation at its old path; its responses carry Deprecation (RFC 9745) and a Link to the docs on the base URL, and its spans and metrics carry zitadel.api.root_path so the traffic left on it can be counted before GA removes it. api/client holds the prefix and builds the generated client on an origin; the server, the integration harness and the benchmark use it. The session no-store rule matches both spellings, and the audit records the operation instead of the mount's pattern. vercel.json routes /api/* to the server first, and the docs say where the API lives. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 2750b4a The changes in this PR will be included in the next version bump. This PR includes changesets to release 24 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 |
Brings in #2358's server, so CI and this branch's Vercel preview run against a server that serves /api/v1. The PR's base is that branch, so its diff is unchanged. When #2357 and #2358 have merged, rebase with: git rebase --onto origin/main claude/api-v1-gates-and-server Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolves the conflict in docs/runbooks/cloud.md, where both sides rewrote the paragraph on the deployment checks: it keeps this branch's /api/v1/schemas check and main's new CLI suite. main dropped the request chain's query-redaction argument, for which this branch wrapped the chain, so buildHTTPMux now passes the chain to MountAPI as it is. The generated code both sides changed matches a fresh server:generate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolves the conflict in docs/runbooks/cloud.md's service table: main now builds every cloud service through one turbo graph (#2425), and this branch adds /api/* to what the server serves. The server row takes main's build and this branch's paths. The generated code matches a fresh server:generate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolves the conflicts in buildHTTPMux and its tests: main added the event retention trigger, a mount of its own, and this branch replaced the API's catch-all with MountAPI. buildHTTPMux takes both, the trigger ahead of MountAPI, and main's trigger test expects the root alias where it expected the API. main's meter views keep only the attributes they list on the API's request metrics, which would have dropped zitadel.api.root_path, the mark this branch puts on the root alias's traffic. The views keep it now, the mount test collects through them, and the configuration guide lists it. The generated code matches a fresh server:generate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolves the conflict in the server's run: main passes the console's origins to the runtime resolver (#2462), and this branch builds the API's two servers on the next line. The file takes both. Nothing main added decides by request path: the console origins gate a flow's opening by its Origin header, wherever the API is mounted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolves the conflicts with ADR 083's session cookies: - The Vite and Angular proxies' session-cookie edits take both migrations: main replaces the hooks from before ADR 083, and this branch finds the CLI's entry by either version of its bearer hook. main's new code calls this branch's cliEntry instead of the cliEntryStatements it renamed. - doctor's tests keep this branch's v2-proxy test beside main's two for the hooks from before ADR 083. - sdk-core's tests for the prefixed session probe, sign-in and sign-out use ADR 083's cookie names. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The cloud functions check BotID only in front of the sign-in widget's
POST /flow and /flow/{id}/submit, matched by exact path. Once the widget
calls the API under /api/v1 (ADR 077), those calls would pass unchecked.
The check reads both spellings, as the SDK and dev-proxy gates do.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolves the conflicts with main's security headers and ADR 083: - buildHTTPMux returns main's securityheaders.Middleware around the mux, with main's /csp-report mount ahead of MountAPI's. - main's tests move onto this branch's mounts: the loopback-cookie test drives the API's test doubles under the prefix and at the root, the headers test also reads /api/v1/users, and TestSessionCookieNames mounts the API through MountAPI and calls the prefix. - TestRootPathAliasServesTheSignIn reads ADR 083's cookie name. - The cloud runbook's service table takes main's cloud-functions service and this branch's /api/* for the server. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…mpact-506209 No conflicts. Brings the branch up to date so the PRs stacked on it show only their own changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The hosted cloud's functions check the sign-in widget's flow writes for bots by path (ADR 084), so section 5 lists them with the checks that accept both spellings. The version check a separate PR proposed for every CLI command is not part of this rollout; section 5 names the checks zitadel start and zitadel setup already make. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ath-gates Stacks this PR on #2356 (ADR 077's amendment), so the stack's top tests the whole change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Stacks this PR on #2358 instead of the merge branch of #2357 and #2358, and brings in main through them. Conflicts: - ADR 077, its README row and the design docs keep this PR's "Implemented" and "shipped" wording, with #2356's new section 5 text and main's other edits to the resource map. - The console's Vite config is main's, restructured for the cloud's add-on, with this PR's proxy for /api/v1; the test base moved to vitest.config.ts, which now names the origin. The console's specs that main added or changed call /api/v1, as the rest do. - sdk-core's revokeSession (ADR 083, main) asks for the CSRF token and revokes under the prefix; its tests and the six server SDKs' tests take main's cookie names and this PR's prefixed URLs. - The scaffold guidance, sdk-next's docs, the CLI's SKILL.md, the console README and src/api/zitadel.ts take main's text with this PR's /api/v1 paths. The CLI's local-server tests and console-real's response match take main's cases on the prefixed paths. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in #2358's fix for the docs playground's session reads. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review SummaryThis 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.
🟢 Approval recommended
A thorough review of the routing logic, client helper, path handling, tests, and configuration surfaced no concrete defects, with the only placeholder (the deprecation date) intentionally flagged and tracked as a pre-merge step.
No open issues 🎉
What changed in this PR
This PR (third in the ADR 077 stack) moves the resource API from the server root to the /api/v1 prefix while keeping backward compatibility: the server still answers every operation at its old root path until 1.0.0, marking those responses as deprecated (RFC 9745 Deprecation + Link headers) and tagging their spans/metrics with zitadel.api.root_path=true. Health probes (/livez, /readyz), the console, the runtime document, and IdP callbacks remain at the root. A new hand-written api/client package (PathPrefix, BaseURL, New) centralizes prefixing for the server, integration harness, and benchmark.
The implementation is careful and well-tested: it mounts the prefixed server at both /api/v1 and /api/v1/ to serve the API's own req.not_found instead of a ServeMux redirect; uses a separate unprefixed server for probes so orchestrator traffic isn't counted as alias traffic; makes deprecation headers depend on FindPath so 404s, 405s, and CORS preflights get none; and uses slices.Clip to avoid option-slice aliasing across the three servers.
Changes:
- Add
internal/api/mount.go(NewServers/MountAPI/withRootPathDeprecation) andapi/clientpackage; rewirebuildHTTPMuxand the integration harness to mount the three servers. - Update path-reading code (
WithSessionStateNoStore, audit route recording) to accept both the prefixed and root spellings; keep the root-path metric attribute in the meter views. - Update the OpenAPI spec server to
/api/v1, cloudvercel.jsonrouting, deployment e2e checks, docs, and a@zitadel/serverminor changeset.
| File | Description |
|---|---|
internal/api/mount.go (+ mount_test.go) |
Core: builds prefixed/probe/root servers, mounts them, adds deprecation headers on root operations |
api/client/client.go (+ client_test.go) |
New package: PathPrefix, BaseURL (de-dups prefix), New |
internal/audit/request_middleware.go (+ test) |
Records operation as route; isAPIMount avoids recording mount patterns |
internal/api/session_cache.go (+ tests) |
isNoStoreOperation strips /api/v1 before matching session paths |
internal/instrumentation/zotel/meter.go (+ test) |
Keeps zitadel.api.root_path in ogen request attributes |
cmd/server/server.go, cmd/server/mux*_test.go |
buildHTTPMux takes api.Servers and calls MountAPI; tests cover full routing table |
internal/api/integration_test/helpers/* |
EnsureAPIServers/APIBaseURL/NewApiClient use the prefix; harness field renamed |
internal/api/integration_test/*_test.go |
Raw requests switched to harness.APIBaseURL(t); new root_path_alias_test.go |
tools/bench/* |
Harness/k6 module use client.New; /readyz stays at root |
e2e/console/...routes.spec.ts, e2e/schemas/...schemas.spec.ts |
Assert /api/v1 prefix and deprecated root paths |
apps/docs/**, docs/**, api/openapi/**, api/generated/** |
Doc/spec updates (server URL, probes at root, base-URL section); generated comments only |
vercel.json, apps/cloud/README.md, .changeset/server-api-path-prefix.md |
Route /api/* to server first; runbook/README/changeset updates |
Notes for the human reviewer: the deprecation date (rootPathDeprecatedSince = 2026-10-25) is an intentional placeholder with a TODO and is called out in the PR description as a pre-merge step, so I did not flag it. Final approval is deferred to a human.
Review effort: Balanced
…d's checks The CLI's doctor verdicts on an SPA dev proxy and the cloud functions' bot check each spelled /api/v1 out again, beside @zitadel/api's API_PREFIX. Both now derive it: the CLI names the prefixed exchange path once (PREFIXED_EXCHANGE_PATH) and its verdicts and messages use it; the cloud functions import API_PREFIX, with @zitadel/api as a dependency, its build ahead of theirs in moon and turbo, and their tests reading its source. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in #2357's shared API prefix for the CLI's and cloud's checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The spec's servers URL is the contract, but nothing held client.PathPrefix (Go) or API_PREFIX (@zitadel/api) to it: changing the spec alone would have left the server's mount and every client behind. A test on each side now reads the spec and compares. The docs' playground session helper and cURL base take API_PREFIX instead of spelling /api/v1 out again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in #2358's spec checks and #2357's shared prefix. The cloud functions' sign-in forwarder and directory both import API_PREFIX from @zitadel/api now, so the constant this branch had added to zitadel.ts goes; base-url.spec.ts keeps this branch's imports beside the new test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The specs import @zitadel/api's dist/, as Next does: the source condition the previous commit set reaches only Vite's client resolution, not the SSR mode a node-environment test runs in. Locally a dist/ was there; in CI, where nothing had built it, three suites failed with "Cannot find package '@zitadel/api/runtime/base-url'". The test task now waits for api:build in moon and @zitadel/api#build in turbo, as sdk-core's and the test kit's do, and the ineffective condition goes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in #2357's build edge for the cloud functions' tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Context
apps/api/, are still open; whichever lands second ports onto the other. See Notes.Summary
Mount. The server answers every spec operation under
/api/v1.internal/api/mount.gobuilds the API's generated servers over one handler with the same options (api.NewServers). One function mounts them for the production mux and the integration harness (api.MountAPI):WithPathPrefix("/api/v1")) at/api/v1/, and at the bare/api/v1so it gets ADR 076'sreq.not_foundinstead of a ServeMux redirect;/livezand/readyzat the root, from an unprefixed server of their own;/console/runtime.jsonand the IdP callbacks keep their own mounts.Deprecation. When a root path names an operation, the response carries:
Deprecation: @<epoch>(RFC 9745);Link: <https://preview.zitadel.com/docs/reference/api#base-url>; rel="deprecation"; type="text/html".Probes, 404s, 405s and CORS preflights get neither header. No
Sunset.Metric. The root alias is built with
WithAttributes(zitadel.api.root_path=true), so its spans and itsogen.server.*metrics count the traffic still on the root before GA removes it. The probes have their own server so that orchestrator traffic doesn't count as alias traffic. The server's meter views (internal/instrumentation/zotel) keep the attribute, and the configuration guide's Metrics section lists it.api/clientis a new hand-written package (MIT, underapi/). It exportsPathPrefix,BaseURL(origin)(drops a trailing/or/api/v1, so the prefix is never doubled) andNew(origin, sec, opts...). The server, the integration harness (helpers.NewApiClient,Harness.APIBaseURL) and the benchmark (Bootstrap, the k6 module) use it. The benchmark's/readyzcheck stays at the root.Code that reads the path before ogen.
WithSessionStateNoStorematches both spellings./api/v1/for every request.Spec.
servers: [{url: /api/v1}], with no name, so ogen generates nothing for it.Cloud.
vercel.jsonsends/api/(.*)to the server as its first rewrite. The catch-all stays.Deployment checks.
e2e/schemasexpects/api/v1/schemasand/api/v1/schemas/{id}without the header, and/schemasand/schemas/{id}with it.e2e/console's routes spec checks the prefix and the root alias.Docs.
curlServer) and its test usehttp://localhost:8080/api/v1.Validation
maina fifth time and stacking on feat: accept /api/v1 paths in the SDK and dev-proxy gates #2357 (see Notes), at 6a27e50:moon run server:lint server:test: pass.go test -count=1 -p 1 -tags postgres_integration ./internal/api/integration_test/...against a throwaway local Postgres 18, as in the Postgres bullet below: 201 tests passed, none failed or were skipped, includingTestRootPathAliasServesTheSignInandmain's newTestSessionCookieNames.moon run docs:typecheck docs:lint docs:e2e: 39 passed, among them the playground tests that failed on this branch's preview before the fix./api/v1/users/me401 withoutDeprecation,/users/meand/schemas401 with it,/livezand/api/v1/readyz200 without it,/api/v1/nope404. The deployment checkscli,consoleandschemas (Preview)pass, so the clients of this branch, still on the root paths, work against it in the cloud.go build ./...,go vet -tags postgres_integrationon the server, service and API packages,moon run server:lint server:test(which also ranserver:format,server:openapi,server:check-generateandserver:vet) andgo test ./apps/cloud/...: pass. The integration lane is left to CI this time: the conflict was one line, andmainadded no integration test.moon run server:generate: no change, so the generated code matches a fresh run;moon run server:openapi server:vet server:lint server:test server:test-sqlite bench:vet bench:lint bench:test: pass;moon run server:check-generate-pruned, run on its own: pass, no drift;moon run e2e:typecheck e2e:lint docs:typecheck docs:lintandturbo boundaries: pass;TestMountAPIMarksRootPathTrafficfails withzitadel.api.root_pathtaken out of the meter views, and passes with it;go test -v -count=1 -p 1 -tags postgres_integration ./internal/api/integration_test/...against a throwaway local Postgres 18, as in the Postgres bullet below: 199 tests passed, none failed or were skipped, includingTestRootPathAliasServesTheSignInand the testsmainadded.moon run server:generate: only the probe descriptions' comments changed inapi/generated.moon run server:openapi: 0 errors, 0 warnings.moon run server:format server:lint server:test: pass.moon run server:test-sqlite: pass.moon run server:check-generate-pruned, run on its own: pass, no drift.go test ./...intools/bench: pass.moon run e2e:typecheck e2e:lint docs:typecheck docs:lint: pass.biome checkon the changed TypeScript: clean.go vet -tags={postgres,spanner,sqlite}_integration ./internal/api/integration_test/...: pass.server:test-postgreswas not run. The integration package ran against a throwaway local Postgres 18 instead (ZITADEL_TEST_POSTGRES_URL):go test -v -count=1 -p 1 -tags postgres_integration ./internal/api/integration_test/. 188 tests passed, none failed or were skipped, includingTestRootPathAliasServesTheSignIn.moon run e2e:console-embedded e2e:console-real e2e:console-platform e2e:demo-next-mock e2e:demo-next-real e2e:demo-nuxt-mockand the React and Next journeys (moon run e2e:journey -- --framework <id>) passed against this server.pnpm check:cloud(needs the preview), and the docs Playwright suite (apps/docs/tests/pages.spec.tschanged).internal/api/mount_test.go, with real generated servers:/api/v1,/api/v1/,/api/v1/nope,/api/v1x/…,/nopeand/livez/;cmd/server/mux_test.go: the whole routing table throughbuildHTTPMux, including OPTIONS on both spellings and CSRF recording on every mount.mux_errors_test.go: ADR 076's page and envelope at/api/v1and/api/v1/no-such-page.TestRootPathAliasServesTheSignInruns a real handoff exchange and session read at the root and checks:DeprecationandLinkheaders;/livez.Release notes / changeset
.changeset/server-api-path-prefix.md,@zitadel/serverminor. The server answers the API under/api/v1, and the probes, the console and the callbacks stay at the root. Until 1.0.0 the root paths still answer, with aDeprecationheader and aLink. Not breaking: nothing a client calls today stops answering.Notes
api/client) and a TypeScript one (@zitadel/api'sbase-url.spec.ts) holdclient.PathPrefixandAPI_PREFIXto the spec'sserversURL, so a change to the contract alone fails CI; the docs' playground session helper and cURL base takeAPI_PREFIX. Checked:go test ./api/client/,moon run api:test api:lint docs:typecheck docs:lint docs:e2e server:lint(docs: 39 passed).mainis merged in five times to resolve conflicts:docs/runbooks/cloud.md: both sides rewrote the paragraph on the deployment checks. It keeps this PR's/api/v1/schemascheck andmain's new CLI suite.mainalso dropped the request chain's query-redaction argument, for which this PR wrapped the chain, sobuildHTTPMuxnow passes it toMountAPIas it is.serverrow:mainnow builds every cloud service through one turbo graph (build(deploy): build every cloud service through one turbo graph #2425), and this PR adds/api/*to what the server serves. The row takesmain's build and this PR's paths.buildHTTPMuxand its tests:mainadded the event retention trigger (feat: let a scheduler start the audit event purge instead of the server's timer #2397), a mount of its own at/cron/events-retention, and this PR replaced the API's catch-all withMountAPI.buildHTTPMuxtakes both, the trigger ahead ofMountAPI, andmain's trigger test expects the root alias where it expected the API.mainalso made the meter views keep only the attributes they list on the API's request metrics (feat(telemetry): cap metric series and limit API request metrics to the route template #2337), which would have droppedzitadel.api.root_pathwithout a test failing. The views keep it now,TestMountAPIMarksRootPathTrafficcollects through them, and the configuration guide lists it with the other request attributes.run:mainnow passes the console's origins to the runtime resolver (feat: let the console be reached at more origins than public_base's #2462), next to where this PR builds the API's servers. The file takes both. Nothingmainadded decides by request path: the new origins gate a flow's opening by itsOriginheader, wherever the API is mounted.buildHTTPMuxand the tests that drive the API:mainwraps the mux in its security headers (feat: send security headers and a Content-Security-Policy from every service #2480), adds/csp-reportahead of the API, and renamed the session cookies (ADR 083).buildHTTPMuxreturnsmain's wrapped handler withMountAPIinside;main's loopback-cookie test drives the API's test doubles under the prefix and at the root, the headers test also reads/api/v1/users,TestSessionCookieNamesmounts the API throughMountAPI, andTestRootPathAliasServesTheSignInreads the new cookie name. The runbook's table takesmain's cloud-functions service./api/v1since this PR; its session helper (apps/docs/components/session-auth.tsx,main's docs: send the API playground's requests with the reader's session #2476) now reads the session and its CSRF token there too, and its browser tests stub the prefixed paths.rootPathDeprecatedSinceininternal/api/mount.goto the date of the release that ships this.2026-10-25(@1792886400) holds its place.github.com/zitadel/nextgen, so a rebase mostly follows renames:cmd/,internal/andapi/openapimove underapps/api/;internal/api/generated;api/clientmoves to the public module asgo.zitadel.com/zitadel/v5/client, and the integration harness andtools/benchimport it from there.packages/go/README.md's example should useclient.New;vercel.json's/api/(.*)rule goes after build: serve Go vanity-import metadata for go.zitadel.com from the cloud #2274'sgo.zitadel.comhost rule;apps/api/follow then.POST /livezgets the probe server's 405, not the alias.client.Newtakes the security source, asNewClientrequires.🤖 Generated with Claude Code