Skip to content

scorecard: collect results only when a results file is requested - #912

Draft
justaugustus wants to merge 1 commit into
ossf:mainfrom
justaugustus:fix/scorecard-results-daemon-growth
Draft

justaugustus wants to merge 1 commit into
ossf:mainfrom
justaugustus:fix/scorecard-results-daemon-growth

Conversation

@justaugustus

Copy link
Copy Markdown
Member

uploadSARIF appends every scanned result to a package-level slice, but only WriteResults reads it, and only a -once run with -results-file calls WriteResults. A daemon kept every result for the life of the process. Collection also happens before the upload and before change detection records the commit. When a repo's upload keeps failing (for example a 403 while the App lacks security_events: write), the same result was added on every cycle.

Collection is now off by default. main turns it on only for a -once run with -results-file. The check runs before the JSON conversion, so the daemon also skips that work.

Verification: the new sarif_results_test.go covers both modes. With collection off, 50 failing cycles keep 0 entries. With it on, one cycle keeps 1 entry. deadcode wasn't run locally because the installed binary is too old for Go 1.27. EnableResultsCollection is called from main, so CI's deadcode step should pass.

Review focus: in a -once run, a result is still collected when its upload fails. That seems right, because the results file records the scan, not the upload. Is that the intended behavior?

uploadSARIF appends every scanned result to a package-level slice that
only WriteResults reads, and only a -once run with -results-file calls
WriteResults. A daemon kept every result for the life of the process.
Collection also happens before the upload and before change detection
records the commit, so a repo whose upload keeps failing, such as a 403
while the App lacks security_events: write, added the same result every
cycle.

Collect only after main turns collection on, which it does for a -once
run with -results-file.

Assisted-by: LLM
Signed-off-by: Stephen Augustus <foo@auggie.dev>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the change making Scorecard result collection opt-in.

No open issues 🎉

What changed in this PR

This PR makes Scorecard result collection opt-in, preventing daemon runs from retaining scan results indefinitely or performing unnecessary JSON conversion.

Changes:

  • Disables collection by default and enables it only for -once runs with -results-file.
  • Preserves collection of scan results when uploads fail.
  • Adds regression coverage for repeated failed uploads with collection disabled and a single failed upload with collection enabled.
File Description
pkg/​policies/​scorecard/​sarif.go Adds an explicit collection toggle and skips conversion when disabled.
pkg/​policies/​scorecard/​sarif_results_test.go Tests result retention in both collection modes when uploads fail.
cmd/​allstar/​main.go Enables collection when a one-time run requests a results file.

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants