Skip to content

oci-build: add oci-security-scan target and scheduled workflow - #688

Open
wallrj wants to merge 6 commits into
cert-manager:mainfrom
wallrj:oci-security-scan
Open

oci-build: add oci-security-scan target and scheduled workflow#688
wallrj wants to merge 6 commits into
cert-manager:mainfrom
wallrj:oci-security-scan

Conversation

@wallrj

@wallrj wallrj commented Aug 5, 2026

Copy link
Copy Markdown
Member

What

Adds OCI image vulnerability scanning to makefile-modules, so every project gets it for free.

Example

▶️ https://github.com/cert-manager/csi-driver-spiffe/actions/runs/31049028008 — a real pre-merge run of the combined workflow in cert-manager/csi-driver-spiffe#577, a multi-image repo (build_names := manager approver) which also scans its two third-party sidecar images. The job summary page shows a readable trivy report per image:

  • cert-manager.local/cert-manager-csi-driver-spiffe ✅ clean
  • cert-manager.local/cert-manager-csi-driver-spiffe-approver ✅ clean
  • registry.k8s.io/sig-storage/livenessprobe:v2.19.0 ❌ 13 fixable (5 MEDIUM, 8 HIGH)
  • registry.k8s.io/sig-storage/csi-node-driver-registrar:v2.17.0 ❌ 13 fixable (5 MEDIUM, 8 HIGH)

...and the security-scan (v0.15.0) matrix job shows the latest released tag being checked (govulncheck clean; the tag predates this module so the image scan skips itself with a notice).

How

oci-build module — new make targets:

  • oci-scan-<build_name> — builds the image for the local architecture and scans it with trivy (the same tool used by the Artifact Hub security report). Reports only vulnerabilities which are fixable (--ignore-unfixed) and of severity MEDIUM, HIGH or CRITICAL, vulnerability scanner only (--scanners vuln — the secret scanner is slow), human readable table output, non-zero exit if any are found. Policy flags are overridable via trivy_scan_flags.
  • oci-scan-extra-images — scans the image refs listed in the new oci_scan_extra_images variable, for third-party sidecar images deployed alongside the repo's own images (e.g. csi-driver's livenessprobe and node-driver-registrar).
  • oci-security-scan — aggregate target which scans all images in build_names plus the extra images (handles multi-image projects). Run this on a release branch just before tagging. All images are scanned even if an earlier one fails, so every report is produced before the target exits non-zero.
  • When running in GitHub Actions (detected by GITHUB_STEP_SUMMARY being set — some consumer repos run CI on GitLab, where behaviour is unchanged) each report is also appended to the job summary, because the trivy table is hard to read in the raw job log.

go module — the existing nightly govulncheck workflow becomes a single combined security-scan workflow:

  • Runs verify-govulncheck and (where the repo builds OCI images — guarded by target existence) make --keep-going oci-security-scan.
  • Scans the default branch, the two newest release-X.Y branches and the latest non-pre-release tag, giving early warning when released images contain fixable vulnerabilities.
  • The file keeps its historic govulncheck.yaml name so GitHub treats it as the same registered workflow: workflow_dispatch keeps working on any branch (which allowed pre-merge CI testing of this change), and no stale workflow files are left in downstream repos.

Why

We want early warning when our released OCI images contain known fixable vulnerabilities, and a pre-release check so we don't tag releases containing them. cert-manager has bespoke trivy-scan-* targets; this makes the capability available to all repos via makefile-modules, and keeps a single nightly security workflow per repo.

Testing

🤖 Generated with Claude Code

@cert-manager-prow cert-manager-prow Bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. labels Aug 5, 2026
@cert-manager-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign sgtcodfish for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@cert-manager-prow cert-manager-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 5, 2026
Add an oci-scan-<build_name> target for each OCI image and an
oci-security-scan aggregate target, which scan the images using trivy for
OS and library vulnerabilities which have a known fix and a severity of
MEDIUM, HIGH or CRITICAL. The scan fails (exit code 1) if any such
vulnerabilities are found, and prints a human readable report.

Also generate a scheduled GitHub Actions workflow in downstream
repositories, which runs oci-security-scan every night against the
default branch, the two newest release branches and the latest release
tag, to give early warning when released images, or images about to be
released, contain fixable vulnerabilities.

Signed-off-by: Richard Wall <richard@the-moon.net>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@cert-manager-prow cert-manager-prow Bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 5, 2026
wallrj and others added 3 commits August 5, 2026 16:19
Instead of generating a second scheduled workflow file, extend the
existing govulncheck workflow (shipped by the go module) into a single
nightly security-scan workflow which runs verify-govulncheck and, where
the repository builds OCI images, oci-security-scan. It scans the
default branch, the two newest release branches and the latest release
tag.

