Skip to content

Secrets and incidents

This page is for operators who look after the secrets of an Adiutor server. It covers what each secret protects, how to rotate the auth secret without losing data, and what to do after a suspected leak.

Secret Where it is set What it protects How to make one
BETTER_AUTH_SECRET The environment Signs session cookies. Encrypts authenticator secrets, backup codes, the mail server’s and file storage’s secrets saved in Settings, and webhooks’ addresses and signing secrets. 32+ characters openssl rand -base64 32
BETTER_AUTH_SECRETS The environment (optional) Newer versions of the secret above, for rotating it (below) As above, one per version
CRON_SECRET The environment, and your cron service Lets a cron service call the jobs’ endpoint. 32+ characters, only when one does openssl rand -base64 32
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY The environment (see Docker) Encrypts what Server Functions carry between the browser and the server. The same on every instance and release openssl rand -base64 32
The providers’ client secrets GITHUB_CLIENT_SECRET, GOOGLE_CLIENT_SECRET Sign-in with GitHub and Google At the provider
The mail server’s password SMTP_URL, or Settings Sending email as your sender At your mail provider
The file storage’s keys ATTACHMENTS_*, or Settings Reading and writing every attached file At the storage (S3 keys, SFTP key or password)
The database’s password DATABASE_URL All of Adiutor’s data In PostgreSQL

Keep secrets out of images and repositories. Make .env readable only by the user the app runs as: chmod 600 .env when that user owns it, or, on A plain Node.js server, where root owns it, chown root:adiutor .env && chmod 640 .env. Give each environment its own secrets.

BETTER_AUTH_SECRET signs cookies and encrypts authenticator secrets, backup codes, the secrets saved in Settings and webhooks’ addresses and signing secrets. To replace it without losing that data, use versioned secrets:

  1. Keep BETTER_AUTH_SECRET as it is, and add BETTER_AUTH_SECRETS=1:<new secret>, with a new secret of at least 32 characters. New data is encrypted with the new secret, and data encrypted before still decrypts with BETTER_AUTH_SECRET.
  2. Restart Adiutor and whatever runs the jobs (with Docker Compose, docker compose up -d).
  3. Next time, add the newest secret in front: BETTER_AUTH_SECRETS=2:<newer secret>,1:<new secret>. The newest comes first, and each version number appears once.

Drop an old version only when nothing encrypted with it is left: authenticator secrets and backup codes people set up before, the mail server’s and storage’s secrets in Settings, which are encrypted again when a staff Admin saves them again, and webhooks. A webhook whose secrets can no longer be read is turned off until a staff Admin gives it its address and a new secret.

Changing the current secret signs everyone out once, because session cookies are signed with it. It also changes what Adiutor works out from the secret: the keys that stand for people in a text being written, and the versions in the addresses of people’s pictures, so each picture is fetched once more.

Run the commands as described in Commands.

  • A session cookie or a user’s device. End all of that person’s sessions and forget the devices they trusted, so a stolen one asks for the second step again. They get an email about it.

    Terminal window
    pnpm sessions:revoke-all --user [email protected]

    A staff Admin can do the same with Sign out everywhere on the user’s Activity tab.

  • The database. Sessions need their signed cookie, so the database alone gives no way in. To be safe, end every session and forget every trusted device. Nobody is emailed: tell the users yourself if needed. Authenticator secrets and backup codes in the database are encrypted with the auth secret, and passwords are hashed.

    Terminal window
    pnpm sessions:revoke-all --yes
  • The auth secret. Rotate it as above, which signs everyone out, then run pnpm sessions:revoke-all --yes. The mention keys and picture versions follow the new secret, so the old one can no longer check a guess at who they stand for. If the database may have leaked too, ask users with an authenticator app to set it up again, since its secrets were encrypted with the old secret.

  • CRON_SECRET. Replace it, and update the cron service that calls the jobs’ endpoint.

  • A provider’s client secret. Make a new one at GitHub or Google, and replace it in the environment.

  • The mail server’s or storage’s password. Change it at the mail server or storage, then in Settings or in the environment.

Both pnpm sessions:revoke-all forms are recorded in the audit log, with how many sessions were ended.

Morgan Manager ([email protected]) loses a laptop. Alex Admin opens Morgan’s page and presses Sign out everywhere on its Activity tab, and Morgan gets an email. Or the operator runs pnpm sessions:revoke-all --user [email protected] on the server.

  • pnpm sessions:revoke-all needs either --user or --yes; it never signs everyone out without being asked.
  • Never run pnpm db:seed on a server: see Commands.

Adiutor's code is released under the MIT License. The Adiutor name and logo aren’t covered by it; see the notice.

Set in Inter and JetBrains Mono, under the SIL Open Font License (Inter, JetBrains Mono).