CI: Show Trivy table output before SARIF upload; always upload SARIF; fail late on CRITICAL/HIGH
This commit is contained in:
53
.github/workflows/docker-build.yml
vendored
53
.github/workflows/docker-build.yml
vendored
@@ -96,33 +96,44 @@ jobs:
|
||||
build-args: |
|
||||
CADDY_IMAGE=${{ steps.caddy.outputs.image }}
|
||||
|
||||
# Step 8: Run Trivy security scan
|
||||
- name: 🔍 Run Trivy vulnerability scanner
|
||||
if: github.event_name != 'pull_request'
|
||||
id: trivy
|
||||
uses: aquasecurity/trivy-action@master
|
||||
with:
|
||||
image-ref: ${{ fromJSON(steps.meta.outputs.json).tags[0] }}
|
||||
format: 'sarif'
|
||||
output: 'trivy-results.sarif'
|
||||
exit-code: '1'
|
||||
severity: 'CRITICAL,HIGH'
|
||||
|
||||
# Step 9: Upload Trivy results to GitHub Security tab
|
||||
- name: 📤 Upload Trivy results to GitHub Security
|
||||
uses: github/codeql-action/upload-sarif@v3
|
||||
if: github.event_name != 'pull_request' && steps.trivy.outcome == 'success'
|
||||
with:
|
||||
sarif_file: 'trivy-results.sarif'
|
||||
|
||||
# Step 10: Run Trivy with table output for workflow logs
|
||||
# Step 8: Run Trivy scan (table output first for visibility)
|
||||
- name: 📋 Run Trivy scan (table output)
|
||||
if: github.event_name != 'pull_request' && steps.trivy.outcome == 'success'
|
||||
if: github.event_name != 'pull_request'
|
||||
id: trivy_table
|
||||
continue-on-error: true
|
||||
uses: aquasecurity/trivy-action@master
|
||||
with:
|
||||
image-ref: ${{ fromJSON(steps.meta.outputs.json).tags[0] }}
|
||||
format: 'table'
|
||||
severity: 'CRITICAL,HIGH'
|
||||
exit-code: '0'
|
||||
|
||||
# Step 9: Run Trivy security scan (SARIF)
|
||||
- name: 🔍 Run Trivy vulnerability scanner
|
||||
if: github.event_name != 'pull_request'
|
||||
id: trivy
|
||||
continue-on-error: true
|
||||
uses: aquasecurity/trivy-action@master
|
||||
with:
|
||||
image-ref: ${{ fromJSON(steps.meta.outputs.json).tags[0] }}
|
||||
format: 'sarif'
|
||||
output: 'trivy-results.sarif'
|
||||
exit-code: '0'
|
||||
severity: 'CRITICAL,HIGH'
|
||||
|
||||
# Step 10: Upload Trivy results to GitHub Security tab
|
||||
- name: 📤 Upload Trivy results to GitHub Security
|
||||
uses: github/codeql-action/upload-sarif@v3
|
||||
if: github.event_name != 'pull_request' && (steps.trivy.outcome == 'success' || steps.trivy.outcome == 'failure')
|
||||
with:
|
||||
sarif_file: 'trivy-results.sarif'
|
||||
|
||||
# Step 11: Fail if vulnerabilities found
|
||||
- name: ❌ Check for vulnerabilities
|
||||
if: github.event_name != 'pull_request' && steps.trivy_table.outcome == 'failure'
|
||||
run: |
|
||||
echo "::error::CRITICAL or HIGH vulnerabilities found in image"
|
||||
exit 1
|
||||
|
||||
# Step 11: Create a summary
|
||||
- name: 📋 Create summary
|
||||
|
||||
Reference in New Issue
Block a user