chore: migrate from Trivy to Grype for vulnerability scanning#154
chore: migrate from Trivy to Grype for vulnerability scanning#154
Conversation
| name: Grype Security Scan | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6 | ||
|
|
||
| - name: Run Trivy vulnerability scanner in repo mode | ||
| uses: aquasecurity/trivy-action@b6643a29fecd7f34b3597bc6acb0a98b03d33ff8 # 0.33.1 | ||
| - name: Run Grype vulnerability scanner | ||
| id: grype-scan | ||
| uses: anchore/scan-action@7037fa011853d5a11690026fb85feee79f4c946c # v7.3.2 | ||
| with: | ||
| scan-type: 'fs' | ||
| ignore-unfixed: true | ||
| format: 'sarif' | ||
| output: 'trivy-results.sarif' | ||
| severity: 'CRITICAL,HIGH' | ||
| path: "." | ||
| only-fixed: true | ||
| output-format: "sarif" | ||
| severity-cutoff: "high" | ||
| fail-build: false | ||
|
|
||
| - name: Upload Trivy scan results to GitHub Security tab | ||
| - name: Upload Grype scan results to GitHub Security tab | ||
| uses: github/codeql-action/upload-sarif@19b2f06db2b6f5108140aeb04014ef02b648f789 # v4 | ||
| if: always() | ||
| with: | ||
| sarif_file: 'trivy-results.sarif' | ||
| category: 'trivy-fs' | ||
|
|
||
| - name: Run Trivy vulnerability scanner in IaC mode | ||
| uses: aquasecurity/trivy-action@b6643a29fecd7f34b3597bc6acb0a98b03d33ff8 # 0.33.1 | ||
| with: | ||
| scan-type: 'config' | ||
| hide-progress: false | ||
| format: 'sarif' | ||
| output: 'trivy-config-results.sarif' | ||
| exit-code: '1' | ||
| severity: 'CRITICAL,HIGH' | ||
|
|
||
| - name: Upload Trivy IaC scan results to GitHub Security tab | ||
| uses: github/codeql-action/upload-sarif@19b2f06db2b6f5108140aeb04014ef02b648f789 # v4 | ||
| if: always() | ||
| with: | ||
| sarif_file: 'trivy-config-results.sarif' | ||
| category: 'trivy-config' No newline at end of file | ||
| sarif_file: ${{ steps.grype-scan.outputs.sarif }} |
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 14 hours ago
In general, the fix is to explicitly declare a permissions block in the workflow, using the least privileges needed. For a security scanning job that checks out the code and uploads SARIF results to GitHub’s Security tab, the job needs read access to the repository contents and security events. The minimal and appropriate set is typically contents: read and security-events: write (the latter is required for uploading SARIF).
The best way to fix this without changing functionality is to add a permissions block at the job level under grype-scan:. This scopes the permissions just to this job and avoids affecting any other jobs that might be added later. Concretely, in .github/workflows/security.yml, under jobs:, and indented to align with runs-on, add:
permissions:
contents: read
security-events: writeThis preserves the workflow’s behavior (checkout still works; SARIF upload still works) while constraining the GITHUB_TOKEN to only what is needed.
| @@ -10,6 +10,9 @@ | ||
| grype-scan: | ||
| name: Grype Security Scan | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| security-events: write | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6 |
|
You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool. What Enabling Code Scanning Means:
For more information about GitHub Code Scanning, check out the documentation. |
Replace aquasecurity/trivy-action with anchore/scan-action (Grype) v7.3.2 for vulnerability scanning. Grype provides equivalent vulnerability detection capabilities. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
d48c0ff to
9753159
Compare
Summary
aquasecurity/trivy-actionwithanchore/scan-action(Grype) v7.3.2 for vulnerability scanningTest plan
🤖 Generated with Claude Code