Code Monkey home page Code Monkey logo

snyk-images's Introduction

Getting started with the Snyk CLI

Introduction to Snyk and the Snyk CLI

Snyk is a developer-first, cloud-native security tool to scan and monitor your software development projects for security vulnerabilities. Snyk scans multiple content types for security issues:

  • Snyk Open Source: Find and automatically fix open-source vulnerabilities
  • Snyk Code: Find and fix vulnerabilities in your application code in real time
  • Snyk Container: Find and fix vulnerabilities in container images and Kubernetes applications
  • Snyk Infrastructure as Code: Find and fix insecure configurations in Terraform and Kubernetes code

Learn more about what Snyk can do and sign up for a free account.

The Snyk CLI brings the functionality of Snyk into your development workflow. You can run the CLI locally from the command line or in an IDE. You can also run the CLI in your CI/CD pipeline. The following shows an example of Snyk CLI test command output.

Snyk CLI test command output example

Snyk CLI test command output

Snyk CLI scanning supports many languages and tools. For detailed information, see the following:

This page explains how to install, authenticate, and start scanning using the CLI. Snyk also has an onboarding wizard to guide you through these steps. For a demonstration, view Starting with Snyk: an overview of the CLI onboarding flow.

Install the Snyk CLI and authenticate your machine

To use the CLI, you must install it and authenticate your machine. See Install or update the Snyk CLI and Authenticate the CLI with your account. You can refer to the release notes for a summary of changes in each release. Before scanning your code, review the Code execution warning for Snyk CLI.

Note: Before you can use the CLI for Open Source scanning, you must install your package manager. The needed third-party tools, such as Gradle or Maven, must be in the PATH.

You can use the CLI in your IDE or CI/CD environment. For details, see Install as part of a Snyk integration.

Test your installation

After authenticating, you can test your installation. For a quick test, run snyk --help.

Alternatively, you can perform a quick test on a public npm package, for example snyk test ionic.

Look at the test command report in your terminal. The report shows the vulnerabilities Snyk found in the package. For each issue found, Snyk reports the severity of the issue, provides a link to a detailed description, reports the path through which the vulnerable module got into your system, and provides guidance on how to fix the problem.

Scan your development Project

Note: Before using the Snyk CLI to test your Open Source Project for vulnerabilities, with limited exceptions, you must build your Project. For details, see Open Source Projects that must be built before testing.

In addition, depending on the language of your open-source Project, you may need to set up your language environment before using the Snyk CLI. For details, refer to Supported languages, frameworks, and feature availability overview.

After you have installed the CLI and authenticated your machine, to scan an open-source Project, use cd /my/project/ to change the current directory toafolder containing a supported package manifest file, such as package.json, pom.xml, or composer.lock. Then run snyk test. All vulnerabilities identified are listed, including their path and fix guidance.

To scan your source code run snyk code test.

You can scan a Docker image by its tag running, for example: snyk container test ubuntu:18.04.

To scan a Kubernetes (K8s) file run the following:
snyk iac test /path/to/kubernetes_file.yaml

For details about using the Snyk CLI to scan each content type, see the following:

Monitor your Open Source or Container Project

Snyk can monitor your Open Source or Container integrated SCM Project periodically and alert you to new vulnerabilities. To set up your Project to be monitored, run snyk monitor or snyk container monitor.

This creates a snapshot of your current dependencies so Snyk can regularly scan your code. Snyk can then alert you about newly disclosed vulnerabilities as they are introduced or when a previously unavailable patch or upgrade path is created. The following code shows an example of the output of the snyk monitor command.

> snyk monitor
Monitoring /project (project-name)...

Explore this snapshot at
https://app.snyk.io/org/my-org/project/29361c2c-9005-4692
-8df4-88f1c040fa7c/history/e1c994b3-de5d-482b-9281-eab4236c851e

Notifications about newly disclosed issues related to these
dependencies will be emailed to you.

