Skip to content

Separate signing and encryption secrets, make encryption keys rotatable #98

Open

Description

@JuansesDev

Problem

JWT_SECRET is used for five unrelated purposes: signing session tokens, signing unsubscribe and click-tracking links, encrypting stored SMTP credentials, encrypting stored IMAP credentials, and encrypting the license key. One secret, no versioning.

The practical consequence is that the secret cannot be rotated. Rotating it logs every user out (acceptable) and makes every stored SMTP and IMAP credential undecryptable (not acceptable — every project stops sending until someone re-enters credentials by hand). A leaked or merely old secret therefore stays in place, which is the opposite of what a secret-hygiene story needs.

Proposal

Separate signing from encryption and make encryption keys rotatable:

  • Introduce ENCRYPTION_KEY for data at rest (SMTP, IMAP, license key). JWT_SECRET keeps signing sessions and links only. On upgrade, a missing ENCRYPTION_KEY falls back to JWT_SECRET so nothing breaks, with a startup WARN recommending the split.
  • Version the key: ENCRYPTION_KEYS accepts a comma-separated list, newest first. Ciphertext carries the key version; decryption tries the matching version; encryption always uses the newest.
  • Lazy re-encryption: whenever a credential is read with an older key version, rewrite it with the newest. An optional senddock-cli secrets rotate (see senddock-cli — admin and ops CLI bundled in the Docker image #76) re-encrypts everything eagerly.
  • JWT_SECRET rotation path: document that it invalidates sessions and signed links, and support a short dual-key grace window for link verification so in-flight unsubscribe and tracking links keep working after rotation.
  • Startup check: refuse to boot if ENCRYPTION_KEYS is set but cannot decrypt a sample row, to fail loudly on misconfiguration instead of silently disabling sending.

Acceptance

  • ENCRYPTION_KEY / ENCRYPTION_KEYS read by config, with JWT_SECRET fallback and startup warning
  • Versioned ciphertext format for SMTP, IMAP and license key, with migration of existing rows to version 1 on first read
  • Lazy re-encryption on read; unit tests for encrypt/decrypt across versions and for rotation
  • Grace window for link signature verification during JWT_SECRET rotation
  • Docs: configuration reference for the new variables and a "Rotating secrets" runbook under self-hosting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions