Refuse local runs for hosted-runner-only flows

Problem

A foundational flow can be marked as runnable only through GitLab-hosted infrastructure, for example because it needs to read files from a merge request rather than a local checkout, or because its results must land in GitLab (such as the Vulnerability Report). One of the two ways a flow run can be started does not check that restriction.

Because of that gap, a flow built to run only on GitLab-hosted infrastructure could still be started on a user's own machine, producing output that never reaches GitLab and consuming resources nobody asked for.

Change

Make the unchecked path refuse a run when the flow is marked hosted-runner-only, behind a feature flag. See the linked confidential issue for full mechanism detail.

Impact

Situation Before this MR After this MR
Flow has no hosted-runner-only restriction Works both ways Unchanged
Flow is hosted-runner-only; started the already-checked way Already runs on GitLab-hosted infrastructure Unchanged
Flow is hosted-runner-only; started the other way Runs on the user's own machine (the gap this MR closes) Refused, with a message pointing the user at GitLab instead

This is shared code: every flow type that can be started directly by a user goes through this one authorizer class. Only flows that opt in to the hosted-runner-only restriction are affected; today, that's BLSA.

Context

Found while reviewing why a flow built to run only on GitLab-hosted infrastructure could still be started elsewhere. An earlier version of this MR took a different, broader approach; a reviewer found it risked affecting flows it was never meant to touch. This version is narrower: it only acts on the specific restriction a flow has already opted into. Full root-cause writeup and design discussion are in the linked confidential issue. This description stays generic on purpose; gitlab-org/gitlab is public.

Testing

Spec additions in flow_execution_authorizer_spec.rb cover: a hosted-runner-only flow being refused on both project and group containers, the background (automatic) path being unaffected, and the feature flag reverting to today's behavior when disabled.

Before this went to review, a 5-reviewer adversarial panel (surface/API shape, simpler-design alternatives, contract and backward-compatibility, red-checked test coverage, and a claim audit of this description and the commit messages) went over the diff independently. One real finding came back: the refusal message pointed users toward configuring a runner, which isn't the actual fix for a client-side call. Reworded to point at the real fix (run it in GitLab, not an IDE/CLI session) and re-verified. No other issues survived.

End-to-end verification, driven through the same production API endpoint a CLI/IDE client actually calls (POST /api/v4/ai/duo_workflows/workflows, no start_workflow / item_consumer_id — the request shape a real client-executed call sends), in a GDK pinned to this MR's exact head commit:

Scenario Request Result
Hosted-runner-only flow, client-executed, flag on BLSA flow, no hosted runner in the loop 403 Forbidden — "This flow can only be run in GitLab, not from an IDE or CLI session"
Same request, flag off identical 201 Created — workflow created normally
Flag back on, same request repeated identical 403 Forbidden again — reproducible, not a one-off
Flow without the restriction, flag on a flow that never opted into hosted-runner-only, same project 201 Created — unaffected

This confirms both halves end to end: the flag genuinely gates the refusal (off → allowed, on → refused, on again → refused), and the fix only touches flows that opted into the restriction — everything else passes through unchanged.

Also re-verified in the same sandbox: bundle exec rspec on the changed spec file — 44 examples, 0 failures, including a red-check (temporarily reverting the new check and confirming the two refusal examples fail on their actual assertion, not a load error, before restoring). bundle exec rubocop on the changed file — 0 offenses.

How to reproduce the original gap

  1. Pick a flow marked to run only on GitLab-hosted infrastructure.
  2. On master (before this MR), start that flow the way described in the linked issue. It runs, but not the way it was designed to.
  3. On this branch, with the feature flag on, the same attempt is refused.

References

Edited by Meir Benayoun

Merge request reports

Loading
Loading