Loading
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::ProvisionAgenticScanTriggerServicereturns the project's activesecurity_policytrigger, 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::SyncAutonomousServiceAccountRoleServicereturnsexcess_access:, andAi::RunFlowScheduleWorkerreads it instead of computing it.- The business logic flow lists
security_policyin 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')- The first call creates the trigger (
event_types: [10]) and a service account at the flow account's role; audit events includeservice_account_createdandflow_trigger_created. - 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
- Split from Dispatch scheduled business logic scans from sc... (!257271 - merged) on review. Depends on Add security_policy event type to flow triggers (!269275 - merged).
- Design: https://gitlab.com/gitlab-org/gitlab/-/work_items/638792+. Issue: https://gitlab.com/gitlab-org/gitlab/-/work_items/630266+
Edited by Meir Benayoun