The file keeps its historic govulncheck.yaml name so that GitHub
continues to treat it as the same registered workflow, which means it
can be triggered with workflow_dispatch on any branch (including
pre-merge testing of this change), and no stale workflow files are left
in downstream repositories.

Signed-off-by: Richard Wall <richard@the-moon.net>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Skip the secret scanner, which is slow and not the purpose of this
target.

Signed-off-by: Richard Wall <richard@the-moon.net>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Some repositories (csi-driver, csi-driver-spiffe) deploy third party
sidecar images alongside the images they build. List them in the new
oci_scan_extra_images variable to have oci-security-scan scan them too.
The trivy policy flags are factored into a trivy_scan_flags variable
shared by all the scan targets.

Signed-off-by: Richard Wall <richard@the-moon.net>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
wallrj added a commit to cert-manager/csi-driver that referenced this pull request Aug 5, 2026
Demonstrates cert-manager/makefile-modules#688: klone.yaml temporarily
points the oci-build module at the fork branch, which adds:

- make oci-scan-manager / make oci-security-scan: build the OCI image
  and scan it with trivy for fixable MEDIUM, HIGH and CRITICAL
  vulnerabilities, failing if any are found.
- A generated nightly GitHub Actions workflow which runs the scan
  against the default branch, the two newest release branches and the
  latest release tag.

DO NOT MERGE until cert-manager/makefile-modules#688 is merged and
klone.yaml is repointed at the upstream module.

Signed-off-by: Richard Wall <richard@the-moon.net>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
wallrj and others added 2 commits August 5, 2026 22:22
Trivy's table format is hard to read in the raw GitHub Actions job log
because of line wrapping and timestamps. Append each scan report to
$GITHUB_STEP_SUMMARY (inside a fenced code block, one heading per image)
where it renders as fixed-width text on the run page.

Only do this when GITHUB_STEP_SUMMARY is set, because some repos using
this module run their CI on GitLab; there and locally the behaviour is
unchanged (report on stdout, non-zero exit on findings).

Signed-off-by: Richard Wall <richard@the-moon.net>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Previously oci-scan-extra-images exited at the first vulnerable image,
so only the first report appeared in the log and job summary. Scan every
image, then exit non-zero if any scan failed. Likewise run the workflow
step with make --keep-going so a vulnerable built image does not prevent
the remaining oci-scan-* prerequisites from running.

Signed-off-by: Richard Wall <richard@the-moon.net>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@wallrj
wallrj requested a lite review from Copilot August 5, 2026 21:44
@wallrj
wallrj marked this pull request as ready for review August 5, 2026 21:45
@cert-manager-prow cert-manager-prow Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 5, 2026

Copilot AI left a 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.

Pull request overview

This PR adds an OCI image vulnerability scanning capability to the oci-build makefile module (via Trivy) and integrates it into the Go base nightly workflow so downstream repositories can automatically scan code (govulncheck) and built images (trivy) across relevant refs.

Changes:

  • Add oci-scan-*, oci-scan-extra-images, and oci-security-scan targets to run Trivy vulnerability scanning (including optional GitHub Actions job summary output).
  • Introduce configurable oci_scan_extra_images and trivy_scan_flags defaults for scanning sidecar/third-party images and applying a default vulnerability policy.
  • Update the existing govulncheck.yaml workflow to a combined security-scan workflow that scans the default branch, newest release branches, and latest non-pre-release tag, and conditionally runs oci-security-scan.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
modules/oci-build/01_mod.mk Adds Trivy scan helper + new scan targets (per-image, extra images, aggregate).
modules/oci-build/00_mod.mk Adds configuration variables for extra images and Trivy policy flags; wires scan targets into target lists.
modules/go/base/.github/workflows/govulncheck.yaml Converts the nightly workflow into a combined security scan with ref discovery + conditional OCI scanning.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +93 to +103
define trivy_scan
report=$$(mktemp); \
$(TRIVY) image $2 $(trivy_scan_flags) --output $$report; \
code=$$?; \
cat $$report; \
if [ -n "$${GITHUB_STEP_SUMMARY:-}" ]; then \
{ echo "### $1"; echo '```'; cat $$report; echo '```'; echo; } >> "$$GITHUB_STEP_SUMMARY"; \
fi; \
rm -f $$report; \
exit $$code
endef
Comment on lines +134 to +139
.PHONY: oci-security-scan
## Scan all the OCI images built by this repository, and any extra images
## listed in oci_scan_extra_images, for known vulnerabilities; failing if any
## fixable vulnerabilities of severity MEDIUM, HIGH or CRITICAL are found.
## @category [shared] Build
oci-security-scan: $(oci_scan_targets) oci-scan-extra-images
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants