Configuring OpenID Connect for GitLab
This document outlines the steps required to configure Pulumi Cloud to accept GitLab id_tokens and exchange them for organization access tokens.
OidcIssuer resource in the Pulumi Service provider.organization tokens. Depending on your Pulumi edition, you can also use personal or team tokens by adjusting the token type in the authorization policies and the requested-token-type parameter.Prerequisites
- You must be an admin of your Pulumi organization.
Register the OIDC Issuer
- Navigate to Settings → Access Management → OIDC Issuers and select Register issuer.
- Name the issuer and set the issuer URL to
https://gitlab.com/(or your GitLab self-managed URL). - Submit the form.
Configure the authorization policies
Select the issuer name.
Set Decision to Allow.
Set Token type to Organization.
Add a policy to allow OIDC and configure the audience and subject claims for your organization and repositories:
- Aud:
urn:pulumi:org:<org-name> - Sub:
project_path:<namespace>/<project>:ref_type:branch:ref:<branch-name>
For more information about GitLab token claims, see the official GitLab documentation.
- Aud:
Select Save policies.
Set up GitLab CI to use Pulumi OIDC authentication
In your .gitlab-ci.yml, configure the job to request an ID token and use it with the Pulumi CLI:
variables:
PULUMI_ORG: "org-name"
.pulumi-oidc:
image:
name: pulumi/pulumi:latest
entrypoint: [""]
id_tokens:
GITLAB_OIDC_TOKEN:
aud: "urn:pulumi:org:${PULUMI_ORG}"
before_script:
- pulumi login --oidc-token "$GITLAB_OIDC_TOKEN" --oidc-org "$PULUMI_ORG" --cloud-url https://api.pulumi.com
Replace org-name with your Pulumi organization name.
Sample GitLab CI pipeline
variables:
PULUMI_ORG: "org-name"
STACK_NAME: "org-name/project-name/stack-name"
stages:
- preview
- deploy
.pulumi-oidc:
image:
name: pulumi/pulumi:latest
entrypoint: [""]
id_tokens:
GITLAB_OIDC_TOKEN:
aud: "urn:pulumi:org:${PULUMI_ORG}"
before_script:
- pulumi login --oidc-token "$GITLAB_OIDC_TOKEN" --oidc-org "$PULUMI_ORG" --cloud-url https://api.pulumi.com
pulumi-preview:
extends: .pulumi-oidc
stage: preview
script:
- cd infrastructure
- npm ci
- pulumi preview --stack "$STACK_NAME"
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
pulumi-up:
extends: .pulumi-oidc
stage: deploy
script:
- cd infrastructure
- npm ci
- pulumi up --stack "$STACK_NAME" --yes
rules:
- if: $CI_COMMIT_BRANCH == "main"
environment:
name: production
Thank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.