UNPKG

11.9 kBMarkdownView Raw
1<p align="center">
2 <img src="https://snyk.io/style/asset/logo/snyk-print.svg" />
3</p>
4
5<p align="center">
6 <a href="https://snyk.io/docs/?utm_campaign=docs&utm_medium=github&utm_source=full_docs">Documentation</a> |
7 <a href="https://snyk.io/test/">Test your project</a>
8</p>
9
10<p align="center">
11 Snyk helps you find, fix and monitor known vulnerabilities in open source
12</p>
13
14<p align="center">
15 <a href="https://snyk.io/test/github/snyk/snyk"><img src="https://snyk.io/test/github/snyk/snyk/badge.svg" alt="Known Vulnerabilities"/></a>
16 <a href="https://snyk.io/features/"><img src="https://badgen.net/npm/dm/snyk" alt="Monthly Downloads"/></a>
17</p>
18
19---
20
21## What is Snyk?
22
23<p align="center">
24 <a href="https://youtu.be/4ng5usM6fd8">
25 <img alt="What is Snyk?" src="https://i3.ytimg.com/vi/4ng5usM6fd8/maxresdefault.jpg" width="75%" height="75%" />
26 </a>
27</p>
28
29## Table Of Contents:
30
31- [Installation](#installation)
32- [CLI](#cli)
33- [Features](#features)
34- [Docker](#docker)
35- [Badge](#badge)
36
37## Installation
38
391. Install the Snyk utility using `npm install -g snyk`.
402. Once installed you will need to authenticate with your Snyk account: `snyk auth`
41
42For more detail on how to authenticate take a look at the [CLI authentication](https://snyk.io/docs/using-snyk#authentication?utm_campaign=docs&utm_medium=github&utm_source=CLI_authentication) section of the Snyk documentation.
43
44## CLI
45
46```console
47snyk [options] [command] [package]
48```
49
50Run `snyk --help` to get a quick overview of all commands or for full details on the CLI read the snyk.io [CLI docs](https://snyk.io/docs/using-snyk?utm_campaign=docs&utm_medium=github&utm_source=cli).
51
52The package argument is optional. If no package is given, Snyk will run the command against the current working directory allowing you test you non-public applications.
53
54## Features
55
56- **Find** known vulnerabilities by running `snyk test` on a project either as a one off or as part of your CI process.
57- **Fix** vulnerabilities using `snyk wizard` and `snyk protect`.
58 - `snyk wizard` walks you through finding and fixing known vulnerabilities in your project. Remediation options include configuring your policy file to update, auto patch and ignore vulnerabilities. (npm only)
59 - `snyk protect` your code from vulnerabilities by applying patches and optionally suppressing specific vulnerabilities.
60- **Alert** `snyk monitor` records the state of dependencies and any vulnerabilities on snyk.io so you can be alerted when new vulnerabilities or updates/patches are disclosed that affect your repositories.
61- **Prevent** new vulnerable dependencies from being added to your project by running `snyk test` as part of your CI to fail tests when vulnerable Node.js or Ruby dependencies are added.
62
63## Snyk CLI Docker images
64
65[See all snyk/snyk-cli images](https://hub.docker.com/r/snyk/snyk-cli)
66
67Snyk is also provided as a set of Docker images that carry the runtime environment of each package manager. For example, the npm image will carry all of the needed setup to run `npm install` on the currently running container. Currently there are images for npm, Ruby, Maven, Gradle and SBT.
68
69The images can perform `snyk test` by default on the specified project which is mounted to the container as a read/write volume, and `snyk monitor` if the `MONITOR` environment variable is set when running the docker container. If you want an HTML report for `test` command (`--json` is appended automatically). An HTML file called `snyk_report.html` and a CSS file called `snyk_report.css` will be generated. The image also writes a file called `snyk-res.json` for internal use and `snyk-error.log` for errors that we can look at if something goes wrong.
70
71The following environment variables can be used when running the container on docker:
72
73- `SNYK_TOKEN` - Snyk API token, obtained from [https://app.snyk.io/account](https://app.snyk.io/account).
74- `USER_ID` - [OPTIONAL] Current user ID on the host machine. If not provided will take the user ID of the currently running user inside the container. This is used for CI builds such as Jenkins where we are running with a non-privileged user and want to allow the user to access the mounted project folder.
75- `MONITOR` - [OPTIONAL] If set, will generate an html report via `snyk-to-html` and runs `snyk monitor` after running `snyk test`.
76- `PROJECT_FOLDER` - [OPTIONAL] If set, this will cd to the directory inside the mounted project dir to run snyk inside it.
77- `ENV_FLAGS` - [OPTIONAL] additional environment parameters to pass to `snyk test` when running the container.
78- `TARGET_FILE` - [OPTIONAL] additional environment parameters to pass to `snyk test` & `snyk monitor` equal to `--file` option in the cli.
79
80Docker images are tagged according to the package manager runtime they include, the package manager version and snyk version.
81The general format of tags is [snyk-version]-[package-manager]-[package-manager-version] or just [package-manager]-[package-manager-version] if we want to use the latest version of snyk. Please see available tags to see the available options.
82
83[snyk-version] - The version of snyk that is installed in the image, if version is omitted it will use the latest version.
84[package-manager] - One of the available package managers (e.g: npm, mvn, gradle, etc...).
85[package-manager-version] - The version of the package manager that is installed inside the image.
86
87Please see the following examples on how to run Snyk inside docker:
88
89### Node.js (npm)
90
91[See all snyk/snyk-cli npm images](https://hub.docker.com/r/snyk/snyk-cli/tags?page=1&name=npm)
92
93The host project folder will be mounted to `/project` on the container and will be used to read the dependencies file and write results for CI builds.
94
95Here's an example of running `snyk test` and `snyk monitor` in the image (with the latest version of Snyk) for npm:
96
97```
98docker run -it
99 -e "SNYK_TOKEN=<TOKEN>"
100 -e "USER_ID=1234"
101 -e "MONITOR=true"
102 -v "<PROJECT_DIRECTORY>:/project"
103 snyk/snyk-cli:npm test --org=my-org-name
104```
105
106### RubyGems
107
108[See all snyk/snyk-cli rubygems images](https://hub.docker.com/r/snyk/snyk-cli/tags?page=1&name=rubygems)
109
110The host project folder will be mounted to `/project` on the container and will be used to read the dependencies file and write results for CI builds.
111
112Here's an example of running `snyk test` and `snyk monitor` in the image (with the latest version of Snyk) for RubyGems:
113
114```
115docker run -it
116 -e "SNYK_TOKEN=<TOKEN>"
117 -e "USER_ID=1234"
118 -e "MONITOR=true"
119 -v "<PROJECT_DIRECTORY>:/project"
120 snyk/snyk-cli:rubygems test --org=my-org-name
121```
122
123### Maven 3.5.4
124
125[See all snyk/snyk-cli maven images](https://hub.docker.com/r/snyk/snyk-cli/tags?page=1&name=maven)
126
127The host project folder will be mounted to `/project` on the container and will be used to read the dependencies file and write results for CI builds.
128You may also need to mount the local `.m2` and `.ivy2` folders.
129
130Here's an example of running `snyk test` and `snyk monitor` in the image (with the latest version of Snyk) for Maven:
131
132```
133docker run -it
134 -e "SNYK_TOKEN=<TOKEN>"
135 -e "USER_ID=1234"
136 -e "MONITOR=true"
137 -v "<PROJECT_DIRECTORY>:/project"
138 -v "/home/user/.m2:/home/node/.m2"
139 -v "/home/user/.ivy2:/home/node/.ivy2"
140 snyk/snyk-cli:maven-3.5.4 test --org=my-org-name
141```
142
143### SBT 0.13.16 / SBT 1.0.4
144
145[See all snyk/snyk-cli sbt images](https://hub.docker.com/r/snyk/snyk-cli/tags?page=1&name=sbt)
146
147The host project folder will be mounted to `/project` on the container and will be used to read the dependencies file and write results for CI builds.
148You may also need to mount the local `.m2` and `.ivy2` folders.
149
150Here are examples of running `snyk test` and `snyk monitor` in the image (with the latest version of Snyk) for SBT:
151
152*Note*: the `dependency-tree` or `sbt-dependency-graph` or `sbt-coursier` (included by default in latest sbt versions) module is required for `snyk` to process Scala projects.
153```
154docker run -it
155 -e "SNYK_TOKEN=<TOKEN>"
156 -e "USER_ID=1234"
157 -e "MONITOR=true"
158 -v "<PROJECT_DIRECTORY>:/project"
159 -v "/home/user/.m2:/home/node/.m2"
160 -v "/home/user/.ivy2:/home/node/.ivy2"
161 snyk/snyk-cli:sbt-0.13.16 test --org=my-org-name
162```
163
164```
165docker run -it
166 -e "SNYK_TOKEN=<TOKEN>"
167 -e "USER_ID=1234"
168 -e "MONITOR=true"
169 -v "<PROJECT_DIRECTORY>:/project"
170 -v "/home/user/.m2:/home/node/.m2"
171 -v "/home/user/.ivy2:/home/node/.ivy2"
172 snyk/snyk-cli:sbt-1.0.4 test --org=my-org-name
173```
174
175### Gradle 2.8 / Gradle 4.4 / Gradle 5.4
176
177[See all snyk/snyk-cli gradle images](https://hub.docker.com/r/snyk/snyk-cli/tags?page=1&name=gradle)
178
179The host project folder will be mounted to `/project` on the container and will be used to read the dependencies file and write results for CI builds.
180You may also need to mount the local `.gradle`.
181
182Here's an example of running `snyk test` and `snyk monitor` in the image (with the latest version of Snyk) for Gradle:
183
184```
185docker run -it
186 -e "SNYK_TOKEN=<TOKEN>"
187 -e "USER_ID=1234"
188 -e "MONITOR=true"
189 -v "<PROJECT_DIRECTORY>:/project"
190 -v "/home/user/.gradle:/home/node/.gradle"
191 snyk/snyk-cli:gradle-2.8 test --org=my-org-name
192```
193
194```
195docker run -it
196 -e "SNYK_TOKEN=<TOKEN>"
197 -e "USER_ID=1234"
198 -e "MONITOR=true"
199 -v "<PROJECT_DIRECTORY>:/project"
200 -v "/home/user/.gradle:/home/node/.gradle"
201 snyk/snyk-cli:gradle-4.4 test --org=my-org-name
202```
203
204```
205docker run -it
206 -e "SNYK_TOKEN=<TOKEN>"
207 -e "USER_ID=1234"
208 -e "MONITOR=true"
209 -v "<PROJECT_DIRECTORY>:/project"
210 -v "/home/user/.gradle:/home/node/.gradle"
211 snyk/snyk-cli:gradle-5.4 test --org=my-org-name
212```
213
214### Docker
215
216[See all snyk/snyk-cli docker images](https://hub.docker.com/r/snyk/snyk-cli/tags?page=1&name=docker)
217
218The host project folder will be mounted to `/project` on the container and will be used to read the dependencies file and write results for CI builds.
219
220The image being tested is expected to be available locally.
221
222Here's an example of running `snyk test` and `snyk monitor` in the image (with the latest version of Snyk) for Docker:
223
224```
225docker run -it
226 -e "SNYK_TOKEN=<TOKEN>"
227 -e "USER_ID=1234"
228 -e "MONITOR=true"
229 -v "<PROJECT_DIRECTORY>:/project"
230 -v "/var/run/docker.sock:/var/run/docker.sock"
231 snyk/snyk-cli:docker test --docker myapp:mytag --file=<DOCKERFILE>
232```
233
234### Python 2 / Python 3
235
236[See all snyk/snyk-cli python images](https://hub.docker.com/r/snyk/snyk-cli/tags?page=1&name=python)
237
238The host project folder will be mounted to `/project` on the container and will be used to read the dependencies file and write results for CI builds.
239
240Here's an example of running `snyk test` and `snyk monitor` in the image (with the latest version of Snyk) for Maven:
241
242- *setup.py*
243```
244docker run -it
245 -e "SNYK_TOKEN=<TOKEN>"
246 -e "USER_ID=1234"
247 -e "MONITOR=true"
248 -e "TARGET_FILE=setup.py"
249 -v "<PROJECT_DIRECTORY>:/project"
250 snyk/snyk-cli:python-3 test --org=my-org-name
251```
252
253- *Pipfile*
254```
255docker run -it
256 -e "SNYK_TOKEN=<TOKEN>"
257 -e "USER_ID=1234"
258 -e "MONITOR=true"
259 -e "TARGET_FILE=Pipfile"
260 -v "<PROJECT_DIRECTORY>:/project"
261 snyk/snyk-cli:python-3 test --org=my-org-name
262```
263
264- *requirements.txt*
265
266```
267docker run -it
268 -e "SNYK_TOKEN=<TOKEN>"
269 -e "USER_ID=1234"
270 -e "MONITOR=true"
271 -e "TARGET_FILE=requirement-dev.txt"
272 -v "<PROJECT_DIRECTORY>:/project"
273 snyk/snyk-cli:python-3 test --org=my-org-name
274```
275
276## Badge
277
278Make users feel more confident in using your website by adding your Snyk badge!
279
280<a href="https://snyk.io/test/github/snyk/snyk"><img src="https://snyk.io/test/github/snyk/snyk/badge.svg" alt="Known Vulnerabilities"/></a>
281
282```
283[![Known Vulnerabilities](https://snyk.io/package/npm/snyk/badge.svg)](https://snyk.io/package/npm/snyk)
284```
285
286[![Analytics](https://ga-beacon.appspot.com/UA-69111857-2/Snyk/snyk?pixel)](https://snyk.io/)