Статьи
Обучающие материалы
Достижение целей DevSecOps с помощью Bitbucket Pipelines и Snyk Pipe

Саймон Мейпл
Региональный технический директор, Snyk
Достижение целей DevSecOps путем интеграции Snyk с Bitbucket Pipelines и Jira.
Time
5-minute read.
Audience
Developers, security/application teams, and DevOps/DevSecOps engineers.
Prerequisites
You have a Snyk account. Get started here.
You have an Atlassian Bitbucket account. Log in here, or get started here.
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
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:
scan-app: &scan-app
- step:
name: "Scan open source dependencies"
caches:
- node
script:
- pipe: snyk/snyk-scan:0.4.3
variables:
SNYK_TOKEN: $SNYK_TOKEN
LANGUAGE: "npm"
PROJECT_FOLDER: "app/goof"
TARGET_FILE: "package.json"
CODE_INSIGHTS_RESULTS: "true"
SEVERITY_THRESHOLD: "high"
DONT_BREAK_BUILD: "true"
MONITOR: "false"
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:
1. SNYK_TOKEN
is passed into the pipe as a repository variable previously defined in the [Bitbucket Configuration] module.
2. 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.
3. CODE_INSIGHTS_RESULTS
defaults to false
. However, since we want to create a Code Insight report with Snyk test results, set this to true
.
4. 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.
5. The 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 true
.
You can run Snyk security scans on your pull requests and view results in Code Insights with the help of the new Snyk Security Connect App on the Atlassian Marketplace. It's easy to get started and you can install the app with just a few clicks.
Сканирование образов контейнеров

К 2022 году более 75 процентов международных организаций будут выполнять в рабочей среде контейнерные приложения (данные Gartner). Наряду с широким распространением контейнеров наблюдается всплеск их уязвимостей. Так, в 2018 году количество выявленных уязвимостей операционных систем увеличилось в четыре раза. И в то же время 80 процентов разработчиков заявляют, что не тестируют образы контейнеров во время разработки. Они либо не считают это своей обязанностью, либо привыкли, что проблемы устраняет кто-то другой. Из-за этого масштабирование безопасности контейнеров становится сложной задачей для быстрорастущих компаний.
Сканирование образа контейнера в конвейере
Как и в предыдущем разделе, посвященном сканированию приложения, в этом разделе основное внимание уделяется тому, как настроить файл bitbucket-pipelines.yml, чтобы создать образ Docker для приложения, сканировать образ и затем отправить его в реестр. Ниже более подробно рассматривается этап сканирования образа контейнера:
scan-push-image: &scan-push-image
- step:
name: "Scan and push container image"
services:
- docker
script:
- docker build -t $IMAGE ./app/goof/
- docker tag $IMAGE $IMAGE:${BITBUCKET_COMMIT}
- pipe: snyk/snyk-scan:0.4.3
variables:
SNYK_TOKEN: $SNYK_TOKEN
LANGUAGE: "docker"
IMAGE_NAME: $IMAGE
PROJECT_FOLDER: "app/goof"
TARGET_FILE: "Dockerfile"
CODE_INSIGHTS_RESULTS: "true"
SEVERITY_THRESHOLD: "high"
DONT_BREAK_BUILD: "true"
MONITOR: "false"
Здесь создается образ контейнера и выполняется его маркировка, после чего образ контейнера сканируется с использованием элемента конвейера Snyk Scan. Значения переменных CODE_INSIGHTS_RESULTS, SEVERITY_THRESHOLD
и DONT_BREAK_BUILD
остаются прежними. Кроме того, передается несколько дополнительных поддерживаемых переменных, которые относятся к Snyk Pipe, чтобы выполнить запрос на сканирование образа контейнера вместо сканирования приложения. А именно: переменной LANGUAGE
(Язык) присваивается значение docker
, объявляется переменная IMAGE_NAME
(Имя образа) и передается соответствующая переменная репозитория, а переменной TARGET_FILE
(Целевой файл) присваивается значение Dockerfile
.
Теперь ваш конвейер сканирует образ контейнера на наличие известных уязвимостей, а также код приложения.
См. другие интеграции для Atlassian Open DevOps
Поделитесь этой статьей
Следующая тема
Рекомендуемые статьи
Добавьте эти ресурсы в закладки, чтобы изучить типы команд DevOps или получать регулярные обновления по DevOps в Atlassian.

Сообщество DevOps

Семинар по моделированию
