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-autoflowrequest 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-autoflowtokens, 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 getgitlab-iam-data-access. - The token carries the account's own organization and skips the Artifact Registry organization inference. AutoFlow uses
gitlab.origin_idas 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-registryaudience 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
- gitlab-org/cluster-integration/gitlab-agent#1200 (closed) - the decision that Rails stays the only minter, because
StartWorkflowdoesn't authorize users - gitlab-org/cluster-integration/gitlab-agent!4854 (merged) - AutoFlow limits a token to its organization's namespace
- !260389 (closed) - the earlier attempt
- gitlab-org/cluster-integration/gitlab-agent#1253 - AutoFlow on the public listener only
- gitlab-com/gl-infra/platform/runway/team#947 (closed) - Cloudflare gRPC for Runway
- Slack thread asking the team for this short-term solution (internal): https://gitlab.slack.com/archives/C0BCXSV8NAV/p1793796516153479
Screenshots or screen recordings
Not applicable, there is no UI change.
How to set up and validate locally
-
Create a personal access token with the
apiscope. -
Request a
gitlab-autoflowtoken. It fails with400andaudience 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" -
In the Rails console, enable the flag for your user:
Feature.enable(:token_exchange_autoflow_audience, User.find_by_username('<your_username>')) -
Request the token again and print its
audclaim. 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.