Skip to content

Commit 1099a3a

Browse files
authored
feat: add security scan workflow for Docker images (#68)
1 parent c4c2bcf commit 1099a3a

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: "Security: Docker Image Scan"
2+
3+
on:
4+
workflow_dispatch:
5+
workflow_run:
6+
workflows: ["Build: Docker Images"]
7+
types:
8+
- completed
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.event_name }}
12+
cancel-in-progress: true
13+
14+
permissions:
15+
contents: read
16+
security-events: write
17+
packages: read
18+
19+
jobs:
20+
scan:
21+
runs-on: ubuntu-latest
22+
name: Scan - Quarto ${{ matrix.QUARTO_VERSION }}
23+
if: ${{ github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' }}
24+
strategy:
25+
matrix:
26+
include:
27+
- QUARTO_VERSION: release
28+
IMAGE_TAG: release
29+
- QUARTO_VERSION: prerelease
30+
IMAGE_TAG: prerelease
31+
steps:
32+
- name: Checkout code
33+
uses: actions/checkout@v5
34+
35+
- name: Login to Docker registry
36+
uses: docker/login-action@v3
37+
with:
38+
registry: ghcr.io
39+
username: ${{ github.actor }}
40+
password: ${{ secrets.GITHUB_TOKEN }}
41+
42+
- name: Pull Docker image
43+
env:
44+
IMAGE_TAG: ${{ matrix.IMAGE_TAG }}
45+
run: |
46+
docker pull ghcr.io/${GITHUB_REPOSITORY}:${IMAGE_TAG}
47+
48+
- name: Run Trivy vulnerability scanner
49+
uses: aquasecurity/[email protected]
50+
with:
51+
image-ref: ghcr.io/${{ github.repository }}:${{ matrix.IMAGE_TAG }}
52+
format: sarif
53+
output: trivy-results-${{ matrix.QUARTO_VERSION }}.sarif
54+
severity: CRITICAL,HIGH,MEDIUM
55+
scanners: vuln,secret,config
56+
list-all-pkgs: true
57+
58+
- name: Upload Trivy results to GitHub Security tab
59+
uses: github/codeql-action/upload-sarif@v3
60+
if: always()
61+
with:
62+
sarif_file: trivy-results-${{ matrix.QUARTO_VERSION }}.sarif
63+
category: trivy-${{ matrix.QUARTO_VERSION }}
64+
65+
- name: Upload scan results as artifact
66+
uses: actions/upload-artifact@v5
67+
if: always()
68+
with:
69+
name: trivy-results-${{ matrix.QUARTO_VERSION }}
70+
path: trivy-results-${{ matrix.QUARTO_VERSION }}.sarif
71+
retention-days: 30
72+
73+
- name: Generate summary
74+
if: always()
75+
env:
76+
QUARTO_VERSION: ${{ matrix.QUARTO_VERSION }}
77+
IMAGE_TAG: ${{ matrix.IMAGE_TAG }}
78+
run: |
79+
(
80+
echo "## Security Scan Results: ${QUARTO_VERSION}"
81+
echo ""
82+
echo "**Image:** \`ghcr.io/${GITHUB_REPOSITORY}:${IMAGE_TAG}\`"
83+
echo ""
84+
echo "**Scan Date:** $(date -u '+%Y-%m-%d %H:%M:%S UTC')"
85+
echo ""
86+
echo "Results have been uploaded to the [Security tab](https://github.com/${GITHUB_REPOSITORY}/security/code-scanning)."
87+
) >>${GITHUB_STEP_SUMMARY}

0 commit comments

Comments
 (0)