Repository navigation
feat(api): rotate a client secret, ending the old one now or after a day - #3561
Conversation
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
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 0cd4e7e 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 |
… 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
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
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}) |
| 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
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
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


Context
publishApplicationwith itsIdempotency-Keyreplaced 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_dayanswers the first for registered clients. The open application stack (#3405 → #3406 → #3410 → #3424, and #3409) addszitadel application createand public clients. It touchesendpoints/applications/methods.yamlandservice/application.gobut 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, aspublishApplicationasks) gives one confidential client of a registered application a new secret and returns it once.previous_secrets:revokedeletes 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_daykeeps them working for 24 hours beside the new one, so a planned change signs nobody out.previous_secrets_end_at.domain.LiveApplicationClientSecrets, read from each secret's storedcreated_at).AuthenticateClientapplies the rule to every client.application.client_secret.rotated: the client, the newest revision,previous_secrets_end_at, and as actor the credential that rotated it. A retry ofpublishApplicationwith the sameIdempotency-Keyrecords the same event, with its end time "now".app.declared: its secret is a variable, which is set and deployed. A public client is refused withapp.invalid, and an unknown slug withapp.client_not_found.x-zitadel-destructiveandx-zitadel-returns-secret, with an agent note telling the agent to ask whichprevious_secretsto send. On the MCP endpoint the tool asks the person before it runs and says its answer holds a credential.rotatejoins the operation-ID verbs (redocly.yaml).application.writerow, 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 withrevokeand withkeep_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 ./...inapps/api(with the Console built) and inpackages/go: pass.turbo run lint check-generate --filter=@zitadel/server: the spec lint, analyzers and generated-file check pass.formatflagsinternal/flowengine/sso_test.goon main too; this change does not touch it.pnpm run check-openapi-rules: 15 tests pass. The CLI'sapi-coveragetest passes with the operation listed inNOT_CALLED, sincezitadel api rotateApplicationClientSecretsends it.invalid_grantwhen the secret authenticates andinvalid_clientwhen it does not. Afterkeep_one_day, the first and second secrets both authenticate. Afterrevoke, only the third does. An unknown slug isapp.client_not_found. Both rotations recorded the event with the end time and the credential's token ID.full-prruns 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/rotate-application-client-secret.md(@zitadel/server, minor).rotateApplicationClientSecretreplaces a client secret and returns the new one once, ending the previous secrets at once or after a day.Notes
keep_one_dayrotation kept.TestApplicationService_ClientSecretsPerClientholds the invariant, andTestClientSecretWriterspins the writes that store a secret, so a new one must join the test.created_at(the database's clock; the server's on SQLite), andprevious_secrets_end_atis 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.publishApplicationwithin its key's 24 hours deletes kept secrets too, asrevokedoes; its event says so.listBudgetgoes 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 existingApplicationstag, so it adds no tool set.revokeandkeep_one_day, not a default.application.write, as for revising the application, thoughrevokeremoves credentials. The catalog row says so.zitadel api, or later the Console. The alternative is to send it unasked, ascancelInvitationis, since a leak must end fast.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.https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
Generated by Claude Code