Skip to main content

How to rotate shared keys

Replace an enrollment group's shared key without interrupting devices that are still using the old one.

Each group holds two slots, primary and secondary. Both authenticate, which is what makes rotation non-disruptive: you fill the second slot, distribute the new key, then promote it.

Prerequisites​

  • An enrollment group id
  • A JWT access token with onboarding management permissions
  • A way to deliver the new key to devices — firmware update, configuration push, or re-flash
export API="https://api.example.com/api"
export TOKEN="YOUR_ACCESS_TOKEN"
export GROUP_ID="YOUR_ENROLLMENT_GROUP_ID"

Steps​

1. Check the current slots​

curl -s "$API/enrollment-groups/$GROUP_ID/shared-keys" \
-H "Authorization: Bearer $TOKEN"
{ "primaryKey": "THE_CURRENT_KEY", "secondaryKey": null }

You need an empty secondary slot to start. If both are populated, a previous rotation was left half-finished — go to step 3 and flip first.

2. Generate into the empty slot​

curl -X POST "$API/enrollment-groups/$GROUP_ID/shared-keys/generate" \
-H "Authorization: Bearer $TOKEN"
{ "primaryKey": "THE_CURRENT_KEY", "secondaryKey": "THE_NEW_KEY" }

Both keys now authenticate. Nothing has broken and nothing is urgent.

3. Distribute the new key​

Push secondaryKey to every device in the group. Take as long as you need — devices holding the old key keep working throughout.

Do not proceed until you are confident every device has the new key.

4. Flip​

curl -X POST "$API/enrollment-groups/$GROUP_ID/shared-keys/flip" \
-H "Authorization: Bearer $TOKEN"
{ "primaryKey": "THE_NEW_KEY", "secondaryKey": null }

The old key is now invalid. Any device that did not receive the new key can no longer bootstrap.

warning

Flip is irreversible. The previous primary key is discarded, not archived.

Verify it worked​

curl -s "$API/enrollment-groups/$GROUP_ID/shared-keys" \
-H "Authorization: Bearer $TOKEN" | jq '{primaryKey, secondaryKey}'

secondaryKey should be null and primaryKey should be the value you distributed. Confirm a real device can still bootstrap before considering the rotation finished.

Variations​

First key for a new group. Step 2 alone. With both slots empty, generate fills primary and is idempotent while primary is empty.

Abandoning a rotation. There is no way to clear the secondary slot without flipping. If you generated a key you no longer want to use, flip to it and rotate again.

If it doesn't work​

409 conflict on generate — both slots are already populated. Flip first, then generate.

409 conflict on flip — there is no secondary key to promote. Generate one first.

500 key_decryption_failed — stored ciphertext could not be decrypted, which usually means the service's master key is misconfigured. This is an operator problem, not a request problem.

Devices fail to bootstrap after the flip — they still hold the old key. There is no rollback; re-distribute the current primary key.

See also​