-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-secrets.mdc
More file actions
52 lines (42 loc) · 1.93 KB
/
docker-secrets.mdc
File metadata and controls
52 lines (42 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
---
description: Flag hardcoded passwords, tokens, and registry credentials in Docker configurations. Suggest environment variables or Docker secrets.
alwaysApply: true
standards-version: 1.6.3
---
# Docker Secrets and Credential Safety
## Patterns to Flag
### Hardcoded Credentials
- Passwords, tokens, or API keys directly in Dockerfiles (`ENV PASSWORD=`, `ARG SECRET=`)
- Hardcoded credentials in docker-compose.yml environment sections
- Registry passwords in plain text (`docker login --password`)
- Database connection strings with embedded passwords
- AWS, GCP, or Azure credentials in Docker configs
### Dangerous Commands
- `docker login --password` or `docker login -p` in scripts or CI configs - use `--password-stdin` instead
- `COPY .env` in Dockerfiles - secrets should not be baked into images
- `ENV` instructions containing keys, tokens, or passwords
- `ARG` instructions for secrets that persist in image layer history
### Configuration Files
- `.env` files committed with actual credential values
- `config.json` or `daemon.json` with registry auth tokens in plain text
- Docker Swarm secrets stored as plain text files
## What to Do
- Use environment variables passed at runtime (`docker run -e`, compose `environment:` with variable substitution)
- Use Docker secrets for Swarm deployments (`docker secret create`)
- Use BuildKit secret mounts for build-time secrets (`--mount=type=secret`)
- Use credential helpers for registry authentication (`docker-credential-*`)
- Reference `.env` files via `env_file:` in compose instead of hardcoding values
- Use `--password-stdin` for `docker login` commands
## Examples
Flagged:
```dockerfile
ENV DB_PASSWORD=mysecretpassword
ARG GITHUB_TOKEN=ghp_xxxxxxxxxxxx
```
Correct:
```dockerfile
# Pass at runtime: docker run -e DB_PASSWORD
ENV DB_PASSWORD=""
# Use BuildKit secrets: docker build --secret id=github_token,src=./token.txt
RUN --mount=type=secret,id=github_token cat /run/secrets/github_token
```