Skip to content

Commit 4daa4df

Browse files
committed
Merge #438: fix: [#437] restore third-party Trivy SARIF uploads
b397688 fix: [#437] upload third-party Trivy SARIF with codeql action (Jose Celano) Pull request description: ## Summary Fix the Docker security scanning workflow so third-party Trivy SARIF results are uploaded through a supported path. ## Changes - Add `security-events: write` permission to `scan-third-party-images` - Upload third-party SARIF directly with `github/codeql-action/upload-sarif@v4` - Use stable per-image categories: `docker-third-party-${sanitized-image}` - Remove the unsupported custom `gh api /code-scanning/sarifs` upload loop - Restrict aggregate uploader to project SARIF artifacts only ## Why The previous custom upload was failing with HTTP 422 (`"category" is not a permitted key`) and silently skipping third-party uploads, which caused PR warnings like `configurations not found`. ## Validation - `cargo run --bin linter yaml` passes Closes #437 ACKs for top commit: josecelano: ACK b397688 Tree-SHA512: fb0fafb74f35724c8cb75ae3e525440eda52239eb9015827e8662ae76593d6db680f13b3ff8437ca7d054729192bef4814a7d4f8c23da0b1ffdae770ca3410dd
2 parents 5b8f28e + b397688 commit 4daa4df

1 file changed

Lines changed: 12 additions & 41 deletions

File tree

.github/workflows/docker-security-scan.yml

Lines changed: 12 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ jobs:
194194
timeout-minutes: 15
195195
permissions:
196196
contents: read
197+
security-events: write
197198

198199
strategy:
199200
fail-fast: false
@@ -237,12 +238,21 @@ jobs:
237238
path: trivy.sarif
238239
retention-days: 30
239240

241+
# Use the supported CodeQL upload action so category tracking works
242+
# for dynamic third-party image configurations.
243+
- name: Upload third-party SARIF
244+
if: always()
245+
uses: github/codeql-action/upload-sarif@v4
246+
with:
247+
sarif_file: trivy.sarif
248+
category: docker-third-party-${{ steps.sanitize.outputs.name }}
249+
continue-on-error: true
250+
240251
upload-sarif-results:
241252
name: Upload SARIF Results to GitHub Security
242253
runs-on: ubuntu-latest
243254
needs:
244255
- scan-project-images
245-
- scan-third-party-images
246256

247257
# Always run so we don't lose security visibility
248258
if: always()
@@ -254,7 +264,7 @@ jobs:
254264
- name: Download all SARIF artifacts
255265
uses: actions/download-artifact@v7
256266
with:
257-
pattern: sarif-*-${{ github.run_id }}
267+
pattern: sarif-project-*-${{ github.run_id }}
258268

259269
# Upload each SARIF file with CodeQL Action using unique categories.
260270
# The category parameter enables proper alert tracking per image.
@@ -280,42 +290,3 @@ jobs:
280290
sarif_file: sarif-project-ssh-server-${{ github.run_id }}/trivy-ssh-server.sarif
281291
category: docker-project-ssh-server
282292
continue-on-error: true
283-
284-
# Dynamic upload of all third-party image SARIF results.
285-
# Iterates over every sarif-third-party-* artifact directory so
286-
# no manual step additions are needed when images change version.
287-
# The category is derived from the artifact directory name so
288-
# GitHub Code Scanning properly tracks alerts per image.
289-
- name: Upload all third-party SARIF results
290-
if: always()
291-
env:
292-
GH_TOKEN: ${{ github.token }}
293-
shell: bash
294-
run: |
295-
for sarif_dir in sarif-third-party-*; do
296-
if [[ ! -d "$sarif_dir" ]]; then
297-
continue
298-
fi
299-
sarif_file="$sarif_dir/trivy.sarif"
300-
if [[ ! -f "$sarif_file" ]]; then
301-
echo "No SARIF file in $sarif_dir, skipping"
302-
continue
303-
fi
304-
305-
# Derive unique Code Scanning category from the artifact directory name.
306-
# Example: sarif-third-party-mysql-8.4-12345 -> docker-third-party-mysql-8.4
307-
artifact_name="${sarif_dir%-${{ github.run_id }}}"
308-
category="docker-${artifact_name#sarif-}"
309-
310-
echo "Uploading $sarif_file with category: $category"
311-
312-
gh api \
313-
--method POST \
314-
-H "Accept: application/vnd.github+json" \
315-
"/repos/${{ github.repository }}/code-scanning/sarifs" \
316-
-f "commit_sha=${{ github.sha }}" \
317-
-f "ref=${{ github.ref }}" \
318-
-f "sarif=$(gzip -c "$sarif_file" | base64 -w 0)" \
319-
-f "category=$category" \
320-
|| echo "Warning: Upload failed for $sarif_file (category: $category)"
321-
done

0 commit comments

Comments
 (0)