agentleFS
HayatelinHayatelin/devsecops-skills/skills/dockerfile-hardening/SKILL.md

dockerfile-hardening

Skill0 starsChanged 5 months agoMITView on GitHub

Harden a Dockerfile / container image against common misconfigurations. Trigger when the user says "harden this Dockerfile", "is my container secure", "review my Docker image", or when adding/editing a Dockerfile or container build before shipping.

  • Reads credentials
  • Deletes or force-pushes
  • Installs packages

1 other project uses a version of this.

Adopted by

Most recently taken up by

  • Other versions1 project uses a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 1

    1. kaandgnsh/Claude-Blue★ 0same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository8 other files it gives its agents.

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    After a base-image bump or when an image scan (Trivy/Grype) flags issues.

    line 14
  2. Distinctive:

    Read the Dockerfile and note the base image, what runs as root, how secrets are handled, and the layer structure.

    line 18
  3. Distinctive:

    Verify the image still builds and runs after hardening.

    line 22

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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

When to use

  • Writing or reviewing a Dockerfile, Containerfile, or container build before it goes to a registry or production.
  • The user asks "is this image secure?" or wants a before/after hardening pass.
  • After a base-image bump or when an image scan (Trivy/Grype) flags issues.

Process

  1. Read the Dockerfile and note the base image, what runs as root, how secrets are handled, and the layer structure.
  2. Apply the checklist below, top to bottom.
  3. Produce a before/after Dockerfile so the change is reviewable.
  4. Recommend a scan to confirm: trivy image <tag> (or grype <tag>) and hadolint Dockerfile for lint.
  5. Verify the image still builds and runs after hardening.

Checklist

  • Non-root user — create and USER appuser; don't run as root. Use a numeric UID for k8s runAsNonRoot.
  • Pinned base image by digest — FROM python:3.12-slim@sha256:..., not :latest. Prefer minimal bases (slim, distroless, alpine) to shrink attack surface.
  • Multi-stage build — build deps in a builder stage; copy only artifacts into a lean runtime stage. Keeps compilers/secrets out of the final image.
  • No secrets in layers — never COPY .env, never ARG/ENV a secret (it persists in history). Use BuildKit secret mounts: RUN --mount=type=secret,id=token ....
  • .dockerignore — exclude .git, .env, secrets, node_modules, build cruft so they never enter the context.
  • Minimal layers & cleanup — combine RUN steps; clean package caches in the same layer (rm -rf /var/lib/apt/lists/*); no leftover temp files.
  • Pin package versions — pin apt/pip/npm versions for reproducibility; copy lockfiles and install from them.
  • Drop capabilities & no new privileges — document running with --cap-drop=ALL (add back only what's needed), --security-opt=no-new-privileges, and a read-only root filesystem where possible.
  • HEALTHCHECK — add a HEALTHCHECK so orchestrators detect a broken container.
  • No unnecessary tooling — don't ship curl/wget/compilers/shells you don't need at runtime (distroless helps).

How to fix — before/after sketch

Before:

FROM python:latest
COPY . .
RUN pip install -r requirements.txt
CMD ["python", "app.py"]

After:

FROM python:3.12-slim@sha256:<digest> AS build
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir --prefix=/install -r requirements.txt

FROM python:3.12-slim@sha256:<digest>
RUN useradd -m -u 10001 appuser
WORKDIR /app
COPY --from=build /install /usr/local
COPY --chown=appuser:appuser . .
USER appuser
HEALTHCHECK CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')"
CMD ["python", "app.py"]

Pair with a .dockerignore (.git, .env, **/__pycache__, node_modules) and run at deploy time with --cap-drop=ALL --security-opt=no-new-privileges --read-only.

Report back

Give a short list of what was hardened (non-root, pinned digest, multi-stage, no secrets, .dockerignore, healthcheck, caps), the before/after Dockerfile, and the scan/lint commands to confirm. Flag anything that needs a runtime/orchestrator change (capabilities, read-only FS) the Dockerfile alone can't enforce.

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.