You can log in to your Snyk account and navigate to the Projects page to find the latest snapshot and scan results:

Snyk monitor snapshot and scan results

Snyk monitor snapshot and scan results

For more information, see Monitor your Projects at regular intervals.

Running out of tests

Snyk allows unlimited tests for public repositories. If you are on the Free plan, you have a limited number of tests per month. Paid plans have unlimited tests on private and public repositories. If you are on the Free plan and notice that your test count is quickly being used, even with public repositories, you can remedy this by telling Snyk the public url of the repository that is being scanned by the Snyk CLI. This ensures that Snyk does not count a public repository towards the test limits.

If you run out of tests on an open-source Project, follow these steps:

  • Run snyk monitor.
  • Open the Snyk UI and navigate to the settings of the Project.
  • Enter the URL of your open-source repository in Git remote URL.

Additional information about the Snyk CLI

Run snyk help or see the CLI commands and options summary.

See the course Introduction to the Snyk CLI for a quick video training session.

Snyk also provides a cheat sheet (blog post) and a video tutorial.

In particular, see the information about the following options that you may find useful:

  • --severity-threshold=low|medium|high|critical: Report only vulnerabilities of the specified level or higher.
  • --json: Print results in JSON format.
  • --all-projects: Auto-detect all Projects in the working directory.

For detailed information about the CLI, see the CLI docs.

Getting support for the Snyk CLI

Submit a ticket to Snyk support whenever you need help with the Snyk CLI or Snyk in general. Note that Snyk support does not actively monitor GitHub Issues on any Snyk development project.

Contributing to the Snyk CLI

The Snyk CLI project is open-source, but Snyk does not encourage outside contributors.

You may look into design decisions for the Snyk CLI.

The Snyk CLI repository is a monorepo that also covers other projects and tools, such as @snyk/protect, also available at npm package for snyk-protect command.

Security

For any security issues or concerns, see the SECURITY.md file in the GitHub repository.

snyk-images's People

Contributors

adrukh avatar asaf92 avatar avishagp avatar bastiandoetsch avatar bikochan avatar bmvermeer avatar brewinski avatar cat2608 avatar cb-sl avatar dragos-cojocari avatar dubonzi avatar garethr avatar grahamburgsma avatar harshsharma22 avatar j-luong avatar jackub avatar jdunsby avatar jpjuni0r avatar kjeld-p avatar liamg avatar maxjeffos avatar michelkaporin avatar muscar avatar ndclt avatar peterschafer avatar sebsnyk avatar swinton avatar team-hammerhead avatar thisislawatts avatar ysknmt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

snyk-images's Issues

Commands with spaces failing Snyk Action Workflow

We noticed in the last few hours our GitHub actions using https://github.com/snyk/actions/tree/master/gradle-jdk17 were failing and I believe it is related to this recent change: #35

Screen Shot 2022-09-16 at 1 07 13 PM

To confirm this, I tested it locally running the docker image and was able to produce the same issue:

docker run --rm -it --env SNYK_TOKEN -v $(PWD):/app snyk/snyk:gradle-jdk17 "snyk" "code test" "--sarif-file-output=snyk.sarif --org=advanced-qem"
The following option combination is not currently supported: code test + sarif-file-output

Contrast that with

docker run --rm -it --env SNYK_TOKEN -v $(PWD):/app snyk/snyk:gradle-jdk17 "snyk" "code" "test" "--sarif-file-output=snyk.sarif --org=advanced-qem"

Testing /app ...


✔ Test completed

Organization:      advanced-qem
Test type:         Static code analysis
Project path:      /app

Summary:

✔ Awesome! No issues were found.

From what I can tell, the docker command is recognizing it as an entire command coming from the Snyk Action workflow.

with:
  command: code test
  args: "--sarif-file-output=snyk.sarif --org=advanced-qem"

Git does not run as it's blocked by `safe.directory`, causing `go list` to fail

