no-plaintext-secrets
API keys and passwords written literally in a Compose file end up in version control. Where to put Compose secrets instead: interpolation, env_file, or secrets.
On this page
A Compose file is code: it gets committed, reviewed, forked, and pushed to template registries. A literal OPENAI_API_KEY: sk-… in environment: therefore publishes the credential to everyone with repo access, and to every clone, mirror, and backup, forever. This rule flags environment entries (map or list syntax) whose key looks like a credential (PASSWORD, SECRET, TOKEN, API_KEY, …) and whose value is a literal rather than a ${VAR} interpolation. A URL without embedded credentials (AUTH_URL: http://auth:8080) names an endpoint, not a secret, so the rule skips it. The rule also skips a key whose last word describes a credential without holding it: where it lives (file, path, dir, sock, socket), how long it lasts or how long it is (ttl, timeout, seconds, minutes, hours, days, expire, expires, expiry, expiration, expires_in, length), how many or how large (limit, budget, count, size), which one it is or which scheme guards it (name, type, mode, driver, method, policy, provider, algorithm), or whether it is on (enabled, disabled). POSTGRES_PASSWORD_FILE: /run/secrets/db_password, SSH_AUTH_SOCK, TOKEN_TTL_SECONDS, ACCESS_TOKEN_EXPIRE_MINUTES, TOKEN_LIMIT and POSTGRES_HOST_AUTH_METHOD are not reported. A key that starts with MAX_ or MIN_ names a bound, so MAX_TOKEN is not reported either. A key that ends in a word that can hold the credential itself, such as AUTH_HEADER, PASSWORD_HASH, SECRET_KEY or API_TOKEN_ID, is still reported. The rule skips on/off values too: true, false, yes, no, on, off, 0 and 1, as in MYSQL_RANDOM_ROOT_PASSWORD=1. A key that names a credential by its role or provider is reported too, such as OPENAI_KEY, LITELLM_MASTER_KEY or N8N_ENCRYPTION_KEY. The _KEY names covered start with a word such as master, encryption, signing, access, service, admin, license, hmac, jwt or a model provider. The names PRIMARY_KEY, PUBLIC_KEY and AWS_ACCESS_KEY_ID are not enough to report a value. A value that has the shape of a provider token is reported under any key name, those included. A value with no digit, no long unbroken run of characters, or the EXAMPLE suffix of the AWS sample ID is a placeholder and is not treated as a token. The shapes are sk-, hf_, the GitHub prefixes ghp_, gho_, ghu_, ghs_ and ghr_, github_pat_, and AWS access key ids (AKIA, ASIA), each followed by a long literal run of characters. A report names the key and never the value. A URL value that carries a literal password in its user part, such as DATABASE_URL: postgres://app:hunter2@db/app, is reported under any key name, and so is a development password like postgres://postgres:postgres@db. A URL with only a user name (ssh://git@host), an empty password, a password that names a variable or a template slot (${DB_PASSWORD}, $PW, #{pw}, {{pw}}, %s), and a key that ends in _FILE are not reported. Keep the password out of the URL with postgres://app:${DB_PASSWORD}@db/app, which Compose resolves from the host environment. The rule reads environment and build.args, in list and map syntax, and does not read command, healthcheck or labels. A build arg stays in the image history, so anyone who can pull the image can read it. Pass the value as a Compose secrets: entry and read it in the Dockerfile with RUN --mount=type=secret.
What the rule catches
services:
agent:
image: my-agent:1.2.0
environment:
OPENAI_API_KEY: sk-proj-abc123
DB_PASSWORD: hunter2Scanning this file reports:
⚠ WARN [docker-doctor/no-plaintext-secrets]
Potential secret in service 'agent' environment: 'OPENAI_API_KEY'. A literal value here lives in version control in plain text.Why it matters
Committed credentials are one of the most common real-world breach vectors, and compose files travel further than people expect: they get pasted into issues, copied into starter templates, and pushed to public forks. Agent stacks concentrate the risk, since one file often holds keys for a model provider, a search API, and a database at once. Apart from token-shaped values, the rule only inspects the key name, so it cannot tell a real key from a placeholder; treat a hit on a placeholder as a prompt to switch to interpolation before the placeholder becomes real.
How to fix it
Move the value to an env_file kept out of version control, interpolate it from the host environment (${VAR}), or use Compose secrets:.
services:
agent:
image: my-agent:1.2.0
environment:
# resolved from the host environment / .env at compose up time
OPENAI_API_KEY: ${OPENAI_API_KEY}
env_file:
- .env.local # gitignoredPick the mechanism by how sensitive the value is:
${VAR}interpolation: Compose resolves it from the host environment or a.envfile atcompose uptime; the compose file carries only the reference.env_file: point it at a gitignored file to keep whole blocks of configuration out of version control.- Compose
secrets: mounts the value as a file rather than an environment variable, which also keeps it out ofdocker inspectoutput and crash dumps.
If a real credential has already been committed, rotate it. Removing the line only hides it from the working tree, not from git history.
Rule details
- Rule key —
docker-doctor/no-plaintext-secrets - Category — Compose
- Default severity —
warning - Applies to — Docker Compose files
Explain this rule from the CLI:
npx @docker-doctor/cli@latest rules explain docker-doctor/no-plaintext-secretsChange its severity — or turn it off — in your config file:
// docker-doctor.config.ts
export default {
rules: {
"docker-doctor/no-plaintext-secrets": "off",
},
};Severity affects the health score: error findings cost more points than warning, and info costs the least.