etlmcp encrypts the credentials it keeps before they reach its database: the OAuth tokens of your ad-platform connections, the secrets of your destinations, and the PKCE verifier it holds while you connect a platform. It uses Fernet, a recipe from the Python cryptography library that combines AES-128 in CBC mode with an HMAC-SHA256 signature. You can list several keys: the first one encrypts, and any of them can decrypt, so keys rotate without downtime. A production server refuses to start without keys, and there is no built-in fallback key.
What is encrypted
Three database columns hold ciphertext only:
| Column | What it holds |
|---|---|
connections.token_enc |
The access and refresh tokens a platform grants when you connect it |
destinations.secret_enc |
A destination's secret part, such as a PostgreSQL password or the headers you add to a webhook |
oauth_states.verifier_enc |
The PKCE verifier of a connect that is in progress |
Tokens are encrypted each time they are written: when you first connect, when you reconnect, and when etlmcp refreshes an access token. A destination secret is encrypted when you add the destination and again whenever you replace the secret.
The rest of a destination's settings, such as a host name or a webhook URL, are kept as plain settings beside the secret, because they are not credentials. The dashboard shows only whether a secret is saved, never the secret itself. The REST API and the MCP server return a destination's non-secret settings and leave the secret out entirely.
The OAuth state value of a connect is not kept at all: etlmcp stores only its SHA-256 hash, and the verifier next to it is encrypted.
The algorithm: Fernet
Fernet is the authenticated encryption scheme of the cryptography library. Its documentation describes each token as AES in CBC mode with a 128-bit key and PKCS7 padding, signed with HMAC using SHA-256, with a fresh random initialization vector each time. A Fernet key is 32 bytes written in URL-safe base64. Because every token is signed, a value that was changed in the database fails to decrypt instead of decrypting to something else.
Each Fernet token also carries the time it was made. That timestamp is readable without the key, so someone with database access can see when a value was written, but not what it holds.
Keys and rotation
The keys come from one setting, ETLMCP_ENCRYPTION_KEYS, a comma-separated list of Fernet keys. etlmcp wraps them in the library's MultiFernet:
- The first key in the list encrypts every new value.
- To decrypt, each key is tried in order until one works.
To rotate, put the new key first and keep the old ones after it. New writes use the new key at once, and values written under an old key still decrypt. etlmcp has no step that re-encrypts every stored value in one pass: an old value moves to the new key only when it is written again, for example when a token is refreshed or you save a destination's secret. Keep an old key in the list until nothing encrypted with it is left. If you remove it too early, those values can no longer be decrypted.
No fallback key in production
On start, the web app, the background worker and the migrate command check the production settings and stop with an error that names each problem. For encryption they refuse:
- an empty
ETLMCP_ENCRYPTION_KEYS; - any value that is not a valid Fernet key;
- the public development key that ships in the repository's Docker Compose file.
Outside production, when no key is set, etlmcp makes a random key for the life of the process and logs a warning. Anything encrypted with it cannot be read after a restart, so this is for local development only.
Short-lived values expire
For values that only need to live briefly, etlmcp has a sealing step: it encrypts the value with a Fernet timestamp and, when the value comes back, refuses any token older than the maximum age set for it, or any token that was altered. In the code today, the value sealed this way is the OAuth state of the Google consent flow behind the Google Sheets destination, which is coming. When that destination is available, an expired or altered state is treated as invalid and the Google connect does not go through.
When a saved secret cannot be read
If a destination's secret was encrypted with a key that is no longer configured, etlmcp cannot decrypt it. When you then edit that destination without entering a new secret, the request is refused with:
the saved secret can no longer be read — enter it again
Enter the password or headers again and save. The new value is encrypted with the current first key, so etlmcp can read it again.