Skip to content

update: added Trivy CVE scan to service images - #1290

Draft
sho6000 wants to merge 4 commits into
Sunbird-Knowlg:masterfrom
sho6000:trivy-cve
Draft

update: added Trivy CVE scan to service images#1290
sho6000 wants to merge 4 commits into
Sunbird-Knowlg:masterfrom
sho6000:trivy-cve

Conversation

@sho6000

@sho6000 sho6000 commented Jul 23, 2026

Copy link
Copy Markdown

Summary

Adds Trivy CVE scanning for service images. A reusable workflow (cve-check.yml) runs after each build/push and uploads results to GitHub's Code Scanning tab. trivy-action is pinned to a commit SHA (not a version tag) to avoid a known resolution bug, and permissions are granted from the calling job so the scan can actually upload SARIF results.

Motivation

Get visibility into known CVEs in published images without manual scanning. No specific issue — proactive security addition.

Type of change

  • New feature

How Has This Been Tested?

  • Validated end-to-end in an isolated test repo: built a vulnerable image, confirmed Trivy detects real CVEs, and confirmed results appear in Code Scanning.
  • Verified the same flow on knowlg-service.yml / search-service.yml.

Checklist

  • Self-reviewed
  • No new warnings
  • Automated tests one new tag creation (not validated)

Summary by CodeRabbit

  • New Features
    • Added automated vulnerability scanning for service container images.
    • High- and critical-severity findings are reported in the repository’s security dashboard.
    • Container image builds now automatically trigger a security scan after successful publishing.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

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: e3fb5f3f-5779-47f6-b1fb-e65fca039546

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

Adds a reusable Trivy workflow for container image CVE scanning and wires the Knowlg and search service build workflows to expose pushed image references and trigger conditional scan jobs.

Changes

CVE scan integration

Layer / File(s) Summary
Reusable Trivy scanning workflow
.github/workflows/cve-scan.yml
Defines a required image input, authenticates to GHCR, scans HIGH and CRITICAL vulnerabilities with Trivy, and uploads SARIF results.
Service image output and scan wiring
.github/workflows/knowlg-service.yml, .github/workflows/search-service.yml
Exposes the pushed Docker image from each build job and adds dependent conditional CVE scan jobs that pass the image reference to cve-check.yml.

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

Possibly related PRs

Suggested reviewers: aimansharief

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding Trivy CVE scanning for service images.
Description check ✅ Passed The description covers the summary, motivation, change type, testing, and checklist, with only minor template gaps like an explicit issue reference and dependencies.
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

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
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Nitpick comments (1)
.github/workflows/cve-scan.yml (1)

31-32: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick win

Disable checkout credential persistence.

actions/checkout defaults persist-credentials to true, unnecessarily retaining Git credentials for later steps, including the third-party scanner. Set it to false or remove checkout if no repository files are needed. (github.com)

Proposed fix
       - name: Checkout code
         uses: actions/checkout@v4
+        with:
+          persist-credentials: false
🤖 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/cve-scan.yml around lines 31 - 32, Update the
actions/checkout step in the CVE scan workflow to disable credential persistence
by setting persist-credentials to false; keep the checkout step otherwise
unchanged.

Sources: MCP tools, Linters/SAST tools

🤖 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/workflows/cve-scan.yml:
- Around line 34-35: Update the CVE scan workflow’s registry login step to
authenticate against the registry owning inputs.image rather than hardcoding
ghcr.io. Add the required registry-specific credential inputs to the reusable
workflow and use those inputs with the configured REGISTRY_URL, preserving the
existing docker login flow for all supported private registries.
- Around line 41-43: Update the Trivy configuration in the workflow’s SARIF
output block to enable the limit-severities-for-sarif option, while retaining
severity: HIGH,CRITICAL, so generated SARIF findings contain only HIGH and
CRITICAL results.

In @.github/workflows/knowlg-service.yml:
- Around line 111-113: Update the reusable workflow references from
cve-check.yml to the existing cve-scan.yml in
.github/workflows/knowlg-service.yml lines 111-113 and
.github/workflows/search-service.yml lines 106-108, preserving the existing
image input.
- Line 101: Remove secret-derived REGISTRY_URL from the image outputs in the
image-build steps of .github/workflows/knowlg-service.yml (line 101) and
.github/workflows/search-service.yml (line 96); output only non-secret image
components such as name, tag, and repository, then pass the registry
configuration separately as secrets to cve-check.yml while preserving the
cve-scan job inputs.

