2019-10-12 21:52:04 +05:30
---
2021-09-04 01:27:46 +05:30
stage: Secure
group: Static Analysis
2022-11-25 23:54:43 +05:30
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments
2019-10-12 21:52:04 +05:30
---
2023-04-23 21:23:45 +05:30
# Application security **(ULTIMATE)**
2019-07-31 22:56:46 +05:30
2021-06-08 01:23:25 +05:30
GitLab can check your application for security vulnerabilities including:
- Unauthorized access.
- Data leaks.
2022-07-16 23:28:13 +05:30
- Denial of Service (DoS) attacks.
2021-06-08 01:23:25 +05:30
2022-07-23 23:45:48 +05:30
< i class = "fa fa-youtube-play youtube" aria-hidden = "true" > < / i >
For an overview of GitLab application security, see [Shifting Security Left ](https://www.youtube.com/watch?v=XnYstHObqlA&t ).
2021-06-08 01:23:25 +05:30
Statistics and details on vulnerabilities are included in the merge request. Providing
actionable information _before_ changes are merged enables you to be proactive.
2022-07-23 23:45:48 +05:30
To help with the task of managing and addressing vulnerabilities, GitLab provides a security
dashboard you can access from your project or group. For more details, see
[Security Dashboard ](security_dashboard/index.md ).
2021-04-17 20:07:23 +05:30
2022-07-23 23:45:48 +05:30
## Application coverage
2019-10-12 21:52:04 +05:30
2022-07-23 23:45:48 +05:30
GitLab analyzes various details of your application, either as part of your CI/CD pipeline or on a
schedule. Coverage includes:
- Source code.
- Dependencies in your projects or container images.
- Vulnerabilities in a running web application.
- Infrastructure as code configuration.
2022-11-25 23:54:43 +05:30
Each of the GitLab application security tools is relevant to specific stages of the feature development workflow.
- Commit
- SAST
- Secret Detection
- IaC Scanning
- Dependency Scanning
- License Scanning
- Coverage-guided Fuzz Testing
- Build
- Container Scanning
- Test
- API Security
- DAST
- Deploy
- Operational Container Scanning
![CI/CD stages and matching GitLab application security tools ](img/secure_tools_and_cicd_stages.png )
2022-07-23 23:45:48 +05:30
### Source code analysis
Source code analysis occurs on every code commit. Details of vulnerabilities detected are provided
in the merge request.
A source code analysis can:
- Analyze source code for vulnerabilities - [Static Application Security Testing (SAST) ](sast/index.md ).
- Analyze the Git repository's history for secrets - [Secret Detection ](secret_detection/index.md ).
### Analysis of the running web application
Analysis of the web application occurs on every code commit. As part of the CI/CD pipeline, your
application is built, deployed to a test environment, and subjected to the following tests:
- Test for known application vectors - [Dynamic Application Security Testing (DAST) ](dast/index.md ).
2022-11-25 23:54:43 +05:30
- Analysis of APIs for known attack vectors - [API Security ](dast_api/index.md ).
2022-07-23 23:45:48 +05:30
- Analysis of web APIs for unknown bugs and vulnerabilities - [API fuzzing ](api_fuzzing/index.md ).
2020-05-24 23:13:21 +05:30
2022-07-23 23:45:48 +05:30
### Dependency analysis
Dependency analysis occurs on every code commit. Your application's dependencies are collated and
checked against a database of known vulnerabilities.
Dependency analysis can run:
- At build time - [Dependency Scanning ](dependency_scanning/index.md ).
- For projects that use container images, also after the final container
image is built - [Container Scanning ](container_scanning/index.md ).
For more details, see
[Dependency Scanning compared to Container Scanning ](dependency_scanning/index.md#dependency-scanning-compared-to-container-scanning ).
Additionally, dependencies in operational container images can be analyzed for vulnerabilities
2022-11-25 23:54:43 +05:30
on a regular schedule or cadence. For more details, see [Operational Container Scanning ](../../user/clusters/agent/vulnerabilities.md ).
2022-07-23 23:45:48 +05:30
### Infrastructure analysis
Your application's infrastructure is a source of potential vulnerabilities. To help defend
against this, infrastructure analysis occurs on every merge request. Checks are run against:
- Infrastructure as Code (IaC) configuration files that define your application's deployment
environment - [Infrastructure as Code (IaC) Scanning ](iac_scanning/index.md ).
2019-09-30 21:07:59 +05:30
2022-04-04 11:22:00 +05:30
## Vulnerability scanner maintenance
The following vulnerability scanners and their databases are regularly updated:
| Secure scanning tool | Vulnerabilities database updates |
|:----------------------------------------------------------------|:---------------------------------|
2023-06-20 00:43:36 +05:30
| [Container Scanning ](container_scanning/index.md ) | A job runs on a daily basis to build new images with the latest vulnerability database updates from the upstream scanner. GitLab monitors this job through an internal alert that tells the engineering team when the database becomes more than 48 hours old. For more information, see the [Vulnerabilities database update ](container_scanning/index.md#vulnerabilities-database ). |
2022-07-16 23:28:13 +05:30
| [Dependency Scanning ](dependency_scanning/index.md ) | Relies on the [GitLab Advisory Database ](https://gitlab.com/gitlab-org/security-products/gemnasium-db ). It is updated on a daily basis using [data from NVD, the `ruby-advisory-db` and the GitHub Advisory Database as data sources ](https://gitlab.com/gitlab-org/security-products/gemnasium-db/-/blob/master/SOURCES.md ). See our [current measurement of time from CVE being issued to our product being updated ](https://about.gitlab.com/handbook/engineering/development/performance-indicators/#cve-issue-to-update ). |
2022-04-04 11:22:00 +05:30
| [Dynamic Application Security Testing (DAST) ](dast/index.md ) | The scanning engine is updated on a periodic basis. See the [version of the underlying tool `zaproxy` ](https://gitlab.com/gitlab-org/security-products/dast/blob/main/Dockerfile#L1 ). The scanning rules are downloaded at scan runtime. |
2023-04-23 21:23:45 +05:30
| [Static Application Security Testing (SAST) ](sast/index.md ) | The source of scan rules depends on which [analyzer ](sast/analyzers.md ) is used for each [supported programming language ](sast/index.md#supported-languages-and-frameworks ). GitLab maintains a ruleset for the Semgrep-based analyzer and updates it regularly based on internal research and user feedback. For other analyzers, the ruleset is sourced from the upstream open-source scanner. Each analyzer is updated at least once per month if a relevant update is available. |
2022-04-04 11:22:00 +05:30
In versions of GitLab that use the same major version of the analyzer, you do not have to update
2023-04-23 21:23:45 +05:30
them to benefit from the latest vulnerabilities definitions. The security tools are released as
2022-04-04 11:22:00 +05:30
Docker images. The vendored job definitions that enable them use major release tags according to
[semantic versioning ](https://semver.org/ ). Each new release of the tools overrides these tags.
Although in a major analyzer version you automatically get the latest versions of the scanning
tools, there are some [known issues ](https://gitlab.com/gitlab-org/gitlab/-/issues/9725 ) with this
approach.
2021-06-08 01:23:25 +05:30
## Security scanning with Auto DevOps
2021-01-29 00:20:46 +05:30
2021-06-08 01:23:25 +05:30
To enable all GitLab Security scanning tools, with default settings, enable
2022-10-11 01:57:18 +05:30
[Auto DevOps ](../../topics/autodevops/index.md ):
2020-06-23 00:09:42 +05:30
2020-11-24 15:15:51 +05:30
- [Auto SAST ](../../topics/autodevops/stages.md#auto-sast )
- [Auto Secret Detection ](../../topics/autodevops/stages.md#auto-secret-detection )
- [Auto DAST ](../../topics/autodevops/stages.md#auto-dast )
- [Auto Dependency Scanning ](../../topics/autodevops/stages.md#auto-dependency-scanning )
- [Auto License Compliance ](../../topics/autodevops/stages.md#auto-license-compliance )
- [Auto Container Scanning ](../../topics/autodevops/stages.md#auto-container-scanning )
2020-06-23 00:09:42 +05:30
2023-03-17 16:20:25 +05:30
While you cannot directly customize Auto DevOps, you can [include the Auto DevOps template in your project's `.gitlab-ci.yml` file ](../../topics/autodevops/customize.md#customize-gitlab-ciyml ).
2020-06-23 00:09:42 +05:30
2021-06-08 01:23:25 +05:30
## Security scanning without Auto DevOps
2019-09-30 21:07:59 +05:30
2023-04-23 21:23:45 +05:30
To enable all GitLab security scanning tools with the option of customizing settings, add the
2021-06-08 01:23:25 +05:30
GitLab CI/CD templates to your `.gitlab-ci.yml` file.
2020-03-13 15:44:24 +05:30
2022-08-13 15:12:31 +05:30
WARNING:
All customization of GitLab security scanning tools should be tested in a merge request before
merging these changes to the default branch. Failure to do so can give unexpected results,
including a large number of false positives.
2021-06-08 01:23:25 +05:30
To enable Static Application Security Testing, Dependency Scanning, License Scanning, and Secret
Detection, add:
2021-01-29 00:20:46 +05:30
2021-06-08 01:23:25 +05:30
```yaml
include:
- template: Security/Dependency-Scanning.gitlab-ci.yml
- template: Security/License-Scanning.gitlab-ci.yml
- template: Security/SAST.gitlab-ci.yml
- template: Security/Secret-Detection.gitlab-ci.yml
```
2020-10-24 23:57:45 +05:30
2021-06-08 01:23:25 +05:30
To enable Dynamic Application Security Testing (DAST) scanning, add the following to your
`.gitlab-ci.yml` . Replace `https://staging.example.com` with a staging server's web address:
2020-07-28 23:09:34 +05:30
2021-06-08 01:23:25 +05:30
```yaml
include:
- template: Security/DAST.gitlab-ci.yml
2020-07-28 23:09:34 +05:30
2021-06-08 01:23:25 +05:30
variables:
DAST_WEBSITE: https://staging.example.com
```
2020-07-28 23:09:34 +05:30
2021-06-08 01:23:25 +05:30
### Override the default registry base address
2020-07-28 23:09:34 +05:30
2022-05-07 20:08:51 +05:30
By default, GitLab security scanners use `registry.gitlab.com/security-products` as the
2022-07-23 23:45:48 +05:30
base address for Docker images. You can override this for most scanners by setting the CI/CD variable
2023-04-23 21:23:45 +05:30
`SECURE_ANALYZERS_PREFIX` to another location. This affects all scanners at once.
2020-07-28 23:09:34 +05:30
2022-07-23 23:45:48 +05:30
The [Container Scanning ](container_scanning/index.md ) analyzer is an exception, and it
does not use the `SECURE_ANALYZERS_PREFIX` variable. To override its Docker image, see
2022-08-27 11:52:29 +05:30
the instructions for
[Running container scanning in an offline environment ](container_scanning/index.md#running-container-scanning-in-an-offline-environment ).
2020-05-24 23:13:21 +05:30
2022-11-25 23:54:43 +05:30
### Use security scanning tools with merge request pipelines
By default, the application security jobs are configured to run for branch pipelines only.
To use them with [merge request pipelines ](../../ci/pipelines/merge_request_pipelines.md ),
you must reference the [`latest` templates ](../../development/cicd/templates.md ).
All `latest` security templates support merge request pipelines.
2023-04-23 21:23:45 +05:30
For example, to run both SAST and Dependency Scanning, the following template is used:
2022-11-25 23:54:43 +05:30
```yaml
include:
- template: Jobs/Dependency-Scanning.latest.gitlab-ci.yml
- template: Jobs/SAST.latest.gitlab-ci.yml
```
NOTE:
Mixing `latest` and `stable` security templates can cause both MR and branch pipelines to run. We recommend choosing `latest` or `stable` for all security scanners.
NOTE:
Latest templates can receive breaking changes in any release.
2021-06-08 01:23:25 +05:30
## Default behavior of GitLab security scanning tools
2021-04-17 20:07:23 +05:30
2021-06-08 01:23:25 +05:30
### Secure jobs in your pipeline
2020-05-24 23:13:21 +05:30
2022-07-23 23:45:48 +05:30
If you add the security scanning jobs as described in [Security scanning with Auto DevOps ](#security-scanning-with-auto-devops ) or [Security scanning without Auto DevOps ](#security-scanning-without-auto-devops ) to your `.gitlab-ci.yml` each added [security scanning tool ](#application-coverage ) behave as described below.
2019-07-31 22:56:46 +05:30
2022-03-02 08:16:31 +05:30
For each compatible analyzer, a job is created in the `test` , `dast` or `fuzz` stage of your pipeline and runs on the next new branch pipeline.
Features such as the [Security Dashboard ](security_dashboard/index.md ), [Vulnerability Report ](vulnerability_report/index.md ), and [Dependency List ](dependency_list/index.md )
that rely on this scan data only show results from pipelines on the default branch, only if all jobs are finished, including manual ones. One tool might use many analyzers.
2019-09-04 21:01:54 +05:30
2022-07-23 23:45:48 +05:30
Our language and package manager specific jobs attempt to assess which analyzers they should run for your project so that you can do less configuration.
2019-09-04 21:01:54 +05:30
2023-04-23 21:23:45 +05:30
If you want to override this to increase the pipeline speed, you may choose which analyzers to exclude if you know they are not applicable (languages or package managers not contained in your project) by following variable customization directions for that specific tool.
2019-09-04 21:01:54 +05:30
2021-06-08 01:23:25 +05:30
### Secure job status
2019-09-04 21:01:54 +05:30
2022-07-23 23:45:48 +05:30
Jobs pass if they are able to complete a scan. A _pass_ result does not indicate if they did, or did not, identify findings. The only exception is coverage fuzzing, which fails if it identifies findings.
2020-04-08 14:13:33 +05:30
2021-06-08 01:23:25 +05:30
Jobs fail if they are unable to complete a scan. You can view the pipeline logs for more information.
2020-04-08 14:13:33 +05:30
2022-07-16 23:28:13 +05:30
All jobs are permitted to fail by default. This means that if they fail, it does not fail the pipeline.
2020-04-08 14:13:33 +05:30
2021-06-08 01:23:25 +05:30
If you want to prevent vulnerabilities from being merged, you should do this by adding [Security Approvals in Merge Requests ](#security-approvals-in-merge-requests ) which prevents unknown, high or critical findings from being merged without an approval from a specific group of people that you choose.
2020-04-08 14:13:33 +05:30
2021-09-30 23:02:18 +05:30
We do not recommend changing the job [`allow_failure` setting ](../../ci/yaml/index.md#allow_failure ) as that fails the entire pipeline.
2021-01-29 00:20:46 +05:30
2021-06-08 01:23:25 +05:30
### JSON Artifact
2021-04-17 20:07:23 +05:30
2021-06-08 01:23:25 +05:30
The artifact generated by the secure analyzer contains all findings it discovers on the target branch, regardless of whether they were previously found, dismissed, or completely new (it puts in everything that it finds).
2021-04-17 20:07:23 +05:30
2021-06-08 01:23:25 +05:30
## View security scan information in merge requests **(FREE)**
2021-04-17 20:07:23 +05:30
2021-06-08 01:23:25 +05:30
> - [Introduced](https://gitlab.com/groups/gitlab-org/-/epics/4393) in GitLab Free 13.5.
> - Made [available in all tiers](https://gitlab.com/gitlab-org/gitlab/-/issues/273205) in 13.6.
2023-01-13 00:05:48 +05:30
> - Report download dropdown list [added](https://gitlab.com/gitlab-org/gitlab/-/issues/273418) in 13.7.
2021-06-08 01:23:25 +05:30
> - [Feature flag removed](https://gitlab.com/gitlab-org/gitlab/-/issues/249550) in GitLab 13.9.
2021-04-17 20:07:23 +05:30
2021-06-08 01:23:25 +05:30
### All tiers
2021-04-17 20:07:23 +05:30
2021-06-08 01:23:25 +05:30
Merge requests which have run security scans let you know that the generated
2022-04-04 11:22:00 +05:30
reports are available to download. To download a report, select
**Download results**, and select the desired report.
2021-04-17 20:07:23 +05:30
2021-06-08 01:23:25 +05:30
![Security widget ](img/security_widget_v13_7.png )
2019-07-31 22:56:46 +05:30
2021-06-08 01:23:25 +05:30
### Ultimate
2019-07-31 22:56:46 +05:30
2023-07-09 08:55:56 +05:30
A merge request contains a security widget which displays a summary of the _new_ results. New results are determined by comparing the findings of the merge request against the findings of the most recent completed pipeline (`success`, `failed` , `canceled` or `skipped` ) for the commit when the feature branch was created from the target branch.
2019-12-04 20:38:33 +05:30
2023-07-09 08:55:56 +05:30
If security scans have not run for the completed pipeline in the target branch when the feature branch was created, there is no base for comparison. The vulnerabilities from the merge request findings are listed as new in the merge request security widget. We recommend you run a scan of the `default` (target) branch before enabling feature branch scans for your developers.
2021-01-29 00:20:46 +05:30
2022-07-23 23:45:48 +05:30
The merge request security widget displays only a subset of the vulnerabilities in the generated JSON artifact because it contains both new and existing findings.
2019-07-31 22:56:46 +05:30
2021-11-11 11:23:49 +05:30
From the merge request security widget, select **Expand** to unfold the widget, displaying any new and no longer detected (removed) findings by scan type. Select **View full report** to go directly to the **Security** tab in the latest branch pipeline.
![Security scanning results in a merge request ](img/mr_security_scanning_results_v14_3.png )
2021-01-29 00:20:46 +05:30
2021-06-08 01:23:25 +05:30
## View security scan information in the pipeline Security tab
2021-01-29 00:20:46 +05:30
2022-08-13 15:12:31 +05:30
A pipeline's security tab lists all findings in the current branch. It includes new findings introduced by this branch
and existing vulnerabilities already present when you created the branch. These results likely do not match the findings
displayed in the Merge Request security widget, as those do not include the existing vulnerabilities. Refer to [View vulnerabilities in a pipeline ](vulnerability_report/pipeline.md ) for more information.
2019-07-31 22:56:46 +05:30
2021-06-08 01:23:25 +05:30
## View security scan information in the Security Dashboard
2019-07-31 22:56:46 +05:30
2021-06-08 01:23:25 +05:30
The Security Dashboard show vulnerabilities present in a project's default branch. Data is updated every 24 hours. Vulnerability count updates resulting from any feature branches introducing new vulnerabilities that are merged to default are included after the daily data refresh.
2019-07-31 22:56:46 +05:30
2021-06-08 01:23:25 +05:30
For more details, see [Security Dashboard ](security_dashboard/index.md ).
2019-07-31 22:56:46 +05:30
2021-06-08 01:23:25 +05:30
## View security scan information in the Vulnerability Report
2020-10-24 23:57:45 +05:30
2021-06-08 01:23:25 +05:30
The vulnerability report shows the results of the last completed pipeline on the default branch. It is updated on every pipeline completion. All detected vulnerabilities are shown as well as any previous ones that are no longer detected in the latest scan. Vulnerabilities that are no longer detected may have been remediated or otherwise removed and can be marked as `Resolved` after proper verification. Vulnerabilities that are no longer detected are denoted with an icon for filtering and review.
2021-04-29 21:17:54 +05:30
2021-06-08 01:23:25 +05:30
By default, the vulnerability report does not show vulnerabilities of `dismissed` or `resolved` status so you can focus on open vulnerabilities. You can change the Status filter to see these.
2020-10-24 23:57:45 +05:30
2021-06-08 01:23:25 +05:30
[Read more about the Vulnerability report ](vulnerability_report/index.md ).
2020-10-24 23:57:45 +05:30
2020-03-13 15:44:24 +05:30
## Security approvals in merge requests
2019-10-12 21:52:04 +05:30
2022-07-16 23:28:13 +05:30
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/9928) in GitLab 12.2.
> - [Removed](https://gitlab.com/gitlab-org/gitlab/-/issues/357300) the Vulnerability-Check feature in GitLab 15.0.
2023-07-09 08:55:56 +05:30
> - [Removed](https://gitlab.com/gitlab-org/gitlab/-/issues/397067) the License-Check feature in GitLab 16.0.
2019-10-12 21:52:04 +05:30
2021-12-11 22:18:48 +05:30
You can enforce an additional approval for merge requests that would introduce one of the following
security issues:
2020-03-13 15:44:24 +05:30
2022-07-16 23:28:13 +05:30
- A security vulnerability. For more details, read [Scan result policies ](policies/scan-result-policies.md ).
2019-10-12 21:52:04 +05:30
2021-03-11 19:13:27 +05:30
## Using private Maven repositories
2020-04-22 19:07:51 +05:30
If you have a private Apache Maven repository that requires login credentials,
2021-03-11 19:13:27 +05:30
you can use the `MAVEN_CLI_OPTS` CI/CD variable
2020-04-22 19:07:51 +05:30
to pass a username and password. You can set it under your project's settings
so that your credentials aren't exposed in `.gitlab-ci.yml` .
If the username is `myuser` and the password is `verysecret` then you would
2023-03-17 16:20:25 +05:30
[set the following variable ](../../ci/variables/index.md#for-a-project )
2020-04-22 19:07:51 +05:30
under your project's settings:
2021-03-11 19:13:27 +05:30
| Type | Key | Value |
| -------- | ---------------- | ----- |
2020-04-22 19:07:51 +05:30
| Variable | `MAVEN_CLI_OPTS` | `--settings mysettings.xml -Drepository.password=verysecret -Drepository.user=myuser` |
```xml
<!-- mysettings.xml -->
< settings >
...
< servers >
< server >
< id > private_server< / id >
< username > ${private.username}< / username >
< password > ${private.password}< / password >
< / server >
< / servers >
< / settings >
```
2021-12-11 22:18:48 +05:30
## Using a custom scanning stage
2021-06-08 01:23:25 +05:30
2021-12-11 22:18:48 +05:30
When security scanning is enabled by including CI/CD templates as described in the
[Security scanning without Auto DevOps ](#security-scanning-without-auto-devops ) section, the scanning jobs
use the predefined `test` stage by default. If you specify a custom stage in your `.gitlab-ci.yml` file without
including a `test` stage, an error occurs.
2021-06-08 01:23:25 +05:30
2021-12-11 22:18:48 +05:30
For example, the following attempts to use a `unit-tests` stage:
2021-06-08 01:23:25 +05:30
2021-12-11 22:18:48 +05:30
```yaml
include:
- template: Security/Dependency-Scanning.gitlab-ci.yml
- template: Security/License-Scanning.gitlab-ci.yml
- template: Security/SAST.gitlab-ci.yml
- template: Security/Secret-Detection.gitlab-ci.yml
2021-06-08 01:23:25 +05:30
2021-12-11 22:18:48 +05:30
stages:
- unit-tests
2021-09-04 01:27:46 +05:30
2021-12-11 22:18:48 +05:30
custom job:
stage: unit-tests
script:
- echo "custom job"
```
2021-06-08 01:23:25 +05:30
2021-12-11 22:18:48 +05:30
The above `.gitlab-ci.yml` causes a linting error:
2021-06-08 01:23:25 +05:30
2021-12-11 22:18:48 +05:30
```plaintext
2023-03-04 22:38:38 +05:30
Unable to create pipeline
2021-12-11 22:18:48 +05:30
- dependency_scanning job: chosen stage does not exist; available stages are .pre
- unit-tests
- .post
```
This error appears because the `test` stage used by the security scanning jobs isn't declared in the `.gitlab-ci.yml` file.
To fix this issue, you can either:
2021-06-08 01:23:25 +05:30
2021-12-11 22:18:48 +05:30
- Add a `test` stage in your `.gitlab-ci.yml` :
2021-06-08 01:23:25 +05:30
```yaml
include:
- template: Security/Dependency-Scanning.gitlab-ci.yml
- template: Security/License-Scanning.gitlab-ci.yml
- template: Security/SAST.gitlab-ci.yml
- template: Security/Secret-Detection.gitlab-ci.yml
stages:
2021-12-11 22:18:48 +05:30
- test
- unit-tests
custom job:
stage: unit-tests
script:
- echo "custom job"
```
- Override the default stage of each security job. For example, to use a pre-defined stage named `unit-tests` :
```yaml
include:
- template: Security/Dependency-Scanning.gitlab-ci.yml
- template: Security/License-Scanning.gitlab-ci.yml
- template: Security/SAST.gitlab-ci.yml
- template: Security/Secret-Detection.gitlab-ci.yml
stages:
- unit-tests
2021-06-08 01:23:25 +05:30
dependency_scanning:
2021-12-11 22:18:48 +05:30
stage: unit-tests
2021-06-08 01:23:25 +05:30
license_scanning:
2021-12-11 22:18:48 +05:30
stage: unit-tests
2021-06-08 01:23:25 +05:30
sast:
2021-12-11 22:18:48 +05:30
stage: unit-tests
2021-06-08 01:23:25 +05:30
.secret-analyzer:
2021-12-11 22:18:48 +05:30
stage: unit-tests
custom job:
stage: unit-tests
script:
- echo "custom job"
2021-06-08 01:23:25 +05:30
```
2023-04-23 21:23:45 +05:30
For more information about overriding security jobs, see:
2021-12-11 22:18:48 +05:30
- [Overriding SAST jobs ](sast/index.md#overriding-sast-jobs ).
- [Overriding Dependency Scanning jobs ](dependency_scanning/index.md#overriding-dependency-scanning-jobs ).
- [Overriding Container Scanning jobs ](container_scanning/index.md#overriding-the-container-scanning-template ).
2022-10-11 01:57:18 +05:30
- [Overriding Secret Detection jobs ](secret_detection/index.md#configure-scan-settings ).
2023-01-13 00:05:48 +05:30
- [Overriding DAST jobs ](dast/proxy-based.md#customize-dast-settings ).
2021-12-11 22:18:48 +05:30
- [Overriding License Compliance jobs ](../compliance/license_compliance/index.md#overriding-the-template ).
All the security scanning tools define their stage, so this error can occur with all of them.
2022-06-21 17:19:12 +05:30
## Self managed installation options
For self managed installations, you can choose to run most of the GitLab security scanners even when [not connected to the internet ](offline_deployments/index.md ).
Self managed installations can also run the security scanners on a GitLab Runner [running inside OpenShift ](../../install/openshift_and_gitlab/index.md ).
2021-12-11 22:18:48 +05:30
## Security report validation
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/321918) in GitLab 13.11.
> - Schema validation message [added](https://gitlab.com/gitlab-org/gitlab/-/issues/321730) in GitLab 14.0.
2022-08-13 15:12:31 +05:30
GitLab 15.0 enforces validation of the security report artifacts before ingesting the vulnerabilities.
2021-12-11 22:18:48 +05:30
This prevents ingestion of broken vulnerability data into the database. GitLab validates the
2022-08-13 15:12:31 +05:30
artifacts against the [report schemas ](https://gitlab.com/gitlab-org/security-products/security-report-schemas/-/tree/master/dist ),
according to the schema version declared in the report.
2021-12-11 22:18:48 +05:30
2022-08-13 15:12:31 +05:30
The pipeline's **Security** tab lists any report artifacts that failed validation, and the
validation error message.
2022-07-23 23:45:48 +05:30
2022-08-13 15:12:31 +05:30
Validation depends on the schema version declared in the security report artifact:
2022-07-23 23:45:48 +05:30
2022-08-13 15:12:31 +05:30
- If your security report specifies a supported schema version, GitLab uses this version to validate.
- If your security report uses a deprecated version, GitLab attempts validation against that version and adds a deprecation warning to the validation result.
2022-08-27 11:52:29 +05:30
- If your security report uses a supported MAJOR-MINOR version of the report schema but the PATCH version doesn't match any vendored versions, GitLab attempts to validate it against latest vendored PATCH version of the schema.
- Example: security report uses version 14.1.1 but the latest vendored version is 14.1.0. GitLab would validate against schema version 14.1.0.
- If your security report uses a version that is not supported, GitLab attempts to validate it against the latest schema version available in your installation but doesn't ingest the report.
- If your security report does not specify a schema version, GitLab attempts to validate it against the latest schema version available in GitLab. Because the `version` property is required, validation always fails in this case, but other validation errors may also be present.
2022-07-23 23:45:48 +05:30
2022-08-13 15:12:31 +05:30
You can always find supported and deprecated schema versions in the [source code ](https://gitlab.com/gitlab-org/gitlab/blob/master/lib/gitlab/ci/parsers/security/validators/schema_validator.rb ).
2021-12-11 22:18:48 +05:30
## Interact with findings and vulnerabilities
You can interact with the results of the security scanning tools in several locations:
2021-06-08 01:23:25 +05:30
- [Scan information in merge requests ](#view-security-scan-information-in-merge-requests )
2023-04-23 21:23:45 +05:30
- [Project Security Dashboard ](security_dashboard/index.md#view-vulnerabilities-over-time-for-a-project )
2022-03-02 08:16:31 +05:30
- [Security pipeline tab ](security_dashboard/index.md )
2023-04-23 21:23:45 +05:30
- [Group Security Dashboard ](security_dashboard/index.md#view-vulnerabilities-over-time-for-a-group )
2022-10-11 01:57:18 +05:30
- [Security Center ](security_dashboard/index.md#security-center )
2021-06-08 01:23:25 +05:30
- [Vulnerability Report ](vulnerability_report/index.md )
- [Vulnerability Pages ](vulnerabilities/index.md )
- [Dependency List ](dependency_list/index.md )
2021-12-11 22:18:48 +05:30
For more details about which findings or vulnerabilities you can view in each of those locations,
select the respective link. Each page details the ways in which you can interact with the findings
2022-07-16 23:28:13 +05:30
and vulnerabilities. As an example, in most cases findings start out as a _detected_ status.
2021-12-11 22:18:48 +05:30
You have the option to:
2021-06-08 01:23:25 +05:30
- Change the status.
- Create an issue.
- Link it to an existing issue.
2021-09-04 01:27:46 +05:30
- [Resolve the vulnerability ](vulnerabilities/index.md#resolve-a-vulnerability ), if a solution is known.
2021-06-08 01:23:25 +05:30
2021-12-11 22:18:48 +05:30
## Security scanning configuration tips
Each GitLab security scanning tool has a default
[CI/CD configuration file ](https://gitlab.com/gitlab-org/gitlab/-/tree/master/lib/gitlab/ci/templates/Security ),
also known as a _template_ .
When customizing the configuration:
- [Include ](../../ci/yaml/index.md#include ) the scanning tool's CI/CD template. Don't _copy_ the content
of the template.
- Use the [stable ](../../development/cicd/templates.md#stable-version ) version of each template
for production workflows. The stable version changes less often, and breaking changes are only
made between major GitLab versions. The [latest ](../../development/cicd/templates.md#latest-version )
version contains the most recent changes, but may have significant changes between minor GitLab versions.
- Only override values in the template as needed. All other values are inherited from the template.
2022-03-02 08:16:31 +05:30
### Enforce scan execution
Security and compliance teams must ensure that security scans:
- Run on a regular basis for all projects.
- Can't be disabled by developers.
GitLab provides two methods of accomplishing this, each with advantages and disadvantages.
2023-04-23 21:23:45 +05:30
- [Compliance framework pipelines ](../group/compliance_frameworks.md#compliance-pipelines )
2022-03-02 08:16:31 +05:30
are recommended when:
2022-08-13 15:12:31 +05:30
- Scan execution enforcement is required for any scanner that uses a GitLab template, such as SAST IaC, DAST, Dependency Scanning,
2022-03-02 08:16:31 +05:30
License Compliance, API Fuzzing, or Coverage-guided Fuzzing.
- Scan execution enforcement is required for scanners external to GitLab.
2022-08-13 15:12:31 +05:30
- Scan execution enforcement is required for custom jobs other than security scans.
2022-03-02 08:16:31 +05:30
2022-04-04 11:22:00 +05:30
- [Scan execution policies ](policies/scan-execution-policies.md )
2022-03-02 08:16:31 +05:30
are recommended when:
2022-08-13 15:12:31 +05:30
- Scan execution enforcement is required for DAST which uses a DAST site or scan profile.
2023-01-13 00:05:48 +05:30
- Scan execution enforcement is required for SAST, Secret Detection, Dependency Scanning, or Container Scanning with project-specific
variable customizations. To accomplish this, users must create a separate security policy per project.
2022-03-02 08:16:31 +05:30
- Scans are required to run on a regular, scheduled cadence.
2022-06-21 17:19:12 +05:30
- Either solution can be used equally well when:
- Scan execution enforcement is required for SAST or Secret Detection when custom rulesets are not
used.
- Scan execution enforcement is required for Container Scanning with no project-specific variable
customizations.
2022-03-02 08:16:31 +05:30
Additional details about the differences between the two solutions are outlined below:
| | Compliance Framework Pipelines | Scan Execution Policies |
| ------ | ------ | ------ |
2023-01-13 00:05:48 +05:30
| **Flexibility** | Supports anything that can be done in a CI file. | Limited to only the items for which GitLab has explicitly added support. DAST, SAST, Secret Detection, Dependency Scanning, and Container Scanning scans are supported. |
2022-03-02 08:16:31 +05:30
| **Usability** | Requires knowledge of CI YAML. | Follows a `rules` and `actions` -based YAML structure. |
2023-04-23 21:23:45 +05:30
| **Inclusion in CI pipeline** | The compliance pipeline is executed instead of the project's `.gitlab-ci.yml` file. To include the project's `.gitlab-ci.yml` file, use an `include` statement. Defined variables aren't allowed to be overwritten by the included project's YAML file. | Forced inclusion of a new job into the CI pipeline. DAST jobs that must be customized on a per-project basis can have project-level Site Profiles and Scan Profiles defined. To ensure separation of duties, these profiles are immutable when referenced in a scan execution policy. All jobs can be customized as part of the security policy itself with the same variables that are usually available to the CI job. |
2022-03-02 08:16:31 +05:30
| **Schedulable** | Can be scheduled through a scheduled pipeline on the group. | Can be scheduled natively through the policy configuration itself. |
| **Separation of Duties** | Only group owners can create compliance framework labels. Only project owners can apply compliance framework labels to projects. The ability to make or approve changes to the compliance pipeline definition is limited to individuals who are explicitly given access to the project that contains the compliance pipeline. | Only project owners can define a linked security policy project. The ability to make or approve changes to security policies is limited to individuals who are explicitly given access to the security policy project. |
| **Ability to apply one standard to multiple projects** | The same compliance framework label can be applied to multiple projects inside a group. | The same security policy project can be used for multiple projects across GitLab with no requirement of being located in the same group. |
Feedback is welcome on our vision for [unifying the user experience for these two features ](https://gitlab.com/groups/gitlab-org/-/epics/7312 )
2019-12-26 22:10:19 +05:30
## Troubleshooting
2019-10-12 21:52:04 +05:30
2022-08-13 15:12:31 +05:30
<!-- NOTE: The below subsection(`### Secure job failing with exit code 1`) documentation URL is referred in the [/gitlab-org/security-products/analyzers/command ](https://gitlab.com/gitlab-org/security-products/analyzers/command/-/blob/main/command.go#L19 ) repository. If this section/subsection changes, please ensure to update the corresponding URL in the mentioned repository.
-->
2022-11-25 23:54:43 +05:30
2021-11-11 11:23:49 +05:30
### Secure job failing with exit code 1
2022-10-11 01:57:18 +05:30
WARNING:
Debug logging can be a serious security risk. The output may contain the content of
environment variables and other secrets available to the job. The output is uploaded
to the GitLab server and visible in job logs.
2021-11-11 11:23:49 +05:30
If a Secure job is failing and it's unclear why, add `SECURE_LOG_LEVEL: "debug"` as a global CI/CD variable for
more verbose output that is helpful for troubleshooting.
```yaml
variables:
SECURE_LOG_LEVEL: "debug"
```
2021-09-04 01:27:46 +05:30
### Outdated security reports
2021-12-11 22:18:48 +05:30
When a security report generated for a merge request becomes outdated, the merge request shows a
warning message in the security widget and prompts you to take an appropriate action.
2021-09-04 01:27:46 +05:30
This can happen in two scenarios:
- Your [source branch is behind the target branch ](#source-branch-is-behind-the-target-branch ).
- The [target branch security report is out of date ](#target-branch-security-report-is-out-of-date ).
#### Source branch is behind the target branch
2021-12-11 22:18:48 +05:30
A security report can be out of date when the most recent common ancestor commit between the
target branch and the source branch is not the most recent commit on the target branch.
2021-09-04 01:27:46 +05:30
2021-12-11 22:18:48 +05:30
To fix this issue, rebase or merge to incorporate the changes from the target branch.
2021-09-04 01:27:46 +05:30
![Incorporate target branch changes ](img/outdated_report_branch_v12_9.png )
#### Target branch security report is out of date
2021-12-11 22:18:48 +05:30
This can happen for many reasons, including failed jobs or new advisories. When the merge request
shows that a security report is out of date, you must run a new pipeline on the target branch.
Select **new pipeline** to run a new pipeline.
2021-09-04 01:27:46 +05:30
![Run a new pipeline ](img/outdated_report_pipeline_v12_9.png )
2021-01-03 14:25:43 +05:30
### Getting warning messages `… report.json: no matching files`
2022-10-11 01:57:18 +05:30
WARNING:
Debug logging can be a serious security risk. The output may contain the content of
environment variables and other secrets available to the job. The output is uploaded
to the GitLab server and visible in job logs.
2023-06-20 00:43:36 +05:30
This message is often followed by the [error `No files to upload` ](../../ci/jobs/job_artifacts_troubleshooting.md#error-message-no-files-to-upload ),
2021-12-11 22:18:48 +05:30
and preceded by other errors or warnings that indicate why the JSON report wasn't generated. Check
the entire job log for such messages. If you don't find these messages, retry the failed job after
2023-03-17 16:20:25 +05:30
setting `SECURE_LOG_LEVEL: "debug"` as a [custom CI/CD variable ](../../ci/variables/index.md#for-a-project ).
2021-12-11 22:18:48 +05:30
This provides extra information to investigate further.
2021-01-03 14:25:43 +05:30
2020-05-24 23:13:21 +05:30
### Getting error message `sast job: config key may not be used with 'rules': only/except`
2021-09-30 23:02:18 +05:30
When [including ](../../ci/yaml/index.md#includetemplate ) a `.gitlab-ci.yml` template
2021-09-04 01:27:46 +05:30
like [`SAST.gitlab-ci.yml` ](https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Security/SAST.gitlab-ci.yml ),
2020-05-24 23:13:21 +05:30
the following error may occur, depending on your GitLab CI/CD configuration:
```plaintext
2023-03-04 22:38:38 +05:30
Unable to create pipeline
2020-05-24 23:13:21 +05:30
jobs:sast config key may not be used with `rules` : only/except
```
This error appears when the included job's `rules` configuration has been [overridden ](sast/index.md#overriding-sast-jobs )
2021-09-30 23:02:18 +05:30
with [the deprecated `only` or `except` syntax. ](../../ci/yaml/index.md#only--except )
2020-05-24 23:13:21 +05:30
To fix this issue, you must either:
- [Transition your `only/except` syntax to `rules` ](#transitioning-your-onlyexcept-syntax-to-rules ).
- (Temporarily) [Pin your templates to the deprecated versions ](#pin-your-templates-to-the-deprecated-versions )
2023-04-23 21:23:45 +05:30
For more information, see [Overriding SAST jobs ](sast/index.md#overriding-sast-jobs ).
2020-05-24 23:13:21 +05:30
#### Transitioning your `only/except` syntax to `rules`
When overriding the template to control job execution, previous instances of
2021-09-30 23:02:18 +05:30
[`only` or `except` ](../../ci/yaml/index.md#only--except ) are no longer compatible
and must be transitioned to [the `rules` syntax ](../../ci/yaml/index.md#rules ).
2020-05-24 23:13:21 +05:30
2022-07-23 23:45:48 +05:30
If your override is aimed at limiting jobs to only run on `main` , the previous syntax
2020-05-24 23:13:21 +05:30
would look similar to:
```yaml
include:
2021-01-03 14:25:43 +05:30
- template: Security/SAST.gitlab-ci.yml
2020-05-24 23:13:21 +05:30
2022-07-23 23:45:48 +05:30
# Ensure that the scanning is only executed on main or merge requests
2020-05-24 23:13:21 +05:30
spotbugs-sast:
only:
refs:
2022-07-23 23:45:48 +05:30
- main
2020-05-24 23:13:21 +05:30
- merge_requests
```
To transition the above configuration to the new `rules` syntax, the override
would be written as follows:
```yaml
include:
2021-01-03 14:25:43 +05:30
- template: Security/SAST.gitlab-ci.yml
2020-05-24 23:13:21 +05:30
2022-07-23 23:45:48 +05:30
# Ensure that the scanning is only executed on main or merge requests
2020-05-24 23:13:21 +05:30
spotbugs-sast:
rules:
2022-07-23 23:45:48 +05:30
- if: $CI_COMMIT_BRANCH == "main"
2020-05-24 23:13:21 +05:30
- if: $CI_MERGE_REQUEST_ID
```
If your override is aimed at limiting jobs to only run on branches, not tags,
it would look similar to:
```yaml
include:
2021-01-03 14:25:43 +05:30
- template: Security/SAST.gitlab-ci.yml
2020-05-24 23:13:21 +05:30
# Ensure that the scanning is not executed on tags
spotbugs-sast:
except:
- tags
```
To transition to the new `rules` syntax, the override would be rewritten as:
```yaml
include:
2021-01-03 14:25:43 +05:30
- template: Security/SAST.gitlab-ci.yml
2020-05-24 23:13:21 +05:30
# Ensure that the scanning is not executed on tags
spotbugs-sast:
rules:
- if: $CI_COMMIT_TAG == null
```
2023-04-23 21:23:45 +05:30
For more information, see [`rules` ](../../ci/yaml/index.md#rules ).
2020-05-24 23:13:21 +05:30
#### Pin your templates to the deprecated versions
2021-09-30 23:02:18 +05:30
To ensure the latest support, we **strongly** recommend that you migrate to [`rules` ](../../ci/yaml/index.md#rules ).
2020-05-24 23:13:21 +05:30
If you're unable to immediately update your CI configuration, there are several workarounds that
involve pinning to the previous template versions, for example:
```yaml
include:
remote: 'https://gitlab.com/gitlab-org/gitlab/-/raw/12-10-stable-ee/lib/gitlab/ci/templates/Security/SAST.gitlab-ci.yml'
```
Additionally, we provide a dedicated project containing the versioned legacy templates.
2022-07-16 23:28:13 +05:30
This can be used for offline setups or for anyone wishing to use [Auto DevOps ](../../topics/autodevops/index.md ).
2020-05-24 23:13:21 +05:30
Instructions are available in the [legacy template project ](https://gitlab.com/gitlab-org/auto-devops-v12-10 ).
2021-01-29 00:20:46 +05:30
2023-03-04 22:38:38 +05:30
#### Vulnerabilities are found, but the job succeeds. How can you have a pipeline fail instead?
2021-01-29 00:20:46 +05:30
2021-12-11 22:18:48 +05:30
In these circumstances, that the job succeeds is the default behavior. The job's status indicates
success or failure of the analyzer itself. Analyzer results are displayed in the
[job logs ](../../ci/jobs/index.md#expand-and-collapse-job-log-sections ),
[Merge Request widget ](#view-security-scan-information-in-merge-requests ) or
[Security Dashboard ](security_dashboard/index.md ).
2021-01-29 00:20:46 +05:30
2021-03-11 19:13:27 +05:30
### Error: job `is used for configuration only, and its script should not be executed`
2021-01-29 00:20:46 +05:30
2021-03-11 19:13:27 +05:30
[Changes made in GitLab 13.4 ](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/41260 )
to the `Security/Dependency-Scanning.gitlab-ci.yml` and `Security/SAST.gitlab-ci.yml`
templates mean that if you enable the `sast` or `dependency_scanning` jobs by setting the `rules` attribute,
2021-12-11 22:18:48 +05:30
they fail with the error `(job) is used for configuration only, and its script should not be executed` .
2021-01-29 00:20:46 +05:30
2021-03-11 19:13:27 +05:30
The `sast` or `dependency_scanning` stanzas can be used to make changes to all SAST or Dependency Scanning,
such as changing `variables` or the `stage` , but they cannot be used to define shared `rules` .
2021-01-29 00:20:46 +05:30
2021-03-11 19:13:27 +05:30
There [is an issue open to improve extendability ](https://gitlab.com/gitlab-org/gitlab/-/issues/218444 ).
2023-04-23 21:23:45 +05:30
You can upvote the issue to help with prioritization, and
2021-03-11 19:13:27 +05:30
[contributions are welcomed ](https://about.gitlab.com/community/contribute/ ).
2022-03-02 08:16:31 +05:30
### Empty Vulnerability Report, Dependency List, License list pages
If the pipeline has manual steps with a job that has the `allow_failure: false` option, and this job is not finished,
GitLab can't populate listed pages with the data from security reports.
In this case, [the Vulnerability Report ](vulnerability_report/index.md ), [the Dependency List ](dependency_list/index.md ),
2023-04-23 21:23:45 +05:30
and [the License list ](../compliance/license_list.md ) pages are empty.
2022-03-02 08:16:31 +05:30
These security pages can be populated by running the jobs from the manual step of the pipeline.
There is [an issue open to handle this scenario ](https://gitlab.com/gitlab-org/gitlab/-/issues/346843 ).
2023-04-23 21:23:45 +05:30
You can upvote the issue to help with prioritization, and
2022-03-02 08:16:31 +05:30
[contributions are welcomed ](https://about.gitlab.com/community/contribute/ ).