Skip to content

Vulnerability Scanning with Trivy #48

Vulnerability Scanning with Trivy

Vulnerability Scanning with Trivy #48

Workflow file for this run

name: Vulnerability Scanning with Trivy
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *' # Test Trivy daily at midnight
permissions:
contents: read
security-events: write # for uploading SARIF results to the security tab
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
cancel-in-progress: true
defaults:
run:
shell: bash
jobs:
trivy-repo:
name: Trivy - Repository
runs-on: ubuntu-22.04
strategy:
matrix:
version:
- v3
- v2
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ matrix.version }}
- name: Install Trivy
uses: canonical/lxd/.github/actions/install-trivy@main
- name: Download Trivy DB
id: db_download
run: trivy fs --download-db-only --cache-dir /home/runner/vuln-cache
continue-on-error: true
- name: Use previous downloaded database
if: ${{ steps.db_download.outcome == 'failure' }}
uses: actions/cache/restore@3624ceb22c1c5a301c8db4169662070a689d9ea8 # v4.1.1
with:
path: /home/runner/vuln-cache
key: trivy-latest-cache
- name: Run Trivy vulnerability scanner
run: |
trivy fs --skip-db-update \
--scanners vuln,secret,misconfig \
--format sarif \
--cache-dir /home/runner/vuln-cache \
--severity LOW,MEDIUM,HIGH,CRITICAL \
--output trivy-microcluster-repo-scan-results.sarif .
- name: Cache Trivy vulnerability database
if: ${{ steps.db_download.outcome == 'success' }}
uses: actions/cache/save@3624ceb22c1c5a301c8db4169662070a689d9ea8 # v4.1.1
with:
path: /home/runner/vuln-cache
key: trivy-latest-cache
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: "trivy-microcluster-repo-scan-results.sarif"
sha: ${{ github.sha }}
ref: refs/heads/${{ matrix.version }}