Fix secret detection scans for scheduled SEP
What does this MR do and why?
Fix secret detection scans for scheduled scan execution policies by properly passing pipeline context to ScanPipelineService.
As described in #570139, the first scheduled scan execution policy doesn't trigger historic scan as expected. This was caused by ScanPipelineService being called twice during pipeline creation:
- From
CreatePipelineService- with correctSECRET_DETECTION_HISTORIC_SCANvariable - From
ee/lib/ee/gitlab/ci/variables/builder/scan_execution_policies.rb- without pipeline context, causing the variable to be incorrectly set tofalse
This MR fixes the issue by:
- Moving secret detection variable logic from
CreatePipelineServicetoScanPipelineService - Passing
branchandpipeline_sourceparameters toScanPipelineServiceto enable proper context-aware variable calculation - Ensuring
ScanPipelineServicecan determine whether to useSECRET_DETECTION_HISTORIC_SCANorSECRET_DETECTION_LOG_OPTIONSbased on previous pipeline execution history - Updating the CI variables builder to pass pipeline context when initializing
ScanPipelineService
The fix ensures that:
- First scheduled SEP runs trigger historic scans (
SECRET_DETECTION_HISTORIC_SCAN=true) - Subsequent runs use incremental scanning with commit ranges (
SECRET_DETECTION_LOG_OPTIONS) - User-provided
SECRET_DETECTION_HISTORIC_SCANvariables are respected and not overridden
References
Closes #570139
How to set up and validate locally
- Create a scheduled scan execution policy with secret detection
- Trigger the first scheduled pipeline
- Verify that
SECRET_DETECTION_HISTORIC_SCAN=trueis set in the secret detection job - Trigger a second scheduled pipeline
- Verify that
SECRET_DETECTION_LOG_OPTIONSis set with the commit range instead
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Edited by Alan (Maciej) Paruszewski