Skip to content

ci: add the shared scan-image action - #19

Merged
uniqueg merged 2 commits into
mainfrom
ci/scan-image-action
Oct 28, 2026
Merged

uniqueg merged 2 commits into
mainfrom
ci/scan-image-action

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds the shared composite action actions/scan-image, based on FOCA's copy (the newest pins: trivy-action v0.36.0, upload-sarif v4.39.1, upload-artifact v7.0.2). The Trivy binary version is now the input trivy-version (default v0.75.0); the README notes that Dependabot doesn't bump it. Dependabot already covers /actions/*, so no dependabot.yml change is needed.

The rollout in the caller repos is split off into child issues of #11, each blocked by this issue: elixir-cloud-aai/foca#548, elixir-cloud-aai/cloud-registry#270, elixir-cloud-aai/protes#329 (trs-filer has no copy yet).

Closes #14

Verification

  • pre-commit run --all-files (yamllint/schema checks, markdownlint, actionlint, gitleaks): passed.
  • The new steps in the CI test job scan a clean image built FROM scratch (expect success and the full report files) and alpine:3.10.0 (expect the step to fail on fixable findings). CI passed (run 40644536425): the vulnerable scan failed on "Total: 12 (HIGH: 9, CRITICAL: 3)" as intended.

Light lane: the action is a copy of an already reviewed action plus one input; the change touches CI only, with no secrets, permissions or release workflow.

Declined review findings

None.

Open questions

None.

🤖 Generated with Claude Code

Summary by Sourcery

Introduce and validate a shared Trivy-based Docker image scanning action for use across workflows.

New Features:

  • Add a reusable composite action for scanning Docker images with Trivy, uploading actionable findings to code scanning, and optionally publishing full reports.
  • Expose controls for report uploads, failure behavior, and the Trivy binary version.

Enhancements:

  • Document the shared image-scanning action, its inputs, usage, and reporting behavior.

CI:

  • Extend CI coverage to verify successful scans and reports for clean images and expected failures for vulnerable images.
  • Increase the test job timeout to accommodate image scanning.

Documentation:

  • Add the image-scanning action to the repository's action catalog and document its usage and configuration.

Add actions/scan-image, based on FOCA's copy (the newest pins), with
the Trivy binary version as the new input trivy-version. The CI test
job scans a clean image (and checks the full report) and an image with
fixable findings (and expects a failure).

Refs #14

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Adds and documents the shared, pinned actions/scan-image composite action, which uses Trivy to upload fixable findings, optionally publish complete reports, and fail on fixable HIGH/CRITICAL vulnerabilities; CI validates its clean-image and vulnerable-image behavior.

Sequence diagram for the shared image scan action

sequenceDiagram
    participant Job as CI job
    participant Action as scan-image
    participant Trivy as Trivy
    participant CodeQL as Code scanning
    participant Artifact as Workflow artifact

    Job->>Action: Invoke with image, category, upload, report, fail
    Action->>Trivy: Scan image with ignore-unfixed
    Trivy-->>Action: Fixable findings as trivy-results.sarif
    opt upload == true
        Action->>CodeQL: upload-sarif(trivy-results.sarif, category)
    end
    opt report == true
        Action->>Trivy: Scan image as JSON and table
        Trivy-->>Action: trivy-report.json and trivy-report.txt
        Action->>Artifact: Upload trivy-report-category
    end
    opt fail == true
        Action->>Trivy: Scan severity CRITICAL,HIGH with exit-code 1
        Trivy-->>Action: Success or failure on fixable findings
    end
Loading

Flow diagram for CI validation of image scanning

flowchart LR
    Prepare[Prepare clean and vulnerable images] --> Clean[scan-image clean image]
    Clean --> Reports[Check SARIF, JSON, and table reports]
    Prepare --> Vulnerable[scan-image alpine:3.10.0]
    Vulnerable --> Expected[Expect failure on fixable HIGH/CRITICAL findings]
Loading

File-Level Changes

Change Details Files
Introduces a reusable composite action for scanning container images with Trivy and publishing actionable results.
  • Defines required image and category inputs plus controls for SARIF upload, full reports, failure behavior, and Trivy version.
  • Runs pinned Trivy scans for fixable SARIF findings, optional JSON/table reports, and failure checks for fixable HIGH/CRITICAL findings.
  • Optionally uploads SARIF to code scanning and complete reports as category-specific workflow artifacts.
  • Documents permissions, ignore-file behavior, inputs, usage, and manual maintenance of the Trivy version.
actions/scan-image/action.yml
actions/scan-image/README.md
README.md
Adds CI coverage for the new action's success, reporting, and failure paths.
  • Builds a scratch-based clean image and pulls a known vulnerable Alpine image.
  • Verifies clean scans generate JSON, SARIF, and table reports.
  • Verifies scans fail for fixable vulnerabilities while allowing the test job to assert the expected failure.
  • Disables uploads in tests and extends the test job timeout.
.github/workflows/ci.yml

Assessment against linked issues

Issue Objective Addressed Explanation
#14 Add a shared actions/scan-image composite action with the required image, category, Trivy-version, and full-report inputs, and document its behavior and version maintenance. ✅
#14 Ensure Dependabot updates the action pins, document that it does not update the Trivy binary version, and add CI tests for clean-image reports and failure on fixable critical/high findings. ✅
#14 Migrate foca, cloud-registry, and proTES to the shared action, removing their local copies and Dependabot directory entries. ❌ The PR adds the shared action but does not change any caller repositories. It says those migrations are split into separate child issues.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@uniqueg
uniqueg marked this pull request as ready for review October 28, 2026 06:37

@sourcery-ai sourcery-ai Bot 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.

Hey - I've found 6 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="actions/scan-image/action.yml" line_range="45" />
<code_context>
+      uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
+      with:
+        image-ref: ${{ inputs.image }}
+        trivyignores: .trivyignore.yaml
+        ignore-unfixed: true
+        format: sarif
</code_context>
<issue_to_address>
**Pull requests can suppress findings**

When a contributor adds a matching vulnerability to the caller’s `.trivyignore.yaml` in a PR that runs this action, trivy reads the caller’s PR-controlled `.trivyignore.yaml` for the SARIF scan and the failure check, so a contributor can suppress a fixable critical or high finding and make the scan pass without reporting it.

Load accepted findings only from a trusted base-branch configuration, or require trusted review of changes to the ignore file before scanning it.

Also at `actions/scan-image/action.yml:61`, `actions/scan-image/action.yml:71`, `actions/scan-image/action.yml:90`.
</issue_to_address>

### Comment 2
<location path="actions/scan-image/action.yml" line_range="45" />
<code_context>
+      uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
+      with:
+        image-ref: ${{ inputs.image }}
+        trivyignores: .trivyignore.yaml
+        ignore-unfixed: true
+        format: sarif
</code_context>
<issue_to_address>
**Scans fail without an ignore file**

When the caller’s workspace does not contain `.trivyignore.yaml`, the Trivy action receives `.trivyignore.yaml` unconditionally, so Trivy fails before producing scan results and callers cannot use the action.

Make the ignore-file option conditional on the file being present or provide a fallback.

Also at `actions/scan-image/action.yml:61`, `actions/scan-image/action.yml:71`, `actions/scan-image/action.yml:90`.
</issue_to_address>

### Comment 3
<location path="actions/scan-image/action.yml" line_range="91-92" />
<code_context>
+      with:
+        image-ref: ${{ inputs.image }}
+        trivyignores: .trivyignore.yaml
+        severity: CRITICAL,HIGH
+        ignore-unfixed: true
+        exit-code: "1"
+        version: ${{ inputs.trivy-version }}
</code_context>
<issue_to_address>
**Unfixed secrets fail the scan**

When the image contains a CRITICAL or HIGH secret finding, trivy’s `ignore-unfixed` filters vulnerabilities, not secret findings, so the secret remains in the final scan and `exit-code: 1` fails the action outside the fixable-findings gate.

Keep secret findings from triggering the final fixable-vulnerability failure gate.

Also at `actions/scan-image/action.yml:46`.
</issue_to_address>

### Comment 4
<location path="actions/scan-image/action.yml" line_range="44" />
<code_context>
+    - name: Scan image (fixable findings)
+      uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
+      with:
+        image-ref: ${{ inputs.image }}
+        trivyignores: .trivyignore.yaml
+        ignore-unfixed: true
</code_context>
<issue_to_address>
**Scan results describe different images**

When a registry tag is updated between the separate scan steps, each Trivy step resolves `inputs.image` independently, so the SARIF, full report, and failure check can describe different image contents and callers receive contradictory scan results.

Resolve the image reference once and use the same image for every Trivy step.

Also at `actions/scan-image/action.yml:60`, `actions/scan-image/action.yml:70`, `actions/scan-image/action.yml:89`.
</issue_to_address>

### Comment 5
<location path=".github/workflows/ci.yml" line_range="124-127" />
<code_context>
+        env:
+          OUTCOME: ${{ steps.bad-image.outcome }}
+        run: |
+          if [[ "${OUTCOME}" != failure ]]; then
+            echo "::error::Expected the scan of the vulnerable image to fail, got ${OUTCOME}"
+            exit 1
+          fi

   passed:
</code_context>
<issue_to_address>
**Unrelated failures pass the gate test**

When the vulnerable-image scan fails for a reason other than detecting fixable critical or high findings, the CI check accepts any `failure` outcome from the scan step, so a failure before Trivy evaluates the findings passes as though the fixable-findings gate worked.

Verify that the scan failed because it detected fixable critical or high findings, rather than checking only the step outcome.
</issue_to_address>

### Comment 6
<location path="actions/scan-image/action.yml" line_range="80" />
<code_context>
+      if: inputs.report == 'true'
+      uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
+      with:
+        name: trivy-report-${{ inputs.category }}
+        path: |
+          trivy-report.json
</code_context>
<issue_to_address>
**Some categories prevent report uploads**

When `report` is `true` and `category` contains a character rejected in artifact names, such as `/` or `:`, `upload-artifact` rejects the interpolated artifact name, so the artifact step fails and the action does not publish the report.

Sanitize the category before using it in the artifact name or reject invalid categories with a clear validation error.
</issue_to_address>

Sourcery assessment

Approval pending. 6 findings to address first.

Blocking findings: actions/scan-image/action.yml:45, actions/scan-image/action.yml:45, actions/scan-image/action.yml:92, actions/scan-image/action.yml:44, .github/workflows/ci.yml:127, and 1 more


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread actions/scan-image/action.yml Resolved
Comment thread actions/scan-image/action.yml Resolved
Comment thread actions/scan-image/action.yml Resolved
Comment thread actions/scan-image/action.yml Resolved
Comment thread .github/workflows/ci.yml Resolved
Comment thread actions/scan-image/action.yml Resolved
Expect findings in the SARIF results of the vulnerable image, so that
a failure before the scan doesn't pass the test, and document the
ignore file, the category characters, digests and secret findings.

Refs #14

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg merged commit 7cb2cf3 into main Oct 28, 2026
4 checks passed
@uniqueg
uniqueg deleted the ci/scan-image-action branch October 28, 2026 13:26
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.

ci: share the scan-image action

1 participant