---

Nitpick comments:
In @.github/workflows/cve-scan.yml:
- Around line 31-32: Update the actions/checkout step in the CVE scan workflow
to disable credential persistence by setting persist-credentials to false; keep
the checkout step otherwise unchanged.
🪄 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: 83b3f5fc-7328-4628-ab64-6bb8570efc87

📥 Commits

Reviewing files that changed from the base of the PR and between 448714d and e3e8730.

📒 Files selected for processing (3)
  • .github/workflows/cve-scan.yml
  • .github/workflows/knowlg-service.yml
  • .github/workflows/search-service.yml

Comment on lines +34 to +35
- name: Log in to GHCR
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Authenticate against the registry that owns inputs.image.

Both service workflows push to configurable REGISTRY_URL values, but this job only logs into ghcr.io. Scans will fail for Azure, GCP, OCI, or other private registries unless registry-specific credentials are passed to this reusable workflow and used here.

🧰 Tools
🪛 zizmor (1.26.1)

[error] 35-35: code injection via template expansion (template-injection): may expand into attacker-controllable code

(template-injection)

🤖 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/cve-scan.yml around lines 34 - 35, Update the CVE scan
workflow’s registry login step to authenticate against the registry owning
inputs.image rather than hardcoding ghcr.io. Add the required registry-specific
credential inputs to the reusable workflow and use those inputs with the
configured REGISTRY_URL, preserving the existing docker login flow for all
supported private registries.

Comment thread .github/workflows/cve-scan.yml Outdated
Comment on lines +41 to +43
format: 'sarif'
output: 'trivy-results.sarif'
severity: HIGH,CRITICAL

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== workflow excerpt =="
sed -n '1,120p' .github/workflows/cve-scan.yml 2>/dev/null || true

echo "== action refs =="
rg -n "aquasecurity/trivy-action|trivy-results.sarif|severity:" .github/workflows -S || true

echo "== local module docs if present =="
rg -n "limit-severities-for-sarif|HIGH,CRITICAL|SARIF|sarif" .github workflows src node_modules 2>/dev/null | head -200 || true

Repository: Sunbird-Knowlg/knowledge-platform

Length of output: 2786


🌐 Web query:

aquasecurity/trivy-action sarif limit-severities-for-sarif input documentation

💡 Result:

In the aquasecurity/trivy-action GitHub Action, the limit-severities-for-sarif input is a boolean parameter used to control how vulnerability severities are handled when generating SARIF output [1][2]. By default, this input is set to false, which means the SARIF report will include all detected vulnerabilities, regardless of the severities configured in the severity input [1][3]. When set to true, the action ensures the generated SARIF report respects the severity filter (e.g., CRITICAL,HIGH), meaning only vulnerabilities matching those specified levels will be included in the report [3][4]. This parameter is particularly useful for aligning the SARIF report content with the action's exit code behavior, as well as for reducing noise in GitHub Code Scanning alerts [3][5][6]. When limit-severities-for-sarif is false, a scan might report lower-severity vulnerabilities in the SARIF output even if the severity input is restricted, which can lead to inconsistencies where an exit-code check fails due to findings that were supposed to be ignored [4][6]. Documentation for this input is found in the main README.md and action.yaml of the trivy-action repository [1][7]. Example Usage: - name: Run Trivy uses: aquasecurity/trivy-action@master with: format: 'sarif' output: 'trivy-results.sarif' severity: 'CRITICAL,HIGH' limit-severities-for-sarif: 'true'

Citations:


Restrict SARIF findings to HIGH and CRITICAL.

With SARIF output, severity: HIGH,CRITICAL alone can still include all severities because limit-severities-for-sarif defaults to false; Code Scanning will receive lower-severity results unless it is enabled.

Proposed fix
           output: 'trivy-results.sarif'
           severity: HIGH,CRITICAL
+          limit-severities-for-sarif: true
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
format: 'sarif'
output: 'trivy-results.sarif'
severity: HIGH,CRITICAL
format: 'sarif'
output: 'trivy-results.sarif'
severity: HIGH,CRITICAL
limit-severities-for-sarif: true
🤖 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/cve-scan.yml around lines 41 - 43, Update the Trivy
configuration in the workflow’s SARIF output block to enable the
limit-severities-for-sarif option, while retaining severity: HIGH,CRITICAL, so
generated SARIF findings contain only HIGH and CRITICAL results.

Source: MCP tools

