Beta

Create a tenant

A new tenant starts with its own users, OAuth settings, audit history and logs. You are its first Tenant Admin.

Storing and using keys

A private signing key concentrates trust: whoever holds it can write tokens every verifier believes. Protecting it comes down to where it lives, what each key may do, how its public half is published, and how it is replaced without breaking anyone.

A key worth stealing

The photo service now depends on private keys. Its authorization server signs every access token it issues, including the ones the printer sends to the photo API for Ava. Whoever holds that key can create a token saying they are any customer, Ava included, and the photo API and every application that trusts the photo service will believe it. The printer has a private key of its own too, the one it signs its print orders with.

Public keys can be shared freely. Private keys concentrate trust, and protecting them is mostly a question of where they live, who and what can use them, and how they are replaced when the time comes.

Where keys live

The simplest arrangement is a key file on the server, or a key in an environment variable. The application reads it at startup and signs with it directly. It is easy to set up, and easy to leak. The key can end up in backups, container images, source control, crash dumps, or a support screenshot. Anyone who can read the process's files or memory can copy it, and a copied key keeps working wherever the attacker takes it.

A secret manager improves on this by storing the key centrally, restricting which services may read it, and recording each access. The application still receives the key itself, so a compromised application can still copy it. What changes is who can reach it, and the record of who did.

Dedicated key hardware changes the model. A hardware security module (HSM), a cloud key management service, a computer's Trusted Platform Module, or a phone's secure element can generate a key that is marked non-exportable. The application never sees the key. It sends data to the hardware and asks for a signature, and the hardware checks that the caller is allowed to use that key.

Encrypting a software-held key protects its stored copy, but the application must decrypt it to sign, so the private key sits in the application's memory whenever it is in use. That is a different arrangement from a key that never leaves dedicated hardware, even when both are described as protected.

# Key in a file: the application holds the private key
private_key = load_pem("/etc/photos/token-signing.pem")
signature = sign(private_key, token_bytes)

# Non-exportable key: the application asks for a signature
signature = key_service.sign(key_name="photos-token-signing-2026-10",
                             algorithm="ES256", data=token_bytes)

An attacker who takes over the authorization server can still ask the key service to sign while they have that access. They cannot take the key with them, and once the access is removed, their ability to sign ends. That makes the incident smaller and much easier to recover from.

Limiting each key

Using one key for everything is convenient and dangerous. If the photo service's token-signing key also signed its emails and decrypted stored files, one leak would affect all three, and a message signed for one purpose might be accepted for another. Giving each key a single purpose limits both problems.

The same thinking applies to environments and customers. Development and production should never share keys, so a laptop test cannot sign a token that production accepts. A service that signs on behalf of separate organizations can give each its own key, so one organization's verifiers never accept another's tokens.

Permissions matter too. The authorization server needs permission to sign with its key; very few people need permission to manage, export, or delete it. Records of which service used each key, and when, make unusual use visible.

Publishing public keys

The photo API and the other applications need the public half of the token-signing key. The photo service could send it to each one by hand, but it will eventually add applications and change keys. Instead, as Keys, encryption, and signatures described, it publishes its current public keys as a key set at a fixed address on its own HTTPS host. The common format is a JSON Web Key Set (JWKS): a JSON object whose keys array holds one entry per key. This fictional, shortened example holds two:

GET https://auth.photos.example/oauth/jwks

{
  "keys": [
    { "kid": "photos-2026-10", "alg": "ES256", "use": "sig", ... },
    { "kid": "photos-2026-07", "alg": "ES256", "use": "sig", ... }
  ]
}

Each entry has a key ID (kid). A signed token carries the ID of the key that signed it, so a verifier can pick the right key from the set without trying each one. Beside it, alg names the algorithm the key is for and use says it is for signatures; the members shortened here hold the public key's own values. The set contains only public values. A private key never belongs in it, and an entry that carried one would hand the signing key to everyone who reads the set.

As Digital signatures put it, the key ID is only a hint for choosing among keys the verifier already trusts: each verifier fetches the set from the address in its own configuration for the issuer, and usually keeps a cached copy that it fetches again from time to time.

Replacing a key

Keys are replaced on a schedule, when staff with access leave, when algorithms are upgraded, and after a suspected leak. A planned replacement, often called rotation, avoids breaking anything by overlapping the old and new keys. It runs in five stages.

First, the photo service generates the new key and adds its public half to the published set, while it keeps signing with the old key. Second, it waits until verifiers have had time to refresh their cached copies. Third, it starts signing new tokens with the new key. Fourth, it keeps the old public key published until every token the old key signed has expired. Fifth, it removes the old public key and retires the private key.

Publish the new key

Published
Old and new
Signs new tokens
Old key
Verifiers hold
Some: old key only
Tokens in use
From the old key

Wait for verifiers

Published
Old and new
Signs new tokens
Old key
Verifiers hold
Old and new
Tokens in use
From the old key

Sign with the new key

Published
Old and new
Signs new tokens
New key
Verifiers hold
Old and new
Tokens in use
From both keys

Old tokens expire

Published
Old and new
Signs new tokens
New key
Verifiers hold
Old and new
Tokens in use
From the new key

Remove the old key

Published
New only
Signs new tokens
New key
Verifiers hold
New only
Tokens in use
From the new key

A leaked key skips the overlap: the photo service removes it from the published set immediately.

At every stage, each token in use was signed by a key that verifiers can find in their copy of the set.

In the example set above, photos-2026-10 is the new key and photos-2026-07 is still published for tokens signed before the switch. Publishing first means no verifier sees a token signed by a key it cannot find. Keeping the old key until its tokens expire means no valid token is rejected.

A leaked key is different. The photo service removes it from the published set immediately and accepts that tokens it signed will stop working, because some of those tokens may be forgeries. Having practiced planned rotation makes that emergency much less disruptive.

Check your understanding

Try these questions before moving on. If an answer isn't right, use the feedback and try again.

The photo service's signing key is non-exportable in a hardware security module, and an attacker takes over the authorization server. What changes compared with a key in a file? 1 of 3

Choose one answer.

The photo service replaces its token-signing key. Which order avoids rejecting valid tokens? 2 of 3

Choose one answer.

Lab Photos learns that a copy of its token-signing private key sat in a backup that outsiders could read. What should it do with that key's public half in its key set? 3 of 3

Choose one answer.

Try it in the Lab

We value your privacy

We use cookies and similar technologies to enhance your browsing experience, and analytics to understand our traffic. By clicking "Allow all", you consent to optional analytics. Cookie Policy

Learn identity