doc/ci/cloud_services/_index.md
{{< details >}}
{{< /details >}}
[!warning]
CI_JOB_JWTandCI_JOB_JWT_V2were removed in GitLab 17.0. Use ID tokens instead.
GitLab CI/CD supports OpenID Connect (OIDC) to give your build and deployment jobs access to cloud credentials and services. Historically, teams stored secrets in projects or applied permissions on the GitLab Runner instance to build and deploy. OIDC capable ID tokens are configurable in the CI/CD job allowing you to follow a scalable and least-privilege security approach.
ID tokens support cloud providers with OIDC, including:
[!note] Configuring OIDC enables JWT token access to the target environments for all pipelines. When you configure OIDC for a pipeline, you should complete a software supply chain security review for the pipeline, focusing on the additional access. For more information about supply chain attacks, see How a DevOps Platform helps protect against supply chain attacks.
Each job can be configured with ID tokens, which are provided as a CI/CD variable containing the token payload. These JWTs can be used to authenticate with the OIDC-supported cloud provider such as AWS, Azure, GCP, or Vault.
%%{init: { "fontFamily": "GitLab Sans" }}%%
sequenceDiagram
accTitle: Authorization workflow
accDescr: The flow of authorization requests between GitLab and a cloud provider.
participant GitLab
Note right of Cloud: Create OIDC identity provider
Note right of Cloud: Create role with conditionals
Note left of GitLab: CI/CD job with ID token
GitLab->>+Cloud: Call cloud API with ID token
Note right of Cloud: Decode & verify JWT with public key (https://gitlab.com/oauth/discovery/keys)
Note right of Cloud: Validate audience defined in OIDC
Note right of Cloud: Validate conditional (sub, aud) role
Note right of Cloud: Generate credential or fetch secret
Cloud->>GitLab: Return temporary credential
Note left of GitLab: Perform operation
When you configure a conditional role, include stable, unique identifiers such as namespace_id or project_id alongside path-based claims like sub where the cloud provider supports them. These identifiers are independent of paths, so trust policies that reference them are not affected by changes to paths, such as group or project renames.
Support for these condition keys varies by cloud provider and GitLab offering. For example, AWS supports namespace_id and project_id for the gitlab.com OIDC identity provider only. For a provider example, see Configure OpenID Connect in AWS.
To configure the trust between GitLab and OIDC, you must create a conditional role in the cloud provider that checks against the JWT. The condition is validated against the JWT to create a trust specifically against two claims, the audience and subject.
Audience or aud: Configured as part of the ID token:
job_needing_oidc_auth:
id_tokens:
OIDC_TOKEN:
aud: https://oidc.provider.com
script:
- echo $OIDC_TOKEN
Subject or sub: A concatenation of metadata describing the GitLab CI/CD workflow including the group, project, branch, and tag. The sub field is in the following format by default:
project_path:{group}/{project}:ref_type:{type}:ref:{branch_name}| Filter type | Example |
|---|---|
| Filter to any branch | Wildcard supported. project_path:mygroup/myproject:ref_type:branch:ref:* |
| Filter to specific project, main branch | project_path:mygroup/myproject:ref_type:branch:ref:main |
| Filter to all projects under a group | Wildcard supported. project_path:mygroup/*:ref_type:branch:ref:main |
| Filter to a Git tag | Wildcard supported. project_path:mygroup/*:ref_type:tag:ref:1.0 |
To bind cloud trust policies to an immutable identifier, use project_id as the
first component of the sub claim.
Use this option to keep cloud access stable when a project is renamed or moved.
To enable it, set ci_id_token_sub_claim_components to a value similar to
["project_id", "ref_type", "ref"] by using the
projects API endpoint API.
The sub field then has the following format:
project_id:{id}:ref_type:{type}:ref:{branch_name}To connect with your cloud provider, see the following tutorials: