Published on: March 13, 2023
5 min read
Learn step-by-step how to process detected vulnerabilities and spawn merge request approval rules from critical vulnerabilities.
GitLab Premium features several security scanners you can leverage to detect vulnerabilities. However, when you incorporate the scanners into your project pipelines and the scanning job succeeds, you'll want feedback on whether you are introducing vulnerabilities into the codebase. This tutorial provides a mechanism to require a merge request approval if a scanner available on GitLab Premium finds a critical vulnerability.
While this tutorial shows how to add some process around actioning vulnerabilities, we have more robust, governed, and user-friendly functionality available in GitLab Ultimate called a Scan Result Policy. The solution outlined here does not seek to replace that functionality, but rather augment the scan results available in GitLab Premium. If you are an Ultimate user or if you want to compare the two experiences, then you should check out this video introduction instead.
Learn how to do the following:
This is how the GitLab CI pipeline of our test project looks visually. Below we will break down the individual stages.
Add the following to your .gitlab-ci.yml:
secret_detection:
artifacts:
paths:
- gl-secret-detection-report.json
process_secret_detection:
image: python:3.7-alpine3.9
stage: process_vulns
needs:
- job: secret_detection
artifacts: true
before_script:
pip install python-gitlab
script:
- python3 process_vulns.py gl-secret-detection-report.json $PROJECT_ACCESS_TOKEN $CI_PROJECT_ID $CI_COMMIT_SHA
A breakdown of what is going on above:
To create a project access token:
[The process_vulns.py script can be found here.]((https://gitlab.com/gl-demo-premium-smorris/secure-premium-app/-/blob/main/process_vulns.py) Copy that file into your project.
The goal of this script is to require approval from an author (or group of authors) if a critical vulnerability is found.
Note: You will need to change the user ID in the process_vulns.py to match the user ID of your designated Approver at your organization.
The following is a breakdown of what the script is doing:
Run the pipeline and voila! Your pipeline now requires approvers if a critical vulnerability is found!
Watch a video demonstration of how to action security vulnerabilities in GitLab Premium, presented by Sam Morris:
Cover image by Christopher Burns on Unsplash.
50%+ of the Fortune 100 trust GitLab
See what your team can do with the intelligent
DevSecOps platform.