Trivy Security Scan #515
This file contains hidden or 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 Security Scan | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | |
| cancel-in-progress: false | |
| on: | |
| # Runs nightly at 2 AM UTC | |
| schedule: | |
| - cron: "0 2 * * *" | |
| # Only trigger on changes to security scan scripts | |
| push: | |
| paths: | |
| - ".github/workflows/security-scan.yml" | |
| - "hack/vlab-trivy-runner.sh" | |
| - "hack/trivy-setup-airgapped.sh" | |
| - "hack/trivy-setup.sh" | |
| - "justfile" | |
| workflow_dispatch: | |
| inputs: | |
| vm_selection: | |
| type: choice | |
| description: "Select VMs to scan" | |
| required: false | |
| default: "control-gateway" | |
| options: | |
| - "control-gateway" | |
| - "control-only" | |
| - "gateway-only" | |
| - "switch-only" | |
| - "all" | |
| debug_enabled: | |
| type: boolean | |
| description: "Enable debug output" | |
| required: false | |
| default: false | |
| permissions: | |
| contents: read | |
| security-events: write | |
| jobs: | |
| trivy-security-scan: | |
| runs-on: vlab | |
| timeout-minutes: 60 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Go | |
| uses: actions/setup-go@v6 | |
| with: | |
| go-version-file: go.mod | |
| cache: true | |
| - name: Setup local registry | |
| run: just --timestamp _localreg & | |
| - name: Build and push hhfab artifacts | |
| run: just --timestamp oci_repo=127.0.0.1:30000 oci=http push | |
| - name: Set VM scan arguments | |
| id: vm_args | |
| run: | | |
| case "${{ github.event.inputs.vm_selection || 'control-gateway' }}" in | |
| "control-only") | |
| echo "args=--control-only" >> $GITHUB_OUTPUT | |
| ;; | |
| "gateway-only") | |
| echo "args=--gateway-only" >> $GITHUB_OUTPUT | |
| ;; | |
| "switch-only") | |
| echo "args=--switch-only" >> $GITHUB_OUTPUT | |
| ;; | |
| "all") | |
| echo "args=--all" >> $GITHUB_OUTPUT | |
| ;; | |
| "control-gateway"|*) | |
| echo "args=" >> $GITHUB_OUTPUT | |
| ;; | |
| esac | |
| - name: Run VLAB Trivy Security Scan | |
| env: | |
| HHFAB_REG_REPO: 127.0.0.1:30000 | |
| run: | | |
| SCAN_ARGS="${{ steps.vm_args.outputs.args }}" | |
| if [ "${{ github.event_name }}" = "schedule" ]; then | |
| # For scheduled runs, always use strict mode | |
| just security-scan --strict $SCAN_ARGS | |
| else | |
| # For manual runs, allow partial success by default | |
| just security-scan $SCAN_ARGS | |
| fi | |
| - name: Upload SARIF file | |
| if: always() && env.UPLOAD_SARIF == 'true' | |
| uses: github/codeql-action/upload-sarif@v4 | |
| with: | |
| sarif_file: ${{ env.SARIF_FILE }} | |
| category: trivy-container-scan | |
| continue-on-error: true | |
| - name: Upload scan artifacts | |
| uses: actions/upload-artifact@v7 | |
| if: always() | |
| with: | |
| name: security-scan-${{ github.run_number }} | |
| path: | | |
| trivy-reports/ | |
| sarif-reports/ | |
| vlab.log | |
| retention-days: 30 | |
| - name: Setup tmate session for debug | |
| if: ${{ failure() && github.event_name == 'workflow_dispatch' && inputs.debug_enabled }} | |
| uses: mxschmitt/action-tmate@v3 | |
| timeout-minutes: 30 | |
| with: | |
| limit-access-to-actor: true |