Add Trivy support #8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: trivy | ||
on: | ||
push: | ||
branches: | ||
- 2/edge | ||
pull_request: | ||
workflow_call: | ||
inputs: | ||
branch: | ||
type: string | ||
default: '' | ||
jobs: | ||
build: | ||
uses: ./.github/workflows/build.yaml | ||
Check failure on line 14 in .github/workflows/trivy.yaml GitHub Actions / .github/workflows/trivy.yamlInvalid workflow file
|
||
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@v3 | ||
with: | ||
name: charmed_opensearch_rock_amd64 | ||
path: . | ||
- name: Install rockcraft (for skopeo) | ||
run: | | ||
sudo snap install rockcraft --classic --edge | ||
- name: Import locally | ||
run: | | ||
# Unpack artifact | ||
version="$(cat rockcraft.yaml | yq .version)" | ||
sudo skopeo \ | ||
--insecure-policy \ | ||
copy \ | ||
oci-archive:charmed-opensearch_${version}_amd64.rock \ | ||
docker-daemon: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 |