Skip to content

ci: add Trivy security scan to PR pipeline - #1634

Draft
yaroslavmokflmg wants to merge 12 commits into
mainfrom
security/trivy
Draft

ci: add Trivy security scan to PR pipeline#1634
yaroslavmokflmg wants to merge 12 commits into
mainfrom
security/trivy

Conversation

@yaroslavmokflmg

@yaroslavmokflmg yaroslavmokflmg commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Adds a Trivy-based PR security gate:

  • scans repository dependencies (lockfiles / pom.xml) and Dockerfile base images
  • fails the pipeline on HIGH/CRITICAL vulnerabilities with a fix available
  • findings are deduplicated across modules; suppressions go to .trivyignore with a justification comment
  • wired into All Checks so merging is blocked when the scan is red

Summary by CodeRabbit

  • New Features

    • Added automated security scanning for pull requests.
    • Scans repository files, Maven dependencies, and Docker base images for high- and critical-severity vulnerabilities.
    • Reports and deduplicates findings, failing checks when vulnerabilities are detected.
  • Documentation

    • Added guidance for configuring vulnerability exclusions using .trivyignore.

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: cb20bd0d-0db9-4fb9-86a6-5eae0a18bbcf

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The pull-request workflow now runs a local Trivy composite action. The action resolves Maven dependencies, scans repository files and Dockerfile base images, reports deduplicated HIGH and CRITICAL findings, and fails when findings exist.

Changes

Trivy scanning

Layer / File(s) Summary
Trivy scan action
.github/steps/trivy/action.yml, .trivyignore
The composite action prepares Maven dependencies, scans repository files and Dockerfile base images, deduplicates findings, reports occurrence counts, and fails on HIGH or CRITICAL vulnerabilities. The ignore file documents vulnerability ID entries.
Pull-request workflow integration
.github/workflows/test.yml
The workflow runs the scan for open, non-draft pull requests and makes all-checks wait for the scan job.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant PullRequestWorkflow
  participant TrivyAction
  participant Maven
  participant Trivy
  PullRequestWorkflow->>TrivyAction: Run local scan
  TrivyAction->>Maven: Resolve dependencies offline
  TrivyAction->>Trivy: Scan files and Dockerfile base images
  Trivy-->>TrivyAction: Return vulnerability findings
  TrivyAction-->>PullRequestWorkflow: Report findings and fail on HIGH or CRITICAL results
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes adding a Trivy security scan to the pull request pipeline.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch security/trivy

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
.github/workflows/test.yml (1)

49-51: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low value

Consider a job-level timeout.

No timeout-minutes is set for trivy_scan. trivy image pulls a variable number of base images per PR with no explicit timeout on the pull; a stalled registry request could hold the runner for the default GitHub Actions limit. Add a timeout-minutes bound to fail fast instead.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/test.yml around lines 49 - 51, Add a job-level
timeout-minutes setting to the trivy_scan job containing the Trivy scan step,
using a finite bound that fails stalled image pulls promptly while allowing
normal scans to complete.
.github/steps/trivy/action.yml (1)

70-86: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Report loses per-module version detail on dedup.

group_by([.s, .ty, .p, .id]) | map(.[0] + {n: length}) keeps only the first grouped element's InstalledVersion/FixedVersion. If the same package and CVE appear with different installed versions across Maven modules, the printed report shows only one version pair and the occurrence count, without indicating which modules use which version. This does not affect the pass/fail gate, but it makes it harder to know which module needs the version bump.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/steps/trivy/action.yml around lines 70 - 86, Update the
report-generation jq pipeline in the Trivy reporting block so deduplicated
findings retain and display each distinct InstalledVersion/FixedVersion pair,
rather than selecting only the first grouped record via `map(.[0] + {n:
length})`. Keep the existing uniqueness key and occurrence counts, while
including enough per-version detail in each output row to identify which
module/version requires the upgrade.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/steps/trivy/action.yml:
- Around line 47-68: Update the base-image loop around the unresolved-variable
case and the trivy image failure branch to emit distinguishable warnings
identifying the skipped image and reason; do not silently continue. Preserve
existing exclusions for aliases and scratch, and consider propagating a nonzero
status from trivy image failures so the security job fails closed rather than
treating an unscanned image as clean.

In @.github/workflows/test.yml:
- Around line 44-47: Update the actions/checkout@v4 step in the Checkout
workflow block to set persist-credentials to false, while preserving the
existing pull request head SHA ref.

---

Nitpick comments:
In @.github/steps/trivy/action.yml:
- Around line 70-86: Update the report-generation jq pipeline in the Trivy
reporting block so deduplicated findings retain and display each distinct
InstalledVersion/FixedVersion pair, rather than selecting only the first grouped
record via `map(.[0] + {n: length})`. Keep the existing uniqueness key and
occurrence counts, while including enough per-version detail in each output row
to identify which module/version requires the upgrade.

In @.github/workflows/test.yml:
- Around line 49-51: Add a job-level timeout-minutes setting to the trivy_scan
job containing the Trivy scan step, using a finite bound that fails stalled
image pulls promptly while allowing normal scans to complete.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 754b8697-97bd-4d0f-871b-3f705e0a441b

📥 Commits

Reviewing files that changed from the base of the PR and between 0e6a75b and a68f695.

📒 Files selected for processing (3)
  • .github/steps/trivy/action.yml
  • .github/workflows/test.yml
  • .trivyignore

Comment thread .github/steps/trivy/action.yml Outdated
Comment thread .github/workflows/test.yml
@yaroslavmokflmg
yaroslavmokflmg marked this pull request as draft August 3, 2026 17:52
@yaroslavmokflmg yaroslavmokflmg self-assigned this Aug 5, 2026
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