Skip to content

feat(workflows)!: step 4, scan every published image with Trivy - #44

Open
seantronsen wants to merge 12 commits into
seantronsen/release-400from
seantronsen/feat/decouple-trivy
Open

seantronsen wants to merge 12 commits into
seantronsen/release-400from
seantronsen/feat/decouple-trivy

Conversation

@seantronsen

@seantronsen seantronsen commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Description

Decouples Trivy image scanning from the build workflows so repos that publish more than one image get every image scanned, without passing outputs between workflows.

  • trivy-image-scan: finds image names with the new actions/discover-ghcr-images action (the images input, else the ghcr.io entries in the GoReleaser config, else the repo name), verifies they exist, and scans each one at the build's tag (pr-<N> on PRs, else the pushed v* tag; any other trigger fails), one job per image, with a SARIF category per image. GITHUB_TOKEN can't list packages, hence the name sources.
  • Removes the image-ref input; callers grant packages: read instead.

Testbed: OpenCHAMI/github-actions-testbed#7.

Checklist

  • My code follows the style guidelines of this project
  • I have added/updated comments where needed
  • I have added tests that prove my fix is effective or my feature works
  • I have run make test (or equivalent) locally and all tests pass
  • I have updated the relevant documentation (CLI examples, man pages, README, other docs, etc.)
  • DCO Sign-off: All commits are signed off (git commit -s) with my real name and email
  • REUSE Compliance:
    • Each new/modified source file has SPDX copyright and license headers
    • Any non-commentable files include a <filename>.license sidecar
    • All referenced licenses are present in the LICENSES/ directory

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Dependency update
  • Build system/CI

@seantronsen
seantronsen changed the base branch from main to seantronsen/feat/redesign-deployment October 12, 2026 23:14
@seantronsen seantronsen changed the title Seantronsen/feat/decouple trivy feat(workflows)!: step 4, discover published images for scanning and cleanup Oct 12, 2026
@seantronsen
seantronsen added this pull request to stack #40 October 12, 2026 23:15
@seantronsen seantronsen changed the title feat(workflows)!: step 4, discover published images for scanning and cleanup feat(workflows)!: step 4, discover published images for scanning Oct 12, 2026
@seantronsen seantronsen changed the title feat(workflows)!: step 4, discover published images for scanning feat(workflows)!: step 4, scan every published image with Trivy Oct 12, 2026
@seantronsen

Copy link
Copy Markdown
Contributor Author

Tests: OpenCHAMI/github-actions-testbed#7 (the testbed trivy job scans both of its images, github-actions-testbed and github-actions-testbed-alt).

@seantronsen seantronsen reopened this Oct 12, 2026
@seantronsen
seantronsen marked this pull request as ready for review October 12, 2026 23:43
@seantronsen
seantronsen marked this pull request as draft October 12, 2026 23:59
@seantronsen
seantronsen force-pushed the seantronsen/feat/decouple-trivy branch from 271fd5e to e249218 Compare October 13, 2026 00:25
@seantronsen
seantronsen force-pushed the seantronsen/feat/decouple-trivy branch from e249218 to 3f48376 Compare October 13, 2026 19:14
@seantronsen
seantronsen marked this pull request as ready for review October 13, 2026 19:28
@seantronsen

Copy link
Copy Markdown
Contributor Author

Conflicts to be resolved if/when #41 is merged.

@seantronsen seantronsen added this to the v4.0.0 milestone Oct 13, 2026
@seantronsen seantronsen self-assigned this Oct 13, 2026
Base automatically changed from seantronsen/feat/redesign-deployment to seantronsen/release-400 October 13, 2026 21:27
@synackd

synackd commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Will review once this is rebased.

Signed-off-by: Sean Tronsen <sean.tronsen@gmail.com>
Signed-off-by: Sean Tronsen <sean.tronsen@gmail.com>
@seantronsen
seantronsen force-pushed the seantronsen/feat/decouple-trivy branch from 3f48376 to 47c0b6c Compare October 13, 2026 21:40
@seantronsen

