Skip to content

Commit c33289b

Browse files
donislawdevclaude
andauthored
security: hold the OSV scanner image to a recorded digest (#187)
* security: hold the OSV scanner image to a recorded digest The OSV actions are pinned by commit, but each runs the Docker image ghcr.io/google/osv-scanner-action by tag, and a tag can be pushed again. The runner pulls that image while setting the job up, before the first step, so a first step now compares it with .github/osv-scanner-digest and fails on another digest or on no image at all. The scan does not start. In the pull request workflow the check runs before the checkout of the base, so the digest read is the branch's own. A Dependabot update of the action goes red until its new digest is written, which dependabot.yml now says next to the other two things a reviewer needs to know. TestTheScannerImageIsCheckedBeforeItRuns holds the step in every job that runs the scanner, ahead of the scan and of any git checkout, and holds the digest file to one sha256 digest. The deprecated --output and --gh-annotations give way to --output-file and --output-files. table:#stdout is named, because the reporter stops printing the list of findings once the annotations go to a terminal stream. Measured on v2.6.0: the JSON, the SARIF, the annotations and the list come out byte for byte as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * review of #187: the check reads one whole digest, and a test runs it From the CodeRabbit review of #187, each remark checked against the code first. The script took every space out of the digest file before reading it, so a digest split in two was joined into one that passed, while the guard in Go refused the same file. It now matches the whole file at once: one digest, white space around it and none inside. Its message says what to write and where a run prints the value. Nothing ran the script, so one reduced to "exit 0" passed every test. TestTheScannerImageScriptRefusesEveryImageButTheRecordedOne runs it with a docker in front of the real one that answers from files, in ten cases - the recorded image, white space around it, another image behind the tag, two images with one of them another, no image, a digest split in two, two digests, a tag, no file, and a docker with no daemon - and asks each for its exit code and for the reason it prints. The stub's own image ids have to appear in the output, so the test knows it is not talking to the real docker. On Windows it wants Git's bash and says so when it finds another. The guard on the workflows fails rather than skips when their directory is gone, since the check would have gone with it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 0a3fe12 commit c33289b

6 files changed

Lines changed: 490 additions & 10 deletions

File tree

‎.github/dependabot.yml‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ version: 2
1515
# It does NOT delay security fixes. Cooldown applies to version updates, and
1616
# Dependabot security updates are a separate mechanism.
1717
#
18-
# Two things about this repository that a reviewer needs to know before merging
19-
# any of these, and neither is obvious from the diff:
18+
# Three things about this repository that a reviewer needs to know before
19+
# merging any of these, and none is obvious from the diff:
2020
#
2121
# 1. A dependency bump can change the bytes of a generated file, and this
2222
# project promises those bytes inside a major version (D11). The byte
@@ -33,6 +33,14 @@ version: 2
3333
# every one of them, and GPL-3.0 makes that a real question rather than
3434
# a formality.
3535
#
36+
# 3. An update of google/osv-scanner-action goes red too, in the job
37+
# "new vulnerabilities (OSV)", until the digest of its new Docker image
38+
# is written to .github/osv-scanner-digest in the same pull request. The
39+
# action is pinned by commit but runs an image named by a tag, so the
40+
# digest is what holds the image still (O281). Read what the release
41+
# changed, then take the digest from the "Pull down action image" lines
42+
# of that red run and check it against the release before writing it.
43+
#
3644
# None of these are merged on a green tick alone. Every one is read before it
3745
# is accepted: which files of the module changed between the two versions
3846
# (diff the two copies in the module cache, not the release notes), whether

‎.github/osv-scanner-digest‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sha256:71ad04ab2f8798be47870f9b18817ad317c2f8f2f97aa6726ba10d5578bc174a
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Is the scanner image on this runner the one this repository recorded.
4+
#
5+
# The OSV actions are pinned by commit, and each of them names its Docker image
6+
# by a tag, ghcr.io/google/osv-scanner-action:vX.Y.Z, which whoever owns it can
7+
# push again. Pinning the action does not stop that. The runner pulls the image
8+
# while it sets the job up, before the first step, so by the time this runs the
9+
# image is here and has not run yet. If its digest is not the one recorded in
10+
# the file, this fails, and the scan steps after it do not start. Measured on
11+
# the runner 2026-10-15, docs/OSV-2-2026-10-15.md.
12+
#
13+
# Fails rather than passes when there is no image of the scanner at all. That
14+
# would mean the runner stopped pulling it during set-up, and a check that found
15+
# nothing to check has not checked anything.
16+
#
17+
# A Dependabot update of google/osv-scanner-action brings a new image and stops
18+
# here until its digest is written to the file. That is on purpose: it is the
19+
# moment somebody reads what the new release changed.
20+
#
21+
# Usage: osv_scanner_image.sh [file with the digest]
22+
set -euo pipefail
23+
24+
file="${1:-.github/osv-scanner-digest}"
25+
repository="ghcr.io/google/osv-scanner-action"
26+
27+
# One digest and nothing else, white space allowed around it and none inside
28+
# it - the shape TestTheScannerImageIsCheckedBeforeItRuns asks of the file.
29+
# Taking every space out first, as this once did, joined a digest split in two
30+
# into one that passed (review of #187).
31+
raw=$(cat -- "$file" 2>/dev/null || true)
32+
if [[ "$raw" =~ ^[[:space:]]*(sha256:[0-9a-f]{64})[[:space:]]*$ ]]; then
33+
expected="${BASH_REMATCH[1]}"
34+
else
35+
echo "::error::$file does not hold one sha256 digest, so there is nothing to compare the scanner image with. Write one line to it: sha256: and the 64 lowercase hexadecimal characters of the image the OSV actions run, which the Set up job section of a run prints after Digest."
36+
exit 1
37+
fi
38+
39+
ids=$(docker image ls --no-trunc --quiet "$repository")
40+
if [ -z "$ids" ]; then
41+
echo "::error::No image of $repository is on this runner. The runner used to pull it while setting the job up, before any step, and this check relies on that. Read the Set up job section of this run."
42+
exit 1
43+
fi
44+
45+
status=0
46+
for id in $(printf '%s\n' "$ids" | sort -u); do
47+
digests=$(docker image inspect --format '{{range .RepoDigests}}{{println .}}{{end}}' "$id")
48+
if printf '%s\n' "$digests" | grep -qxF "$repository@$expected"; then
49+
echo "osv_scanner_image: $id is $repository@$expected"
50+
continue
51+
fi
52+
echo "::error::The scanner image $id is not the one recorded in $file."
53+
echo "It was pulled as:"
54+
printf '%s\n' "$digests" | sed 's/^/ /'
55+
echo "If google/osv-scanner-action was just updated, read what its new release changed and write the new digest to $file."
56+
echo "If it was not, the image behind the tag has changed, and nothing should run it."
57+
status=1
58+
done
59+
exit "$status"

‎.github/workflows/osv-pull-request.yml‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ jobs:
4747
fetch-depth: 2
4848
persist-credentials: false
4949

50+
# The two OSV actions below are pinned by commit, but they run a Docker
51+
# image named by a tag, and a tag can be pushed again. The runner has
52+
# already pulled that image while setting this job up, so this compares
53+
# it with the digest in .github/osv-scanner-digest before anything runs
54+
# it (O281). Here, before the checkout of the branch this merges into,
55+
# so the digest read is the pull request's own: a Dependabot update that
56+
# writes the new one would otherwise be held to the old one for ever.
57+
- name: the scanner image is the one recorded
58+
run: bash .github/scripts/osv_scanner_image.sh
59+
5060
# Asserted rather than assumed, from the review of #181: with a commit
5161
# of one parent here, HEAD^1 would be the pull request's own previous
5262
# commit, and the comparison would find nothing new for the wrong reason.
@@ -77,7 +87,7 @@ jobs:
7787
with:
7888
scan-args: |-
7989
--format=json
80-
--output=osv-old.json
90+
--output-file=osv-old.json
8191
--no-call-analysis=go
8292
--recursive
8393
./
@@ -94,7 +104,7 @@ jobs:
94104
with:
95105
scan-args: |-
96106
--format=json
97-
--output=osv-new.json
107+
--output-file=osv-new.json
98108
--no-call-analysis=go
99109
--recursive
100110
./
@@ -120,12 +130,18 @@ jobs:
120130
# advisory and the version that fixes it. The annotations on the pull
121131
# request are not - measured 2026-10-14 with findings in two files, one
122132
# annotation came out, for one of them.
133+
#
134+
# table:#stdout is that list, and it has to be named. Once anything else
135+
# goes to a terminal stream - the annotations here - the reporter stops
136+
# printing the table on its own, measured 2026-10-15 on v2.6.0 (3100
137+
# bytes of log down to none). Named, the SARIF, the annotations and the
138+
# table come out byte for byte as they did under the deprecated
139+
# --output and --gh-annotations (docs/OSV-2-2026-10-15.md).
123140
- name: what this pull request adds
124141
uses: google/osv-scanner-action/osv-reporter-action@a345acffa64b0eaede81a3d9aae6141214d9c8fc # v2.6.0
125142
with:
126143
scan-args: |-
127144
--old=osv-old.json
128145
--new=osv-new.json
129-
--output=osv-new.sarif
130-
--gh-annotations=true
146+
--output-files=sarif:osv-new.sarif,gh-annotations:#stderr,table:#stdout
131147
--fail-on-vuln=true

‎.github/workflows/osv-weekly.yml‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,22 @@ jobs:
5757
with:
5858
persist-credentials: false
5959

60+
# The image the OSV actions run, against the digest recorded in
61+
# .github/osv-scanner-digest, before anything runs it. The reasons are
62+
# written beside the same step in osv-pull-request.yml (O281). When it
63+
# fails, nothing is scanned and no SARIF is written, so the upload below
64+
# finds no file and the alerts of the week before stay as they were.
65+
- name: the scanner image is the one recorded
66+
run: bash .github/scripts/osv_scanner_image.sh
67+
6068
- name: scan
6169
id: scan
6270
uses: google/osv-scanner-action/osv-scanner-action@a345acffa64b0eaede81a3d9aae6141214d9c8fc # v2.6.0
6371
continue-on-error: true
6472
with:
6573
scan-args: |-
6674
--format=json
67-
--output=osv-results.json
75+
--output-file=osv-results.json
6876
--no-call-analysis=go
6977
--recursive
7078
./
@@ -81,14 +89,15 @@ jobs:
8189
8290
# Writes the results for the Security tab and fails the job when there
8391
# is any, which is after the file is written - the upload below runs
84-
# either way.
92+
# either way. table:#stdout keeps the list in the log of this step, the
93+
# way the deprecated --output printed it, measured byte for byte
94+
# 2026-10-15 (docs/OSV-2-2026-10-15.md).
8595
- name: results for the Security tab
8696
uses: google/osv-scanner-action/osv-reporter-action@a345acffa64b0eaede81a3d9aae6141214d9c8fc # v2.6.0
8797
with:
8898
scan-args: |-
8999
--new=osv-results.json
90-
--output=osv-results.sarif
91-
--gh-annotations=false
100+
--output-files=sarif:osv-results.sarif,table:#stdout
92101
--fail-on-vuln=true
93102
94103
- name: upload to the Security tab

0 commit comments

Comments
 (0)