Skip to content

refactor(ci): extract trivy image scan into separate reusable workflow - #290

Merged
marcusburghardt merged 4 commits into
complytime:mainfrom
marcusburghardt:refactor/extract-trivy-image-scan
Jun 2, 2026
Merged

refactor(ci): extract trivy image scan into separate reusable workflow#290
marcusburghardt merged 4 commits into
complytime:mainfrom
marcusburghardt:refactor/extract-trivy-image-scan

Conversation

@marcusburghardt

@marcusburghardt marcusburghardt commented May 28, 2026

Copy link
Copy Markdown
Member

Summary

The trivy_image job in reusable_vuln_scan.yml requires elevated permissions
(packages: write, id-token: write) that cause startup failures in callers
that only need source/dependency scanning. GitHub validates all job permissions at
parse time, even for conditionally-skipped jobs.

This PR extracts the trivy_image job into a dedicated reusable_trivy_image_scan.yml
so callers can independently opt into image scanning with the required permissions,
without affecting the lighter-weight vuln scan workflow.

File Change
reusable_trivy_image_scan.yml New -- standalone reusable workflow with the extracted trivy_image job
reusable_vuln_scan.yml Slimmed -- removed trivy_image job, its inputs (enable_trivy_image, image_ref, image_digest), outputs, and cleaned up permissions and concurrency group

Related Issues

Review Hints

  • The two files should be reviewed together. The new reusable_trivy_image_scan.yml is a direct extraction of the trivy_image job from reusable_vuln_scan.yml with its own inputs/outputs.

  • All reusable workflow references in consumer repos are pinned to SHA cfd981e (v0.2.1). Nothing breaks until a SHA is bumped, giving a safe migration window.

  • After this merges and is tagged, consumer repos that use image scanning in their publish pipelines (complytime-collector-components) need to update their ci_publish_ghcr.yml to call reusable_trivy_image_scan.yml instead of reusable_vuln_scan.yml with enable_trivy_image: true. A draft PR is already prepared: refactor(ci): use dedicated trivy image scan workflow complytime-collector-components#247.

  • The synced ci_security.yml across the org does not need changes -- it never used enable_trivy_image. The next org sync will resolve the startup failures automatically.

@marcusburghardt

Copy link
Copy Markdown
Member Author

The failure with OSV-Scanner job will be addressed in a separate PR: #291

@marcusburghardt
marcusburghardt marked this pull request as ready for review May 28, 2026 11:40
@marcusburghardt
marcusburghardt force-pushed the refactor/extract-trivy-image-scan branch from cf24a10 to 52060ff Compare May 28, 2026 14:19
The trivy_image job in reusable_vuln_scan.yml requires elevated permissions
(packages: write, id-token: write) that cause startup failures in callers
that only need source/dependency scanning. GitHub validates all job
permissions at parse time, even for conditionally-skipped jobs.

Extract trivy_image into reusable_trivy_image_scan.yml so callers can
independently opt into image scanning with the required permissions,
without affecting the lighter-weight vuln scan workflow.

Changes:
- New: reusable_trivy_image_scan.yml with the trivy_image job
- Removed: trivy_image job, its inputs (enable_trivy_image, image_ref,
  image_digest), and outputs from reusable_vuln_scan.yml
- Cleaned up concurrency group and permissions in reusable_vuln_scan.yml

Fixes: complytime/.github Security Checks startup failure

Assisted-by: OpenCode (claude-opus-4-6)
Signed-off-by: Marcus Burghardt <maburgha@redhat.com>
The trivy-action installs the Trivy binary at runtime, defaulting to
the latest release if no version is specified. zizmor flags this as
unpinned-tools (supply chain risk).

Pin to v0.70.0 in both reusable_vuln_scan.yml and
reusable_trivy_image_scan.yml.

Assisted-by: OpenCode (claude-opus-4-6)
Signed-off-by: Marcus Burghardt <maburgha@redhat.com>
@marcusburghardt
marcusburghardt force-pushed the refactor/extract-trivy-image-scan branch from 52060ff to c0d6145 Compare May 29, 2026 15:07
Comment thread .github/workflows/reusable_trivy_image_scan.yml

@trevor-vaughan trevor-vaughan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The change makes sense but it needs a CI test in the current repo to self-validate before we push it out using both a positive and negative test case.

It can probably piggyback off of ci_test_publish_ghcr on a temp image.

The scan_result step checked for vulns but never wrote the passed
output to GITHUB_OUTPUT, leaving the scan_passed workflow output
always empty. Add the missing output assignment.

Addresses PR complytime#290 review feedback from @trevor-vaughan.

Assisted-by: OpenCode (claude-opus-4-6)
Signed-off-by: Marcus Burghardt <maburgha@redhat.com>
Add ci_test_trivy_image_scan.yml with positive and negative test cases:

- Positive: builds a clean temp image, scans it, verifies scan_passed
  output and vuln attestation via cosign when digest is provided
- Negative: verifies no attestation is produced when digest is omitted

Follows the ci_test_publish_ghcr.yml pattern: build temp image,
run tests, verify outputs, cleanup package versions.

Addresses PR complytime#290 review feedback from @trevor-vaughan.

Assisted-by: OpenCode (claude-opus-4-6)
Signed-off-by: Marcus Burghardt <maburgha@redhat.com>
sonupreetam
sonupreetam previously approved these changes Jun 1, 2026

@sonupreetam sonupreetam left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@marcusburghardt I agree a CI self-test is valuable as per @trevor-vaughan ask to validate this. Apart from that Everything LGTM, I really liked the separation.

@marcusburghardt

Copy link
Copy Markdown
Member Author

I am working on it. : )

@marcusburghardt

Copy link
Copy Markdown
Member Author

Addressed in 54f7253 and b45514d:

  • 54f7253 — Fixed scan_passed output in reusable_trivy_image_scan.yml (the step never wrote to GITHUB_OUTPUT, leaving the output always empty)
  • b45514d — Added ci_test_trivy_image_scan.yml with positive and negative test cases:
    • Positive: builds a clean temp image, scans it, verifies scan_passed='true' and vuln attestation via cosign when digest is provided
    • Negative: verifies no attestation is produced when digest is omitted

Follows the ci_test_publish_ghcr.yml pattern as suggested.

@marcusburghardt

Copy link
Copy Markdown
Member Author

@sonupreetam would you like to take a quick look again after the last two commits?

@sonupreetam

Copy link
Copy Markdown
Member

@marcusburghardt Everything looks good, thank you!

@marcusburghardt
marcusburghardt merged commit 138d97e into complytime:main Jun 2, 2026
18 checks passed
marcusburghardt added a commit that referenced this pull request Jun 2, 2026
The scan_result step checked for vulns but never wrote the passed
output to GITHUB_OUTPUT, leaving the scan_passed workflow output
always empty. Add the missing output assignment.

Addresses PR #290 review feedback from @trevor-vaughan.

Assisted-by: OpenCode (claude-opus-4-6)
Signed-off-by: Marcus Burghardt <maburgha@redhat.com>
@marcusburghardt
marcusburghardt deleted the refactor/extract-trivy-image-scan branch June 2, 2026 07:44
@beatrizmcouto beatrizmcouto moved this to Backlog in ComplyTime planning Jun 8, 2026
@github-project-automation github-project-automation Bot moved this from Backlog to Done ✔️ in ComplyTime planning Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done ✔️

Development

Successfully merging this pull request may close these issues.

4 participants