Secret Detection
- Tier: Ultimate
- Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated
Getting Started
Download the Solution Component
- Obtain the invitation code from your account team.
- Download the solution component from the solution component webstore by using your invitation code.
Prerequisites
- GitLab Ultimate tier
- Administrator access to your GitLab instance or group
- Secret Detection enabled for your projects
Configure Secret Detection Custom Rules
This guide helps you implement Secret Detection Policy at the global level. This solution extends the default secret detection rules to include the detection of PII data elements like Social Security Number and passwords in clear text. The rule extension is considered as the remote ruleset.
Configure Custom Ruleset
You can set up custom ruleset with the following steps
- Create a top level group
Secret Detection
- From your downloaded component, copy the project
Secret Detection Custom Ruleset
into your newly createdSecret Detection
group.
This custom ruleset extends GitLab pre-build rules. The extension can detect and alert secrets including:
- PII data elements: social security number
- Passwords in plain text.
Custom Ruleset File
The custom ruleset is defined in .gitlab/secret-detection-ruleset.toml
The rules can be defined using regex
PII Data Element Detection
The extended rules for PII data element detection
[[rules]]
id = "ssn"
description = "Social Security Number"
regex = "[0-9]{3}-[0-9]{2}-[0-9]{4}"
tags = ["ssn", "social-security-number"]
keywords = ["ssn"]
Password in Plain Text
The extended rules for password in plain text
[[rules]]
id = "password-secret"
description = "Detect secrets starting with Password or PASSWORD"
regex = "(?i)Password[:=]\\s*['\"]?[^'\"]+['\"]?"
tags = ["password", "secret"]
keywords = ["password", "PASSWORD"]
Access Defined Custom Ruleset
In order to access the custom ruleset, you need to create a group access token which generates a bot user. The bot user can be used to authenticate and access the custom ruleset by any projects that run the secret detection with the global policy.
To set the access and authentication, follow these steps:
- Create a group token: In the group
Secret Detection
, create a group access tokenSecret Detection Group Token
underSettings
menu option, give the tokenreporter
role withread_repository
access
- Create a group variable: Copy the token value and store safely. Add a group variable under
Settings
menu option calledSECRET_DETECTION_GROUP_TOKEN
as the key with the token value. - Obtain the group token bot user: In the same group, navigate to
manage
menu option to selectmember
and look up corresponding bot user for the group access tokenSecrete Detection Group Token
, copy the value representing the bot user for the group in the format of@group_[group_id]_bot_[random_number]
Implementation Guide
This guide covers the steps to configure the policy to run secret detection for all projects using centralized custom ruleset.
Configure Secret Detection Policy
To run secret detection automatically in the pipeline as the enforced global policy, set up the policy at the highest level, in this case the top group level. Follow the steps outlined below to create the new secret detection policy.
Create the policy: In the same group
Secret Detection
, navigate to that group’s Secure > Policies page.Click on New policy.
Select Scan execution policy.
Configure the policy: Give the policy name
Secret Detection Policy
and enter a description and selectSecret Detection
scanSet the Policy scope by selecting either “All projects in this group” (and optionally set exceptions) or “Specific projects” (and select the projects from the dropdown).
Under the Actions section, select “Dependency scanning” instead of “Secret Detection” (default).
Under the Conditions section, you can optionally change “Triggers:” to “Schedules:” if you want to run the scan on a schedule instead of at every commit.
Setup access to the custom ruleset: add CI variables with the value of the bot user, group variable and the URL of the custom ruleset project.
Since the custom ruleset is hosted in a different project and considered as the remote ruleset, the
SECRET_DETECTION_RULESET_GIT_REFERENCE
must be used.variables: SECRET_DETECTION_RULESET_GIT_REFERENCE: "group_[group_id]_bot_[random_number]:$SECRET_DETECTION_GROUP_TOKEN@[custom ruleset project URL]" SECRET_DETECTION_HISTORIC_SCAN: "true"
The UI configuration is shown in this screen:
For detailed information about this CI variable, see this document for details.
- Click Create policy.
Complete Policy Configuration
Upon creating the policy, for reference, here is the complete policy configuration:
---
scan_execution_policy:
- name: Scan Execution for Secret Detection with Custom Rules
description: ''
enabled: true
policy_scope:
projects:
excluding: []
rules:
- type: pipeline
branches:
- "*"
actions:
- scan: secret_detection
variables:
SECRET_DETECTION_RULESET_GIT_REFERENCE: "@group_[group_id]_bot_[random_number]:$SECRET_DETECTION_GROUP_TOKEN@gitlab.com/example_group/secret-detection/secret-detection-custom-ruleset"
SECRET_DETECTION_HISTORIC_SCAN: 'true'
skip_ci:
allowed: true
allowlist:
users: []
approval_policy: []
How It Works
Once the policy is running. all the projects associated with the global policy will have the secret detect
job will run automatically in the pipeline as secret_detection_0
job.
Secrets will be detected and surfaced. If there is a merge request, the net new secrets will be displayed in the MR widget. If it is the default branch merged, they will be shown in the security vulnerability report as following:
An example password in clear is shown below:
Troubleshooting
Policy not applying
Ensure the security policy project you modified is correctly linked to your group. See Link to a security policy project for more.
Docs
Edit this page to fix an error or add an improvement in a merge request.
Create an issue to suggest an improvement to this page.
Product
Create an issue if there's something you don't like about this feature.
Propose functionality by submitting a feature request.
Feature availability and product trials
View pricing to see all GitLab tiers and features, or to upgrade.
Try GitLab for free with access to all features for 30 days.
Get help
If you didn't find what you were looking for, search the docs.
If you want help with something specific and could use community support, post on the GitLab forum.
For problems setting up or using this feature (depending on your GitLab subscription).
Request support