Action — image-scan
Scans a container image for known vulnerabilities (OS packages and language libraries) with Trivy. It is the scan step of cd-docker.yml and ci-docker.yml, which build and load the image before it.
Usage
yaml
steps:
- run: docker build -t my-api:scan .
- uses: KevinDeBenedetti/github-workflows/.github/actions/image-scan@main
with:
image: my-api:scan
fail-on: criticalInputs
| Input | Default | Description |
|---|---|---|
image | (required) | Image reference to scan, loaded in the runner's Docker daemon |
fail-on | critical | Lowest severity that fails the step: low, medium, high or critical |
Steps
- Install the pinned
trivywithinstall-tool - Restore the vulnerability database from the Actions cache (one entry per day and runner architecture)
trivy image --scanners vulnonimage, for the severities atfail-onand above- List each vulnerability in the job summary (package, identifier, severity, installed and fixed versions); the step fails when there is one
Notes
- A vulnerability counts whether a fix exists or not. Silence one with its identifier in a
.trivyignorefile at the root of the checkout. - The image must be in the Docker daemon: a multi-platform build cannot be loaded, so scan the runner's platform.
- No SARIF is written: the findings are in the job summary and the log.
- The script is
image-scan.sh; its tests are intests/image-scan.bats.