run: |
docker push $REGISTRY_URL/${IMAGE_NAME}:${IMAGE_TAG}
echo "Pushed Docker image: $REGISTRY_URL/${IMAGE_NAME}:${IMAGE_TAG}"
echo "image=$REGISTRY_URL/${IMAGE_NAME}:${IMAGE_TAG}" >> $GITHUB_OUTPUT

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== workflow files =="
git ls-files .github/workflows || true

echo
echo "== relevant workflow excerpts =="
for f in .github/workflows/knowlg-service.yml .github/workflows/search-service.yml; do
  if [ -f "$f" ]; then
    echo "--- $f ($(wc -l < "$f") lines) ---"
    nl -ba "$f" | sed -n '1,180p'
  fi
done

echo
echo "== occurrences of REGISTRY_URL and image output =="
rg -n "REGISTRY_URL|GITHUB_OUTPUT|outputs:|download-artifact|upload-artifact|github\\.action_ref|REPOSITORY|IMAGE_NAME|IMAGE_TAG|SCAN|scan" .github/workflows || true

Repository: Sunbird-Knowlg/knowledge-platform

Length of output: 697


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== relevant workflow excerpts using awk ==\n'
for f in .github/workflows/knowlg-service.yml .github/workflows/search-service.yml; do
  if [ -f "$f" ]; then
    echo "--- $f ($(wc -l < "$f") lines) ---"
    awk '{printf "%6d\t%s\n", NR, $0}' "$f" | sed -n '1,180p'
  fi
done

printf '\n== occurrences of REGISTRY_URL and image output ==\n'
grep -RInE "REGISTRY_URL|GITHUB_OUTPUT|outputs:|download-artifact|upload-artifact|github\.action_ref|REPOSITORY|IMAGE_NAME|IMAGE_TAG|SCAN|scan" .github/workflows || true

printf '\n== all references to knowlg/search scan image or reusable workflow ==\n'
grep -RInE "knowlg-service|search-service|image=|scan|security|trivy|sast|sca" .github/workflows || true

Repository: Sunbird-Knowlg/knowledge-platform

Length of output: 19955


Keep secret-derived registry data out of job outputs.

The image output contains ${{ secrets.REGISTRY_URL }}; GitHub can redact outputs that include secret values, making subsequent needs.<job>.outputs.image values empty and skipping the cve-scan jobs. Output only non-secret components like the image name, image tag, and repository, and pass registry configuration as secrets to cve-check.yml.

📍 Affects 2 files
  • .github/workflows/knowlg-service.yml#L101-L101 (this comment)
  • .github/workflows/search-service.yml#L96-L96
🤖 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/knowlg-service.yml at line 101, Remove secret-derived
REGISTRY_URL from the image outputs in the image-build steps of
.github/workflows/knowlg-service.yml (line 101) and
.github/workflows/search-service.yml (line 96); output only non-secret image
components such as name, tag, and repository, then pass the registry
configuration separately as secrets to cve-check.yml while preserving the
cve-scan job inputs.

Source: MCP tools

Comment thread .github/workflows/knowlg-service.yml Outdated
Comment on lines +111 to +113
uses: ./.github/workflows/cve-check.yml
with:
image: ${{ needs.build-and-push.outputs.image }}

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.

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Use the reusable workflow filename that exists.

Both callers reference cve-check.yml, while the added file is cve-scan.yml; actionlint cannot resolve the referenced file.

  • .github/workflows/knowlg-service.yml#L111-L113: change uses to ./.github/workflows/cve-scan.yml.
  • .github/workflows/search-service.yml#L106-L108: change uses to ./.github/workflows/cve-scan.yml.
🧰 Tools
🪛 actionlint (1.7.12)

[error] 111-111: could not read reusable workflow file for "./.github/workflows/cve-check.yml": open /home/jailuser/git/.github/workflows/cve-check.yml: no such file or directory

(workflow-call)

📍 Affects 2 files
  • .github/workflows/knowlg-service.yml#L111-L113 (this comment)
  • .github/workflows/search-service.yml#L106-L108
🤖 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/knowlg-service.yml around lines 111 - 113, Update the
reusable workflow references from cve-check.yml to the existing cve-scan.yml in
.github/workflows/knowlg-service.yml lines 111-113 and
.github/workflows/search-service.yml lines 106-108, preserving the existing
image input.

Source: Linters/SAST tools

@sho6000
sho6000 marked this pull request as draft July 24, 2026 05:34
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