Skip to content

Trivy Scan

Trivy Scan #760

name: Trivy Scan
on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch: {}
permissions:
contents: read
jobs:
trivy-scan:
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
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- name: Free disk space
# https://github.com/actions/virtual-environments/issues/709
run: |
echo "=========original CI disk space"
df -h
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
echo "=========after clean up, the left CI disk space"
df -h
- name: Checkout submodule
uses: Mushus/checkout-submodule@f6a7fddc9798c8f8728b252594243ced3b56e550 # v1.0.1
with:
basePath: # optional, default is .
submodulePath: libvgpu
- name: Get branch name
uses: nelonoel/branch-name@1ea5c86cb559a8c4e623da7f188496208232e49f # v1.0.1
- name: Docker Login
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
with:
username: ${{ secrets.DOCKERHUB_TOKEN }}
password: ${{ secrets.DOCKERHUB_PASSWD }}
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@37fe631027851001ddb9b187196cc803df7f5f0e # v4
- name: install Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7
with:
go-version-file: go.mod
- name: Generating image tag
id: runtime-tag
run: |
echo tag="$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- run: make tidy
- run: SHORT_VERSION=${{ steps.runtime-tag.outputs.tag }} bash ./hack/build.sh
- name: Run Trivy vulnerability scanner (table output)
# Prevent running from the forked repository that doesn't need to upload coverage.
# In addition, running on the forked repository would fail as missing the necessary secret.
if: ${{ github.repository == 'Project-HAMi/HAMi' }}
uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
with:
image-ref: "projecthami/hami:${{ steps.runtime-tag.outputs.tag }}"
format: "table"
ignore-unfixed: true
severity: "CRITICAL"
vuln-type: "os,library"
trivyignores: .trivyignore
- name: Run Trivy vulnerability scanner (SARIF)
uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
with:
image-ref: "projecthami/hami:${{ steps.runtime-tag.outputs.tag }}"
format: "sarif"
output: "trivy-results.sarif"
ignore-unfixed: true
severity: "CRITICAL"
vuln-type: "os,library"
trivyignores: .trivyignore
if: always() && github.repository == 'Project-HAMi/HAMi'
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4
with:
sarif_file: "trivy-results.sarif"
if: always() && github.repository == 'Project-HAMi/HAMi'