-
Notifications
You must be signed in to change notification settings - Fork 536
chore(ci): govulncheck - use official golang/govulncheck-action for SARIF analysis #4599
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ffae7d6
ci(govulncheck): use official golang/govulncheck-action for SARIF ana…
kakkoyun ee7994b
ci(govulncheck): extend SARIF upload to cover contrib modules
kakkoyun f1d8ab7
fix(ci): use go.work as module source in govulncheck contrib scripts
kakkoyun 76535e3
fix(ci): merge govulncheck-contribs SARIF into a single run
kakkoyun 52e6b9c
fix(ci): address govulncheck-action review comments
kakkoyun 2aeaf4b
fix(ci): merge tool.driver.rules from all contrib SARIF runs
kakkoyun 6a13d90
ci(govulncheck): upload OpenVEX artifact
kakkoyun c5d2411
Merge branch 'main' into kakkoyun/govulncheck-action-allowlist
kakkoyun 65c5f23
ci(govulncheck): version OpenVEX product
kakkoyun 735339d
Merge branch 'main' into kakkoyun/govulncheck-action-allowlist
kakkoyun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| #!/bin/bash | ||
| set -euo pipefail | ||
|
|
||
| # Scans each contrib module with govulncheck in SARIF format and merges the | ||
| # results into a single SARIF file for upload to GitHub Code Scanning. | ||
| # | ||
| # Usage: govulncheck-contribs-sarif.sh [output-file] | ||
| # output-file Path for the merged SARIF output (default: govulncheck-contribs.sarif) | ||
| # | ||
| # Requires: govulncheck, jq | ||
|
|
||
| OUTPUT="${1:-govulncheck-contribs.sarif}" | ||
| SARIF_DIR=$(mktemp -d) | ||
| trap 'rm -rf "$SARIF_DIR"' EXIT | ||
|
|
||
| count=0 | ||
| # Use go.work as the authoritative module list — avoids picking up nested | ||
| # test-only go.mod files (e.g. contrib/aws/datadog-lambda-go/test/...) that | ||
| # are not workspace members and cause govulncheck package-load errors. | ||
| grep -E '^\s+\./contrib/' go.work | awk '{print $1}' | while read -r dir; do | ||
| echo "Scanning $dir" | ||
| # Capture the module path (repo-root-relative) before any fallback rewrites | ||
| # $dir — used as the URI prefix when rewriting SARIF paths below. | ||
| module_dir="${dir#./}" # strip leading "./" → "contrib/aws/aws-sdk-go" | ||
|
|
||
| # govulncheck requires at least one .go file in the target directory; | ||
| # fall back to the first subdirectory when the module root has none. | ||
| go_files=$(find "$dir" -maxdepth 1 -type f -name '*.go' | wc -l) | ||
| [[ $go_files -eq 0 ]] && dir=$(realpath "$(ls -d "$dir"/*/ | head -1)") | ||
|
|
||
| safe_name=$(printf '%s' "$module_dir" | tr '/' '_') | ||
| # -format sarif exits 0 even when vulnerabilities are found. | ||
| govulncheck -format sarif -C "$dir" . >"$SARIF_DIR/${safe_name}.sarif" | ||
|
|
||
| # Rewrite URIs to be repo-root-relative so Code Scanning annotations resolve | ||
| # correctly. govulncheck emits paths relative to the module dir with | ||
| # uriBaseId="%SRCROOT%". Prefix each with the module dir and drop uriBaseId | ||
| # so the merged single-run file has unambiguous repo-root-relative paths. | ||
| jq --arg prefix "${module_dir}/" ' | ||
| walk( | ||
| if type == "object" and (.uriBaseId? == "%SRCROOT%") and has("uri") | ||
| then .uri = ($prefix + .uri) | del(.uriBaseId) | ||
| else . | ||
| end | ||
| ) | ||
| ' "$SARIF_DIR/${safe_name}.sarif" >"$SARIF_DIR/${safe_name}.tmp" | ||
| mv "$SARIF_DIR/${safe_name}.tmp" "$SARIF_DIR/${safe_name}.sarif" | ||
|
|
||
| count=$((count + 1)) | ||
| done | ||
|
|
||
| sarif_files=("$SARIF_DIR"/*.sarif) | ||
| if [[ ! -e "${sarif_files[0]}" ]]; then | ||
| echo "No contrib modules found; skipping SARIF merge." | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Merge all per-module SARIF files into one file with a single run. | ||
| # CodeQL upload-sarif rejects files with multiple runs under the same category | ||
| # (https://github.blog/changelog/2025-07-21-code-scanning-will-stop-combining-multiple-sarif-runs-uploaded-in-the-same-sarif-file/). | ||
| # govulncheck uses URI-based artifact locations (not index-based), so merging | ||
| # results across runs is safe — no artifact re-indexing required. | ||
| # | ||
| # tool.driver.rules is merged and deduplicated across all runs: each run only | ||
| # carries the rules referenced by its own results, so a naïve first-wins merge | ||
| # would lose rule descriptors (title, help) for vulns found in later modules. | ||
| jq -s ' | ||
| . as $all | | ||
| { | ||
| "version": .[0].version, | ||
| "$schema": (.[0]."$schema" // ""), | ||
| "runs": [{ | ||
| "tool": ( | ||
| .[0].runs[0].tool | | ||
| .driver.rules = ([$all[].runs[].tool.driver.rules[]?] | unique_by(.id)) | ||
| ), | ||
| "results": [$all[].runs[].results[]?] | ||
| }] | ||
| } | ||
| ' "$SARIF_DIR"/*.sarif >"$OUTPUT" | ||
|
|
||
| echo "Merged $(echo "$SARIF_DIR"/*.sarif | wc -w) SARIF files into $OUTPUT" | ||
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.