OpenFolia

Instance secret key

The key that seals the secrets the server stores: where it comes from, backing it up, several servers, rotation.

The instance secret key seals (AES-256-GCM) every secret the server stores and must use itself: webhook signing and header secrets, queued emails, the S3 secret and the kept backup key of the backups. It is never stored in the database, so a database dump alone opens none of them. It is never logged, never answered by the API and never written to the audit log.

Where it comes from

The API looks, in this order, at:

  1. CCMS_SECRET_KEY: the key itself, 32 random bytes as base64 (openssl rand -base64 32) or 64 hex digits. Then no key file is read or written.
  2. The key file, CCMS_SECRET_KEY_FILE. By default it is ccms-secret.key in the folder that holds the content repository: /data/ccms-secret.key in the containers.
  3. Unless CCMS_SECRET_KEY_GENERATE=false: a new key, made on the first start and written as the key file, with mode 0600 (its folder 0700).

Without any key, webhooks and email stay off. Admin › System shows where the key comes from, never the key.

For one server, set nothing: the first start makes the key file on the data volume.

Back it up

Back up the key together with the database: one without the other loses every stored secret. The backup service puts the key file into every backup. If you set CCMS_SECRET_KEY, keep it in your secret store.

The API refuses to start, with a message and never with a new key, when the key does not open what the database holds (another key set, the wrong file mounted), or when the database holds sealed secrets and there is no key. Restoring the right key file is then enough.

Several servers

Give every server the same key: set CCMS_SECRET_KEY to the same value on each, or let them share one key file on one volume. Set CCMS_SECRET_KEY_GENERATE=false where a missing key must never be made up, for example a hosted setup with a secret store.

Rotate the key

Rotation re-seals every stored secret under a new key, in one transaction. The secrets themselves do not change: webhook receivers notice nothing.

  1. Stop everything that holds the key, the workers too: docker compose stop api worker backup.

  2. Only when CCMS_SECRET_KEY sets the key: set CCMS_SECRET_KEY_NEW to the new key (same format), in the same settings file, for example deploy/api.env (readable by you only: chmod 600 deploy/api.env). With the key file, the rotation makes the new key itself.

  3. Run the rotation:

    docker compose run --rm api node dist/secrets/rotate-secret-key.main.js

    It applies pending migrations, checks the current key as a start does, and says how many secrets it re-sealed. It never prints a key.

  4. With the key file: the file now holds the new key. Back it up again. With CCMS_SECRET_KEY: set it to the new key on every server, and remove CCMS_SECRET_KEY_NEW (never leave it set).

  5. Start the stack: docker compose up -d --wait.

A secret the old key could not open either is left as it was and counted: give that webhook a new secret. A rotation cut off before it finished leaves the old key working; the next start sets the unfinished new key aside as <file>.next.discarded.<time>.<id>. Remove those files once no backup needs them. A key file that is a symbolic link (a mounted secret) is replaced by a plain file, so rotate such a key with CCMS_SECRET_KEY_NEW and update the mount instead.

The old name

CCMS_WEBHOOKS_SECRET_KEY is the old name of CCMS_SECRET_KEY. It is still read when CCMS_SECRET_KEY is unset, with a warning at start-up. Rename it.

On this page