Skip to content

Trivy workflow

Trivy workflow #623

Workflow file for this run

# A workflow that runs Trivy to scan the action Docker image
name: Trivy workflow
on:
pull_request:
branches: [ "main" ]
schedule:
- cron: '32 12 * * 0'
workflow_dispatch:
env:
BRANCH_NAME: ${{ github.ref_name }}
permissions:
contents: read
jobs:
trivy:
permissions:
contents: read # for actions/checkout to fetch code
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
name: Build
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@951b48540b429070694bc8abd82fd6901eb123ca
with:
egress-policy: block
disable-telemetry: true
allowed-endpoints: >
api.github.com:443
auth.docker.io:443
deb.debian.org:80
ghcr.io:443
github.com:443
pkg-containers.githubusercontent.com:443
production.cloudflare.docker.com:443
registry-1.docker.io:443
registry.npmjs.org:443
# Cache directory for trivy
- uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: .trivy
key: ${{ runner.os }}-trivy-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-trivy-
- name: Checkout code
uses: actions/checkout@1e31de5234b9f8995739874a8ce0492dc87873e2 # v4.0.0
- name: Build an image from Dockerfile
run: |
docker build -t trivy-scan-image .
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@1f0aa582c8c8f5f7639610d6d38baddfea4fdcee # 0.9.2
with:
image-ref: trivy-scan-image
format: 'sarif'
output: 'trivy-results.sarif'
severity: 'CRITICAL,HIGH'
cache-dir: .trivy
exit-code: "1" # change to 1, if you want the build to break
ignore-unfixed: true
vuln-type: 'os,library'
# https://github.com/aquasecurity/trivy-action/issues/12 for an explanation
- name: Correct Trivy cache permissions
if: ${{ success() }} || ${{ failure() }}
continue-on-error: true
run: sudo chown -R "$USER":"$GROUP" .trivy
- name: Upload Trivy scan results to GitHub Security tab
if: ${{ success() }} || ${{ failure() }}
uses: github/codeql-action/upload-sarif@959cbb7472c4d4ad70cdfe6f4976053fe48ab394 # tag=v21.3
with:
sarif_file: 'trivy-results.sarif'