- Design and implementation details
Today’s secret detection feature is built around containerized scans of repositories within a pipeline context. This feature is quite limited compared to where leaks or compromised tokens may appear and should be expanded to include a much wider scope.
Secret detection as a platform-wide experience encompasses detection across platform features with high risk of secret leakage, including repository contents, job logs, and project management features such as issues, epics, and MRs.
- Support asynchronous secret detection for:
- push events
- issuable creation
- issuable updates
- issuable comments
The current proposal is limited to asynchronous detection and alerting only.
Blocking secrets on push events is high-risk to a critical path and would require extensive performance profiling before implementing. See a recent example of a customer incident where this was attempted.
Secret revocation and rotation is also beyond the scope of this new capability.
Scanned object types beyond the scope of this MVC include:
- Media types (JPEGs, PDFs,…)
To achieve scalable secret detection for a variety of domain objects a dedicated
scanning service must be created and deployed alongside the GitLab distribution.
This is referred to as the
This service must be:
- highly performant
- horizontally scalable
- generic in domain object scanning capability
Platform-wide secret detection should be enabled by-default on GitLab SaaS as well as self-managed instances.
- Secure authentication to GitLab.com infrastructure
- Performance of scanning against large blobs
- Performance of scanning against volume of domain objects (such as push frequency)
The critical paths as outlined under goals above cover two major object types: Git blobs (corresponding to push events) and arbitrary text blobs.
The detection flow for push events relies on subscribing to the PostReceive hook
and enqueueing Sidekiq requests to the
service fetches enqueued refs, queries Gitaly for the ref blob contents, scans
the commit contents, and notifies the Rails application when a secret is detected.
See Push event detection flow for sequence.
The detection flow for arbitrary text blobs, such as issue comments, relies on
Notes::PostProcessService (or equivalent service) and enqueueing
Sidekiq requests to the
SecretScanningService to process the text blob by object type
and primary key of domain object. The
SecretScanningService service fetches the
relevant text blob, scans the contents, and notifies the Rails application when a secret
The detection flow for job logs requires processing the log during archive to object storage. See discussion in this issue around scanning during streaming and the added complexity in buffering lookbacks for arbitrary trace chunks.
In any case of detection, the Rails application manually creates a vulnerability
Vulnerabilities::ManuallyCreateService to surface the finding within the
existing Vulnerability Management UI.
See technical discovery for further background exploration.
The existing Secret Detection configuration covers ~100 rules across a variety of platforms. To reduce total cost of execution and likelihood of false positives the dedicated service targets only well-defined tokens. A well-defined token is defined as a token with a precise definition, most often a fixed substring prefix or suffix and fixed length.
Token types to identify in order of importance:
- Well-defined GitLab tokens (including Personal Access Tokens and Pipeline Trigger Tokens)
- Verified Partner tokens (including AWS)
- Remainder tokens currently included in Secret Detection CI configuration
Our current secret detection offering utilizes Gitleaks
for all secret scanning within pipeline contexts. By using its
we can scan arbitrary text blobs outside of a repository context and continue to
utilize it for non-pipeline scanning.
Given our existing familiarity with the tool and its extensibility, it should remain our engine of choice. Changes to the detection engine are out of scope unless benchmarking unveils performance concerns.
- Requirements definition for detection coverage and actions
- PoC of secret scanning service
- gRPC commit retrieval from Gitaly
- blob scanning
- benchmarking of issuables, comments, job logs and blobs to gain confidence that the total costs will be viable
- Implementation of secret scanning service MVC (targeting individual commits)
- Security and readiness review
- Deployment and monitoring
- Implementation of secret scanning service MVC (targeting arbitrary text blobs)
- Deployment and monitoring
- High priority domain object rollout (priority
- Issuable comments
- Issuable bodies
- Job logs