Move BL security context to a foundational flow resolver
What does this MR do and why?
The Business Logic Security Scan was the last foundational flow that built its extra context inside BuildAdditionalContextService, behind a workflow_definition check. Every other flow keeps its context in a Context module beside its definition. This MR moves the BL security scan context there too, so the service no longer has flow-specific code.
The BL security scan reads the project's CI/CD variables, the goal (a merge request IID) and the branch the run checks out. It gets them from the runtime context that !268547 (merged) passes to every resolver.
The BL security envelope no longer sends a metadata version, the same as the other flow-owned envelopes. There is only one version of this context today, and the AI Gateway uses 1.0.0 when an envelope has no version. We can add versioning when a second version is necessary.
The scan sends the same dials as before, under the same agent_platform_bl_security_context category. !263659 (merged) already reserves that category, so callers still cannot spoof it.
References
- Stacked on !268547 (merged)
Screenshots or screen recordings
Not applicable. There is no UI change.
How to set up and validate locally
The BL security scan is available only on GitLab.com, with Ultimate, behind the bl_security_analyzer flag. In GDK:
-
Run GDK with
GITLAB_SIMULATE_SAAS=1, and give thegitlab-duogroup an Ultimate plan. -
In a Rails console, turn on the flag for the group:
Feature.enable(:bl_security_analyzer, Group.find_by_full_path('gitlab-duo')) -
In
gitlab-duo/test, go to Settings > CI/CD > Variables. Add an unprotected variableBL_SCAN_EFFORTwith the valuehigh. -
Create a merge request in
gitlab-duo/testthat adds or changes a file. -
Start the scan for that merge request:
curl --request POST "http://gdk.test:3000/api/v4/ai/duo_workflows/workflows" \ --header "PRIVATE-TOKEN: <your_token>" \ --header "Content-Type: application/json" \ --data '{ "project_id": "<gitlab-duo/test project ID>", "workflow_definition": "bl_security/experimental", "goal": "<merge request IID>", "start_workflow": true }' -
Open the session's CI job. In a Rails console, read the BL security envelope that the job got:
build = Ci::Build.find(<job_id>) context = Gitlab::Json.parse(build.variables.to_hash['DUO_WORKFLOW_ADDITIONAL_CONTEXT_CONTENT']) context.find { |c| c['Category'] == 'agent_platform_bl_security_context' }The envelope has no
metadatakey. Its content hasscan_effortset tohigh, andtarget_fileslists the files the merge request changed. The content is the same as onmaster. -
Start a Developer flow session (
developer/v1) the same way. Its job has noagent_platform_bl_security_contextenvelope.
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.