Authenticate GitLab.com CI/CD with workload identity federation
Let GitLab.com CI/CD jobs call Limrun with their ID token instead of a stored API key.
A GitLab CI/CD job can receive an ID token from GitLab and exchange it for a short-lived Limrun access token. Your projects then need no LIM_API_KEY variable, and you control which projects and branches get which permissions. This page covers GitLab.com. For a self-managed GitLab instance, see Self-managed GitLab.
Before you start
You need:
- The
adminrole in your Limrun organization. - The numeric ID of the GitLab group that directly contains your projects. On the group’s overview page, select Actions (⋮) in the upper-right corner, then Copy Group ID.
Create the provider
GitLab.com signs tokens for every project on GitLab.com, so the provider condition must check that a token comes from your group.
-
Open console.limrun.com, go to Settings, then Workload identity federation, and click the + button next to Identity providers.
-
In Issuer, choose GitLab.com. The preset fills in the issuer
https://gitlab.comand its signing keys athttps://gitlab.com/oauth/discovery/keys. -
Keep Token audience as
limrun. The job requests its token with this audience. -
In Provider condition (CEL), replace
NAMESPACE_IDwith your group ID:assertion.namespace_id == 'NAMESPACE_ID'GitLab sends IDs as strings, so keep the quotes. Use the ID rather than the path, because IDs don’t change when a group is renamed.
-
Click Create provider.
Create a binding
-
In the provider’s card, click the + button next to Bindings.
-
Enter a name and a Claim condition (CEL) that selects the jobs to trust. For example, this admits only the
mainbranch of one project:assertion.project_id == 'PROJECT_ID' && assertion.ref == 'main'Run
glab api projects/YOUR_GROUP%2FYOUR_PROJECT | jq .idto find the project ID. GitLab’srefclaim is the short branch name, such asmain; the full ref is inref_path. -
Enter the permissions the jobs need, one per line, such as
xcode:*:all. -
Click Create binding, expand Setup, and copy the binding ID.
Use the token in a job
Name the job’s ID token LIMRUN_WORKLOAD_IDENTITY_TOKEN, and the CLI picks it up directly:
limrun:
image: node:22
id_tokens:
LIMRUN_WORKLOAD_IDENTITY_TOKEN:
aud: limrun
variables:
LIMRUN_WORKLOAD_IDENTITY_BINDING_ID: binding_REPLACE_WITH_BINDING_ID
script:
- npm install --global lim
- lim whoami
id_tokens tells GitLab to put a token with the audience limrun in the variable you name, and aud must match the provider’s audience. The binding ID is not a secret. The token expires at the job’s timeout, or after five minutes if the job has none, so set a timeout that covers your Limrun steps. After lim whoami shows your organization and the binding’s permissions, replace it with your build steps.
The SDKs read the same variables, so a script in the job needs no extra configuration.
Things to know
- Merge requests from forks carry the fork’s IDs. In a merge request pipeline,
namespace_idandproject_iddescribe the source project, so jobs from a fork in another group don’t match your provider. - Match on IDs, not
sub. GitLab’s default subject isproject_path:{group}/{project}:ref_type:{type}:ref:{branch_name}, and projects can customize it.namespace_id,project_id, andrefstay stable.
Self-managed GitLab
A self-managed instance signs only for itself, so it needs no owner check. In Issuer, choose Other identity provider. Enter your instance’s URL, such as https://gitlab.example.com, as the issuer and https://gitlab.example.com/oauth/discovery/keys as the JWKS URL. Limrun must be able to reach the JWKS URL from the internet.
See GitLab’s ID token reference for every claim in the token.