This tutorial outlines how to secure your build workflow on Bitbucket Pipelines with Snyk. An important step in securing your environment is to scan and analyze both your application and Linux-based container project for known vulnerabilities, which helps you identify and mitigate security vulnerabilities. The exercises in this tutorial will help secure your application and container by leveraging the Snyk Pipe for Bitbucket Pipelines to scan the application manifest file and the container base image for its dependencies.
The tutorial, How Snyk and Bitbucket Cloud enable DevSecOps, focused on application dependencies. However, by also scanning your container base image you can detect:
- The operating system (OS) packages installed and managed by the package manager
- Key binaries —layers that were not installed through the package manager
Based on these results, Snyk provides advice and guidance, including:
- Origins of the vulnerabilities in OS packages and key binaries
- Base image upgrade details or a recommendation to rebuild the image
- Dockerfile layer where the affected package was introduced
- Fixed-in version of the operating system and key binary packages
- Security/application teams
- DevOps/DevSecOps engineers
You have a Snyk and Atlassian Bitbucket account.
- Register for a free Snyk account here.
- Log in to your Snyk account here.
- Register for a free Atlassian account here.
- Log in to your Atlassian account here.
Application scanning in your Bitbucket Pipeline
The bitbucket-pipelines.yml file defines your Bitbucket Pipelines builds configuration. If you're new to Bitbucket Pipelines you can learn more about how to get started here.
This tutorial provides a sample bitbucket-pipelines.yml file that contains distinct steps mapped to the workflow. We’ll start by scanning the application, building the Docker image, and then scanning the container image. The following is a closer look at the application scanning step:
This example leverages the Snyk Scan pipe in the pipeline to perform a scan of the application. The source contains a complete, YAML definition of all supported variables, but only those included in this snippet are necessary for this purpose.
Here’s a closer look at a few of these:
SNYK_TOKEN is passed into the pipe as a repository variable previously defined in the [Bitbucket Configuration] module.
PROJECT_FOLDER is the folder where the project resides and normally defaults to. However, in this example, we set this to
app/goof and pass this as an artifact to other steps in ther pipeline.
CODE_INSIGHTS_RESULTS defaults to
false. However, since we want to create a Code Insight report with Snyk test results, set this to
SEVERITY_THRESHOLD reports on issues equal or higher to the provided level. The default is
low. But in this case, we are interested only in
high, so we defined this variable accordingly.
DONT_BREAK_BUILD default is
false, which is expected. Under normal circumstances, you would want to break the build if issues are found. However, for the purpose of this learning exercise, set this to