Skip to content

Commit c5f5a5c

Browse files
committed
Try using snyk container test instead of older approach
1 parent b82ab31 commit c5f5a5c

1 file changed

Lines changed: 17 additions & 20 deletions

File tree

.github/workflows/cicd-pipeline.yml

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -286,30 +286,27 @@ jobs:
286286
provenance: false
287287
tags: ${{ steps.meta.outputs.tags }}
288288
labels: ${{ steps.meta.outputs.labels }}
289-
- name: Remove Python manifests before Snyk container scan
290-
# snyk/actions/docker runs the Snyk CLI inside the snyk/snyk:docker image
291-
# with the repo mounted as the working directory. If a pyproject.toml is
292-
# present there, Snyk tries to resolve it as a Poetry project and shells
293-
# out to `python`, which does not exist in that image ("spawn python ENOENT").
294-
# The image is already built and pushed at this point, so these files are
295-
# no longer needed in the workspace. Removing them makes Snyk scan only the
296-
# container image. (Python dependencies are already scanned by the Snyk
297-
# steps in the build job.)
298-
run: rm -f pyproject.toml poetry.lock
289+
- name: Set up Snyk CLI
290+
uses: snyk/actions/setup@master
299291
- name: Run Snyk on Docker Image
300-
# Snyk can be used to break the build when it detects vulnerabilities.
301-
# In this case we want to upload the issues to GitHub Code Scanning.
302-
# --file=docker/Dockerfile is required for the action to emit snyk.sarif
303-
# (and enables base-image upgrade recommendations).
292+
# Use the modern `snyk container test` subcommand directly instead of the
293+
# snyk/actions/docker action. That action runs legacy `snyk test --docker`,
294+
# which (a) executes inside a container with no `python`, tripping over the
295+
# repo's pyproject.toml, and (b) mishandles `--file`, treating the Dockerfile
296+
# as an open-source manifest ("Could not detect package manager").
297+
# `snyk container test` targets only the image, reads the Dockerfile via
298+
# --file for base-image upgrade advice, and reliably writes SARIF for upload
299+
# to GitHub Code Scanning. continue-on-error keeps a vulnerable image (or a
300+
# scan error) from failing the build.
304301
continue-on-error: true
305-
uses: snyk/actions/docker@master
306302
env:
307303
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
308-
with:
309-
image: ${{ fromJSON(steps.meta.outputs.json).tags[0] }}
310-
args: >
311-
--severity-threshold=high
312-
--file=docker/Dockerfile
304+
IMAGE_URI: ${{ fromJSON(steps.meta.outputs.json).tags[0] }}
305+
run: |
306+
snyk container test "$IMAGE_URI" \
307+
--file=docker/Dockerfile \
308+
--severity-threshold=high \
309+
--sarif-file-output=snyk.sarif
313310
- name: Upload Snyk result to GitHub Code Scanning
314311
# Always attempt to upload, even if the Snyk scan found vulnerabilities and
315312
# exited non-zero. Guarded on the SARIF file existing so that a scan which

0 commit comments

Comments
 (0)