Encryption and Secret Sources
All sensitive credential values in Zerq are encrypted at rest using AES-256-GCM. This page explains the encryption model and how to configure secret sources.
AES-256-GCM encryption at rest
Every sensitive field in every credential is individually encrypted before being written to the database:
- Algorithm: AES-256-GCM (authenticated encryption with associated data)
- Key size: 256-bit (32 bytes), base64-encoded
- Nonce: Unique per-value — each field gets a fresh nonce on every write
- Integrity: GCM authentication tag prevents tampering
- At rest: Ciphertext + nonce stored in the database
- At runtime: Decrypted in-memory only at the moment the gateway needs to make an outbound request
The encryption key is provided via the ENCRYPTION_KEY environment variable on the backend gateway process. If this variable is missing or wrong, credential decryption fails at runtime with an internal error.
Key rotation
The backend image ships a rekey command that re-encrypts every stored secret (credential fields and access profile gateway tokens) from the current key to a new one. It reads both keys from the environment so they stay out of shell history, and it only reports unless you pass -apply.
-
Generate a new key:
openssl rand -base64 32. -
Stop the backend (every replica).
-
From
deploy/, enter both keys without echoing them, then do a dry run and check the counts:read -rsp 'Current key: ' ENCRYPTION_KEY_OLD; echo
read -rsp 'New key: ' ENCRYPTION_KEY_NEW; echo
export ENCRYPTION_KEY_OLD ENCRYPTION_KEY_NEW
docker compose -f docker-compose.platform.images.yml run --rm --no-deps \
-e ENCRYPTION_KEY_OLD -e ENCRYPTION_KEY_NEW --entrypoint ./rekey backend -
Run it again with
-apply. WithREDIS_URLset (as it is in the backend's environment), it also clears cached credentials and profiles, which still hold the old ciphertext. -
Set
ENCRYPTION_KEYto the new key and start the backend.
Values already on the new key are skipped, so an interrupted run can be repeated. rekey exits with an error and lists any value that decrypts with neither key; those are left unchanged. Outside Docker, run go run ./cmd/rekey from backend/ with MONGODB_URI, DB_NAME and optionally REDIS_URL set.
Never log, expose, or commit the ENCRYPTION_KEY value. If compromised, all stored credentials must be re-encrypted with a new key.
What is encrypted
The following fields are encrypted for each credential type. Field names are the JSON keys used by the Management API.
| Credential type | Encrypted fields | Write-only (never returned on reads) |
|---|---|---|
| Basic Auth | password | password |
| API Key | api_key | api_key |
| OAuth2 Client Credentials | client_secret | client_secret |
| mTLS Client Certificate | client_certificate, client_private_key, ca_certificate | client_private_key |
| MongoDB | mongodb_connection_uri | mongodb_connection_uri |
| PostgreSQL | postgresql_connection_string | postgresql_connection_string |
| SQL Server | sqlserver_connection_string | sqlserver_connection_string |
| Oracle | oracle_connection_string | oracle_connection_string |
| Redis | redis_connection_string | redis_connection_string |
| SMTP | smtp_password | smtp_password |
| SendGrid | sendgrid_api_key | sendgrid_api_key |
| Kafka | kafka_sasl_password | kafka_sasl_password |
| IMAP | imap_password | imap_password |
Non-sensitive fields (host, port, username, database name, token URL, env var names) are stored unencrypted for display purposes. The mTLS client and CA certificates are public X.509 material: they are encrypted at rest but decrypted for any reader so their subject and expiry can be inspected. The private key is not.
Secret sources
Zerq supports two sources for credential values:
1. Direct value (stored encrypted)
Enter the value directly in the Management UI. Zerq encrypts it before saving to the database. The UI never displays the value again after saving (show/hide only applies to unencrypted client credentials, not backend credential secrets).
2. Environment variable reference
Instead of storing the value, reference a container environment variable by name. Zerq reads the environment variable at runtime when it needs the value.
See Env-Backed Secrets for the full per-field env-var pattern.
Credential visibility by role
Secret values are write-only on the Management API. Reading a credential never returns a password, API key, client secret, private key or connection string, regardless of role.
| Role | List / get credentials | Reveal stored secret values | Create / update / delete |
|---|---|---|---|
| Viewer | Metadata only: name, type, non-secret fields, env var names, public certificates, and stored_secrets (which secret fields have a value) | No (403) | No |
| Auditor | No (audit logs only) | No | No |
| Modifier | Metadata only | Yes, via POST /api/v1/credentials/:id/reveal (audited) | Yes |
| Admin | No (admin only deletes request and AI log entries) | No | No |
The same rule applies to the gateway token of a client access profile: GET /api/v1/clients/:clientId/profiles/:id/credentials returns metadata only (auth_type, has_credentials, expiry, expired, last_rotated), and the value is returned by the modifier-only POST /api/v1/clients/:clientId/profiles/:id/credentials/reveal, by a rotation, or when an auth type is set. Profile reads (GET /clients/:clientId/profiles[/:id]) never include the stored token.
Values sourced from an environment variable are never resolved by the Management API, not even on reveal; only the variable name is shown.
Roles are separate tiers, not a hierarchy. An identity mapped to both viewer and auditor (for example, a compliance reviewer who also reads request logs) still cannot read secret values.
Editing credentials ("leave blank to keep")
- The edit form shows a stored secret as
•••••••• stored (leave blank to keep). - Leaving a secret field blank on update keeps the stored value. Entering a value replaces it.
PUT /api/v1/credentials/:idmerges the request body onto the stored credential, so omitted fields are kept. Automation and the Management MCPupdate_credentialstool can change a name or host without knowing the secret.- The eye icon next to a stored secret calls the reveal endpoint. So does the IMAP Test connection button when the password field is left blank. Each reveal is recorded in the audit log.
Audit trail
- Create, update and delete actions on credentials are written to the audit log (
credential/create,update,delete). - Every reveal is written to the audit log as
credential/reveal_secret(profile tokens:profile/reveal_credentials), including attempts rejected with403. The revealed values are not stored: the audit rule setsomit_response_body: true.
Related docs
- Env-Backed Secrets — reference environment variables per credential field
- Credentials Overview — how credentials are attached and scoped
- Secret Management — platform-wide secrets strategy