

Docker security scanning CLI cheatsheet | Snyk Blog
source link: https://snyk.io/blog/docker-security-scanning-cheatsheet-2021/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Docker security scanning cheatsheet 2021
Jim Armstrong
January 19, 2021
Docker has an enormous worldwide user base, recently surpassing 10 million users and 242 billion image pulls and has changed the way applications are built.
With the accelerated development velocity that containerization enables, additional security responsibilities are shifting to developers, who now need to maintain container images in addition to their code. That’s why a developer-friendly Snyk integration with Docker is invaluable in today’s security landscape.
At SnykCon 2020, we announced the integration of Snyk-powered container scanning in the latest version of Docker Desktop. This followed our news that Snyk would become the security provider for Docker’s Official Images and that Snyk security scanning would be integrated directly into Docker Hub.
We’ve created a Docker Vulnerability Scanning CLI cheatsheet, to help you get started scanning your container images with Docker Desktop and Snyk, and below we have a few tips to get you started.
Step 1: make sure your version of Docker Desktop is up to date
Docker Desktop has included Snyk’s scanning capabilities for a few months now, but in case you haven’t updated in a while or you aren’t sure if you have the Snyk components, here’s how you can check.
Via the CLI
The docker scan
command will be available. Docker Desktop “About”
If you see the little Snyk icon and version info, you all set$ docker scan --helpUsage: docker scan [OPTIONS] IMAGE A tool to scan your images
Step 2: get logged in!
To start scanning, you need to have a Docker ID and be logged in via Docker Desktop. You’ll get 10 free container images tests per month. But you can get 200 scans per month if you login to Snyk as well. The Snyk login is integrated with your Docker ID so even if you don’t currently have a login with Snyk, it’s simple to get going.
$ docker scan --login
If you want to authenticate with an API token instead, be sure to include the --token
flag and your token as the flag argument. You can find your Snyk API token under Settings –> Service Accounts within the Snyk console.
Signing up for Snyk also unlocks additional open source security scanning features for your dependencies, configuration files, and more. See our recent talk about how Snyk integrates throughout the entire software development lifecycle (SDLC), including integrated developer environments (IDEs), source code management (SCM), continuous integration, and continuous development (CI/CD) platforms, and more.
Step 3a: Docker scan your first container image
With the basic docker scan myapp:mytag
command, you can scan a single Docker image for vulnerabilities. There are a number of additional flags you can include to produce more granular results, which are detailed below.
Step 3b: scan your image along with your Dockerfile
The --file path/to/Dockerfile
option is one of the most generally useful options. By including the Dockerfile you can get base image upgrade recommendations for Docker Official base images, and the vulnerabilities will be mapped to the Dockerfile commands that introduced them.
Step 4: filter your scan results
The --exclude-base
flag, which must be used with the –file flag, will ignore any vulnerabilities that originate from the base image so you can focus on remediating issues within your own container image.
The --dependency-tree
flag will include a package dependency tree along with the vulnerability scan results to make tracking down the source of issues even easier.
The --json
flag allows you to control the scanning results output. With the jq tool, you can then parse and filter the JSON results based on the following keys:
packageName
: name of the top-level packageseverity
: rating based on common vulnerability scoring system (CVSS)id
: identifier within Snyk’s vulnerability databasename
: name of the vulnerability binaryversion
: version installed in the container imagenearestFixedInVersion
: minimum version required to remediate a vulnerabilitydockerfileInstruction
: line where the vulnerable package was introduced in DockerfiledockerBaseImage
: parent image that was detected
The steps above will get you started with container security, but if you want a handy way to remember and want to see more examples, the Docker CLI cheatsheet is your best reference guide. The Docker container scanning CLI is a simple, yet powerful tool for detecting and remediating vulnerabilities early in the development process. This Docker-native solution can be run immediately after you build so that issues are resolved before the image is even pushed to Docker Hub. If you have questions or you’ve come up with a clever use case, we’d love to hear from you on the Snyk Community site.
Recommend
-
11
Go security cheatsheet: 8 security best practices for Go developers Eric Smalling, Gerred Dillon February 9, 2021 ...
-
9
Scanning Red Hat Quay registry images for vulnerabilities with Snyk Jim Armstrong April 1, 2021 We...
-
13
Scanning Harbor registry images for vulnerabilities with Snyk Eric Smalling April 1, 2021 It’s off...
-
12
Automate vulnerability scanning in AWS CodePipeline with Snyk
-
9
Snyk Code adds security scanning for C# and .NET
-
9
Snyk Code adds Go security scanning (beta)
-
11
Snyk Open Source adds beta C/C++ security scanning for unmanaged OSS ...
-
13
Michal BrutvanApril 5, 2022We’re happy to announce the general availability of C/C++ security scanning in Snyk Open Source, enabling development and security teams to find and fix known security vulnerabilities in their...
-
15
Snyk CodeStatic Application Security Testing re-imagined for the developer
-
4
Michal BrutvanSeptember 8, 2022Snyk Open Source supports C and C++ scanning for vendored open source dependencies via CLI — and we are happy to share that it is now available via our CI plugins as well. This...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK