Перейти к содержимому

Rotate signing keys

Это содержимое пока не доступно на вашем языке.

Every token this server signs carries the kid (key id) of the key that signed it, and every relying party verifies it against a published key set. Rotating a key means changing which key signs without leaving any instance, or any relying party, holding a token it cannot verify. Rotate changes the signer in one step. You can also take its steps one at a time. None of them needs a restart.

Each issuer has its own keys, and so its own rotation:

  • The instance’s keys sign for everything served at the root: the default project, the administrators’ project and any project without an address of its own. They are published at /jwks. Only super administrators manage them, on the console’s Keys page or with the jwks_* tools.
  • A project’s keys, for a project with a path, a subdomain or a hostname of its own. It signs with them alone and publishes them under its own issuer, such as https://auth.example.com/acme/jwks or https://acme.auth.example.com/jwks, so a token from one project never verifies against another project’s keys. The team that owns the project manages them on the project’s Signing keys tab, or with the project_key_* tools.

A project without an address has no keys of its own, and its key operations are refused. Its Signing keys tab says that it signs with the instance keys and lists their published ids. To rotate keys for that project alone, give it an address of its own.

The instance’s Keys page and a project’s Signing keys tab show one card per algorithm. Each card describes every key’s state in words: when it can sign, until when it signed, until when it verifies.

A key’s life: published, signing, retired, hidden

Section titled “A key’s life: published, signing, retired, hidden”
  1. Generate. The new key is published: it appears in the key set and verifies, but signs nothing. Every algorithm the server supports is offered: RSA (RS*, PS*), elliptic curve (ES*) and EdDSA.

  2. Promote, once the key has been published for 60 seconds. It becomes the signer of its algorithm, and the key that signed that algorithm before goes back to published, so it keeps verifying the tokens it already signed. The new signer is written first, so there is no moment with no signer.

  3. Retire the old key once you no longer need it to sign. In the console you type the word retire; over the API the body must name the key: { "confirm": "<kid>" }. The key that currently signs cannot be retired. Promote its replacement first.

A retired key stays published for one day, the longest anything it signed can live, and is then hidden: gone from the key set, from the console’s list and from every verification. It is never deleted. The record is kept, and every operation on it answers 404.

Rotate, on an algorithm’s card, does the first two steps at once. The oldest published key of that algorithm that may sign now becomes its signer. The key that signed before goes back to published, so it keeps verifying what it signed. A new key is generated and published, ready for the next rotation.

When no key of the algorithm may sign yet, Rotate only publishes the next key and changes nothing about who signs. The answer gives the earliest time the algorithm can rotate (rotatableAt). Rotate never promotes a key inside its publication window, so pressing it twice, a minute apart, puts a new key in charge.

Retiring leaves a key verifying for a day. For a key that may have leaked, forged tokens verify for that whole day. Revoke now… in a key’s menu ends it at once instead. In the console you type the word revoke; over the API the body names the key, as for retiring.

  • The key leaves the key set and every verification: at once on the instance that revoked it, and on every other instance within the 30 seconds its cache lives. Every token it signed stops verifying, so people signed in with such tokens may have to sign in again.
  • Its state becomes revoked. It is never published again and cannot be brought back. The record is kept, so its kid is never reused.
  • Revoking the key that signs puts another in its place in the same act: the oldest published key of the algorithm that may sign, or else a newly generated key that signs at once. That new key skips the publication window, so a relying party holding a cached key set may reject new tokens until it refreshes it. That is the price of ending a compromised key now rather than in a minute.

Each step is recorded in the audit trail before it takes effect. A rotation or a revocation is one entry, and it names every key the act touched (keys): the key promoted, the one demoted, the one generated, the one revoked.

For an agent, every instance key tool is high-consequence and asks for confirmation: jwks_generate, jwks_promote, jwks_rotate, jwks_retire and jwks_revoke. For a project, retiring and revoking are high-consequence (project_key_retire, project_key_revoke); generating, promoting and rotating are ordinary (project_key_generate, project_key_promote, project_key_rotate), because none of them stops a key from verifying.

An issuer has one signing key per algorithm, not one in total. Ordinary clients get RS256, and a FAPI 2.0 client registered for PS256 or ES256 needs a signer in that algorithm too, so an issuer can sign with several keys at once, each for its own clients. Promoting or rotating a key replaces only its own algorithm’s signer, and revoking a signer puts another in its place, so no step can leave a client’s algorithm without one.

A new algorithm needs no restart. Generate an ES256 key, promote it, and discovery advertises ES256 from then on, so clients can register for it straight away.

The IPSIE SL1 profile signs with PS256 for every client that chose no algorithm, so the profile can only be turned on when every issuer has a PS256 signer: the instance, and each project with an address of its own. Generate a PS256 key for each issuer and promote the key once it can sign. A project created while the profile is on gets a PS256 signer at once.

Making a key costs the server real processor time, and every key stays in the key set that clients download. So each key set, the instance’s and each project’s, has two limits:

  • At most 12 keys held. A key counts while it signs, while it is published, and while it is retired but still verifies. One signer and one published key per algorithm, with a few retired keys, stays well under it.
  • At most 20 keys made in one day. Revoked keys count too, because revoking the signing key can make a new key to replace it.

Generate and Rotate past either limit answer 409 with reason: "key_limit", and the message says what to do: retire a key, or try again later. Revoking the signing key is refused the same way when no published key can take over and 20 keys were already made that day. Keeping a published key ready, as Rotate does, avoids that refusal.

The sixty-second window protects this server’s own instances. It cannot protect a relying party that caches the key set for an hour and never looks again. A relying party that copes with rotation:

  • reads jwks_uri from the issuer’s discovery document rather than having it typed into its configuration, so a project’s own key set is found without anyone remembering it exists;
  • selects the verification key by the token’s kid, never by assuming there is only one key;
  • re-reads the key set when it sees a kid it does not know, with a short cooldown so a stream of forged kids cannot make it fetch on every request.

Most JWT libraries do all three when given the jwks_uri. If yours caches for longer than that, generate the new key well ahead of promoting it, at least as long ahead as that cache lives.

  1. Press Rotate on the algorithm’s card. If no next key was published yet, Rotate publishes one and signs nothing with it.
  2. Wait at least a minute, longer if a relying party caches the key set for longer, then press Rotate again. The next key signs, and a new next key is published.
  3. Retire the old key, typing retire. It keeps verifying for the day a retired key stays published, which outlasts every token it signed, so there is nothing to wait for first.

The same rotation by hand is Generate, then Promote once the key may sign, then Retire.

The upgrade to 0.8.0 moved the instance’s keys into this lifecycle; Upgrading says how it chose which key signs.