Skip to content

Content encryption ​

Each instance encrypts the content it keeps before writing it: the PostgreSQL database and the blob storage only ever receive ciphertext. The key derives from ENCRYPTION_KEY, the instance key: no two instances share it.

What is encrypted ​

ContentWhereHow
Raw message (.eml): body, HTML, headersBlob storageAES-256-GCM, one key per object, in 64 KiB segments
Attachments, files added to runs, instance files, document templates, emails composed before sendingBlob storagesame
Message preview, body excerpt used by searchPostgreSQLAES-256-GCM, random nonce
Draft proposed to an approver, and its editsPostgreSQLsame

Still readable in the database: the subject, the sender, the recipients, the dates, the folders and the labels. The product needs them to sort, filter and group threads; they also appear in the audit logs. Workflow run data (step outputs) is not encrypted yet; it is purged according to retention.

Every encrypted value is authenticated: a modified byte, an object moved under another key or a value copied into another column is rejected on read.

The database no longer sees the text. To keep searching email bodies, the instance stores, next to each message, a secret fingerprint of each word (truncated HMAC-SHA256 with a derived key): the database can answer "this message contains this word" without containing the word.

  • A whole word is found, ignoring accents and case, in the subject, the preview, the sender and the body.
  • A word fragment (invo for invoice) is only found in the subject and the sender.
  • A quoted phrase is searched as its words, regardless of their order.

Turning it on for an existing instance ​

  1. Deploy the version. Encryption is on from the first boot (CONTENT_ENCRYPTION=auto): all new content is encrypted, and older content stays readable.

  2. Migrate the existing data, in a separate container:

    bash
    docker compose run --rm -T app node dist/cli.js content:encrypt run
    docker compose run --rm -T app node dist/cli.js content:encrypt status

    The migration works in batches and records its progress after each one: interrupted, it resumes where it stopped; run again, it rewrites nothing that is done. Exit code 4 reports content that could not be migrated (lastError says which).

  3. Once status reports remaining: 0 for messages and approvals and a finishedAt date for blobs, you can set CONTENT_ENCRYPTION=required: content still stored in clear is then refused instead of served.

On a versioned bucket, the old clear versions stay until your lifecycle rules expire them: delete the noncurrent versions if you do not want to wait.

Key rotation ​

Rotation renews the content key without stopping the service:

  1. Pick a new generation and keep the old one for reading:

    bash
    CONTENT_ENCRYPTION_KEY_ID=c2
    CONTENT_ENCRYPTION_PREVIOUS_KEYS=c1

    If ENCRYPTION_KEY itself changed (after a leak, for instance), give the old key to the old generation: CONTENT_ENCRYPTION_PREVIOUS_KEYS=c1=<previous key in hexadecimal>. Stored credentials (tokens, IMAP passwords) have no rotation yet: changing ENCRYPTION_KEY still means entering them again.

  2. Restart, then run content:encrypt run again: everything sealed by another generation is resealed with the new one.

  3. When status says everything is done, remove CONTENT_ENCRYPTION_PREVIOUS_KEYS and restart.

What it changes for you ​

  • ENCRYPTION_KEY now protects the content of the emails. Without it, a backup no longer makes the emails readable: keep it off the server (see Backups).
  • The cost is low: encrypting and decrypting 20 MB takes a few tens of milliseconds; the migration handles a few thousand messages in a few seconds.
  • Your storage provider's server-side encryption (SSE) is still worth having, but does not replace this: it protects against access to the provider's disks, not against access with your own S3 credentials.

Loop & Roll — the workflow builder for email.