@@ -17,53 +17,122 @@ concurrency:
1717 group : ${{ github.workflow }}-${{ github.event.pull_request.number || github.event.merge_group.head_sha || github.ref }}
1818 cancel-in-progress : true
1919
20+ env :
21+ # Grype is installed from a pinned release tarball verified against a
22+ # hardcoded SHA256 instead of through a third-party action or install
23+ # script, so a hijacked tag or release cannot change what runs here.
24+ # To upgrade: pick a release that has been out for at least a week or two,
25+ # verify the Sigstore signature on grype_<version>_checksums.txt, then copy
26+ # the linux_amd64.tar.gz checksum from that file.
27+ GRYPE_VERSION : " 0.120.1"
28+ GRYPE_SHA256 : " 0a9ee97ef5ae2ee953b0a80098105052e846cdbe319a57d808b519c33cd1343d"
29+ GRYPE_CHECK_FOR_APP_UPDATE : " false"
30+
2031jobs :
21- buildx :
32+ scan :
2233 permissions :
2334 contents : read
2435 actions : read # Required for upload-sarif to get workflow run info
2536 security-events : write # Required for uploading SARIF results
2637 pull-requests : write # Required for PR comments summarizing vulnerabilities
27- if : github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
2838 runs-on : ubuntu-latest
39+ env :
40+ # Fork PRs get a read-only token, so they are scanned but cannot upload
41+ # SARIF results or comment on the PR.
42+ CAN_WRITE : ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository }}
2943 steps :
44+ # The image is large and gets written to disk twice (archive + Grype's
45+ # unpacked layers), so reclaim space from preinstalled toolchains.
46+ - name : Free disk space
47+ run : |
48+ sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc /opt/hostedtoolcache/CodeQL
49+ df -h /
50+
3051 - name : Checkout
31- uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
52+ uses : actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
3253 with :
3354 persist-credentials : false
3455
3556 - name : Set up Docker Buildx
36- uses : docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd
57+ uses : docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069
3758
59+ # Export straight to a tarball rather than loading into the Docker
60+ # daemon, so the scanner reads the archive without another docker save.
3861 - name : Build image
39- uses : docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294
62+ uses : docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc
4063 with :
4164 context : .
4265 file : runscripts/container/Dockerfile
43- load : true
4466 tags : vecoli:latest
67+ outputs : type=docker,dest=${{ runner.temp }}/vecoli.tar
4568 cache-from : type=gha
4669 cache-to : type=gha,mode=max
4770
48- - name : Login to Docker Hub
49- uses : docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2
50- with :
51- username : ${{ vars.DOCKERHUB_USERNAME }}
52- password : ${{ secrets.DOCKERHUB_TOKEN }}
71+ - name : Install Grype
72+ run : |
73+ tarball="$RUNNER_TEMP/grype.tar.gz"
74+ curl -fsSL --proto '=https' --tlsv1.2 -o "$tarball" \
75+ "https://github.com/anchore/grype/releases/download/v${GRYPE_VERSION}/grype_${GRYPE_VERSION}_linux_amd64.tar.gz"
76+ echo "${GRYPE_SHA256} ${tarball}" | sha256sum --check --strict
77+ mkdir -p "$RUNNER_TEMP/grype-bin"
78+ tar -xzf "$tarball" -C "$RUNNER_TEMP/grype-bin" grype
79+ echo "$RUNNER_TEMP/grype-bin" >> "$GITHUB_PATH"
5380
54- - name : Analyze for critical and high CVEs
55- id : docker-scout-cves
56- uses : docker/scout-action@8910519cee8ac046f3ee99686b0dc6654d5ba1a7
57- with :
58- command : cves,recommendations
59- image : vecoli:latest
60- sarif-file : sarif.output.json
61- summary : true
62- only-severities : critical,high,medium
63- only-fixed : true
81+ - name : Scan image for vulnerabilities
82+ run : |
83+ grype "docker-archive:$RUNNER_TEMP/vecoli.tar" \
84+ --name vecoli:latest \
85+ --only-fixed \
86+ -o table \
87+ -o json=grype.json \
88+ -o sarif=grype-all.sarif
89+ rm -f "$RUNNER_TEMP/vecoli.tar"
90+ # Keep critical/high (error) and medium (warning); drop low/negligible (note)
91+ jq '.runs[].results |= map(select(.level != "note"))' grype-all.sarif > grype.sarif
92+
93+ - name : Write job summary
94+ env :
95+ RUN_URL : ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
96+ run : |
97+ jq -r '
98+ [.matches[] | select(.vulnerability.severity | IN("Critical","High","Medium"))]
99+ | sort_by({"Critical":0,"High":1,"Medium":2}[.vulnerability.severity], .artifact.name)
100+ | if length == 0 then "No fixable critical, high, or medium vulnerabilities found."
101+ else
102+ "| Severity | Vulnerability | Package | Installed | Fixed in |",
103+ "|---|---|---|---|---|",
104+ (.[] | "| \(.vulnerability.severity) | [\(.vulnerability.id)](\(.vulnerability.dataSource)) | \(.artifact.name) (\(.artifact.type)) | \(.artifact.version) | \(.vulnerability.fix.versions | join(", ")) |")
105+ end' grype.json > table.md
106+ {
107+ echo "## Grype vulnerability scan (fixable only)"
108+ echo
109+ # PR comments are capped at 65536 characters
110+ head -c 60000 table.md
111+ echo
112+ echo "[Full scan output]($RUN_URL)"
113+ } > summary.md
114+ cat summary.md >> "$GITHUB_STEP_SUMMARY"
115+
116+ - name : Comment on PR
117+ if : github.event_name == 'pull_request' && env.CAN_WRITE == 'true'
118+ env :
119+ GH_TOKEN : ${{ github.token }}
120+ PR_NUMBER : ${{ github.event.pull_request.number }}
121+ run : |
122+ marker='<!-- grype-image-scan -->'
123+ printf '%s\n' "$marker" | cat - summary.md > comment.md
124+ comment_id=$(gh api --paginate "repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/comments" \
125+ --jq ".[] | select(.user.login == \"github-actions[bot]\" and (.body | startswith(\"$marker\"))) | .id" | head -n 1)
126+ if [ -n "$comment_id" ]; then
127+ gh api -X PATCH "repos/$GITHUB_REPOSITORY/issues/comments/$comment_id" -F body=@comment.md > /dev/null
128+ else
129+ gh api -X POST "repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/comments" -F body=@comment.md > /dev/null
130+ fi
64131
132+ # Merge queue refs are ephemeral; master results come from push/schedule
65133 - name : Upload SARIF result
66- id : upload-sarif
67- uses : github/codeql-action/upload-sarif@7434149006143a4d75b82a2f411ef15b03ccc2d7
134+ if : github.event_name != 'merge_group' && env.CAN_WRITE == 'true'
135+ uses : github/codeql-action/upload-sarif@38697555549f1db7851b81482ff19f1fa5c4fedc
68136 with :
69- sarif_file : sarif.output.json
137+ sarif_file : grype.sarif
138+ category : grype-image-scan
0 commit comments