Documentation
Self-hosting / Rotate the master key

Rotate the master key

Replace ENCRYPTION_MASTER_KEY without losing the stored secrets, and what to do if the key is lost.

ENCRYPTION_MASTER_KEY encrypts the stored secrets and the JWT signing key. You can replace it at any time without losing data.

Rotation steps

  1. Generate a new key with openssl rand -base64 32.
  2. On the application and every worker, put the new key in ENCRYPTION_MASTER_KEY and the old one in ENCRYPTION_PREVIOUS_MASTER_KEYS (comma-separated if there are several).
  3. Restart. On startup the application re-encrypts every stored secret with the new key and logs Re-encrypted N stored secret(s). A warning lists the secrets no key could decrypt, to be re-entered.
  4. Remove ENCRYPTION_PREVIOUS_MASTER_KEYS at the next deployment.
How the master key is rotated1/5
› the app and worker-1 decrypt the secrets with key A
  • Secret read with key A
  • Secret written with key B

Secrets are encrypted with the current key

Notification tokens, the database passwords of your monitors and the JWT signing key are stored encrypted with ENCRYPTION_MASTER_KEY, here key A. The application and every worker hold the same key.

If the key is lost

A lost key cannot be recovered. The secrets it encrypted must be re-entered, and the jwt_signing_keys row deleted. Deleting that row signs everyone out.

Suggest a change on GitHub