Copy link
Copy Markdown
Contributor Author

Will review once this is rebased.

done

Comment thread actions/discover-ghcr-images/README.md Resolved
Comment thread .github/workflows/trivy-image-scan.yml Resolved
Comment thread .github/workflows/trivy-image-scan.yml Resolved
Comment thread .github/workflows/trivy-image-scan.yml Resolved
Comment thread .github/workflows/trivy-image-scan.yml Resolved
Signed-off-by: Sean Tronsen <sean.tronsen@gmail.com>
…kflow

Signed-off-by: Sean Tronsen <sean.tronsen@gmail.com>
Signed-off-by: Sean Tronsen <sean.tronsen@gmail.com>
Signed-off-by: Sean Tronsen <sean.tronsen@gmail.com>
Signed-off-by: Sean Tronsen <sean.tronsen@gmail.com>
@seantronsen
seantronsen requested a review from synackd October 19, 2026 16:05
Signed-off-by: Sean Tronsen <sean.tronsen@gmail.com>
Comment thread .github/workflows/trivy-image-scan.yml Dismissed
Comment thread .github/workflows/trivy-image-scan.yml Resolved
Comment thread .github/workflows/trivy-image-scan.yml Resolved
Comment thread .github/workflows/trivy-image-scan.yml Resolved
Signed-off-by: Sean Tronsen <sean.tronsen@gmail.com>
Signed-off-by: Sean Tronsen <sean.tronsen@gmail.com>
@seantronsen

seantronsen commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor Author

The want for simplicity is valid, however, as a generic action, we need to accommodate non-happy-path use cases. Realistically, we probably don't need the arbitrary tag argument, but some repos may allow triggering this via workflow_dispatch, which may or not have a PR tag, so we need to figure out how to deal with that if not with the arbitrary tag argument. Containers are pushed on PRs, so I think at least allowance of PR number specification should be allowed.

Respectfully, I'd like to push back on this: #44 (comment)

I looked around the org first. Some repos support workflow_dispatch for their own Trivy setups, but I didn't find any that actually use it. This workflow is meant to replace those setups as the standard, so it should follow the build workflow's design rather than carry over unused features.

trivy-image-scan scans what build-release-goreleaser publishes, and that only runs on PRs (pr-) and v* tag pushes. A manual run has nothing new to scan, so a PR-number or tag override would just be extra logic for a case the build doesn't support.

So the goals are:

  • Run on the same triggers as the build, and fail clearly on anything else.
  • Drop workflow_dispatch support, along with the override inputs it would need.

Ongoing CVE coverage for published images until their EOL (e.g. a scheduled rescan) is worth having, but that's out of scope for this PR. If it's something you want, I can create a tracking issue and implement immediately after the release of v4.

@seantronsen
seantronsen requested a review from synackd November 2, 2026 20:49
@synackd

synackd commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

I'm fine if we restrict how it runs, as long as we are explicit both in documentation and error modes.

I looked around the org first. Some repos support workflow_dispatch for their own Trivy setups, but I didn't find any that actually use it. This workflow is meant to replace those setups as the standard, so it should follow the build workflow's design rather than carry over unused features.

The org is probably not a good reference. Most of the actions there aren't exactly fleshed out. This PR stack is probably the first attempt at any "standard" flow, which is why I bring up the failure mode accommodation here.

trivy-image-scan scans what build-release-goreleaser publishes, and that only runs on PRs (pr-) and v* tag pushes. A manual run has nothing new to scan, so a PR-number or tag override would just be extra logic for a case the build doesn't support.

So the goals are:

* Run on the same triggers as the build, and fail clearly on anything else.

* Drop workflow_dispatch support, along with the override inputs it would need.

