Provision the security policy trigger for scheduled scans

Why

A scheduled business logic scan from a scan execution policy has no person behind it, so it runs as the project's dedicated security_policy trigger account.
This adds the service that finds or creates that trigger and its account.
Nothing calls it until Dispatch scheduled business logic scans from sc... (!257271 - merged), which runs the scan.

What changes

  • Security::SecurityOrchestrationPolicies::ProvisionAgenticScanTriggerService returns the project's active security_policy trigger, or creates it with a dedicated service account at the flow account's role.
    • It creates as the admin bot, under a lease, in one transaction, and audits both.
    • It skips trials, a flow that cannot run in the project, and an inactive trigger (a stopped trigger is not replaced).
  • Ai::FlowTriggers::SyncAutonomousServiceAccountRoleService returns excess_access:, and Ai::RunFlowScheduleWorker reads it instead of computing it.
  • The business logic flow lists security_policy in its supported events.

How to test

In a GDK in GitLab.com mode, with the business logic flow enabled in a project and the top-level group opted in to beta features, run with bin/rails runner:

project = Project.find_by_full_path('group/project')
consumer = Ai::Catalog::ItemConsumer.where(project: project).includes(:item)
  .find { |c| c.item&.foundational_flow_reference == 'bl_security/experimental' }
result = Security::SecurityOrchestrationPolicies::ProvisionAgenticScanTriggerService.new(
  project: project, params: { item_consumer: consumer, scan: 'business_logic', policy_name: 'Test' }
).execute
pp result.payload[:trigger].attributes.slice('id', 'event_types', 'active', 'autonomous_service_account_id')
  1. The first call creates the trigger (event_types: [10]) and a service account at the flow account's role; audit events include service_account_created and flow_trigger_created.
  2. A second call returns the same trigger and creates nothing.

Verified in a GDK on master 0b951a99, with this MR and the follow-up.
A cron-fired policy created the trigger and its account, ran the scan as that account, and its findings reached the vulnerability report.

Context

Edited by Meir Benayoun

Merge request reports

Loading
Loading