2020-07-24 01:45:22 +00:00
# grype
2020-10-09 15:08:26 +00:00
[![Static Analysis + Unit + Integration ](https://github.com/anchore/grype/workflows/Static%20Analysis%20+%20Unit%20+%20Integration/badge.svg )](https://github.com/anchore/grype/actions?query=workflow%3A%22Static+Analysis+%2B+Unit+%2B+Integration%22)
[![Acceptance ](https://github.com/anchore/grype/workflows/Acceptance/badge.svg )](https://github.com/anchore/grype/actions?query=workflow%3AAcceptance)
2020-08-10 20:46:02 +00:00
[![Go Report Card ](https://goreportcard.com/badge/github.com/anchore/grype )](https://goreportcard.com/report/github.com/anchore/grype)
[![GitHub release ](https://img.shields.io/github/release/anchore/grype.svg )](https://github.com/anchore/grype/releases/latest)
2020-08-10 23:29:35 +00:00
[![License: Apache-2.0 ](https://img.shields.io/badge/License-Apache%202.0-blue.svg )](https://github.com/anchore/grype/blob/main/LICENSE)
2021-04-16 12:55:03 +00:00
[![GitHub go.mod Go version ](https://img.shields.io/github/go-mod/go-version/anchore/grype.svg )](https://github.com/anchore/grype)
2020-08-10 20:46:02 +00:00
2021-05-06 18:35:32 +00:00
A vulnerability scanner for container images and filesystems. [Easily install the binary ](#installation ) to try it out. Works with [Syft ](https://github.com/anchore/syft ), the powerful SBOM (software bill of materials) tool for container images and filesystems.
2020-08-03 15:09:49 +00:00
2020-08-14 19:03:29 +00:00
![grype-demo ](https://user-images.githubusercontent.com/590471/90276236-9868f300-de31-11ea-8068-4268b6b68529.gif )
2020-08-07 19:56:55 +00:00
**Features**
2020-08-24 16:27:07 +00:00
2020-08-07 19:56:55 +00:00
- Scan the contents of a container image or filesystem to find known vulnerabilities.
2020-08-24 16:27:07 +00:00
- Find vulnerabilities for major operating system packages
- Alpine
- BusyBox
- CentOS / Red Hat
- Debian
- Ubuntu
- Find vulnerabilities for language-specific packages
- Ruby (Bundler)
- Java (JARs, etc)
- JavaScript (NPM/Yarn)
- Python (Egg/Wheel)
- Python pip/requirements.txt/setup.py listings
2020-09-25 18:18:03 +00:00
- Supports Docker and OCI image formats
2020-08-03 15:09:49 +00:00
2020-10-08 19:32:56 +00:00
If you encounter an issue, please [let us know using the issue tracker ](https://github.com/anchore/grype/issues ).
2020-08-11 11:07:44 +00:00
2020-08-03 15:09:49 +00:00
## Getting started
2020-08-11 14:54:06 +00:00
[Install the binary ](#installation ), and make sure that `grype` is available in your path. To scan for vulnerabilities in an image:
2020-08-24 16:27:07 +00:00
2020-08-07 19:56:55 +00:00
```
grype < image >
```
2020-08-03 15:09:49 +00:00
2020-08-07 19:56:55 +00:00
The above command scans for vulnerabilities that are visible in the container (i.e., the squashed representation of the image).
To include software from all image layers in the vulnerability scan, regardless of its presence in the final image, provide `--scope all-layers` :
2020-08-03 15:09:49 +00:00
2020-08-07 19:56:55 +00:00
```
grype < image > --scope all-layers
```
Grype can scan a variety of sources beyond those found in Docker.
2020-08-24 16:27:07 +00:00
2020-08-07 19:56:55 +00:00
```
2020-09-25 18:18:03 +00:00
# scan a container image archive (from the result of `docker image save ...`, `podman save ...`, or `skopeo copy` commands)
grype path/to/image.tar
2020-08-07 19:56:55 +00:00
# scan a directory
2020-10-19 14:01:33 +00:00
grype dir:path/to/dir
2020-08-07 19:56:55 +00:00
```
2021-05-06 18:20:03 +00:00
Use [Syft ](https://github.com/anchore/syft ) SBOMs for even faster vulnerability scanning in Grype:
```
# Just need to generate the SBOM once
syft < image > -o json > ./image-sbom.json
# Then scan for new vulnerabilities as frequently as needed
grype sbom:./image-sbom.json
# (You can also pipe the SBOM into Grype)
cat ./image-sbom.json | grype
```
2021-04-13 20:13:48 +00:00
Sources can be explicitly provided with a scheme:
```
docker:yourrepo/yourimage:tag use images from the Docker daemon
docker-archive:path/to/yourimage.tar use a tarball from disk for archives created from "docker save"
oci-archive:path/to/yourimage.tar use a tarball from disk for OCI archives (from Skopeo or otherwise)
oci-dir:path/to/yourimage read directly from a path on disk for OCI layout directories (from Skopeo or otherwise)
dir:path/to/yourproject read directly from a path on disk (any directory)
registry:yourrepo/yourimage:tag pull image directly from a registry (no container runtime required)
```
2020-09-25 18:18:03 +00:00
The output format for Grype is configurable as well:
2020-08-07 19:56:55 +00:00
```
2020-09-25 18:18:03 +00:00
grype < image > -o < format >
2020-08-07 19:56:55 +00:00
```
2020-09-25 18:18:03 +00:00
Where the `format` s available are:
- `table` : A columnar summary (default).
2021-03-30 17:15:57 +00:00
- `cyclonedx` : An XML report conforming to the [CycloneDX 1.2 ](https://cyclonedx.org/ ) specification.
- `json` : Use this to get as much information out of Grype as possible!
- `template` : Lets the user specify the output format. See [Using Templates ](#using-templates ) below.
### Using Templates
2021-04-09 20:31:13 +00:00
Grype lets you define custom output formats, using [Go templates ](https://golang.org/pkg/text/template/ ). Here's how it works:
2021-03-30 17:15:57 +00:00
2021-04-09 20:31:13 +00:00
- Define your format as a Go template, and save this template as a file.
2021-03-30 17:15:57 +00:00
- Set the output format to "template" (`-o template`).
- Specify the path to the template file (`-t ./path/to/custom.template`).
- Grype's template processing uses the same data models as the `json` output format — so if you're wondering what data is available as you author a template, you can use the output from `grype <image> -o json` as a reference.
**Example:** You could make Grype output data in CSV format by writing a Go template that renders CSV data and then running `grype <image> -o ~/path/to/csv.tmpl` .
2021-04-09 20:31:13 +00:00
Here's what the `csv.tmpl` file might look like:
```gotemplate
"Package","Version Installed","Vulnerability ID","Severity"
{{- range .Matches}}
"{{.Artifact.Name}}","{{.Artifact.Version}}","{{.Vulnerability.ID}}","{{.Vulnerability.Severity}}"
{{- end}}
```
Which would produce output like:
```text
"Package","Version Installed","Vulnerability ID","Severity"
"coreutils","8.30-3ubuntu2","CVE-2016-2781","Low"
"libc-bin","2.31-0ubuntu9","CVE-2016-10228","Negligible"
"libc-bin","2.31-0ubuntu9","CVE-2020-6096","Low"
...
```
2021-03-30 17:15:57 +00:00
### Grype's Database
2020-09-25 18:18:03 +00:00
2020-08-07 19:56:55 +00:00
Grype pulls a database of vulnerabilities derived from the publicly available [Anchore Feed Service ](https://ancho.re/v1/service/feeds ). This database is updated at the beginning of each scan, but an update can also be triggered manually.
2020-08-24 16:27:07 +00:00
2020-08-07 19:56:55 +00:00
```
grype db update
```
## Installation
2020-11-06 17:19:38 +00:00
**Recommended (macOS and Linux)**
2020-08-24 16:27:07 +00:00
2020-08-07 19:56:55 +00:00
```bash
# install the latest version to /usr/local/bin
2020-08-10 23:29:35 +00:00
curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sh -s -- -b /usr/local/bin
2020-08-07 19:56:55 +00:00
# install a specific version into a specific dir
2020-10-09 15:08:26 +00:00
curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sh -s -- -b < SOME_BIN_PATH > < RELEASE_VERSION >
2020-08-07 19:56:55 +00:00
```
2020-11-06 17:19:38 +00:00
**Homebrew (macOS)**
2020-08-24 16:27:07 +00:00
2020-08-07 19:56:55 +00:00
```bash
brew tap anchore/grype
brew install grype
```
2020-09-25 18:06:10 +00:00
## Shell Completion
2020-10-09 14:10:10 +00:00
Grype supplies shell completion through its CLI implementation ([cobra](https://github.com/spf13/cobra/blob/master/shell_completions.md)).
2020-09-25 18:06:10 +00:00
Generate the completion code for your shell by running one of the following commands:
* `grype completion <bash|fish>`
* `go run main.go completion <bash|fish>`
2020-10-08 19:32:56 +00:00
This will output a shell script to STDOUT, which can then be used as a completion script for Grype. Running one of the above commands with the
2020-09-25 18:06:10 +00:00
`-h` or `--help` flags will provide instructions on how to do that for your chosen shell.
2020-10-19 14:01:33 +00:00
Note: [Cobra has not yet released full ZSH support ](https://github.com/spf13/cobra/issues/1226 ), but as soon as that gets released, we will add it here!
2020-09-25 18:06:10 +00:00
2020-08-07 19:56:55 +00:00
## Configuration
Configuration search paths:
- `.grype.yaml`
- `.grype/config.yaml`
- `~/.grype.yaml`
- `<XDG_CONFIG_HOME>/grype/config.yaml`
Configuration options (example values are the default):
```yaml
2020-09-25 18:06:10 +00:00
# enable/disable checking for application updates on startup
check-for-app-update: true
# same as --fail-on ; upon scanning, if a severity is found at or above the given severity then the return code will be 1
# default is unset which will skip this validation (options: negligible, low, medium, high, critical)
fail-on-severity: ''
# same as -o ; the output format of the vulnerability report (options: table, json, cyclonedx)
2020-08-07 19:56:55 +00:00
output: "table"
# same as -s ; the search space to look for packages (options: all-layers, squashed)
scope: "squashed"
# same as -q ; suppress all output (except for the vulnerability list)
quiet: false
db:
2020-09-25 18:06:10 +00:00
# check for database updates on execution
auto-update: true
2020-08-07 19:56:55 +00:00
# location to write the vulnerability database cache
cache-dir: "$XDG_CACHE_HOME/grype/db"
# URL of the vulnerability database
update-url: "https://toolbox-data.anchore.io/grype/databases/listing.json"
2021-04-13 20:13:48 +00:00
# options when pulling directly from a registry via the "registry:" scheme
registry:
# skip TLS verification when communicating with the registry
# GRYPE_REGISTRY_INSECURE_SKIP_TLS_VERIFY env var
insecure-skip-tls-verify: false
# credentials for specific registries
auth:
- # the URL to the registry (e.g. "docker.io", "localhost:5000", etc.)
# GRYPE_REGISTRY_AUTH_AUTHORITY env var
authority: ""
# GRYPE_REGISTRY_AUTH_USERNAME env var
username: ""
# GRYPE_REGISTRY_AUTH_PASSWORD env var
password: ""
# note: token and username/password are mutually exclusive
# GRYPE_REGISTRY_AUTH_TOKEN env var
token: ""
- ... # note, more credentials can be provided via config file only
2020-09-25 18:06:10 +00:00
log:
# location to write the log file (default is not to have a log file)
file: ""
2020-08-03 15:09:49 +00:00
2020-09-25 18:06:10 +00:00
# the log level; note: detailed logging suppress the ETUI
level: "error"
2020-08-03 15:09:49 +00:00
2020-09-25 18:06:10 +00:00
# use structured logging
structured: false
2020-08-03 15:09:49 +00:00
```
2020-09-14 16:06:29 +00:00
2020-08-11 11:07:44 +00:00
## Future plans
The following areas of potential development are currently being investigated:
2020-08-24 16:27:07 +00:00
2020-08-11 11:07:44 +00:00
- Support for allowlist, package mapping
2021-05-06 18:20:03 +00:00
- Accept alternative SBOM formats (CycloneDX, SPDX) as input