Skip to main content

API gateway secrets management: encryption, env vars, Vault

API gateway secrets management in Zerq: AES-256-GCM storage with write-only reads, env-var secrets fed from Vault, rekey for key rotation, and what it lacks.

  • security
  • secrets-management
  • api-management
  • compliance
Zerq team

Updated November 2026: rewritten against the current code. Zerq has no HashiCorp Vault client. This version describes the mechanisms that exist: AES-256-GCM storage with write-only reads and an audited reveal, environment-variable-backed secrets, and the rekey tool.

API gateway secrets management in Zerq rests on two mechanisms, not on a Vault client. A secret is either stored encrypted with AES-256-GCM under a key you hold, with reads that never return it and a reveal that is audited, or it is the name of an environment variable that your secrets manager fills in the gateway container and the gateway reads at call time. This post shows both paths with the real field names, the failure modes, and what you give up compared with a native Vault integration.

The question arrives in two forms. The auditor asks who can read the credentials the gateway uses to call your core systems. The security architect asks why the gateway should hold them at all when Vault already exists. Kong, Tyk, Azure API Management and Gravitee answer with a reference syntax that the gateway resolves against the secrets manager itself. Zerq holds no token for Vault; the hop from Vault to the gateway is done by the tooling that feeds every other workload in your cluster. That removes one long-lived credential and one network dependency, and it moves rotation into your rollout process.

What does a gateway have to protect?

Three classes of secret pass through Zerq, and they live in three different places.

Upstream credentials are the Credentials objects the gateway uses to call backends: API keys, Basic Auth passwords, OAuth2 client secrets, mTLS client keys, connection strings for MongoDB, PostgreSQL, SQL Server, Oracle and Redis, and SMTP, SendGrid, Kafka and IMAP passwords. A credential is attached to a collection or to a single proxy through credentials_id, the proxy's own setting wins, and the HTTP request, database, messaging, LLM, agent and crypto workflow nodes read the same store.

Inbound tokens are the gateway tokens of client access profiles, the value a partner or an AI agent presents on every request. They are encrypted at rest with the same key as upstream credentials, they carry an expiry, and they rotate through a modifier-only endpoint that returns the new value once.

Platform secrets are the backend's own: ENCRYPTION_KEY, MONGODB_URI, JWT_SECRET and AUDIT_CHAIN_KEY. They exist only in the environment of the single gateway process, never in the database, and the database itself is your own MongoDB, not a vendor control plane.

How do Kong, Tyk, Azure API Management and Gravitee reference secrets?

