|
| 1 | +name: Security scan |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: [master] |
| 5 | + paths: [pixi.lock] |
| 6 | + pull_request: |
| 7 | + branches: [master] |
| 8 | + paths: [pixi.lock] |
| 9 | + schedule: |
| 10 | + - cron: "0 6 * * *" |
| 11 | + workflow_dispatch: |
| 12 | + |
| 13 | +jobs: |
| 14 | + scan: |
| 15 | + name: SBOM and vulnerability scan |
| 16 | + runs-on: ubuntu-latest |
| 17 | + permissions: |
| 18 | + security-events: write |
| 19 | + contents: write # required by anchore/sbom-action dependency-snapshot upload |
| 20 | + actions: read # required by dawidd6/action-download-artifact on fork PRs |
| 21 | + defaults: |
| 22 | + run: |
| 23 | + shell: bash -l {0} |
| 24 | + steps: |
| 25 | + - uses: actions/checkout@v6 |
| 26 | + - uses: prefix-dev/setup-pixi@v0.9.6 |
| 27 | + with: |
| 28 | + pixi-version: v0.68.1 |
| 29 | + |
| 30 | + - name: Generate SBOM # (master only) |
| 31 | + if: github.ref == 'refs/heads/master' |
| 32 | + uses: anchore/sbom-action@v0.24.0 |
| 33 | + with: |
| 34 | + path: ".pixi/envs/default" |
| 35 | + output-file: sbom.spdx.json |
| 36 | + dependency-snapshot: true |
| 37 | + |
| 38 | + - name: Vulnerability Scan |
| 39 | + id: scan |
| 40 | + uses: anchore/scan-action@v7.4.0 |
| 41 | + with: |
| 42 | + path: ".pixi/envs/default" |
| 43 | + fail-build: false |
| 44 | + severity-cutoff: high |
| 45 | + add-cpes-if-none: true |
| 46 | + output-format: sarif |
| 47 | + |
| 48 | + # Point alerts to pixi.lock so githubs path scoped PR check registers it |
| 49 | + - name: Rewrite SARIF locations to pixi.lock |
| 50 | + run: | |
| 51 | + jq '.runs[].results[].locations[].physicalLocation.artifactLocation.uri = "pixi.lock"' \ |
| 52 | + "${{ steps.scan.outputs.sarif }}" > rewritten.sarif |
| 53 | + mv rewritten.sarif "${{ steps.scan.outputs.sarif }}" |
| 54 | +
|
| 55 | + - name: Upload SARIF |
| 56 | + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository |
| 57 | + uses: github/codeql-action/upload-sarif@v4 |
| 58 | + with: |
| 59 | + sarif_file: ${{ steps.scan.outputs.sarif }} |
| 60 | + category: pixi-vuln-scan |
| 61 | + |
| 62 | + # Fork PRs cant upload SARIF (no access to token), so code scannings native diff |
| 63 | + # does not apply. This builds our own diff from a master-uploaded SARIF artifact instead. |
| 64 | + - name: Upload SARIF as artifact |
| 65 | + if: github.ref == 'refs/heads/master' |
| 66 | + uses: actions/upload-artifact@v7 |
| 67 | + with: |
| 68 | + name: master-sarif |
| 69 | + path: ${{ steps.scan.outputs.sarif }} |
| 70 | + retention-days: 30 |
| 71 | + |
| 72 | + # Fork PRs cant upload SARIF to code scanning (no token write access), so |
| 73 | + # diff against the master baseline artifact here instead |
| 74 | + - name: Download master baseline (fork PRs only) |
| 75 | + if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository |
| 76 | + uses: dawidd6/action-download-artifact@v21 |
| 77 | + with: |
| 78 | + workflow: security-scan.yaml |
| 79 | + name: master-sarif |
| 80 | + branch: master |
| 81 | + if_no_artifact_found: fail |
| 82 | + path: master-baseline |
| 83 | + |
| 84 | + - name: Fail on new CVEs (fork PRs only) |
| 85 | + if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository |
| 86 | + env: |
| 87 | + SARIF_PATH: ${{ steps.scan.outputs.sarif }} |
| 88 | + run: | |
| 89 | + [ -s master-baseline/output ] || { echo "::error::baseline SARIF missing"; exit 2; } |
| 90 | + [ -s "$SARIF_PATH" ] || { echo "::error::PR SARIF missing"; exit 2; } |
| 91 | + new=$(comm -23 \ |
| 92 | + <(jq -r '.runs[].results[] | select(.level == "error") | .ruleId' "$SARIF_PATH" | sort -u) \ |
| 93 | + <(jq -r '.runs[].results[] | select(.level == "error") | .ruleId' master-baseline/output | sort -u)) |
| 94 | + if [ -n "$new" ]; then |
| 95 | + echo "::error::New high+ CVEs vs master:" |
| 96 | + printf '%s\n' "$new" |
| 97 | + exit 1 |
| 98 | + fi |
| 99 | + echo "No new high+ CVEs vs master." |
0 commit comments