agentleFS
saizulsaizul/security-audit-skills/skills/dockerfile-security/SKILL.md

dockerfile-security

Skill0 starsChanged 10 days agoMITView on GitHub

Lint Dockerfiles and Containerfiles for security problems with a stdlib script - containers running as root, unpinned or :latest base images, secrets baked into ENV/ARG or RUN (values never printed), ADD from URLs without checksums, curl piped to sh, .env and private keys copied into the image, disabled TLS verification, chmod 777, sudo, EXPOSE 22 and COPY . without .dockerignore - then rewrite the Dockerfile with multi-stage builds, BuildKit secret mounts, a non-root user and pinned digests. Use when the user asks to review, harden or secure a Dockerfile, "is my Docker image secure", how to pass build secrets (npm token, GitHub token) safely, or why an image leaks credentials in docker history.

  • Pipes a download into a shell
  • Reads credentials

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Verify: if Docker is available and the user agrees: build, then docker history --no-trunc IMAGE | grep -iE 'token|secret|password' (should …

    line 53

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Dockerfile security

Paths below are relative to this skill's folder (in Claude Code: ${CLAUDE_SKILL_DIR}).

When to use

  • The user shares a Dockerfile, Containerfile or *.Dockerfile, or asks to harden one
  • "How do I pass my NPM_TOKEN / GITHUB_TOKEN to docker build safely?"
  • "Can someone see secrets in my image?", a scanner flagged root user or secrets in layers
  • Preparing an image for production or a public registry

When not to use

  • CVEs in OS packages or libraries inside a built image: use an image scanner (Trivy, Grype, Docker Scout) and dependency-audit for app dependencies
  • docker-compose / Kubernetes runtime settings (capabilities, read-only root, network policy): review those manifests separately; see the runtime notes in the reference
  • Hunting secrets across the whole repo: secrets-scan

Workflow

  1. Find the Dockerfiles and the build context (usually the directory with the Dockerfile; check CI or compose build.context).
  2. Lint (read-only).
    python3 scripts/dockerfile_lint.py .                       # finds Dockerfile*, *.Dockerfile, Containerfile
    python3 scripts/dockerfile_lint.py docker/api.Dockerfile --context .
    python3 scripts/dockerfile_lint.py . --json --fail-on high
    Exit 1 = findings at or above --fail-on (default medium), 2 = no Dockerfile / bad path. Secret values are never printed, only variable names.
  3. Treat secret findings as leaks. ENV, ARG values and RUN command lines are stored in the image config and history (docker history --no-trunc) and anyone who can pull the image can read them. If an affected image was pushed to a registry, the secret must be rotated (see the rotation guide in the secrets-scan skill) - rebuilding is not enough.
  4. Add context the linter cannot see: does the app need root (binding ports < 1024 can be solved with a higher port), what does the final stage really need, is there a .dockerignore, are images pulled from a trusted registry, is the base image maintained?
  5. Rewrite using references/hardened-dockerfile.md: multi-stage build, pinned base (tag + digest), RUN --mount=type=secret for build secrets, unprivileged USER, COPY instead of ADD, checksum-verified downloads, minimal final image, .dockerignore. Keep the user's build behaviour; explain each change.
  6. Verify if Docker is available and the user agrees: build, then docker history --no-trunc IMAGE | grep -iE 'token|secret|password' (should be empty) and docker run --rm IMAGE id -u (should not be 0). Re-run the linter.

Output

dockerfile lint: 1 file(s), 3 high, 8 medium, 4 low, 1 info
HIGH   Dockerfile:3   DF003 ARG GITHUB_TOKEN has a default secret value; build args are visible in image history
HIGH   Dockerfile:10  DF006 secret file copied into the image: .env
MEDIUM Dockerfile:1   DF001 base image 'node' is not tagged
MEDIUM Dockerfile:15  DF002 final USER is root
...
Rewritten Dockerfile (diff) + .dockerignore, and: "GITHUB_TOKEN was in image history of
registry.example.com/app:1.4 -> rotate it".

Rule reference

RuleSeverityMeaning
DF001medium / infobase image untagged or :latest (info: comes from a build arg)
DF002mediumfinal stage runs as root
DF003high / mediumsecret in ENV, ARG or RUN
DF004medium / lowADD from URL without --checksum; ADD for plain files
DF005mediumcurl ... | sh
DF006high.env, keys, .npmrc, credentials copied into the image
DF007mediumTLS verification disabled
DF008medium / lowworld-writable permissions; sudo
DF009lowEXPOSE 22
DF010lowCOPY . without .dockerignore
DF011mediumRUN --security=insecure
DF012infono HEALTHCHECK

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.