As of November 2026, from each vendor's documentation:

  • Kong Gateway resolves references such as {vault://env/my-secret} inside the gateway. Open-source Kong is limited to environment variables as the backend; Enterprise adds HashiCorp Vault (token, Kubernetes and AppRole auth), AWS Secrets Manager, GCP Secret Manager, Azure Key Vault and CyberArk Conjur, and can re-check a secret on a TTL.
  • Tyk resolves kv://store/path references on load and on every reload, not per request. The env, inline, file, hashicorp_vault and hashicorp_consul stores are available to all users; the AWS, Azure and GCP managers are Enterprise Edition.
  • Azure API Management stores a named value of type Key vault, reads it with a managed identity, and picks up a changed Key Vault secret within four hours.
  • Gravitee APIM references secret://provider/name:key for Kubernetes, HashiCorp Vault, AWS Secrets Manager and Azure Key Vault; its Vault provider polls for changes.

These are real integrations, and where you want the gateway to own the Vault relationship they are the right tool. Each also gives the gateway a credential to the secrets manager and a dependency on it at load time. Zerq has neither: a credential field is either a ciphertext in your own MongoDB or the name of an environment variable, with no third source and no resolver to configure. The comparison pages cover the other differences; this post stays on secrets.

How does Zerq store a secret it has to hold?

At startup the backend reads ENCRYPTION_KEY, a base64-encoded 32-byte key, and refuses to start without it or with a key of the wrong length. Every secret field is encrypted on its own with AES-256-GCM, with a fresh random nonce for each write, and stored as base64 of the nonce followed by the ciphertext. GCM is authenticated encryption, so an altered ciphertext fails to decrypt rather than decrypting to garbage. The key value is masked in debug output.

Which fields are encrypted, and which of them are write-only, comes from one registry in the code:

Credential typeEncrypted fieldReturned on a read?
basicpasswordNever
api_keyapi_keyNever
oauth2_clientclient_secret (client_id is stored in plain text)Never
mtlsclient_private_keyNever
mtlsclient_certificate, ca_certificateYes, decrypted for any role: public X.509 material whose subject and expiry operators need to see
mongodb, postgres, sqlserver, oracle, redisthe connection stringNever
smtp, sendgrid, kafka, imapsmtp_password, sendgrid_api_key, kafka_sasl_password, imap_passwordNever

A read is the same for every role. GET /api/v1/credentials/:id needs the viewer role and returns the metadata plus a stored_secrets list naming the secret fields that hold a value, with the fields themselves blank:

{
  "id": "6650f1c2a9e4b3d7c1e20f11",     // credential ID referenced by collections and proxies
  "name": "payments-core",               // display name
  "type": "api_key",                     // one of the types in the table above
  "key_in": "header",                    // where the key goes on the upstream request
  "key_name": "X-Api-Key",               // header or query parameter name
  "api_key": "",                         // always blank on a read, whatever the caller's role
  "api_key_use_env": false,              // false: the value is stored encrypted
  "api_key_env_var": "",                 // only set for env-backed credentials
  "stored_secrets": ["api_key"],         // which secret fields have a value, without the values
  "updated_at": "2026-11-05T08:14:02Z"   // last change, audited as credential/update
}

Reading the value is a separate, privileged action. POST /api/v1/credentials/:id/reveal needs the modifier role, answers with Cache-Control: no-store, and is written to the audit log as credential / reveal_secret. The audit rule for that route sets omit_response_body: true, so the entry proves who revealed what and when without holding the secret. This is what the auditor sees, chained to its neighbors like every other audit record:

{
  "actor_id": "[email protected]",      // the OIDC email claim of the person who clicked reveal
  "actor_type": "modifier",                  // the caller's management roles, comma-joined
  "resource_type": "credential",             // from the audit rule
  "action": "reveal_secret",                 // from the audit rule
  "ip_address": "10.40.2.17",                // source address of the management request
  "metadata": {
    "url": "/api/v1/credentials/6650f1c2a9e4b3d7c1e20f11/reveal",
    "request_body": "",                      // the reveal takes no body
    "response_body": "",                     // omitted by rule: the secret is never stored here
    "status_code": 200
  },
  "seq": 48377,                              // position in the hash chain
  "prev_hash": "c1a4…",                      // hash of the previous entry
  "hash": "7e09…",                           // SHA-256, or HMAC-SHA256 with AUDIT_CHAIN_KEY
  "created_at": "2026-11-05T08:20:41Z"
}

Updates do not require the secret either. PUT /api/v1/credentials/:id merges the request body onto the stored credential, so a field left out is kept and a secret field sent blank keeps its stored value. The console shows such a field as •••••••• stored (leave blank to keep) and offers an eye icon that calls the reveal endpoint. The update itself is audited as credential / update, with the secret values in the submitted body replaced by [REDACTED].

Roles are separate tiers, not a ladder, and that matters here. An identity that holds only the admin role cannot even list credentials:

RoleList and read credentialsReveal a stored valueCreate, update, delete
ViewerMetadata and stored_secretsNo, 403No
AuditorNo, audit log onlyNoNo
ModifierMetadataYes, auditedYes
AdminNo; the admin tier only deletes request and AI log entriesNoNo

A compliance reviewer mapped to viewer and auditor can see that a credential exists, when it changed and who revealed it, and still cannot read it. That is the write-only rule of the security model: setting up the role groups is an identity-provider task, and what each role sees in the audit log is covered separately. The Management MCP exposes the same endpoints as list_credentials, get_credentials, create_credentials, update_credentials and delete_credentials, each forwarding the caller's own bearer token, and has no reveal tool.

How does a Vault secret reach Zerq without being stored?

Every secret field in the table above has two companion fields: <field>_use_env and <field>_env_var. Set the first to true and the second to a variable name, and nothing but the name is written to MongoDB:

POST /api/v1/credentials
{
  "name": "payments-core",               // display name
  "type": "api_key",                     // credential type
  "key_in": "header",                    // apply as a request header
  "key_name": "X-Api-Key",               // header name the upstream expects
  "api_key_use_env": true,               // do not store a value
  "api_key_env_var": "PAYMENTS_API_KEY"  // read this variable from the gateway's environment instead
}

Two properties follow from the code. First, the management API never resolves the variable: a read returns the name, and so does the reveal endpoint, because both paths blank env-backed fields before responding. Nobody with a console login can learn the value through Zerq, whatever their role. Second, the gateway reads the variable at the moment it builds the upstream request, with a plain os.Getenv. If the variable is unset or empty, the lookup fails with environment variable PAYMENTS_API_KEY is not set, the request is not forwarded, and the caller gets 502 Bad Gateway with the body Upstream credentials could not be applied. The cause lands in the request log's error field and in the server log, never in the response. An HTTP request node in a workflow fails the same way and takes its error branch. Failing closed is deliberate: a gateway that falls back to an unauthenticated upstream call when a secret is missing turns a configuration slip into a security incident.

So the integration question becomes: how does PAYMENTS_API_KEY get into the gateway container's environment? Three patterns cover most deployments.

Pattern 1: Vault Secrets Operator or External Secrets Operator on Kubernetes

Both operators copy a secret from Vault (or, through External Secrets Operator, from AWS Secrets Manager, Azure Key Vault or Google Secret Manager) into a Kubernetes Secret, and the Deployment exposes it as environment variables. The gateway never talks to Vault; the operator's service account does.

apiVersion: external-secrets.io/v1
kind: ExternalSecret
metadata:
  name: gateway-upstream            # one object per group of upstream secrets
spec:
  refreshInterval: 1h              # how often the operator re-reads Vault and rewrites the Secret
  secretStoreRef:
    kind: ClusterSecretStore
    name: vault-kv                  # the store that holds the Vault address and auth method
  target:
    name: gateway-upstream          # the Kubernetes Secret that will be created
  data:
    - secretKey: PAYMENTS_API_KEY   # key inside the Kubernetes Secret, and the env var name
      remoteRef:
        key: gateway/payments       # path in the Vault KV engine
        property: api_key           # field inside that Vault secret
# Deployment, backend container
envFrom:
  - secretRef:
      name: gateway-upstream        # every key becomes an environment variable
env:
  - name: ENCRYPTION_KEY            # the platform key is delivered the same way
    valueFrom:
      secretKeyRef:
        name: gateway-platform
        key: ENCRYPTION_KEY

The limit is in Kubernetes, not in Zerq. A container's environment is fixed when it starts; the Kubernetes documentation says so for ConfigMaps, which are delivered the same way as Secrets: values consumed as environment variables are not updated automatically and require a pod restart. The Vault Secrets Operator can trigger that restart, since its documentation lists automatic secret rotation for Deployment, ReplicaSet and StatefulSet resources. With External Secrets Operator, the rollout is a step in your runbook.

Pattern 2: Vault Agent Injector

The injector runs a Vault Agent sidecar that renders secrets to files under /vault/secrets, not to environment variables. The backend image is Debian-based and ships a shell, so the container command can load a rendered file before starting the gateway:

# Pod annotations: render one file in KEY=value form
vault.hashicorp.com/agent-inject: "true"
vault.hashicorp.com/role: "gateway"                       # Vault role bound to the pod's service account
vault.hashicorp.com/agent-inject-secret-upstream.env: "kv/data/gateway/payments"
vault.hashicorp.com/agent-inject-template-upstream.env: |
  {{- with secret "kv/data/gateway/payments" -}}
  PAYMENTS_API_KEY={{ .Data.data.api_key }}
  {{- end }}
# backend container: export the rendered variables, then start the gateway
command: ["sh", "-c", "set -a; . /vault/secrets/upstream.env; set +a; exec ./main"]

The same restart rule applies: the agent keeps the file fresh, but the shell read it once. The rendered file lives on the agent's shared memory volume; treat it as a secret on disk all the same.

Pattern 3: Docker Compose and single hosts

The published compose file passes the platform secrets from the host environment, for example ENCRYPTION_KEY: ${ENCRYPTION_KEY:-}. Add upstream variables to the backend service the same way, keep the .env file that fills them out of version control or render it with Vault Agent on the host, and treat a restart of the backend container as the rotation step.

What does rotation look like, step by step?

Four procedures, one per secret class, each with the evidence it leaves.

Rotating an environment-backed secret

  1. Write the new version in Vault. Vault's audit device records who did it.
  2. Wait for the operator's sync, or trigger it; refreshInterval in the ExternalSecret above bounds the delay.
  3. Roll the gateway Deployment so the new value is in the process environment. Until then every replica still uses the old value, which is why the upstream must accept both for the overlap window.
  4. Verify one request through a proxy that uses the credential. A 502 with Upstream credentials could not be applied means the variable did not arrive.
  5. Revoke the old value at the upstream.

Nothing changes in Zerq during this procedure, so nothing appears in Zerq's audit log. Your evidence is Vault's audit log, the sync and rollout events, and request logs showing traffic continuing. The gateway has no secret to protect and no record of a secret it never saw.

Rotating a stored secret

  1. Send PUT /api/v1/credentials/:id with the new value in the secret field, or type it over the stored placeholder in the console. The audit log records credential / update with the value redacted.
  2. The cache entry creds:{id} is dropped by the update rule at once. With the Redis cache that drop is shared by every replica; with the in-memory cache, only the replica that handled the update drops its copy and the others keep theirs for up to the 10-minute TTL. Run multi-replica deployments with CACHE_TYPE=redis.
  3. For mTLS credentials there is no extra step: the gateway caches one HTTP transport per distinct certificate, key and CA bundle, so a new key gets a new transport without invalidation. For OAuth2 client credentials, the cached access token stays in use until 60 seconds before its own expiry; the next fetch uses the new client secret.

Rotating the encryption key

  1. Generate the new key with openssl rand -base64 32.
  2. Stop every backend replica. The tool is designed to run against a quiet database.
  3. Run rekey from the backend image with ENCRYPTION_KEY_OLD and ENCRYPTION_KEY_NEW in its environment. Without -apply it only reports; check that the unreadable count is zero.
  4. Run it again with -apply. It re-encrypts every credential field and every profile token, skips values already on the new key so an interrupted run can be repeated, lists anything that decrypts with neither key and leaves it unchanged, and, when REDIS_URL is set, deletes the cached creds:* and profile:* entries that still hold old-key ciphertext.
  5. Start the backend with ENCRYPTION_KEY set to the new key.
rekey dry run (nothing written; pass -apply to write): 23 re-encrypted, 0 already on the new key, 0 unreadable
rekey applied: 23 re-encrypted, 0 already on the new key, 0 unreadable
removed 19 cached credentials and profiles from Redis

Env-backed fields are skipped by rekey because there is nothing to re-encrypt, which is one more argument for them. The certificate rotation checklist covers the rest of the platform-level list.

Rotating an inbound profile token

  1. Call POST /api/v1/clients/:clientId/profiles/:id/rotate with an optional expiry. It needs the modifier role and is audited as profile / rotate_credentials.
  2. The response carries the new token once, with expiry and last_rotated. A later GET of the profile's credentials returns metadata only, and the modifier-only reveal is audited like the credential reveal.
  3. Deliver the token to the client. An expired token is refused with 401 Authentication credentials have expired.

There is no scheduler for this inside Zerq. The expiry is enforced, the endpoint is scriptable, and the Management MCP has rotate_profile_credentials, so a CI job in your environment runs the cadence and the audit log proves it ran.

Which regulation asks which question?

RequirementWhat the auditor asksWhere Zerq's evidence is
PCI DSS v4.0.1 req. 8.6.2Are passwords for application and system accounts hard-coded in scripts or configuration files?Env-backed fields store a variable name; stored values are AES-256-GCM ciphertext; stored_secrets on a read shows that no API path returns them
PCI DSS v4.0.1 req. 8.3.2Are stored authentication factors rendered unreadable with strong cryptography?AES-256-GCM per field, key outside the database, rekey for key rotation
HIPAA §164.312(a)(2)(iv) and (b)Is credential material encrypted, and is privileged access recorded?Encryption at rest; every reveal is an audit entry without the secret
DORA Art. 9(4)(c) and (d)Are logical access and cryptographic keys controlled by policy and tooling?Role tiers from OIDC claims; ENCRYPTION_KEY outside the database; a documented, repeatable key rotation
NIS2 Art. 21(2)(h) and (i)Is there a cryptography policy and an access control policy you can demonstrate?The field registry and role table above are the demonstration; the audit chain is the record

The mapping helps you produce evidence; it does not make a platform compliant, and an assessor will also want the Vault side of the story for env-backed values.

An API gateway secrets management checklist

Eight yes-or-no questions to ask of any gateway, with Zerq's answers in brackets.

  1. Can a read-only role retrieve a stored secret through any API or UI path? (No. Reads return stored_secrets, not values.)
  2. Is every privileged reveal written to a log the revealer cannot edit? (Yes. reveal_secret entries are hash-chained and readable only by the auditor role.)
  3. Does the audit record of a reveal contain the secret? (No. The rule omits the response body.)
  4. Can a secret be referenced by name so that it never enters the database? (Yes. <field>_use_env and <field>_env_var.)
  5. Can the management plane resolve a referenced value? (No, not even on reveal.)
  6. When a reference cannot be resolved, does the request fail open or closed? (Closed. 502, request not forwarded, cause in the request log.)
  7. Does the gateway hold a long-lived credential to the secrets manager? (No. There is no client; the sync tooling holds the Vault identity.)
  8. Can the master key be rotated without re-entering every secret? (Yes, with rekey, in a maintenance window.)

Limitations and when Zerq isn't the right fit

Zerq has no client for HashiCorp Vault, AWS Secrets Manager, Azure Key Vault or Google Secret Manager. It cannot request dynamic secrets, hold leases or renew them. If your design needs per-instance database credentials with a four-hour TTL, an operator can sync them into a Secret, but the gateway needs a restart to read the new value, which defeats the short TTL. Use a stored credential rotated from your pipeline through the API, or a gateway with a native resolver.

A changed environment value needs a rollout. Kong's TTL re-check, Azure API Management's four-hour refresh and Gravitee's polling pick up a rotated value without a restart; Zerq does not. Plan overlap windows at the upstream.

rekey runs with the backend stopped. Key rotation is a maintenance window, not a live operation.

There is no built-in rotation schedule and no expiry reminder for profile tokens; expiry is enforced at request time and the cadence is yours to run. ENCRYPTION_KEY is a single environment variable with no KMS or HSM wrapping, so protect it with the same injection tooling as the upstream secrets and rotate it with rekey when the set of people who could have seen it changes.

The mTLS client and CA certificates are readable by every management role by design, because operators need their subject and expiry. If your policy treats certificates themselves as secrets, that is a mismatch.

What this looks like in practice

Illustrative scenario, not a specific customer deployment.

A bank's platform team runs the gateway on OpenShift next to an existing Vault. Before the change, fourteen upstream API keys sat in a Helm values file encrypted with SOPS; rotating one meant a pull request, a redeploy and a spreadsheet entry, and the previous gateway's admin console showed the keys to anyone with an operator login, which the last internal review had flagged.

The team configured a ClusterSecretStore for Vault with Kubernetes auth, one ExternalSecret with fourteen keys and a one-hour refresh, and envFrom on the backend Deployment. Each credential in Zerq was created with api_key_use_env: true and the variable name, so MongoDB holds fourteen names and no values. Two partner-issued mTLS keys that arrive as files, not through Vault, were stored as mtls credentials; their private keys are write-only and their certificates are visible so expiry can be watched. Four engineers map to the modifier role, two reviewers map to auditor and viewer, and nobody maps to both modifier and auditor.

After the change, the review question "who can read the payments key?" has a short answer: nobody through the gateway, and the people in the Vault policy for kv/gateway/payments through Vault, with Vault's audit device as the record. The two stored keys show up as reveal_secret entries only on the days an engineer actually looked at them. A rotation of the payments key is a Vault write at 09:00, a sync by 10:00, a rollout at 10:05 and a revocation at the provider at 10:30, with no change in Zerq and no entry in its audit log, because nothing in Zerq changed. That absence is the point.

Closing summary

Zerq keeps upstream secrets in one of two places, your MongoDB as AES-256-GCM ciphertext or your container environment as a named variable, and in neither case can a management read return the value. The reveal path is modifier-only and audited without the secret. Env-backed values are never resolved by the management plane, are read at call time, and fail closed with a 502 when missing. Vault, AWS, Azure and Google secrets reach the gateway through the Vault Secrets Operator, External Secrets Operator, Vault Agent or an env file, and a rotated value needs a rollout. rekey rotates the master key in a maintenance window. What Zerq lacks is a native secrets-manager client, dynamic secrets and restart-free rotation, and you should weigh that against Kong, Tyk, Azure API Management and Gravitee before you choose.

Sources


Zerq is an enterprise API gateway built for regulated industries — one platform for API management, AI agent access, compliance audit, and developer portal, running entirely in your own infrastructure. See how it works or request a demo to walk through your specific requirements.