Starting from a recent version of Snyk image, it upgraded to Git
2.30.2-1+deb11u1, which backported the safe.directory option [1].

# image built 2 days ago
$ docker run --rm --entrypoint bash -i b44a997189b5 -c 'dpkg -l | grep -w git; git help --config | grep safe.directory'
ii  git                        1:2.30.2-1+deb11u1             amd64        fast, scalable, distributed revision control system
ii  git-man                    1:2.30.2-1+deb11u1             all          fast, scalable, distributed revision control system (manual pages)
safe.directory

# image built 9 days ago
$ docker run --rm --entrypoint bash -i 5f988dd42068 -c 'dpkg -l | grep -w git; git help --config | grep safe.directory'
ii  git                        1:2.30.2-1                     amd64        fast, scalable, distributed revision control system
ii  git-man                    1:2.30.2-1                     all          fast, scalable, distributed revision control system (manual pages)

Now since I guess inside Docker we run everything as root, however the
mounted Git repository is owned by user/group runner (uid 1000, gid
1000 IIRC), Git now refuses to do anything in the repository.

And in Go projects, apparently snyk calls go list to check the dependencies,
which calls Git internally, it now complains

'go list -json -deps ./...' command failed with error: error obtaining VCS status: exit status 128
    Use -buildvcs=false to disable VCS stamping.

Two workarounds right now. One, add a GOFLAGS: "-buildvcs=false" environment
variable; two, run this before Synk:

- name: Set work directory as Git safe directory in Docker
  run: |
    git config --global safe.directory '*'
    mkdir -p /home/runner/runner/agent/_work/_temp/_github_home
    cp "$HOME/.gitconfig" "/home/runner/runner/agent/_work/_temp/_github_home/.gitconfig"

