Skip to content

Add Trivy support

Add Trivy support #3

Workflow file for this run

name: trivy
on:
push:
branches:
- 2/edge
pull_request:
workflow_call:
inputs:
branch:
type: string
default: ''
jobs:
build:
uses: ./.github/workflows/build.yaml
with:
branch: ${{ inputs.branch }}
scan:
name: Trivy scan and sbom generation
needs: build
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ inputs.branch }}
- name: Download rock file
uses: actions/download-artifact@v4
with:
name: charmed_opensearch_rock_amd64
path: .
- name: Install rockcraft (for skopeo)
run: |
sudo snap install rockcraft --classic --edge
- name: Get Artifact Name
id: artifact
run: |
BASE_ARTIFACT=$(make help | grep 'Artifact: ')
echo "base_artifact_name=${BASE_ARTIFACT#'Artifact: '}" >> $GITHUB_OUTPUT
- name: Import locally
run: |
# Unpack artifact
sudo rockcraft.skopeo --insecure-policy copy \
docker-archive:charmed_opensearch_rock_amd64 \
docker-daemon:trivy/charmed_opensearch_rock_amd64:test
- name: Run Trivy vulnerability scanner
uses: aquasecurity/[email protected]
with:
image-ref: 'trivy/charmed_opensearch_rock_amd64:test'
format: 'sarif'
output: 'trivy-results.sarif'
severity: 'MEDIUM,HIGH,CRITICAL'
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
if: always()
with:
sarif_file: 'trivy-results.sarif'
ref: ${{ inputs.branch }}
- name: Run Trivy in GitHub SBOM mode and submit results to Dependency Graph
uses: aquasecurity/[email protected]
with:
scan-type: 'image'
format: 'spdx-json'
output: 'dependency-results.sbom.json'
image-ref: 'trivy/charmed_opensearch_rock_amd64:test'
github-pat: ${{ secrets.GITHUB_TOKEN }}
severity: "MEDIUM,HIGH,CRITICAL"
scanners: "vuln"
- name: Upload trivy report as a Github artifact
uses: actions/upload-artifact@v4
with:
name: trivy-sbom-report
path: '${{ github.workspace }}/dependency-results.sbom.json'
retention-days: 90