Skip to content
Back to search

reduce-image-cves

SkillWorks with Claude CodeGitHub

Reduce CVEs in a container image. Scan the original image, sort findings by fix status, then upgrade packages, remove unneeded ones, or move to a smaller base image. Prove the app still works with repeatable tests, rescan, and write a report that lists the remaining risks. Use when asked to harden, slim down, de-CVE, or fix vulnerabilities in a Docker/OCI image.

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/orikir--reduce-image-cves/badge.svg)](/listings/orikir--reduce-image-cves)

HTML

<a href="/listings/orikir--reduce-image-cves"><img src="/api/listings/orikir--reduce-image-cves/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

Copy the folder into your skills directory:

git clone <this repo> ~/.claude/skills/reduce-image-cves          # all projects
# or: <project>/.claude/skills/reduce-image-cves                   # one project

Then ask Claude something like *"reduce the CVEs in redis:7-bookworm"* or run `/reduce-image-cves`.

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

SKILL.md · Manifest · 54 lines
  1. ---
  2. name: reduce-image-cves
  3. description: Reduce CVEs in a container image. Scan the original image, sort findings by fix status, then upgrade packages, remove unneeded ones, or move to a smaller base image. Prove the app still works with repeatable tests, rescan, and write a report that lists the remaining risks. Use when asked to harden, slim down, de-CVE, or fix vulnerabilities in a Docker/OCI image.
  4. ---
  5. # Reduce CVEs in a container image
  6. **Scripts produce every number; you make the decisions.** Never retype scan numbers — paste script output.
  7. The mission in one line: find out what the app *actually* uses, then remove the rest, replace what can't be
  8. fixed, upgrade what can — and prove with the same tests that nothing broke.
  9. ## Setup
  10. ```bash
  11. S=<skill>/scripts; mkdir -p cve-work/<app> && cd cve-work/<app> # run everything from here
  12. mkdir -p summaries && bash $S/preflight.sh | tee summaries/tools.txt # tools, versions, DB date, env traps
  13. ```
  14. ## Workflow
  15. | # | Step | Run | Your decision |
  16. |---|---|---|---|
  17. | 1 | Inspect | `inspect_image.sh IMAGE` | What does the app need at runtime? (`runtime-deps.txt`: libs + entrypoint tools → packages; ldd misses dlopen/plugins — cover those in tests) |
  18. | 2 | Baseline | `scan.sh IMAGE@DIGEST baseline` | — (refuses to overwrite; freezes the grype DB from now on) |
  19. | 3 | Origin | `summarize_scan.py scans/baseline.json --by-source --md` | Per source package: not needed → **remove** / fix exists → **upgrade** / needed, no fix → **replace base** / the app → **accept**. This is the plan. |
  20. | 4 | Fixable? | read `summaries/baseline.txt` fix-state table | If 0 are `fixed`, upgrading can't help — go to 5/6. Try a newer tag with `scan.sh`. |
  21. | 5 | Remove | `templates/Dockerfile.purge-debian` → `build_scan.sh purge` | KEEP list. Replace root-only entrypoints (chown/setpriv/gosu) with a minimal one + `USER`. |
  22. | 6 | New base | `scan_bases.sh IMG…` → `Dockerfile.<name>` → `build_scan.sh <name>` | Keep the original libc; rebuild from the same source + build behaviour; install runtime libs as packages. |
  23. | 7 | Upgrade | add the upgrade to the chosen Dockerfile → `build_scan.sh` | Only what has a fix (rolling distros: `apk upgrade`). |
  24. | 8 | Leftovers | read `summaries/compare-<final>.txt` (shows how grype matched each) | Vendor tracker: fix coming? disputed? reachable in this app? Note source + date. |
  25. | 9 | Test | `app_test.sh` (+ app checks) on every image, `RUNS=3` → `compare_tests.py tests/original.tsv tests/<x>.tsv` | Define "working" (main feature, data types, persistence, network by name, TLS accept *and* reject, user, shutdown). Exit 1 = regression or flaky → blocks the change. Run any user-supplied test script unchanged too. |
  26. | 10 | Final | `scan.sh <tag> final`, `summarize_scan.py --compare … --removed`, `--outcome BASE STEP… FINAL --md` | Explain every NEW CVE. Tag meaningfully (`<app>:<ver>-<base>-<purpose>`). |
  27. | 11 | Report | `templates/REPORT.md` (styled .docx: `tech-report` skill) | Leftover table (decision + mitigation), prioritized next steps, behaviour changes. Map any required sections to a checklist. |
  28. All scripts take `DOCKER=podman`. `build_scan.sh` takes `VERSION_CMD="<app> --version"` as a smoke check.
  29. ## Rules
  30. - A CVE is fixed only when a rescan shows it gone.
  31. - No candidate with a regression ships.
  32. - Count unique CVE IDs (not matches); compare only scans from the same DB build, and state its date.
  33. - A 0-CVE static/distroless result can mean the libraries are invisible to the scanner — never pick it for that.
  34. - Report skipped steps and behaviour changes (fixed `USER`, removed tools, no shell).
  35. ## Traps
  36. - **DB drift:** the same image can score differently tomorrow. `scan.sh` freezes the DB after the baseline;
  37. `--compare` warns on mixed DBs and lists added/removed IDs and severity changes.
  38. - **Purging essential Debian packages** leaves half-removed (still reported) packages unless removal scripts are
  39. skipped — the template does it.
  40. - **snap docker** can't see `/tmp`: bind-mount files from `$HOME`. `~/snap` without the x bit breaks the client.
  41. - **WSL from Windows:** put commands in script files (no inline quoting), strip CRLF (`sed -i 's/\r$//'`).
  42. - **Size:** report `docker image inspect` (uncompressed), not grype's size; `scan.sh` prints it.
