SHADE is young: 0.1.0-next.2 is a pre-release, and 0.1.0 isn't out yet.

SHADE
Run SHADE

Rotating APP_SECRET

APP_SECRET seals the secrets SHADE stores (email and payment keys, modules' secret settings, webhook signing secrets, team members' two-factor secrets) and signs sessions and links. Replace it when it may have leaked, when someone who knew it leaves, or on a schedule of your own. Nothing is lost: the old secret keeps opening what it sealed until everything is sealed again with the new one (decision 0007 point 12).

The key behind erased people's objections to list mail (Privacy) is one of those stored secrets: it is sealed again like the others and itself stays the same, so every objection keeps working after the old secret is gone.

The steps

  1. Make a new secret: openssl rand -base64 48.
  2. Set both, on every application of the instance (admin, public and worker), with the same values:
    • APP_SECRET: the new secret;
    • APP_SECRET_PREVIOUS: the old one. Several old ones are separated by commas, newest first.
  3. Restart the containers. Everyone is signed out once and signs in again (see below).
  4. Seal everything again, where the API runs:
    node console/rotate-secrets.mjs
    

    In a checkout of SHADE: pnpm --filter @shadestack/api rotate-secrets. It seals the stored secrets again in batches (--batch-size <n>, 100 by default), then asks each trusted module to do the same for what it keeps in its own tables. It prints what it did per kind and per module. You can run it while the instance serves, and again: what is sealed with the new secret is left alone.
  5. When it says everything is sealed (exit code 0), remove APP_SECRET_PREVIOUS from every application and restart them. Exit code 2 means something is left: a value no secret opens (it has to be entered again in the admin), or a module that failed. Keep APP_SECRET_PREVIOUS until a run ends with 0.
  6. Keep the old secret with your backups for as long as you keep backups made before today (6 months by default). Those backups hold values sealed with it: after restoring one, set the old secret in APP_SECRET_PREVIOUS and run rotate-secrets again.

A generated APP_SECRET (the deployment template's, in its secrets volume) is rotated the same way: read it once (cat /app/secrets/app/APP_SECRET in the admin container) for APP_SECRET_PREVIOUS, and set the new one in the environment, where it wins over the file. Keep the new one set afterwards: removing it brings back the generated one, which no longer opens what was sealed since. Confirm the kept copy again for the new secret (POST /api/backups/kept-copy).

While APP_SECRET_PREVIOUS is set, admins see a warning at the top of Settings: how many stored secrets are still sealed with the old secret, or, once none is, whether rotate-secrets has finished with the new one (it is what covers the modules' own secrets). It stays until the variable is removed.

node console/restore.mjs handover <folder> --show-secrets prints APP_SECRET_PREVIOUS too while it is set: a client who takes a backup made before the change needs it.

A known limit: a module's uninstall backup (Modules, after uninstalling) keeps the module's tables as they were, so a secret the module sealed there is not sealed again. To restore one taken before the change, set the old secret in APP_SECRET_PREVIOUS again, restore it, and run rotate-secrets.

What changes for people

WhatDuring and after the change
Team members and users who are signed inSigned out once; they sign in again. "Trust this browser" is asked again.
Two-factor codes and backup codesKeep working.
Links in emails already sent (confirm, cancel, move) and codesKeep working: rotate-secrets seals their key again.
A preview link opened just beforeKeeps working for its 10 minutes.
A user's address confirmation link sent in the hour beforeNo longer works; the user asks for a new one. Password reset links keep working.
API tokens, program tokens, webhook receivers, backupsNot affected.
Rate limitsCount from zero once.
Hashed IP addresses (audit log, form submissions, analytics)The same address hashes differently from now on; analytics may count a returning visitor twice that day.

For module developers

A trusted module that seals values in its own tables with ctx.vault.seal gives the manifest part onSecretsRotated(ctx): it reads its sealed values, seals each again with ctx.vault.reseal(value) unless ctx.vault.isCurrent(value), and resolves to how many it sealed. It runs as the module on every run of the command, so it leaves current values alone. A secret in a link the module sent (a keyed hash, ctx.vault.hash) is checked with ctx.vault.hashMatches(value, hash), which accepts the old secret's hash too.