Skip to content

feat(api): rotate a client secret, ending the old one now or after a day - #3561

Merged
fforootd merged 3 commits into
mainfrom
claude/rotate-client-secret
Dec 2, 2026
Merged

fforootd merged 3 commits into
mainfrom
claude/rotate-client-secret

Conversation

@fforootd

@fforootd fforootd commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Context

  • Refs Applications: resource and access model #1283
  • Builds the operation ADR 092 open question 9 decided on 2026-12-02: a leaked client secret is replaced through an operation of its own. Until now only a retry of publishApplication with its Idempotency-Key replaced one, which an MCP tool cannot send.

Related work found in a search of issues and pull requests: #2791 (closed) left "a credentials resource for adding, rotating and revoking secrets" out of scope. #1283 (open) lists "Credentials can be rotated while keeping the integration running" and "rotation, overlap, expiry and revocation" as design questions; keep_one_day answers the first for registered clients. The open application stack (#3405 → #3406 → #3410 → #3424, and #3409) adds zitadel application create and public clients. It touches endpoints/applications/methods.yaml and service/application.go but builds no rotation. This change puts its operation in files of its own, so only small textual merges remain.

Summary

  • rotateApplicationClientSecret (POST /applications/{application_id}/client_secret/rotate, application.write, the editor relation on the project, as publishApplication asks) gives one confidential client of a registered application a new secret and returns it once.
  • The caller must choose previous_secrets:
    • revoke deletes the secrets the client held, for one that leaked. Every app that still sends one fails to authenticate until it has the new secret.
    • keep_one_day keeps them working for 24 hours beside the new one, so a planned change signs nobody out.
  • The answer carries previous_secrets_end_at.
  • The overlap needs no migration and no job. A secret stops authenticating a day after a newer one was issued (domain.LiveApplicationClientSecrets, read from each secret's stored created_at). AuthenticateClient applies the rule to every client.
  • It records application.client_secret.rotated: the client, the newest revision, previous_secrets_end_at, and as actor the credential that rotated it. A retry of publishApplication with the same Idempotency-Key records the same event, with its end time "now".
  • An application a release declares is refused with app.declared: its secret is a variable, which is set and deployed. A public client is refused with app.invalid, and an unknown slug with app.client_not_found.
  • Marked x-zitadel-destructive and x-zitadel-returns-secret, with an agent note telling the agent to ask which previous_secrets to send. On the MCP endpoint the tool asks the person before it runs and says its answer holds a credential.
  • rotate joins the operation-ID verbs (redocly.yaml).
  • Docs: ADR 092 (§3 budget, §4, Risks, open question 9), ADR 094's related decisions, the permission catalog's application.write row, the Applications tag, and the reference page.

Validation

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

  • go test ./internal/domain/ ./internal/service/ ./internal/api/ ./internal/mcp/: pass. New tests cover the overlap rule as a table; rotation with revoke and with keep_one_day; the event's payload, which holds no secret; each refusal; authentication with a kept secret within the day and after it; the gate contract row (editor on the project), and the platform project's rule that a configuration write asks admin there.
  • go test ./... in apps/api (with the Console built) and in packages/go: pass.
  • turbo run lint check-generate --filter=@zitadel/server: the spec lint, analyzers and generated-file check pass. format flags internal/flowengine/sso_test.go on main too; this change does not touch it.
  • pnpm run check-openapi-rules: 15 tests pass. The CLI's api-coverage test passes with the operation listed in NOT_CALLED, since zitadel api rotateApplicationClientSecret sends it.
  • A local server with OAuth on. A probe of the token endpoint with a code that is no code answers invalid_grant when the secret authenticates and invalid_client when it does not. After keep_one_day, the first and second secrets both authenticate. After revoke, only the third does. An unknown slug is app.client_not_found. Both rotations recorded the event with the end time and the credential's token ID.
  • Over MCP, with the Go SDK's client: the tool lists as "Rotate a client secret", destructive, 1,765 bytes, with the credential and confirmation notes. A call asked the endpoint's question with its arguments, and after a yes answered the new secret.
  • Not run there: 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.

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

Release notes / changeset

  • Changeset: .changeset/rotate-application-client-secret.md (@zitadel/server, minor). rotateApplicationClientSecret replaces a client secret and returns the new one once, ending the previous secrets at once or after a day.

Notes

  • One secret per client. The overlap rule runs at every client authentication, for every client. On main, every write that stores a client secret leaves a client one: create stores one per new client, a revision stores one only for a client it adds (a revision cannot remove one), and a keyed retry deletes before it stores. Declared applications keep their secret in a variable. No migration, seed or other package writes the table. The one-day rule therefore ends only secrets a keep_one_day rotation kept. TestApplicationService_ClientSecretsPerClient holds the invariant, and TestClientSecretWriters pins the writes that store a secret, so a new one must join the test.
  • Clocks. The day is read from the stored created_at (the database's clock; the server's on SQLite), and previous_secrets_end_at is that time plus 24 hours. A skew between the database and the API servers shortens or lengthens the overlap by the skew and never makes the stated end wrong.
  • Existing behaviour, now visible: a keyed retry of publishApplication within its key's 24 hours deletes kept secrets too, as revoke does; its event says so.
  • The tool list grows. The tool weighs 1,766 bytes in the list, so listBudget goes from 142,000 to 143,766. 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. The operation carries the existing Applications tag, so it adds no tool set.
  • Decisions taken for review:
    • The overlap is the caller's required choice between revoke and keep_one_day, not a default.
    • The day is fixed.
    • The scope is application.write, as for revising the application, though revoke removes credentials. The catalog row says so.
    • Destructive, so the endpoint asks. A client on an earlier protocol revision cannot rotate through a tool, and uses the API, zitadel api, or later the Console. The alternative is to send it unasked, as cancelInvitation is, since a leak must end fast.
  • What this answers of Applications: resource and access model #1283, and what it leaves open:
    • Answered for a registered client's secret: "How can credentials be replaced while keeping the integration running?" (keep_one_day). Of "Client credentials: creation, visibility, rotation, overlap, expiry and revocation", it answers rotation, overlap (a fixed day), and revocation of every previous secret at once (revoke). The audit row holds: the event names the credential that acted and carries no secret value.
    • Left open: expiry of a secret by itself; revoking one secret while keeping the others; listing a client's secrets or their age; a credentials resource for keys and PATs; and everything about machine identities.
  • Not built: a CLI command of its own, and a Console action.
  • Follow-up: once the skill on the endpoint lands (feat(api): serve an Agent Skill on the MCP endpoint through the Skills extension #3550), it should name this operation.
  • Written in the session https://claude.ai/code/session_0137eGmSarR3gn9oz3Btwd8H; the draft was opened by the coordinating session below.

https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U


Generated by Claude Code

rotateApplicationClientSecret (POST /applications/{application_id}/
client_secret/rotate) gives one confidential client of a registered
application a new secret and returns it once. The caller chooses what
becomes of the secrets the client held: `revoke` ends them at once, for a
secret that leaked; `keep_one_day` keeps them working for 24 hours beside
the new one, so a planned change signs nobody out. A secret stops
authenticating a day after a newer one was issued, read from the stored
created_at, so the overlap needs no migration and no job.

It asks application.write and the editor relation on the project, as a
publish does, and records application.client_secret.rotated, whose payload
now says when the previous secrets end. It is marked destructive and
returns-secret, so the MCP endpoint asks the person before it runs and the
tool says its answer holds a credential. The tool weighs 1,766 bytes, by
which the tool list's budget is raised.

ADR 092 and 094 record what is built; the permission catalog, the
Applications tag and its reference page name the operation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmSarR3gn9oz3Btwd8H
@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: 0cd4e7e

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

… more

The one-day rule ends a secret a day after a newer one was stored, so it
is safe on existing data only while every other write leaves a client one
secret. TestApplicationService_ClientSecretsPerClient runs every write that
stores a secret in sequence against an in-memory store and counts the rows
each client holds; TestClientSecretWriters pins those writes, so a new one
joins the test first.

A kept secret's end time is now read from the stored row's created_at,
the time the rule compares, so the answer and the event state the end the
servers enforce. The response and event payload say it is when the last of
the previous secrets ends: one an earlier keep_one_day kept ends sooner.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmSarR3gn9oz3Btwd8H
@fforootd
fforootd marked this pull request as ready for review December 2, 2026 14:08
Copilot AI balanced review requested due to automatic review settings December 2, 2026 14:08
@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:38.992788Z 604bbee 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

Concurrent rotations can invalidate newly returned secrets while retaining superseded ones indefinitely, and unbounded secret history causes authentication costs to grow with each rotation.

2 open issues
What changed in this PR

Adds dedicated secret rotation for registered confidential clients, supporting immediate revocation or a 24-hour overlap for planned replacements.

Changes:

  • Adds the authorized rotation endpoint and MCP tool.
  • Enforces overlap expiry during authentication and records rotation deadlines in audit events.
  • Updates generated Go contracts, tests, documentation, and release notes.
File Description
redocly.yaml Allows the rotate operation verb.
packages/​go/​api/​oas_validators_gen.go Generates rotation request validation.
packages/​go/​api/​oas_security_gen.go Maps rotation to application.write.
packages/​go/​api/​oas_schemas_gen.go Generates rotation and audit types.
packages/​go/​api/​oas_response_decoders_gen.go Decodes rotation responses.
packages/​go/​api/​oas_request_encoders_gen.go Encodes rotation requests.
packages/​go/​api/​oas_parameters_gen.go Defines rotation parameters.
packages/​go/​api/​oas_operations_gen.go Adds the rotation operation constant.
packages/​go/​api/​oas_json_gen.go Generates rotation JSON serialization.
packages/​go/​api/​oas_interfaces_gen.go Adds the rotation response interface.
packages/​go/​api/​oas_client_gen.go Exposes rotation in the Go client.
docs/​design/​api/​system-permission-catalog.md Documents rotation permissions.
docs/​adrs/​094-project-permission-model.md Records the authorization decision.
docs/​adrs/​092-mcp-server.md Documents rotation tooling and budget.
apps/​docs/​content/​docs/​reference/​api/​applications/​index.mdx Explains secret replacement choices.
apps/​cli/​tests/​unit/​cli/​commands/​api-coverage.test.ts Records generic CLI API coverage.
apps/​api/​internal/​service/​mocks/​service.mock.go Generates the rotation service mock.
apps/​api/​internal/​service/​application.go Implements rotation, expiry filtering, and events.
apps/​api/​internal/​service/​application_test.go Tests rotation and secret lifecycle behavior.
apps/​api/​internal/​service/​application_secret_writers_test.go Guards the secret-writer inventory.
apps/​api/​internal/​mcp/​catalog_test.go Updates tool budget and credential assertions.
apps/​api/​internal/​domain/​event_payload.go Adds the previous-secret deadline.
apps/​api/​internal/​domain/​application.go Defines the overlap expiry rule.
apps/​api/​internal/​domain/​application_test.go Tests overlap boundaries.
apps/​api/​internal/​api/​platform_configuration_internal_test.go Covers platform-project authorization.
apps/​api/​internal/​api/​generated/​oas_validators_gen.go Generates server request validation.
apps/​api/​internal/​api/​generated/​oas_unimplemented_gen.go Adds the generated handler stub.
apps/​api/​internal/​api/​generated/​oas_server_gen.go Extends the server interface.
apps/​api/​internal/​api/​generated/​oas_security_gen.go Generates rotation scope requirements.
apps/​api/​internal/​api/​generated/​oas_schemas_gen.go Generates server rotation types.
apps/​api/​internal/​api/​generated/​oas_router_gen.go Routes rotation requests.
apps/​api/​internal/​api/​generated/​oas_response_encoders_gen.go Encodes rotation responses.
apps/​api/​internal/​api/​generated/​oas_request_decoders_gen.go Decodes rotation requests.
apps/​api/​internal/​api/​generated/​oas_parameters_gen.go Parses rotation parameters.
apps/​api/​internal/​api/​generated/​oas_operations_gen.go Adds the server operation constant.
apps/​api/​internal/​api/​generated/​oas_json_gen.go Generates server JSON serialization.
apps/​api/​internal/​api/​generated/​oas_interfaces_gen.go Adds the server response interface.
apps/​api/​internal/​api/​generated/​oas_handlers_gen.go Generates rotation request handling.
apps/​api/​internal/​api/​authz_contract_internal_test.go Pins the editor authorization requirement.
apps/​api/​internal/​api/​application.go Authorizes and delegates rotation requests.
apps/​api/​api/​openapi/​openapi-spec.yaml Registers the rotation endpoint.
apps/​api/​api/​openapi/​endpoints/​events/​webhooks/​application-client_secret-rotated.yaml Updates generated event documentation.
apps/​api/​api/​openapi/​endpoints/​events/​payloads/​application-payload.yaml Defines the audit deadline field.
apps/​api/​api/​openapi/​endpoints/​applications/​by_id/​client_secret/​rotate/​rotateApplicationClientSecret-error-response.yaml Generates the rotation error contract.
apps/​api/​api/​openapi/​endpoints/​applications/​by_id/​client_secret/​rotate/​rotate-client-secret-response.yaml Defines the secret and deadline response.
apps/​api/​api/​openapi/​endpoints/​applications/​by_id/​client_secret/​rotate/​rotate-client-secret-request.yaml Requires client and revocation choice.
apps/​api/​api/​openapi/​endpoints/​applications/​by_id/​client_secret/​rotate/​methods.yaml Defines endpoint behavior and MCP annotations.
apps/​api/​api/​openapi/​bundled/​openapi.json Regenerates the bundled API contract.
apps/​api/​api/​cmd/​gen_event_schemas/​main.go Updates rotation event documentation generation.
.changeset/​rotate-application-client-secret.md Adds server release notes.

Review effort: Balanced

return err
}
}
stored, err := storeClientSecrets(ctx, stmts, []*domain.ApplicationClient{client}, []string{secret})
Comment on lines +979 to +980
if !input.KeepPrevious {
if err := stmts.DeleteApplicationClientSecrets(ctx, input.ProjectID, client.ID); err != nil {
main replaced the one budget on the whole tool list with three checks
(#3555), so the raise this branch made to that budget goes. The tool
fits them: 80 tools on a plain URL, and the list a default consent
yields is unchanged in count.

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
Merged via the queue into main with commit 9693d9c Dec 2, 2026
17 checks passed
@fforootd
fforootd deleted the claude/rotate-client-secret branch December 2, 2026 15:37
@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 the client secret's rotation (#3561) and the session type (#3551). The generated router conflicted, so the server's code is generated again from the merged spec. ADR 092's measured figures count rotation's tool: 88 on a plain URL.

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

This branch was successfully deployed

1 active deployment
Preview — 0cd4e7e0 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