No description
Find a file
Alex Goodman f75889c694
Disable ETUI when piping input (#463)
* disable etui when piping input

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>

* restore jotframe version

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>

* remove test code

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>

* raise error from IsPipedInput

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>

* factor out verbosity check to function

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
2021-10-20 12:40:57 -04:00
.github remove unnecessary codeql checkout from second parent commit (#458) 2021-10-18 13:18:56 -04:00
cmd Disable ETUI when piping input (#463) 2021-10-20 12:40:57 -04:00
grype Disable ETUI when piping input (#463) 2021-10-20 12:40:57 -04:00
internal Disable ETUI when piping input (#463) 2021-10-20 12:40:57 -04:00
schema/cyclonedx use test config for schema validations 2021-05-26 12:30:21 -04:00
test Silence usage and errors on root command (#462) 2021-10-20 09:50:59 -04:00
ui Upgrade config, UI, and command package patterns (#406) 2021-10-01 13:03:50 -04:00
.bouncer.yaml Bugfixes + Integration test for sbom input vs grype library comparison (#424) 2021-09-22 21:53:32 -04:00
.gitignore add docker image to release process 2021-03-23 10:00:13 -04:00
.golangci.yaml update linter + fix whitespace (#443) 2021-10-06 09:49:42 -04:00
.goreleaser.yaml Support gomod configuration in goreleaser (#391) 2021-10-01 09:37:36 -04:00
CONTRIBUTING.md Improve documentation (#441) 2021-10-04 09:29:41 -04:00
DEVELOPING.md Update high level docs (#162) 2020-09-25 14:06:10 -04:00
Dockerfile add docker image to release process 2021-03-23 10:00:13 -04:00
go.mod Add APK version constraint parsing (#455) 2021-10-18 17:27:02 +00:00
go.sum Add APK version constraint parsing (#455) 2021-10-18 17:27:02 +00:00
gon.hcl Add signed and notarized ZIP release asset 2020-11-11 17:30:50 -05:00
install.sh Avoid Finder window flash during install 2020-11-11 17:19:53 -05:00
LICENSE add apache v2 license 2020-06-24 14:37:36 -04:00
main.go rename to grype 2020-07-23 21:29:05 -04:00
Makefile update linter + fix whitespace (#443) 2021-10-06 09:49:42 -04:00
README.md Announce upcoming webinar (#457) 2021-10-15 16:21:26 +00:00

Static Analysis + Unit + Integration Acceptance Go Report Card GitHub release GitHub go.mod Go version License: Apache-2.0 Slack Invite

A vulnerability scanner for container images and filesystems. Easily install the binary to try it out. Works with Syft, the powerful SBOM (software bill of materials) tool for container images and filesystems.

Announcement: Join us on October 20, 11am-noon PT for a webinar where well discuss Anchores open source and enterprise solutions. Save your seat!


grype-demo

Features

  • Scan the contents of a container image or filesystem to find known vulnerabilities.
  • Find vulnerabilities for major operating system packages:
    • Alpine
    • Amazon Linux
    • BusyBox
    • CentOS
    • Debian
    • Distroless
    • Oracle Linux
    • Red Hat (RHEL)
    • Ubuntu
  • Find vulnerabilities for language-specific packages:
    • Ruby (Gems)
    • Java (JAR, WAR, EAR, JPI, HPI)
    • JavaScript (NPM, Yarn)
    • Python (Egg, Wheel, Poetry, requirements.txt/setup.py files)
  • Supports Docker and OCI image formats

If you encounter an issue, please let us know using the issue tracker.

Installation

curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sh -s -- -b /usr/local/bin

...or, you can specify a release version and destination directory for the installation:

curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sh -s -- -b <DESTINATION_DIR> <RELEASE_VERSION>

Homebrew

brew tap anchore/grype
brew install grype

Note: Currently, Grype is built only for macOS and Linux.

Getting started

Install the binary, and make sure that grype is available in your path. To scan for vulnerabilities in an image:

grype <image>

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:

grype <image> --scope all-layers

Supported sources

Grype can scan a variety of sources beyond those found in Docker.

# scan a container image archive (from the result of `docker image save ...`, `podman save ...`, or `skopeo copy` commands)
grype path/to/image.tar

# scan a directory
grype dir:path/to/dir

Use 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

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)

Output formats

The output format for Grype is configurable as well:

grype <image> -o <format>

Where the formats available are:

  • table: A columnar summary (default).
  • cyclonedx: An XML report conforming to the CycloneDX 1.2 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" below.

Using templates

Grype lets you define custom output formats, using Go templates. Here's how it works:

  • Define your format as a Go template, and save this template as a file.

  • 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.

Here's what the csv.tmpl file might look like:

"Package","Version Installed","Vulnerability ID","Severity"
{{- range .Matches}}
"{{.Artifact.Name}}","{{.Artifact.Version}}","{{.Vulnerability.ID}}","{{.Vulnerability.Severity}}"
{{- end}}

Which would produce output like:

"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"
...

Gating on severity of vulnerabilities

You can have Grype exit with an error if any vulnerabilities are reported at or above the specified severity level. This comes in handy when using Grype within a script or CI pipeline. To do this, use the --fail-on <severity> CLI flag.

For example, here's how you could trigger a CI pipeline failure if any vulnerabilities are found in the ubuntu:latest image with a severity of "medium" or higher:

grype ubuntu:latest --fail-on medium

Specifying matches to ignore

If you're seeing Grype report false positives or any other vulnerability matches that you just don't want to see, you can tell Grype to ignore matches by specifying one or more "ignore rules" in your Grype configuration file (e.g. ~/.grype.yaml). This causes Grype not to report any vulnerability matches that meet the criteria specified by any of your ignore rules.

Each rule can specify any combination of the following criteria:

  • vulnerability ID (e.g. "CVE-2008-4318")
  • package name (e.g. "libcurl")
  • package version (e.g. "1.5.1")
  • package type (e.g. "npm"; these values are defined here)
  • package location (e.g. "/usr/local/lib/node_modules/**"; supports glob patterns)

Here's an example ~/.grype.yaml that demonstrates the expected format for ignore rules:

ignore:
  
  # This is the full set of supported rule fields:
  - vulnerability: CVE-2008-4318
    package:
      name: libcurl
      version: 1.5.1
      type: npm
      location: "/usr/local/lib/node_modules/**"

  # We can make rules to match just by vulnerability ID:
  - vulnerability: CVE-2017-41432
  
  # ...or just by a single package field:
  - package:
      type: gem

Vulnerability matches will be ignored if any rules apply to the match. A rule is considered to apply to a given vulnerability match only if all fields specified in the rule apply to the vulnerability match.

When you run Grype while specifying ignore rules, the following happens to the vulnerability matches that are "ignored":

  • Ignored matches are completely hidden from Grype's output, except for when using the json or template output formats; however, in these two formats, the ignored matches are removed from the existing matches array field, and they are placed in a new ignoredMatches array field. Each listed ignored match also has an additional field, appliedIgnoreRules, which is an array of any rules that caused Grype to ignore this vulnerability match.

  • Ignored matches do not factor into Grype's exit status decision when using --fail-on <severity>. For instance, if a user specifies --fail-on critical, and all of the vulnerability matches found with a "critical" severity have been ignored, Grype will exit zero.

Note: Please continue to report any false positives you see! Even if you can reliably filter out false positives using ignore rules, it's very helpful to the Grype community if we have as much knowledge about Grype's false positives as possible. This helps us continuously improve Grype!

Grype's database

Grype pulls a database of vulnerabilities derived from the publicly available Anchore Feed Service. This database is updated at the beginning of each scan, but an update can also be triggered manually.

grype db update

Shell completion

Grype supplies shell completion through its CLI implementation (cobra). Generate the completion code for your shell by running one of the following commands:

  • grype completion <bash|zsh|fish>
  • go run main.go completion <bash|zsh|fish>

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 -h or --help flags will provide instructions on how to do that for your chosen shell.

Configuration

Configuration search paths:

  • .grype.yaml
  • .grype/config.yaml
  • ~/.grype.yaml
  • <XDG_CONFIG_HOME>/grype/config.yaml

Configuration options (example values are the default):

# 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)
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

# same as --file; write output report to a file (default is to write to stdout)
file: ""

db:
  # check for database updates on execution
  auto-update: true

  # 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"

# 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
  # use http instead of https when connecting to the registry
  # GRYPE_REGISTRY_INSECURE_USE_HTTP env var
  insecure-use-http: 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


log:
  # location to write the log file (default is not to have a log file)
  file: ""

  # the log level; note: detailed logging suppress the ETUI
  level: "error"

  # use structured logging
  structured: false

Future plans

The following areas of potential development are currently being investigated:

  • Support for allowlist, package mapping
  • Accept alternative SBOM formats (CycloneDX, SPDX) as input