Skip to content

scan-trivy.yml

Run Trivy vulnerability scans on container images and/or configuration files and upload SARIF reports to GitHub Security.

Inputs

InputTypeDescriptionRequiredDefault
IMAGEstringImage used to perform scan (e.g., docker.io/debian:latest)No-
REGISTRY_USERNAMEstringUsername used to login into registryNo-
REGISTRY_PASSWORDstringPassword used to login into registryNo-
PATHstringPath used to perform config scanNo-
FORMATstringFormat of the report (sarif, table, json, ...)Notable
PR_NUMBERstringPR number for comment postingNo-
GITHUB_SECURITY_TABbooleanWhether to upload SARIF to GitHub Security TabNofalse
RUNS_ONstringRunner labels as JSON array (e.g., '["ubuntu-24.04"]' or '["self-hosted", "linux"]')No["ubuntu-24.04"]

Permissions

ScopeAccessDescription
contentsreadRead repository contents
security-eventswriteUpload SARIF to code scanning
pull-requestswritePost a comment on the pull request
packagesreadPull images from GHCR

Notes

  • images-scan runs only if IMAGE is provided; config-scan runs only if PATH is provided.
  • FORMAT controls output format: table (default) prints results to workflow summary, sarif enables GitHub Security Tab integration.
  • When GITHUB_SECURITY_TAB: true and FORMAT: sarif, uploads results to the Security tab.
  • PR comments link to either the GitHub Security Tab (when GITHUB_SECURITY_TAB: true) or the Workflow Summary page.
  • Registry authentication: uses GitHub token for ghcr.io, otherwise uses provided credentials.
  • Skips common directories via skip-dirs: **/node_modules in config scan.

Examples

The examples show the two main output modes: a quick table-format scan for direct feedback, and GitHub Security Advisory integration to populate the repository's Security tab.

Simple scan with table output

Runs both an image scan and a configuration path scan in parallel. Results are printed as a table in the workflow summary. When PR_NUMBER is set, a PR comment is posted linking back to the summary page.

yaml
jobs:
  vuln-scan:
    uses: this-is-tobi/github-workflows/.github/workflows/scan-trivy.yml@v0
    with:
      IMAGE: ghcr.io/my-org/my-image:1.2.3
      PATH: ./apps/api
      FORMAT: table
      PR_NUMBER: ${{ github.event.pull_request.number }}

Scan with GitHub Security Tab integration

FORMAT: sarif produces a SARIF report that is uploaded to the repository's Security → Code scanning tab when GITHUB_SECURITY_TAB: true. Findings are deduplicated and tracked across runs; the PR comment links to the Security tab instead of the workflow summary.

yaml
jobs:
  vuln-scan:
    uses: this-is-tobi/github-workflows/.github/workflows/scan-trivy.yml@v0
    with:
      IMAGE: ghcr.io/my-org/my-image:1.2.3
      PATH: ./apps/api
      FORMAT: sarif
      GITHUB_SECURITY_TAB: true
      PR_NUMBER: ${{ github.event.pull_request.number }}