Gate flow workload variables on owner opt-in and allowlist
What does this MR do and why?
Makes project and group CI/CD variables available to flow workloads when both gates are met:
- The owner selected Allow in GitLab Duo Agent Platform workloads on the variable (MR 4a/4b).
- The key is listed under
variablesin.gitlab/duo/agent-config.yml(MR 2).
Gitlab::Ci::Variables::Builder::{Project,Group}filter requested keys with newallowed_in_workloadsscopes;Builder::Instancereturns nothing for workload requests.Ai::DuoWorkflows::StartWorkflowServicepasses the allowlisted keys (minus reserved workload names) to the workload and unmasks them in the job.- Masking, file type, environment scope and protected-ref behavior (MR 3) are preserved.
- Documents the setting and the
variableskey.
Behavior change for flow triggers: Ai::FlowTriggers::RunService already passed a flow definition's variables without any opt-in. Those variables are now only resolved when the owner selected the checkbox, and instance variables are no longer resolved (Changelog: changed commit, documented).
The first commit is MR 2 and disappears after MR 2 merges and this branch is rebased.
References
| # | Merge request | Base |
|---|---|---|
| 1 | !254470 (merged) Add columns | master |
| 2 | !254471 (merged) Parse variables in agent-config.yml |
master |
| 3 | !254472 Persist source ref protection | 1 |
| 4a | !254473 Expose allowed_in_workloads on APIs |
1 |
| 4b | !254474 Settings checkbox | 4a |
| 5 | !252729 Gate workload variables (feature becomes active) | 3, needs 2 |
Screenshots or screen recordings
Not applicable: no UI change (see MR 4b).
How to set up and validate locally
-
In a project, create variable
MY_API_TOKENand select Allow in GitLab Duo Agent Platform workloads. CreateOTHER_TOKENwithout it. -
On the default branch, add to
.gitlab/duo/agent-config.yml:variables: - MY_API_TOKEN - OTHER_TOKEN -
Run a flow and open its CI job log (
printenvin a custom flow step, or inspect the job's variables):MY_API_TOKENis present,OTHER_TOKENis not. -
Remove
MY_API_TOKENfrom the YAML and rerun: it is absent. -
Mark
MY_API_TOKENas Protect variable. Start the flow from an unprotected branch: absent. From a protected branch: present. -
Create an instance variable (Admin > CI/CD > Variables) and list it in the YAML: never present.
-
Mark
MY_API_TOKENmasked: its value shows as[MASKED]in the job log.
Database queries
CI database. allowed_in_workloads is a boolean filter applied after the existing unique indexes; no new index. Rows are bounded by the project or group hierarchy and the 50-key maximum. Query plans: pending (postgres.ai links to follow).
Project variables (index_ci_variables_on_project_id_and_key_and_environment_scope; protected-ref variant omits "protected" = FALSE):
SELECT "ci_variables".* FROM "ci_variables"
WHERE "ci_variables"."project_id" = 278964
AND "ci_variables"."protected" = FALSE
AND (environment_scope IN ('*', 'production')
OR 'production' LIKE REPLACE(REPLACE(REPLACE(environment_scope, '%', '\%'), '_', '\_'), '*', '%'))
AND "ci_variables"."allowed_in_workloads" = TRUE
AND "ci_variables"."key" IN ('ALLOWED_ONE', 'ALLOWED_TWO')
ORDER BY CASE environment_scope WHEN '*' THEN 0 WHEN 'production' THEN 2 ELSE 1 END ASC;Group variables (index_ci_group_variables_on_group_id_and_key_and_environment; group_id IN is the existing self-and-ancestors list):
SELECT "ci_group_variables".* FROM "ci_group_variables"
WHERE "ci_group_variables"."group_id" IN (9970)
AND "ci_group_variables"."protected" = FALSE
AND (environment_scope IN ('*', 'production')
OR 'production' LIKE REPLACE(REPLACE(REPLACE(environment_scope, '%', '\%'), '_', '\_'), '*', '%'))
AND "ci_group_variables"."allowed_in_workloads" = TRUE
AND "ci_group_variables"."key" IN ('ALLOWED_ONE', 'ALLOWED_TWO')
ORDER BY CASE environment_scope WHEN '*' THEN 0 WHEN 'production' THEN 2 ELSE 1 END ASC;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.