Skip to content
LogoLogo

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 generate
A 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 acme

The 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

  1. In the organization switcher, choose Apps.
  2. Find the app.
  3. Choose the app.
  4. In Public keys, choose Add key.
  5. In the window Add a public key, put the Public key value in the field Public key.
  6. 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

  1. Set PICKED_APP_PRIVATE_KEY on the server to the new private key.
  2. Deploy the server again.
  3. 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

  1. 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.
  2. Choose Remove below that key.
  3. Read the warning in the window Remove key 1, added <date>?.
  4. 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.

TaskGraphQLMCP toolRun
Register the new public keyappPublicKeyAddNoneNone
Remove the old keyappPublicKeyRemoveNoneNone

appPublicKeyRemove takes the key ID as kid. The publicKeys field of app lists the keys of the app.