As stated above, limiting the run mode for this action to tag pushes is fine as long asthe documentation is clear about that and any attempt to run otherwise is met with a clear error. My thought for workflow_dispatch is if a scan needs to run to scan a test image, but I don't see that as a common use case.

Comment thread .github/workflows/trivy-image-scan.yml Resolved
Co-authored-by: Devon Bautista <17506592+synackd@users.noreply.github.com>
Signed-off-by: Sean Tronsen <sean.tronsen@gmail.com>
@seantronsen

Copy link
Copy Markdown
Contributor Author

The want for simplicity is valid, however, as a generic action, we need to accommodate non-happy-path use cases. Realistically, we probably don't need the arbitrary tag argument, but some repos may allow triggering this via workflow_dispatch, which may or not have a PR tag, so we need to figure out how to deal with that if not with the arbitrary tag argument. Containers are pushed on PRs, so I think at least allowance of PR number specification should be allowed.

Respectfully, I'd like to push back on this: #44 (comment)

I looked around the org first. Some repos support workflow_dispatch for their own Trivy setups, but I didn't find any that actually use it. This workflow is meant to replace those setups as the standard, so it should follow the build workflow's design rather than carry over unused features.

trivy-image-scan scans what build-release-goreleaser publishes, and that only runs on PRs (pr-) and v* tag pushes. A manual run has nothing new to scan, so a PR-number or tag override would just be extra logic for a case the build doesn't support.

So the goals are:

  • Run on the same triggers as the build, and fail clearly on anything else.
  • Drop workflow_dispatch support, along with the override inputs it would need.

Ongoing CVE coverage for published images until their EOL (e.g. a scheduled rescan) is worth having, but that's out of scope for this PR. If it's something you want, I can create a tracking issue and implement immediately after the release of v4.

Tracking issue created: #61

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

I think this is largely good, just a documentation nit.

Comment thread README.md Outdated

### trivy-image-scan (Reusable Workflow)
Scans an already-pushed container image with Trivy and uploads SARIF findings to GitHub Advanced Security. Designed to chain after `build-release-goreleaser`.
Scans already-pushed container images with Trivy and uploads SARIF findings to GitHub Advanced Security. It scans each image at the build's tag (`pr-<N>` on pull requests, else the pushed `v*` tag; any other trigger fails), one job per image, by digest. Fork PRs publish no images and are skipped. GitHub doesn't let `GITHUB_TOKEN` list packages, so image names come from `images`, else the `ghcr.io` entries in the GoReleaser config (`dockers_v2[].images`), else the repository name (see `discover-ghcr-images`). Every name must be an existing package; all bad names are reported, then the run fails. Run it after `build-release-goreleaser`.

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.

This paragraph explicitly states that unsupported triggers fail, but that restriction is embedded in the longer explanation of scanning and image discovery. The usage example below starts at jobs:, so someone copying it could miss which caller events are supported.

I think it might be better to put a short callout immediately before Usage and include the caller's triggers in the example, since that would make the restriction easier to discover before running the workflow. For example:

Supported triggers: Call this workflow from pull_request events or push events for tags beginning with v. Other events—including workflow_dispatch, workflow_run, and release—fail with an error. Run the scan after the image-publishing job.

on:
  pull_request:
  push:
    tags: ['v*']

That would also make the documentation's event names directly match the trigger check and error message. This is a readability suggestion; the restriction is already documented correctly.

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.

Related to #44 (comment)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm fine with this and will do it when I get home, but it also hints at a larger docs update. In another PR higher up in the stack, I reorganized all the docs into a focused layout, but my original plan was to hold off on major content changes across the board until the current stack is approved (another reason for the release staging setup) to avoid unnecessary contention over the .md files (simplifies stack rebases).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Tracking issue created: #64

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Signed-off-by: Sean Tronsen <sean.tronsen@gmail.com>
@seantronsen
seantronsen requested a review from synackd November 5, 2026 00:04
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.

4 participants