Rotate signing keys
Move your realm to a new signing key whenever you choose, without any app or API refusing a token.
API
Your security policy says signing keys are replaced every year, or you’ve stopped trusting one. Keys never rotate on their own, so each rotation is a call you make. A rotation moves the realm to a new signing key by publishing it first and signing with it later, so every app and API already holds the new key by the time it meets a token signed with it.
Before you start: you need the MODIFY right on the realm’s keySettings, which a group holding RealmOwner
has, and your session in $CVYUH_SESSION: Call the API shows how to get it. It’s done through the
API. Check that the apps and APIs that verify your tokens pick keys by kid and refetch on an unknown one: see
What your apps should do.
Rotate
Section titled “Rotate”-
Check the publish lead. Read
GET https://foobar.cvyuh.com/api/v0/am/objects/v1/keySettings/keySettings:rotation.publishLeadSecs(3,600 by default) is the soonest the new key may start signing. To give apps longer, raise it:Terminal window curl -X PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/keySettings/keySettings \-H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \-H "Content-Type: application/json" \-d '{ "rotation": { "publishLeadSecs": 7200 } }' -
Rotate one algorithm, naming when the new key starts signing:
Terminal window curl -X PUT https://foobar.cvyuh.com/api/v0/am/keys/v1/signing \-H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \-H "Content-Type: application/json" \-d '{ "algorithm": "ES256", "validFrom": "<RFC 3339 time, at least the publish lead from now>" }'The realm answers
204, and the new key is in the published key set at once, beside the current one. -
Repeat for
RS256andPS256if you’re rotating every key. Each algorithm rotates on its own. -
Wait. Apps, gateways and APIs pick the new key up as their caches of the key set refresh, within five minutes by default. At
validFromthe new key starts signing.
Check it worked
Section titled “Check it worked”List the keys with GET https://foobar.cvyuh.com/api/v0/am/keys/v1. The new oauth2/signing version shows its validFrom and state: "valid". Once its validFrom has passed, the version it replaced shows state: "retained": still published, so
the tokens it signed verify until they expire.
You can also open https://foobar.cvyuh.com/oauth2/jwks in a browser: the new key’s kid is there from step 2.
If it fails
Section titled “If it fails”400, “a rotated key signs too soon”.validFromis sooner than the publish lead. The detail names the earliest time allowed; send that or later.400once the realm holds 100 versions. Revoke an old version first: see Revoke a signing key.- An API refuses tokens after
validFrom. It didn’t refetch the key set. Restart it or clear its key cache, and give it the rules in What your apps should do.
Each rotation is recorded on the realm’s audit trail under your name, never the key: see Signing keys.
Undo it
Section titled “Undo it”Until a minute before its validFrom, you can revoke the new version (DELETE https://foobar.cvyuh.com/api/v0/am/keys/v1/signing/<version>)
and the current key keeps signing. After that, rotate again to a fresh key.
Related
Section titled “Related”- Revoke a signing key: retire the old key, or one you believe is exposed.
- Signing keys: the settings and limits a rotation follows.
- Check what clients discover: how apps find the new key.