Skip to main content

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.

  1. Generate a new key: openssl rand -base64 32.

  2. Stop the backend (every replica).

  3. 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
  4. Run it again with -apply. With REDIS_URL set (as it is in the backend's environment), it also clears cached credentials and profiles, which still hold the old ciphertext.

  5. Set ENCRYPTION_KEY to 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.

danger

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 typeEncrypted fieldsWrite-only (never returned on reads)
Basic Authpasswordpassword
API Keyapi_keyapi_key
OAuth2 Client Credentialsclient_secretclient_secret
mTLS Client Certificateclient_certificate, client_private_key, ca_certificateclient_private_key
MongoDBmongodb_connection_urimongodb_connection_uri
PostgreSQLpostgresql_connection_stringpostgresql_connection_string
SQL Serversqlserver_connection_stringsqlserver_connection_string
Oracleoracle_connection_stringoracle_connection_string
Redisredis_connection_stringredis_connection_string
SMTPsmtp_passwordsmtp_password
SendGridsendgrid_api_keysendgrid_api_key
Kafkakafka_sasl_passwordkafka_sasl_password
IMAPimap_passwordimap_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.

RoleList / get credentialsReveal stored secret valuesCreate / update / delete
ViewerMetadata only: name, type, non-secret fields, env var names, public certificates, and stored_secrets (which secret fields have a value)No (403)No
AuditorNo (audit logs only)NoNo
ModifierMetadata onlyYes, via POST /api/v1/credentials/:id/reveal (audited)Yes
AdminNo (admin only deletes request and AI log entries)NoNo

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/:id merges the request body onto the stored credential, so omitted fields are kept. Automation and the Management MCP update_credentials tool 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 with 403. The revealed values are not stored: the audit rule sets omit_response_body: true.