-
Notifications
You must be signed in to change notification settings - Fork 180
update: added Trivy CVE scan to service images #1290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| # This workflow uses actions that are not certified by GitHub. | ||
| # They are provided by a third-party and are governed by | ||
| # separate terms of service, privacy policy, and support | ||
| # documentation. | ||
| # | ||
| # Reusable workflow: scans a single image reference with Trivy and uploads the | ||
| # results to the GitHub Security tab. Called by each service's build-and-push | ||
| # workflow right after it pushes to ghcr.io, passing the exact image tag that | ||
| # was just pushed. | ||
|
|
||
| name: Run CVE Scan on Service Images | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| image: | ||
| required: true | ||
| type: string | ||
|
|
||
| jobs: | ||
| scan: | ||
| name: trivy Scan | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| packages: read | ||
| contents: read # Required to checkout and read repo files | ||
| security-events: write # Required to upload SARIF files to Security tab | ||
| actions: read # Required for upload-sarif to process results on private repos | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Log in to GHCR | ||
| run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | ||
|
|
||
| - name: Run Trivy vulnerability scanner | ||
| uses: aquasecurity/trivy-action@7b7aa264d83dc58691451798b4d117d53d21edfe | ||
| with: | ||
| image-ref: ${{ inputs.image }} | ||
| format: 'sarif' | ||
| output: 'trivy-results.sarif' | ||
| severity: CRITICAL | ||
|
|
||
| - name: Upload Trivy scan results to GitHub Security tab | ||
| uses: github/codeql-action/upload-sarif@v4 | ||
| with: | ||
| sarif_file: 'trivy-results.sarif' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,8 @@ jobs: | |
| needs: check-config | ||
| if: needs.check-config.outputs.should_build == 'true' | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| image: ${{ steps.push.outputs.image }} | ||
|
|
||
| # CSP (cloud service provider) selects the Maven profile and Docker build-arg. | ||
| # Set the repository/environment variable CSP to azure | aws | gcp | oci. Defaults to azure. | ||
|
|
@@ -92,7 +94,21 @@ jobs: | |
|
|
||
| # Step 7: Push Docker Image | ||
| - name: Push Docker Image | ||
| id: push | ||
| 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 || trueRepository: 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 || trueRepository: Sunbird-Knowlg/knowledge-platform Length of output: 19955 Keep secret-derived registry data out of job outputs. The 📍 Affects 2 files
🤖 Prompt for AI AgentsSource: MCP tools |
||
|
|
||
| cve-scan: | ||
| needs: build-and-push | ||
| if: needs.build-and-push.outputs.image != '' | ||
| permissions: | ||
| contents: read | ||
| packages: read | ||
| security-events: write | ||
| actions: read | ||
| uses: ./.github/workflows/cve-scan.yml | ||
| with: | ||
| image: ${{ needs.build-and-push.outputs.image }} | ||
|
|
||
There was a problem hiding this comment.
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_URLvalues, but this job only logs intoghcr.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