But I think in the long run we should either add the safe.directory
automatically (but don't use *), or run synk with the same uid/gid of the
owner/group of the repository.

[1] https://release.debian.org/proposed-updates/bullseye_diffs/git_2.30.2-1+deb11u1.debdiff

Commands with the Bash logical (&&) operator does not work

Hi, I wanted to execute snyk test and snyk monitor in one container call. But only snyk test is executed and then the container exits. The output is as follows:

$ docker run --rm -it --env SNYK_TOKEN -v $PWD:/app snyk/snyk:golang 'snyk test && snyk monitor'

Testing /app...

Organization:      <>
Package manager:   gomodules
Target file:       go.mod
Project name:      app
Open source:       no
Project path:      /app
Licenses:          enabled

✔ Tested /app for known issues, no vulnerable paths found.

Next steps:
- Run `snyk monitor` to be notified about new related vulnerabilities.
- Run `snyk test` as part of your CI/test.

I have set the x flag in /user/local/bin/docker-entrypoint.sh (set -x) and the output is as follows:

$ docker run --rm -it --env SNYK_TOKEN -v $PWD:/app local/snyk:golang 'snyk test && snyk monitor'
+ [ -z  ]
+ command -v pip
+ [ -x  ]
+ command -v mvn
+ [ -x  ]
+ command -v go
+ [ -x /usr/local/go/bin/go ]
+ [ -f Gopkg.toml ]
+ exit_code=0
+ [ 0 -ne 0 ]
+ [ -z  ]
+ [  = test -a  = true ]
+ [  = test -a  = true ]
+ cmd_string=snyk test && snyk monitor
+ eval exec snyk test && snyk monitor
+ exec snyk test

Testing /app...

Organization:      <>
Package manager:   gomodules
Target file:       go.mod
Project name:      app
Open source:       no
Project path:      /app
Licenses:          enabled

✔ Tested /app for known issues, no vulnerable paths found.

Next steps:
- Run `snyk monitor` to be notified about new related vulnerabilities.
- Run `snyk test` as part of your CI/test.

Here you can see that only the first command is executed with exec and then the process is terminated. If your container offers the possibility to execute multiple commands by an Bash logical (&&) operator, then the following code changes could fulfill this:

- eval "exec ${cmd_string}"
+ eval "${cmd_string}"

The following output shows the execution:

$ docker run --rm -it --env SNYK_TOKEN -v $PWD:/app local/snyk:golang 'snyk test && snyk monitor'
+ [ -z  ]
+ command -v pip
+ [ -x  ]
+ command -v mvn
+ [ -x  ]
+ command -v go
+ [ -x /usr/local/go/bin/go ]
+ [ -f Gopkg.toml ]
+ exit_code=0
+ [ 0 -ne 0 ]
+ [ -z  ]
+ [  = test -a  = true ]
+ [  = test -a  = true ]
+ cmd_string=snyk test && snyk monitor
+ eval snyk test && snyk monitor
+ snyk test

Testing /app...

Organization:      <>
Package manager:   gomodules
Target file:       go.mod
Project name:      app
Open source:       no
Project path:      /app
Licenses:          enabled

✔ Tested /app for known issues, no vulnerable paths found.

Next steps:
- Run `snyk monitor` to be notified about new related vulnerabilities.
- Run `snyk test` as part of your CI/test.


+ snyk monitor

Monitoring /app (app)...

Explore this snapshot at https://app.snyk.io/org/<>/project/<>

Notifications about newly disclosed issues related to these dependencies will be emailed to you.

Another solution would be the GitHub entrypoint example dockerfile-support-for-github-actions

- cmd_string="$* $JSON_OUTPUT $SARIF_OUTPUT"
- eval "exec ${cmd_string}"
+ sh -c "$* $JSON_OUTPUT $SARIF_OUTPUT"

The following output shows the execution:

$ docker run --rm -it --env SNYK_TOKEN -v $PWD:/app local/snyk:golang 'snyk test && snyk monitor'
+ [ -z  ]
+ command -v pip
+ [ -x  ]
+ command -v mvn
+ [ -x  ]
+ command -v go
+ [ -x /usr/local/go/bin/go ]
+ [ -f Gopkg.toml ]
+ exit_code=0
+ [ 0 -ne 0 ]
+ [ -z  ]
+ [  = test -a  = true ]
+ [  = test -a  = true ]
+ sh -c snyk test && snyk monitor

Testing /app...

Organization:      <>
Package manager:   gomodules
Target file:       go.mod
Project name:      app
Open source:       no
Project path:      /app
Licenses:          enabled

✔ Tested /app for known issues, no vulnerable paths found.

Next steps:
- Run `snyk monitor` to be notified about new related vulnerabilities.
- Run `snyk test` as part of your CI/test.



Monitoring /app (app)...

Explore this snapshot at https://app.snyk.io/org/<>/project/<>/history<>

Notifications about newly disclosed issues related to these dependencies will be emailed to you.

Skip test phase for Maven

Snyk needs to mvn install before running the test.
Looking at the maven lifecycle install is the after test phase.
This mean all tests will be called during a mvn install.
If one of the tests fails the build breaks and snyk test will not be reached.

I don't believe running the test suite is part of the scope.
Maybe call mvn install -DskipTests or make it configurable?

GitLab image compatability

Maybe on oversight on my part and I've missed out something, I will upload my Ci/Cd file showing my usage of snyk later today.

It appears the GitLab runner can't run custom images properly, failing to run exec on the entry point, however eval works

image

https://gitlab.com/gitlab-org/gitlab-runner/-/issues/1253

I'm not in a position to run my own image on the pipeline at the moment so can't really test it, but I was wondering if I had made a configuration mistake, and if not is it possible to change exec -> eval here without repercussions to other platforms where this is already functional, like GitHub Actions, CircleCI, etc.

When will these images become official

Hello,

We are interested in using these images, but the description says they are experimental. Is there an ETA when they will stop being experimental?

Thank you

Images here vs. Images in snyk/snyk-cli

Hello,
A question, more than an issue:

What is the difference between the images here vs. those in snyk/snyk-cli? And which ones should we use to scan our dependencies?

Thanks!

docker-entrypoint.sh fails to be able to run commands that require a shell

docker-entrypoint.sh contains

if ! [ -z "${COMMAND}" ]; then
    eval ${COMMAND}
else
...

This means that unless you override the entrypoint to be /bin/sh you will have problems with using this docker container in CI if CI passes it complex scripts, e.g. shell check

if [ -x /usr/local/bin/bash ]; then
	exec /usr/local/bin/bash 
elif [ -x /usr/bin/bash ]; then
	exec /usr/bin/bash 
elif [ -x /bin/bash ]; then
	exec /bin/bash 
elif [ -x /usr/local/bin/sh ]; then
	exec /usr/local/bin/sh 
elif [ -x /usr/bin/sh ]; then
	exec /usr/bin/sh 
elif [ -x /bin/sh ]; then
	exec /bin/sh 
elif [ -x /busybox/sh ]; then
	exec /busybox/sh 
else
	echo shell not found
	exit 1
fi

or, more easy to test:

$ docker run -ti snyk/snyk:golang-1.18 'if [ -z "" ]; then echo asdf; fi'
/usr/local/bin/docker-entrypoint.sh: 1: eval: Syntax error: "then" unexpected

https://docs.gitlab.com/ee/ci/docker/using_docker_images.html recommends

For Docker 17.06 and later:

image:
  name: super/sql:experimental
  entrypoint: [""]

For Docker 17.03 and earlier:

image:
  name: super/sql:experimental
  entrypoint: ["/bin/sh", "-c"]

which is a working workaround.

however, IMO this should not be needed, in which case eval is not appropriate in the default entrypoint.

docker-entrypoint.sh fails shellcheck

It's recommended to lint shell scripts using shellcheck, there's a couple of potential commands in the docker-entrypoint.sh that may not be POSIX compliant

Snyk CLI handle Snyk API instability gracecfully

This has happened a few times that it feels warranted, but I'd like the snyk CLI to gracefully handle the inability for it to reach Snyk API. We're going to be minting our own docker image to wrap a handler on if it encounters a 5xx error, but would be great if the CLI did that so it's not massively disruptive when Snyk itself is having an issue (vs. finding something vulnerable).

golang: Pulling from docker.io/snyk/snyk
Digest: sha256:8c23008def1171ba2e2c22c4afa6d73e0e32699cf51b07befcd1c80150509c18
+ snyk test project --project-name="org/project" --org="<redacted>" --fail-on=upgradable
Internal error (reference: 29f94950-46f3-4f6c-a64b-66f64a22cfe9)

This could be done at the docker entrypoint (or in the CLI itself). Happy to close this and raise in the CLI repo, depending on how the team wants to dispense.

Add support of MONITOR environment var

Would be nice to add the MONITOR=true feature of the classic images in order to have the results + the monitor results in one call.

It would save the time of bootstraping the project.

Require Linux/ARM64 docker image for snyk/snyk-images

Hi Team,

I have been working on building snyk/snyk-images docker image for both amd64 and arm64 platforms.Successfully built the docker image having base image available for both the platforms. I have added buildx support to GitHub Actions build.yml workflow to release multi-arch images.

Changes Required: odidev@22ad16a

Do you have any plans for releasing ARM64 images?

It will be very helpful if an ARM64 image is available. If interested, I will raise a PR.

ARM 64 Support

Missing Arm64 support on docker images; Org migrating to Graviton/Arm based instances and missing support for it is a deal breaker for us to keep using Snyk. Anything that can be shared at the moment?

Saw #22 , #59 and #68 being all related.

Mac OS X support

Hey guys! Is there a way to create also linux/arm64v8 images? I'm currently using Mac and I cannot make it work or at least I haven't found the way to do it.

I only see AMD64 image in DockerHub.

Cheers.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.