Rotating client credentials
Every client credential is replaced sooner or later. A planned replacement keeps the old and new credentials valid together until every server has switched; a leaked one is revoked first, even if that causes an outage.
Why credentials change
The printer's website runs on six servers. Each one loads the client secretA shared secret that a confidential client uses to prove itself to the authorization server, much like a password for an application. It belongs on a backend, never in code sent to browsers or phones. when it starts. One afternoon, a developer replaces the secret in the photo service's console, copies the new value into the secrets store, and starts restarting servers one at a time.
For the next few minutes, the servers that have not restarted keep sending the old secret, and the token endpointThe authorization server address where clients exchange an authorization code, refresh token, or other grant for tokens, in a direct request rather than through a browser redirect. now rejects it. Some customers connecting their photo accounts see an error. Nothing was stolen and nothing was misconfigured for long, but replacing the credential still broke the service.
A client credential is replaced for ordinary reasons as well as alarming ones. A policy may require secrets to be replaced every year, or the server may issue them with an expiry date. A developer who had access to the secret may leave the company. The printer may move from a client secret to a key pairA private key and a public key generated together and mathematically linked. The private key creates signatures and the public key checks them, but the private key cannot practically be worked out from the public one., or from one signing algorithm to another. And sometimes a credential turns up somewhere it should not be, such as a public repository or a log file.
Because replacement is certain to happen, it should be routine: practiced, documented, and possible without downtime. A rotation that only happens during an emergency tends to go badly, because the first time anyone tries the procedure is the moment it matters most.
Overlapping old and new
The outage above happened because the old and new secrets were never valid at the same time. Many authorizationDeciding whether a requested action is permitted, such as whether a signed-in account may delete a particular photo. Authentication says which account is asking; authorization decides what it can do. servers avoid that by allowing a client to hold two secrets during a change. The rotation then has four steps:
- Add. Create a second secret for
photo-printer. The old one keeps working. - Deploy. Put the new secret in the secrets store and restart or reload every server, at whatever pace is safe.
- Confirm. Check that requests are now arriving with the new secret. A server that records which secret each request used, or when each secret was last used, makes this a fact rather than a guess.
- Remove. Delete the old secret.
Each step can be undone until the last one. If a server turns out to have its own forgotten copy of the configuration, the confirm step shows it still using the old secret, and the team fixes that before removing anything.
When a server allows only one secret per client, the overlap disappears. Replacing it becomes a coordinated switch: change the secret and the deployed configuration as close together as possible, and accept a short window of failures. Knowing which kind of server you are dealing with before the day of the rotation is part of planning it.
Replace the secret
- Old secret
- Stops at once
- Servers not yet restarted
- Rejected
Some customers see an error
Add, deploy, confirm, remove
- Old secret
- Works until removed
- Servers not yet restarted
- Still accepted
No request fails
Revoke the leaked credential first
- Old secret
- Stops at once
- Servers not yet restarted
- Rejected
A short, honest outage
A careful overlap assumes no one else holds the old credential.
Rotating a key pair
Key pairs make overlap natural. The Storing and using keys lesson described publishing public keys in a set, each labeled with a key identifier. If the printer registered the address of its published key setA JSON document, published at a fixed HTTPS address, that lists an issuer's current public keys so others can verify its signatures. It never contains private keys. rather than a single key (the registration field for that address is called jwks_uri), it can rotate without asking the photo service to change anything:
GET /oauth/jwks.json HTTP/1.1
Host: printer.example
{
"keys": [
{ "kid": "printer-2026-10", "kty": "EC", "crv": "P-256", "x": "...", "y": "..." },
{ "kid": "printer-2027-01", "kty": "EC", "crv": "P-256", "x": "...", "y": "..." }
]
}All domains, identifiers, keys, and credentials in these examples are fictional, and the key values are shortened. The path is the printer's choice; what matters is that the registration points to it.
The printer first adds the new public keyThe half of a key pair that can be shared freely. It checks signatures made with the matching private key and can encrypt data that only that private key can decrypt., printer-2027-01, to the set while still signing with the old one. Once the photo service can see the new key, the printer starts signing assertions with it. The server sees an unfamiliar kid in an assertion's header, fetches the set again if its cached copy does not include it, and verifies the signatureA value made with a private key that lets anyone holding the matching public key check that a message came from the key's holder and has not been changed. It proves origin and integrity; it does not hide the message.. After the last assertion signed with the old key has expired, a matter of minutes, the printer removes the old key from the set.
At no point does a secret need to be copied between servers, and at no point is there a moment where the only valid credential is one the printer has not deployed yet. If the registration holds a single key instead of an address, the same steps apply, but adding and removing keys means updating the registration.
When a credential has leaked
A careful overlap assumes no one else holds the old credential. If the printer's secret has appeared in a public repository, that assumption is gone. Every minute the old secret remains valid, someone else can use it.
The order changes. RevokeCancelling a credential, token, certificate, or authenticator before it would expire, so that it is no longer accepted. Whether every copy stops working at once depends on how services check it. the leaked credential first, even if that breaks the printer until the new one is deployed. A short, honest outage is better than leaving a working credential in a stranger's hands while the deployment proceeds at a comfortable pace.
Then consider what the credential could already have been used for. Tokens issued before the revocation do not disappear on their own. Access tokens remain usable until they expire, unless the service can revoke them. Refresh tokens are bound to the client that received them, as The refresh token grant explained, so someone holding both the leaked secret and a stolen refresh tokenA longer-lived credential that a client sends to the authorization server, never to an API, to get new access tokens without asking the person again. could have kept obtaining access. Depending on what the logs show, the photo service may revoke the tokens issued to the client, and the printing company may need to tell affected customers.
Logs help most when they were written before anything went wrong. Records of tokenA piece of data issued by a trusted service that a client presents as a credential, for example to call an API or to report a sign-in. Some tokens carry readable claims; others are random strings that only the issuer can interpret. requests that show the client, the authenticationChecking evidence that someone, or some application, controls an account, such as a password or a passkey. It establishes which account is being used, not what that account may do. method, which credential was used, and where the request came from let the team tell normal use from misuse. They must never contain the secret or the assertion itself.
Check your understanding
Try these questions before moving on. If an answer isn't right, use the feedback and try again.
Try it in the Lab
- Rotate a client secret with an overlap, a leaked one without, then a key pairRun add, deploy, confirm and remove on lab-tmp-rotation-client's secret across two servers with no failed request, respond to a leak revoke-first, then rotate its signing key the same way.