README.md · README · 42 lines
  1. # reduce-image-cves
  2. A [Claude Code](https://claude.com/claude-code) skill that cuts the CVE count of a container image without breaking the app.
  3. It finds out what the app actually uses, removes the rest, replaces what can't be fixed, upgrades what can, and proves with the same tests before and after that nothing broke. Scripts produce every number; Claude makes the decisions.
  4. ## Install
  5. Copy the folder into your skills directory:
  6. ```bash
  7. git clone <this repo> ~/.claude/skills/reduce-image-cves # all projects
  8. # or: <project>/.claude/skills/reduce-image-cves # one project
  9. ```
  10. Then ask Claude something like *"reduce the CVEs in redis:7-bookworm"* or run `/reduce-image-cves`.
  11. ## Requirements
  12. `docker` (or `podman`), [`grype`](https://github.com/anchore/grype), `python3`. Optional: `openssl` (TLS test certificates), `syft`.
  13. Run `scripts/preflight.sh` to check.
  14. ## What's inside
  15. | Path | Purpose |
  16. |---|---|
  17. | `SKILL.md` | The workflow: step → script → decision |
  18. | `scripts/preflight.sh` | Check tools, record versions + grype DB date, warn about environment traps |
  19. | `scripts/inspect_image.sh` | Digest, config, history, packages; map app libraries and entrypoint tools to packages |
  20. | `scripts/scan.sh` | Scan + summarize + compare with the baseline (protects the baseline, freezes the DB) |
  21. | `scripts/build_scan.sh` | Build `Dockerfile.<name>`, smoke-check, scan, compare |
  22. | `scripts/scan_bases.sh` | Scan and rank candidate base images |
  23. | `scripts/summarize_scan.py` | Unique-CVE summary, `--by-source`, `--compare`, `--outcome`, `--oneline`, `--md` |
  24. | `scripts/app_test.sh` | Repeatable smoke-test harness (readiness polling, exact checks, N runs, TSV) |
  25. | `scripts/compare_tests.py` | Line up test results across images; exit 1 on regressions or flaky checks |
  26. | `templates/Dockerfile.purge-debian` | Remove unused Debian packages cleanly and flatten into `scratch` |
  27. | `templates/REPORT.md` | Report skeleton |
  28. ## Example
  29. [`examples/redis`](examples/redis): `redis:7-bookworm` went from 113 → 4 unique CVEs (0 Critical/High) and 167 → 79 MB,
  30. with 114/114 functional checks passing on both images. Includes the Dockerfiles, test scripts, results and the full report.

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.