Rotating the encryption key (self-hosting)
For whoever runs an Indrava server, how to replace ENCRYPTION_KEY without losing connected channels, using pnpm reseal.
This page is for whoever runs an Indrava server. On a server somebody else runs for you there is nothing to do.
ENCRYPTION_KEY seals what Indrava stores about your channels (the tokens the platforms gave it) and hashes the tokens of review, report and connect links. Replace it when it may have leaked, or on your own schedule. Done in the order below, no channel has to be reconnected and the server does not go down beyond one restart.
Steps
Make a new key:
openssl rand -hex 32.Set it as
ENCRYPTION_KEY, and put the old key inENCRYPTION_KEY_PREVIOUS. If older keys are already listed there, keep them, comma-separated, newest first. The api and the worker must have the same values.Restart the api and the worker together.
Re-seal the stored channel credentials with the new key. From the repository, with both keys in
.env:pnpm resealIn the api container, where pnpm is not installed, run the same script directly:
node --env-file=.env scripts/reseal.ts.It prints one line:
re-sealed 12, already current 0, unreadable 0. Run it again until it saysre-sealed 0andunreadable 0.Remove the old key from
ENCRYPTION_KEY_PREVIOUSand restart.
What pnpm reseal does
It opens each stored channel credential with whichever listed key fits and seals it again with the new one. It works in batches, can run while the api and the worker are running, and can be run any number of times. It prints counts and channel ids, never a key or a token.
A channel it lists as unreadable was sealed with a key that is no longer listed anywhere. Put that key back in ENCRYPTION_KEY_PREVIOUS and run it again, or reconnect the channel on Channels.
Between the restart and the last step
New values are sealed, and new links hashed, with the new key at once.
Channels keep publishing: a credential not yet re-sealed still opens with the old key.
A review, report or connect link made before the rotation still works, and moves to the new key the first time somebody opens it.
With the
localstorage driver, a signed media download link made before the restart works until it runs out (15 minutes).
What does not survive removing the old key
Links cannot be re-hashed in bulk: only the token gives the new hash, and Indrava does not store tokens. A review or report link that nobody opened between the rotation and step 6 stops working when the old key is removed. Make a new link for it. To avoid this, leave the old key listed until the links you care about have been opened or have expired.
Do not remove the old key before step 5 is clean: a credential still sealed with it could no longer be opened, and its channel would have to be reconnected.