Skip to content

feat: upload bakery trivy scan SARIF to GitHub code scanning - #734

Draft
bschwedler wants to merge 3 commits into
feat/trivy-security-scanfrom
feat/trivy-sarif-code-scanning
Draft

feat: upload bakery trivy scan SARIF to GitHub code scanning#734
bschwedler wants to merge 3 commits into
feat/trivy-security-scanfrom
feat/trivy-sarif-code-scanning

Conversation

@bschwedler

Copy link
Copy Markdown
Contributor

Splits the GitHub code-scanning half of #722 into its own PR so that one can merge without breaking every caller.

bakery trivy scan needs two identifiers per target that #722 conflated into one string: a version-stable category, so code scanning can diff a PR against its baseline, and a unique filename, so two versions of an image don't overwrite each other. Keying the filename off the category collapsed 50 images-connect targets onto 6 SARIF files. Here the filename stays uid-keyed and the category rides in each run's automationDetails.id, which upload-sarif preserves — so one directory upload carries a distinct category per file.

Not wired into bakery-build-pr.yml: fork PRs get a read-only token, so requesting security-events: write there would fail for exactly the contributors that workflow's Detect Fork job exists to support. Main also only analyses latest versions, so PR-time uploads of older versions would have no baseline and would report every finding as new.

Do not merge before the three product repos grant security-events: write to their calling jobs. That ordering is what #729 tracks; merging early reproduces the failure this split exists to avoid.

@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown

Test Results

2 147 tests   2 147 ✅  8m 2s ⏱️
    1 suites      0 💤
    1 files        0 ❌

Results for commit 26ac4e4.

♻️ This comment has been updated with latest results.

@bschwedler
bschwedler force-pushed the feat/trivy-sarif-code-scanning branch from 8a8a0fd to d4a933d Compare August 11, 2026 18:35
`bakery trivy scan` needs two different identifiers per target, and the
previous design conflated them. The code-scanning category must omit the
version so a PR can be diffed against its baseline, but the results
filename must include it or two versions of one image overwrite each
other -- 50 connect targets collapsed onto 6 files.

Split them. results_file stays keyed on image_target.uid; scan_category
is stamped into each run's automationDetails.id as "<category>/".
upload-sarif only fills automationDetails in when it is absent, so a
single directory upload can carry a distinct category per file, which is
what code scanning has required since runs sharing a category stopped
being combined in July 2025.

The category's architecture now comes from the platform the CLI actually
resolved rather than the host's. A target is not platform-scoped
(image_os.platforms is a list), so host arch was only correct for native
scans and mislabelled every cross-arch scan.
Re-adds the security-events: write grant and the upload step held back
from #722, now that the category no longer has to be smuggled through
the SARIF filename.

Uses github/codeql-action/upload-sarif rather than a hand-rolled `gh api`
loop. The action handles gzip/base64 and validation, and it surfaces a
403 instead of swallowing it the way the previous `|| true` did. No
`category:` input is passed, because each file already supplies its own
via automationDetails.id -- passing one would give every run in the
directory the same category, which code scanning rejects.

Deliberately not added to bakery-build-pr.yml. Fork PRs get a read-only
token, so a job requesting security-events: write there would fail for
exactly the contributors that workflow's Detect Fork job exists to
support. Main also only analyses latest versions, so PR-time uploads of
older versions would have no baseline and would report every finding as
new.

Merging this requires the three product repos to grant security-events:
write to their calling jobs first, per #729.
Keeps only why `category:` is omitted; the mechanism is in the commit
that introduced the stamping.
@bschwedler
bschwedler force-pushed the feat/trivy-sarif-code-scanning branch from d4a933d to 26ac4e4 Compare August 11, 2026 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant