project_id claim match on the Virtual Account Claims (or Agent Subject) mapping.
For concepts and the shared exchange API, see Workload Identity Federation.
Prerequisites
- A GitLab project on GitLab.com, GitLab Self-Managed, or GitLab Dedicated, where you can edit
.gitlab-ci.yml. - The project ID. You can find it on the project overview page and under Settings > General.
- A Virtual Account or Agent with the permissions the job needs.
Configure the job
GitLab issues an ID token only when the job requests one withid_tokens. Set aud to the audience you will register on TrueFoundry:
$TFY_ID_TOKEN. The token expires when the job times out. If the job has no timeout, it expires after 5 minutes. Exchange it early in the job.
A typical token looks like this:
project_id, namespace_id, and ref_protected as strings.
Configure TrueFoundry
- Go to Settings > Security & Access > Identity Providers, then add a provider of type GitLab.
- Enter these values:
An issuer and audience pair can belong to only one identity provider. All GitLab.com projects share the issuer
https://gitlab.com, so use an audience specific to your tenant, such as truefoundry-<tenant>.
- Map the Virtual Account or Agent to the provider on
project_id.
claims)
gitlab is project_id. It is unique within a GitLab instance and does not change when the project is renamed. To narrow access further, add claims such as ref_protected: "true" or sub.
Exchange and call TrueFoundry
Add the exchange step to your pipeline:TFY_ACCESS_TOKEN as the Authorization: Bearer header for the AI Gateway or other APIs. For Agents, set tfy_subject to agent:<agent-name>. For the full exchange flow, see Workload Identity Federation.
Don’t print the ID token or the access token with echo. Job logs are visible to everyone who can access the project.
Scope the mapping
project_idalone allows every branch, tag, and merge request pipeline in that project. Pipelines from forks carry the fork’sproject_id, so they don’t match.- Add
ref_protected: "true"to allow only protected branches and tags. subincludes the branch or tag name, for exampleproject_path:your-group/your-project:ref_type:branch:ref:main. Use it only when one specific ref should authenticate, because it changes for every branch, tag, and merge request.- Don’t store a long-lived Virtual Account token in CI/CD variables when federation is available.