@@ -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