Allow the gitlab-autoflow audience in token exchange behind a flag

What does this MR do and why?

POST /api/v4/token_exchange can now mint tokens for the gitlab-autoflow audience, but only for users who have the token_exchange_autoflow_audience feature flag enabled. With such a token, a user can run AutoFlow workflows on Runway staging through Relay's public API (a planned glab autoflow start-workflow). This is a short-term solution until STS and Trigger provide proper authentication and authorization for AutoFlow.

The flag limits who can mint. It does NOT limit what a token can do: AutoFlow lets anyone holding one start arbitrary workflow definitions in the namespace of the token's organization (since gitlab-org/cluster-integration/gitlab-agent!4854 (merged)), and those workflows run with AutoFlow's own permissions, not the user's. That's why the flag is meant for staging.gitlab.com and a few users only.

How it behaves:

  • Without the flag, a gitlab-autoflow request gets the same 400 as an unknown audience, so for everyone else the endpoint looks exactly like it does today. I went with 400 over 403 because that's how the endpoint answers an audience it won't mint today.
  • CI job tokens can't mint gitlab-autoflow tokens, even for a flagged user. A job runs as the user who started it, so anyone who can change the CI config of a project that user runs pipelines in would get the flag too.
  • The token names only gitlab-autoflow. AutoFlow doesn't use the IAM data access API, so it doesn't get gitlab-iam-data-access.
  • The token carries the account's own organization and skips the Artifact Registry organization inference. AutoFlow uses gitlab.origin_id as the only namespace the token can address, and Artifact Registry memberships say nothing about which organization that should be. The inference's 409 for users in more than one Artifact Registry organization would only block them for no reason.
  • The gitlab-artifact-registry audience works exactly as before.

This revives !260389 (closed), now behind a flag, and without the Artifact Registry organization and the data access audience for AutoFlow tokens.

References

Screenshots or screen recordings

Not applicable, there is no UI change.

How to set up and validate locally

  1. Create a personal access token with the api scope.

  2. Request a gitlab-autoflow token. It fails with 400 and audience does not have a valid value:

    curl --silent --request POST --header "PRIVATE-TOKEN: <your_token>" \
      --data "audience=gitlab-autoflow" "http://gdk.test:3000/api/v4/token_exchange"
  3. In the Rails console, enable the flag for your user:

    Feature.enable(:token_exchange_autoflow_audience, User.find_by_username('<your_username>'))
  4. Request the token again and print its aud claim. It is ["gitlab-autoflow"]:

    curl --silent --request POST --header "PRIVATE-TOKEN: <your_token>" \
      --data "audience=gitlab-autoflow" "http://gdk.test:3000/api/v4/token_exchange" \
      | jq -r '.token | split(".")[1] | @base64d | fromjson | .aud'

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.

Edited by Timo Furrer

Merge request reports

Loading
Loading