Skip to content

upload sarif from trivy scan #616

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 34 additions & 21 deletions .github/workflows/trivy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
# This workflow fails if run too frequently, due to rate limiting.
#pull_request:
schedule:
- cron: '0 14 * * 1' # each Monday at 9am EST
- cron: "0 14 * * 1" # each Monday at 9am EST
workflow_dispatch:

jobs:
Expand All @@ -15,29 +15,42 @@ jobs:
fail-fast: false
matrix:
include:
- dir: batch
- dir: bastion
- dir: cis
- dir: sdarq/frontend
- dockerfile: sdarq/backend/Dockerfile
- dir: zap
- dir: batch
- dir: bastion
- dir: cis
- dir: sdarq/frontend
- dockerfile: sdarq/backend/Dockerfile
- dir: security-controls
- dir: zap
env:
SARIF_PATH: ${{ matrix.dir }}/trivy-results.sarif

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4

- uses: broadinstitute/dsp-appsec-trivy-action@v1
with:
context: ${{ matrix.dir || '.' }}
dockerfile: ${{ matrix.dockerfile || 'Dockerfile' }}
severities: UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL
# sarif: ${{ !github.base_ref && env.SARIF_PATH || '' }}
- uses: broadinstitute/dsp-appsec-trivy-action@v1
with:
context: ${{ matrix.dir || '.' }}
dockerfile: ${{ matrix.dockerfile || 'Dockerfile' }}
severities: UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL
sarif: ${{ !github.base_ref && env.SARIF_PATH || '' }}

# NOTE: this functionality is limited to public repos only;
# TODO: uncomment the Cron schedule and Sarif config when made public
# - name: Upload Trivy scan results to GitHub Security tab
# uses: github/codeql-action/upload-sarif@v1
# if: ${{ !github.base_ref }} # omit upload on PRs
# with:
# sarif_file: ${{ env.SARIF_PATH }}
- name: Check if SARIF file exists
id: sarif_check
run: |
if [ -f "${{ env.SARIF_PATH }}" ]; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi

- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/[email protected]
if: ${{ steps.sarif_check.outputs.exists == 'true' && !github.base_ref }}
with:
sarif_file: ${{ env.SARIF_PATH }}

- name: Log SARIF upload skipped
if: ${{ steps.sarif_check.outputs.exists != 'true' || github.base_ref }}
run: |
echo "SARIF upload skipped: either SARIF file missing or this is a PR."