A developer demos a new feature and the deploy works on the first try. You compliment them. They cheerfully explain that they put the API key in the Dockerfile as ENV STRIPE_KEY=sk_live_... so the new dev would not have to “mess with secrets” on their first ticket. The key is now in your private container registry, in every layer of every cache, in the build logs of the CI runner, and — because the registry replicates to your DR region — in two object stores you do not personally administer. Rotating it means rebuilding and re-tagging every image that ever included it.
What’s happening
There are three places a secret can live on a PaaS app, and the choice has real operational consequences.
Option A — baked into the image. ENV directive in the Dockerfile, or copied in as a config file. The secret travels with the image: it is in the registry, in every replica that pulls the image, in docker history output for anyone with read access, and in the build cache. Rotating means rebuild + redeploy of every dependent image. It is the easiest pattern to ship and the hardest to undo.
Option B — env var set in the PaaS dashboard. The image stays clean. The platform stores the secret in its own store, injects it into the container’s environment at start time, and the application reads os.environ['STRIPE_KEY'] the same way it would for any other config. Rotating is a dashboard edit plus a restart of the relevant service. This is the 12-factor default and a clear improvement over baking, but the secret still exists in plaintext in the platform’s database, in every container’s /proc/<pid>/environ, and is captured by any process listing tool a compromised neighbor could run.
Option C — pulled at startup from a secrets manager. The container’s environment has no secret. It has a vault address and a service-account credential (issued by the platform’s identity service, short-lived). At process start, an init step calls Vault / AWS Secrets Manager / Doppler / Bitwarden, retrieves the actual secret, and either writes it to a tmpfs file the app reads, or execs the application with the env var populated. Rotation is a single write to Vault — the next container restart picks up the new value. The audit trail is “the application identity X read secret Y at time Z” which is exactly the question you’ll be asked during a breach review.
Option C has tradeoffs: a Vault outage is now a deploy-time dependency, and you need to think about token TTLs and re-auth. But for any environment where “who could have read this secret in the last 90 days” needs an answer, it’s the only viable choice.
How to verify
Look for secrets in the image. This catches both deliberate ENV and accidentally-copied .env files:
# Inspect history of a built image
docker history --no-trunc your-org/app:latest \
| grep -E '(ENV|SECRET|KEY|TOKEN|PASSWORD|PWD)' \
| grep -vE '^.*#\s*(buildkit|missing)'
# Scan layers for credential-shaped strings
docker save your-org/app:latest -o /tmp/image.tar
tar -xf /tmp/image.tar -C /tmp/image-extracted/
grep -rE '(AKIA[0-9A-Z]{16}|sk_live_[A-Za-z0-9]{24,}|-----BEGIN.*KEY-----)' \
/tmp/image-extracted/ 2>/dev/null \
| head -20
Any hit is a finding. Rotate the matched secret and fix the build.
Check what is in /proc/<pid>/environ on a running container — this is what shows up to anyone with the same UID:
# From a debug shell inside the container
cat /proc/1/environ | tr '\0' '\n' \
| grep -E '(SECRET|TOKEN|KEY|PASSWORD)='
If your secret-bearing env vars are visible there, you are using Option B. That may be appropriate for non-critical secrets (a feature flag) but not for STRIPE_KEY.
The fix
Move every production secret to Option C. The migration pattern, with a Vault example:
Step 1 — provision short-lived platform identity for each app.
# Issue a Vault AppRole bound to the app's PaaS identity
vault write auth/approle/role/app-prod \
token_policies="app-prod" \
token_ttl=15m token_max_ttl=1h
# Read role_id (long-lived, OK to set as env var)
vault read auth/approle/role/app-prod/role-id
# Issue secret_id — store this in the PaaS env, scoped to the service
vault write -f auth/approle/role/app-prod/secret-id
The platform now holds the role_id and secret_id; the actual secrets stay in Vault.
Step 2 — write the secrets in Vault.
vault kv put secret/app-prod/stripe \
key=sk_live_... \
webhook_secret=whsec_...
vault kv put secret/app-prod/db \
url='postgresql://app:...@db.internal:5432/app'
Step 3 — Dockerfile pulls secrets at startup, not at build.
# Dockerfile — clean image, no secrets
FROM node:22-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY src ./src
FROM gcr.io/distroless/nodejs22-debian12
WORKDIR /app
COPY --from=build /app /app
# Tiny init that fetches secrets from Vault and execs the app
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
USER 65532:65532
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD ["node", "src/index.js"]
#!/bin/sh
# entrypoint.sh — distroless-compatible: keep simple, use busybox or a Go init in a real build
set -eu
: "${VAULT_ADDR:?VAULT_ADDR not set}"
: "${VAULT_ROLE_ID:?role_id not set}"
: "${VAULT_SECRET_ID:?secret_id not set}"
# Auth to vault
TOKEN=$(wget -qO- --post-data="{\"role_id\":\"${VAULT_ROLE_ID}\",\"secret_id\":\"${VAULT_SECRET_ID}\"}" \
--header="Content-Type: application/json" \
"${VAULT_ADDR}/v1/auth/approle/login" \
| sed -n 's/.*"client_token":"\([^"]*\)".*/\1/p')
# Pull secrets
fetch() {
wget -qO- --header="X-Vault-Token: ${TOKEN}" \
"${VAULT_ADDR}/v1/secret/data/$1" \
| sed -n "s/.*\"$2\":\"\([^\"]*\)\".*/\1/p"
}
export STRIPE_KEY=$(fetch app-prod/stripe key)
export STRIPE_WEBHOOK_SECRET=$(fetch app-prod/stripe webhook_secret)
export DATABASE_URL=$(fetch app-prod/db url)
# Drop the bootstrap creds — the app should never see them
unset VAULT_ROLE_ID VAULT_SECRET_ID
# exec the application
exec "$@"
Step 4 — verify the secret is not in the environment list of the running process for unprivileged neighbors. A tmpfs file is even better than env vars for very sensitive values:
# Variant: write secret to tmpfs, app reads from file
mkdir -p /run/secrets
mount -t tmpfs -o size=1m,mode=0400,uid=65532 tmpfs /run/secrets
echo -n "${STRIPE_KEY}" > /run/secrets/stripe_key
chmod 0400 /run/secrets/stripe_key
unset STRIPE_KEY
The application reads /run/secrets/stripe_key. That file is invisible to other UIDs on the same host and never appears in /proc/<pid>/environ.
When is Option B still acceptable? For low-value, non-rotating config (a feature flag name, a public client ID, a region code) that is not a secret in any meaningful sense. The distinction is “would compromise of this value require an incident response” — if no, env var is fine; if yes, Vault.
For PaaS apps with secret injection wired into the deploy pipeline, audited reads, and rotation runbooks, our Cloud PaaS team builds this in as part of deployment management. If your secrets currently live in a Dockerfile and a shared 1Password vault, book a secrets-tier review.