PoC for Flexible Scan Execution Policy Trigger Conditions
What does this MR do and why?
This MR implements a proof of concept for flexible trigger conditions in Scan Execution Policies. It adds two key enhancements:
- Pipeline Source Filtering: Allows policies to be applied selectively based on pipeline source (push, web, API, merge request event, etc.)
-
Extended Branch Type Targeting: Adds two new branch types for more granular policy application:
-
target_default: Targets source branches with open merge requests to the default branch -
target_protected: Targets source branches with open merge requests to protected branches
-
These enhancements provide more precise control over when security scans are executed, allowing teams to optimize scan coverage while reducing unnecessary scans.
Implementation Details
- Added
pipeline_sourceparameter to policy evaluation methods - Extended branch type matching to support the new
target_defaultandtarget_protectedtypes - Added logic to identify source branches from open merge requests targeting specific branch types
- Updated JSON schemas to include the new branch types and pipeline source filtering options
- Added method to check if a policy applies to a specific pipeline source
References
How to set up and validate locally
-
Create or modify a scan execution policy to include the new trigger conditions:
rules: - type: pipeline branch_type: target_protected pipeline_source: including: - merge_request_event - webInsert at cursor
-
Create a merge request targeting a protected branch
-
Verify that the scan execution policy is applied correctly based on the pipeline source and branch type
Edited by Alan (Maciej) Paruszewski