Skip to main content
GitLab CI/CD jobs can request an OIDC ID token from your GitLab instance. A job can exchange that token for a short-lived TrueFoundry access token. This way, you don’t need to store a Virtual Account token as a CI/CD variable. TrueFoundry requires a 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 with id_tokens. Set aud to the audience you will register on TrueFoundry:
GitLab makes the token available to the job as $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:
GitLab sends project_id, namespace_id, and ref_protected as strings.

Configure TrueFoundry

  1. Go to Settings > Security & Access > Identity Providers, then add a provider of type GitLab.
  2. 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>.
  1. Map the Virtual Account or Agent to the provider on project_id.
Virtual Account Claims
Agent Subject (the YAML key is still claims)
The required key for 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:
Use 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_id alone allows every branch, tag, and merge request pipeline in that project. Pipelines from forks carry the fork’s project_id, so they don’t match.
  • Add ref_protected: "true" to allow only protected branches and tags.
  • sub includes the branch or tag name, for example project_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.

Troubleshooting