Skip to content

fix(identity): clean up keycloak rotation state when rotation is disabled - #874

Merged
ron96g merged 1 commit into
mainfrom
fix/identity-disable-secret-rotation
Nov 19, 2026
Merged

ron96g merged 1 commit into
mainfrom
fix/identity-disable-secret-rotation

Conversation

@ron96g

@ron96g ron96g commented Nov 18, 2026

Copy link
Copy Markdown
Member

What

Adding identity.cp.ei.telekom.de/disable-secret-rotation: "true" to an existing identity Client now actually opts it out of secret rotation in Keycloak.

Why

Opting out only worked for new clients. For a client that had already taken part in rotation:

  1. The opt-in flag was never removed. We dropped controlplane.secret-rotation from the client PUT body. But a Keycloak client PUT only updates the attributes it contains, and it removes an attribute only when the value is empty. The flag stayed true, so the rotation policy kept applying.
  2. The secret still expired. Keycloak checks client.secret.expiration.time on every client authentication, whether or not a policy applies. Meanwhile our status cleared SecretExpiresAt, so the Application lost its expiry date and expiry notifications would never fire.
  3. An old rotated secret could stay valid while being hidden from the status.
  4. The SecretRotation condition was left stale (Rotated or Accepted).

Changes

  • identity/pkg/keycloak/util/client.go
    • On opt-out, the merged PUT body sends "" for controlplane.secret-rotation and the rotation attributes Keycloak manages (client.secret.expiration.time, client.secret.remaining.expiration.time, client.secret.rotated*). Keycloak removes attributes with empty values.
    • Leftover rotation state counts as drift when rotation is disabled, so clients that are already affected get fixed on their next reconcile.
    • The Keycloak attribute names are defined once here, and graceful_secrets.go reuses them.
  • identity/internal/handler/client/handler.go: removes the SecretRotation condition when rotation isn't supported.
  • Docs: admin-journey/features/secret-rotation.md and architecture/identity.mdx now describe opting out an existing client and opting back in.

Reviewer notes

  • Behavior change: if a grace period is active when a client opts out, the old (rotated) secret stops working immediately. This matches Keycloak's own cleanup (removeClientSecretRotationInfo) and the Application handler, which already assumes opt-out replaces the old secret immediately. It also avoids a valid credential that the status doesn't show.
  • client.secret.creation.time is kept.
  • Not covered: removing secretRotation from a Realm has a similar leftover-expiry problem. I kept this PR to the annotation; the Realm case could be a follow-up.

Verification

  • make test and make lint pass in identity.
  • New or updated tests cover the PUT body on opt-out, drift detection for leftover rotation state, and removal of the stale condition.
  • The code-auditor run is clean.

…bled

Adding the disable-secret-rotation annotation to an existing Client had
no effect in Keycloak. A client PUT only updates the attributes it
contains, so dropping the controlplane.secret-rotation attribute kept it
set and the rotation policy kept applying. The executor-managed
expiration attribute also stayed, so Keycloak still expired the secret
while the status no longer reported an expiry.

On opt-out, send empty values for the opt-in attribute and the rotation
state attributes so Keycloak removes them, treat leftover rotation state
as drift, and remove the stale SecretRotation condition.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@ron96g ron96g self-assigned this Nov 18, 2026
@ron96g
ron96g merged commit df6ce07 into main Nov 19, 2026
140 of 142 checks passed
@ron96g
ron96g deleted the fix/identity-disable-secret-rotation branch November 19, 2026 11:24
dtit-semantic-release Bot pushed a commit that referenced this pull request Nov 19, 2026
## [0.48.4](v0.48.3...v0.48.4) (2026-11-19)

### Bug Fixes

* **gateway,common-server:** back off on unavailable token endpoints and reduce cache memory ([#873](#873)) ([107e81b](107e81b))
* **identity:** clean up keycloak rotation state when rotation is disabled ([#874](#874)) ([df6ce07](df6ce07))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants