-
Notifications
You must be signed in to change notification settings - Fork 9
fix(ci): scan the image by digest and platform, not by tag #1205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -207,6 +207,9 @@ jobs: | |||||||||||||||||
| artifact-metadata: write | ||||||||||||||||||
| env: | ||||||||||||||||||
| RESULTS_FILE: smoke-test-results.json | ||||||||||||||||||
| # Syft scans one platform. The image is multi-platform, so the SBOM covers | ||||||||||||||||||
| # this one only, and the attestation records which. | ||||||||||||||||||
| SBOM_PLATFORM: linux/amd64 | ||||||||||||||||||
|
|
||||||||||||||||||
| steps: | ||||||||||||||||||
| - name: Harden Runner | ||||||||||||||||||
|
|
@@ -289,13 +292,37 @@ jobs: | |||||||||||||||||
| subject-digest: ${{ steps.docker_build.outputs.digest }} | ||||||||||||||||||
| push-to-registry: true | ||||||||||||||||||
|
|
||||||||||||||||||
| - name: Install syft | ||||||||||||||||||
| uses: anchore/sbom-action/download-syft@v0 | ||||||||||||||||||
|
|
||||||||||||||||||
| - name: Generate SBOM for the docker image | ||||||||||||||||||
| uses: anchore/sbom-action@v0 | ||||||||||||||||||
| with: | ||||||||||||||||||
| image: ${{ env.IMAGE }}:${{ inputs.tag }} | ||||||||||||||||||
| format: 'spdx-json' | ||||||||||||||||||
| output-file: 'sbom.spdx.json' | ||||||||||||||||||
| upload-artifact: false | ||||||||||||||||||
| env: | ||||||||||||||||||
| IMAGE: ${{ env.IMAGE }} | ||||||||||||||||||
| DIGEST: ${{ steps.docker_build.outputs.digest }} | ||||||||||||||||||
| run: | | ||||||||||||||||||
| syft -q -o spdx-json --platform "${SBOM_PLATFORM}" \ | ||||||||||||||||||
| "registry:${IMAGE}@${DIGEST}" > sbom.spdx.json | ||||||||||||||||||
|
Comment on lines
+302
to
+304
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing The default shell here is expected=$(docker buildx imagetools inspect "${IMAGE}@${DIGEST}" --raw | jq -r ...)If
which is a wrong diagnosis of a network problem, on a release pipeline, where someone will go looking at the manifest rather than at the retry. It fails closed, so nothing gets attested wrongly — it's the diagnosis that's wrong, and this step exists precisely so failures are legible.
Suggested change
|
||||||||||||||||||
|
|
||||||||||||||||||
| # Syft names the platform image it scanned, never the index ${DIGEST} | ||||||||||||||||||
| # points at, so the subject has to be that platform's entry in it. | ||||||||||||||||||
| expected=$(docker buildx imagetools inspect "${IMAGE}@${DIGEST}" --raw \ | ||||||||||||||||||
| | jq -r --arg p "${SBOM_PLATFORM}" ' | ||||||||||||||||||
| .manifests[]? | ||||||||||||||||||
| | select((.platform.os + "/" + .platform.architecture) == $p) | ||||||||||||||||||
| | .digest') | ||||||||||||||||||
|
Comment on lines
+308
to
+312
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The platform match drops
Fail-closed, so no wrong SBOM escapes; it's the same misdirection as above. A comment pinning the assumption next to select(([.platform.os, .platform.architecture, .platform.variant]
| map(select(. != null)) | join("/")) == $p
or (.platform.os + "/" + .platform.architecture) == $p)Also worth noting |
||||||||||||||||||
| subject=$(jq -r ' | ||||||||||||||||||
| (.relationships[] | select(.relationshipType == "DESCRIBES") | .relatedSpdxElement) as $root | ||||||||||||||||||
| | .packages[] | select(.SPDXID == $root) | ||||||||||||||||||
| | .checksums[]? | select(.algorithm == "SHA256") | .checksumValue | ||||||||||||||||||
| ' sbom.spdx.json) | ||||||||||||||||||
|
|
||||||||||||||||||
| if [ -z "${expected}" ]; then | ||||||||||||||||||
| echo "::error::${IMAGE}@${DIGEST} is not a multi-platform index listing ${SBOM_PLATFORM}"; exit 1 | ||||||||||||||||||
| fi | ||||||||||||||||||
|
Comment on lines
+313
to
+321
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit, ordering: the Two smaller things in the same block:
|
||||||||||||||||||
| if [ "sha256:${subject}" != "${expected}" ]; then | ||||||||||||||||||
| echo "::error::sbom.spdx.json describes sha256:${subject}, not the ${SBOM_PLATFORM} image ${expected}" | ||||||||||||||||||
| exit 1 | ||||||||||||||||||
| fi | ||||||||||||||||||
|
|
||||||||||||||||||
| - name: Attest SBOM to Github | ||||||||||||||||||
| uses: actions/attest@v4.2.2 | ||||||||||||||||||
|
|
@@ -333,6 +360,7 @@ jobs: | |||||||||||||||||
| --name container-sbom | ||||||||||||||||||
| --fingerprint ${{ env.FINGERPRINT }} | ||||||||||||||||||
| --sbom-file sbom.spdx.json | ||||||||||||||||||
| --annotate sbom_platform=${{ env.SBOM_PLATFORM }} | ||||||||||||||||||
| --org ${{ inputs.kosli_org }} | ||||||||||||||||||
|
|
||||||||||||||||||
| - name: Run Snyk Container Test to scan the Docker image for vulnerabilities | ||||||||||||||||||
|
|
||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SBOM_PLATFORMis a constant, butplatformsis a required caller input.Both callers pass
linux/amd64,linux/arm64today (main.yml:118,release.yml:121), so this is correct as merged. But the two values are now coupled with nothing tying them together: a caller that buildslinux/arm64only gets a hard failure at line 319 reading "is not a multi-platform index listing linux/amd64" — true, but it points at the registry rather than at the input that actually disagrees.Since
preparealready parsesinputs.platformsinto a matrix, the cheapest fix is to emit the first entry as a job output and read it here, which also makes the "SBOM covers one of N" caveat self-maintaining asRUNNER_MAPgrows. Failing that, a one-line assertion inpreparethat the list containslinux/amd64would name the real cause.