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

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:

  1. Run GDK with GITLAB_SIMULATE_SAAS=1, and give the gitlab-duo group an Ultimate plan.

  2. In a Rails console, turn on the flag for the group:

    Feature.enable(:bl_security_analyzer, Group.find_by_full_path('gitlab-duo'))
  3. In gitlab-duo/test, go to Settings > CI/CD > Variables. Add an unprotected variable BL_SCAN_EFFORT with the value high.

  4. Create a merge request in gitlab-duo/test that adds or changes a file.

  5. 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
      }'
  6. 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 metadata key. Its content has scan_effort set to high, and target_files lists the files the merge request changed. The content is the same as on master.

  7. Start a Developer flow session (developer/v1) the same way. Its job has no agent_platform_bl_security_context envelope.

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 Wanderson Policarpo

Merge request reports

Loading
Loading