Add an internal endpoint for a workflow's tool access policies

What does this MR do and why?

Duo Workflow Service gets a session's tool rules from the tool_access_policies claim in its token. This MR adds a second way to get them: an internal endpoint that returns the same rules for a workflow, so DWS can load them from the instance when the token doesn't carry the claim. The DWS side is in gitlab-org/modelops/applied-ml/code-suggestions/ai-assist!7740 (merged).

  • GET /api/v4/ai/duo_workflows/workflows/:id/tool_access_policies returns allow, ask, deny and ceiling for the workflow. It only accepts requests through Workhorse, and only for the caller's own workflow, like GET /:id. The namespace comes from the workflow, not from params. An optional project_id (the session's requested project) can only make the policy stricter, the same as on the claim path. It is ignored unless the caller can read the project and it is in the workflow's root namespace.
  • The resolution moves out of ConnectionConfigService into Ai::DuoWorkflows::ToolAccessPoliciesService, so the endpoint and the claim resolve rules with the same code. The MCP pre-approvals here come from the workflow record, while the claim builds them from the request's workflow_definition and ai_catalog_item_version_id, so allow can differ when those params don't match the record. connection_config_service_spec.rb passes unchanged.
  • CI jobs get a placeholder DUO_WORKFLOW_SERVICE_TOKEN instead of a usable token. The CLI only checks that the variable is set to pick CI mode, and never uses the value. This is behind duo_workflow_ci_service_token_placeholder, a gitlab_com_derisk flag that is off by default and rolled out on GitLab.com first (#637141). Self-Managed gets the placeholder once the flag is removed.

The endpoint has no flag: it is read-only, and a flag rollback must not make DWS's request fail.

References

  • #623436

How to set up and validate locally

  1. Start a Duo session and note the workflow ID.
  2. Through Workhorse, call GET /api/v4/ai/duo_workflows/workflows/<id>/tool_access_policies with the session user's token. It returns the same lists as the session's tool_access_policies claim, when the request params match the workflow.
  3. The same call with another user's token returns 404, and a call straight to Puma returns 403.
  4. Add ?project_id=<id> for a readable project in the same group that denies another tool. That tool is added to deny.
  5. Start a flow in CI and check the job's DUO_WORKFLOW_SERVICE_TOKEN is unused. The job still runs in CI mode.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist.

Edited by Rahul Barnwal

Merge request reports

Loading
Loading