How to rotate an app key
This guide shows you how to replace the private key of an app with a new key. The app continues to work during the change.
Before you start, the app must have one public key, and its server must use the private key of
that public key. You must have the scope organization_apps/update in the organization
of the app.
An app holds two public keys at most. Picked accepts a picked-app-assertion token from
each of them. So you add the new key first, move the server to it, and then remove the
old key.
1. Make a new key
Make a private key and its public key:
npx picked app keys generateA new app key pair. Keep the private key secret; it is printed once:
PICKED_APP_PRIVATE_KEY=MC4CAQAwBQYDK2VwBCIEI…
Public key: 3fJ0b…
Key id: Qm9yZ2…
Set PICKED_APP_PRIVATE_KEY on the app server and where you run `picked app deploy`,
which registers the public key with the app.
Copy the PICKED_APP_PRIVATE_KEY=… line to your secret store. The CLI shows it one time
only.
2. Register the new public key
Use one of the two methods that follow.
With the CLI
Set the new private key in the shell, then deploy the app:
export PICKED_APP_PRIVATE_KEY='MC4CAQAwBQYDK2VwBCIEI…'
npx picked app deploy --org acmeThe CLI registers the public key of the new private key. If the manifest has no change, the CLI writes no version. Refer to How to deploy an app.
In the dashboard
- In the organization switcher, choose Apps.
- Find the app.
- Choose the app.
- In Public keys, choose Add key.
- In the window
Add a public key, put thePublic keyvalue in the field Public key. - Choose Add key.
To make the keys in the dashboard, choose Generate a key pair in place of steps 5 and 6. The
dashboard registers the public key. The window shows the public key in the field Public key,
and the private key in the field PICKED_APP_PRIVATE_KEY until you choose Done. Copy it with
Copy PICKED_APP_PRIVATE_KEY before you choose Done.
The app now holds two keys, and Public keys shows
An app holds two keys at most. Remove one to add another.
If the app holds two keys already, the new key fails with
An app holds at most 2 public keys; remove one before adding another.
3. Move the server to the new key
- Set
PICKED_APP_PRIVATE_KEYon the server to the new private key. - Deploy the server again.
- Set the new private key where your CI runs
picked app deploy.
Each later picked app deploy keeps the new key.
4. Remove the old key
- On the page of the app, find the old key under Public keys. The keys show the oldest
first, so the old key is
Key 1, added <date>. The date is the day that you added it. - Choose Remove below that key.
- Read the warning in the window
Remove key 1, added <date>?. - Choose Remove.
After this, each picked-app-assertion token that the old key signs fails. A server that
still uses the old key cannot get a new installation token. An installation token that the
server got before stays valid until it expires.
API and MCP
You can also do this task with the Management API, the MCP server, or code that you send to picked_run.
| Task | GraphQL | MCP tool | Run |
|---|---|---|---|
| Register the new public key | appPublicKeyAdd | None | None |
| Remove the old key | appPublicKeyRemove | None | None |
appPublicKeyRemove takes the key ID as kid. The publicKeys field of
app lists the keys of the app.
Related
- Public keys of an app — the key format, the key ID and the limit.
- About app authentication — why an app holds two keys.
- App environment variables —
PICKED_APP_PRIVATE_KEYon the server and in the CLI.
