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
- Generate a new key with
openssl rand -base64 32. - On the application and every worker, put the new key in
ENCRYPTION_MASTER_KEYand the old one inENCRYPTION_PREVIOUS_MASTER_KEYS(comma-separated if there are several). - 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. - Remove
ENCRYPTION_PREVIOUS_MASTER_KEYSat the next deployment.
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.
