9.7 KiB
Dependency Scanning [ULTIMATE]
Introduced in GitLab Ultimate 10.7.
Overview
If you are using GitLab CI/CD, you can analyze your dependencies for known vulnerabilities using Dependency Scanning.
You can take advantage of Dependency Scanning by either including the CI job
in your existing .gitlab-ci.yml
file or by implicitly using
Auto Dependency Scanning
that is provided by Auto DevOps.
GitLab checks the Dependency Scanning report, compares the found vulnerabilities between the source and target branches, and shows the information right on the merge request.
The results are sorted by the priority of the vulnerability:
- High
- Medium
- Low
- Unknown
- Everything else
Use cases
It helps to automatically find security vulnerabilities in your dependencies while you are developing and testing your applications. For example when your application is using an external (open source) library which is known to be vulnerable.
Requirements
To run a Dependency Scanning job, you need GitLab Runner with the
docker
or
kubernetes
executor running in privileged mode. If you're using the shared Runners on GitLab.com,
this is enabled by default.
Supported languages and package managers
The following languages and dependency managers are supported.
Language (package managers) | Scan tool |
---|---|
JavaScript (npm, yarn) | gemnasium, Retire.js |
Python (pip) (only requirements.txt supported) |
gemnasium |
Ruby (gem) | gemnasium, bundler-audit |
Java (Maven) | gemnasium |
PHP (Composer) | gemnasium |
Some scanners require to send a list of project dependencies to GitLab's central servers to check for vulnerabilities. To learn more about this or to disable it, refer to the GitLab Dependency Scanning tool documentation.
Configuring Dependency Scanning
To enable Dependency Scanning in your project, define a job in your .gitlab-ci.yml
file that generates the
Dependency Scanning report artifact.
This can be done in two ways:
- For GitLab 11.9 and later, including the provided Dependency Scanning
.gitlab-ci.yml
template (recommended). - Manually specifying the job definition. Not recommended unless using GitLab 11.8 and earlier.
Including the provided template
NOTE: Note: The CI/CD Dependency Scanning template is supported on GitLab 11.9 and later versions. For earlier versions, use the manual job definition.
A CI/CD Dependency Scanning template
with the default Dependency Scanning job definition is provided as a part of your GitLab
installation which you can include
in your .gitlab-ci.yml
file.
To enable Dependency Scanning using the provided template, add the following to
your .gitlab-ci.yml
file:
include:
template: Dependency-Scanning.gitlab-ci.yml
The included template will create a dependency_scanning
job in your CI/CD
pipeline and scan your project's source code for possible vulnerabilities.
The report will be saved as a Dependency Scanning report artifact that you can later download and analyze. Due to implementation limitations, we always take the latest Dependency Scanning artifact available.
Some security scanners require to send a list of project dependencies to GitLab central servers to check for vulnerabilities. To learn more about this or to disable it, check the GitLab Dependency Scanning tool documentation.
Customizing the Dependency Scanning settings
The Dependency Scanning settings can be changed through environment variables by using the
variables
parameter in .gitlab-ci.yml
.
These variables are documented in the
Dependency Scanning tool documentation.
For example:
include:
template: Dependency-Scanning.gitlab-ci.yml
variables:
DEP_SCAN_DISABLE_REMOTE_CHECKS: true
Because template is evaluated before the pipeline configuration, the last mention of the variable will take precedence.
Overriding the Dependency Scanning template
If you want to override the job definition (for example, change properties like
variables
or dependencies
), you need to declare a dependency_scanning
job
after the template inclusion and specify any additional keys under it. For example:
include:
template: Dependency-Scanning.gitlab-ci.yml
dependency_scanning:
variables:
CI_DEBUG_TRACE: "true"
Manual job definition for GitLab 11.5 and later
For GitLab 11.5 and GitLab Runner 11.5 and later, the following dependency_scanning
job can be added:
dependency_scanning:
image: docker:stable
variables:
DOCKER_DRIVER: overlay2
allow_failure: true
services:
- docker:stable-dind
script:
- export DS_VERSION=${SP_VERSION:-$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')}
- |
docker run \
--env DS_ANALYZER_IMAGES \
--env DS_ANALYZER_IMAGE_PREFIX \
--env DS_ANALYZER_IMAGE_TAG \
--env DS_DEFAULT_ANALYZERS \
--env DEP_SCAN_DISABLE_REMOTE_CHECKS \
--env DS_DOCKER_CLIENT_NEGOTIATION_TIMEOUT \
--env DS_PULL_ANALYZER_IMAGE_TIMEOUT \
--env DS_RUN_ANALYZER_TIMEOUT \
--volume "$PWD:/code" \
--volume /var/run/docker.sock:/var/run/docker.sock \
"registry.gitlab.com/gitlab-org/security-products/dependency-scanning:$DS_VERSION" /code
dependencies: []
artifacts:
reports:
dependency_scanning: gl-dependency-scanning-report.json
You can supply many other settings variables
via docker run --env
to customize your job execution.
Manual job definition for GitLab 11.4 and earlier (deprecated)
CAUTION: Caution:
Before GitLab 11.5, the Dependency Scanning job and artifact had to be named specifically
to automatically extract the report data and show it in the merge request widget.
While these old job definitions are still maintained, they have been deprecated
and may be removed in the next major release, GitLab 12.0. You are strongly advised
to update your current .gitlab-ci.yml
configuration to reflect that change.
For GitLab 11.4 and earlier, the job should look like:
dependency_scanning:
image: docker:stable
variables:
DOCKER_DRIVER: overlay2
allow_failure: true
services:
- docker:stable-dind
script:
- export DS_VERSION=${SP_VERSION:-$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')}
- |
docker run \
--env DS_ANALYZER_IMAGES \
--env DS_ANALYZER_IMAGE_PREFIX \
--env DS_ANALYZER_IMAGE_TAG \
--env DS_DEFAULT_ANALYZERS \
--env DS_EXCLUDED_PATHS \
--env DEP_SCAN_DISABLE_REMOTE_CHECKS \
--env DS_DOCKER_CLIENT_NEGOTIATION_TIMEOUT \
--env DS_PULL_ANALYZER_IMAGE_TIMEOUT \
--env DS_RUN_ANALYZER_TIMEOUT \
--volume "$PWD:/code" \
--volume /var/run/docker.sock:/var/run/docker.sock \
"registry.gitlab.com/gitlab-org/security-products/dependency-scanning:$DS_VERSION" /code
artifacts:
paths: [gl-dependency-scanning-report.json]
Security Dashboard
The Security Dashboard is a good place to get an overview of all the security vulnerabilities in your groups and projects. Read more about the Security Dashboard.
Interacting with the vulnerabilities
Once a vulnerability is found, you can interact with it. Read more on how to interact with the vulnerabilities.