Skip to main content
This guide explains how to configure Workload Identity for GitLab CI/CD to authenticate with Bytebase without storing long-lived credentials.

Step 1: Create a Workload Identity in Bytebase

  1. Go to IAM & Admin > Workload Identities and click Create. For an identity scoped to one project, go to the project’s Manage > Workload Identities instead.
  2. Fill in the configuration:
  1. Click Create.
Bytebase builds the Subject Pattern from the group, project, and ref: project_path:my-group/my-project:ref_type:branch:ref:main. Allowing all branches and tags gives project_path:my-group/my-project:*, and leaving the project empty gives project_path:my-group/*. Advanced Settings shows the pattern and the GitLab URL (the token issuer, https://gitlab.com by default). See Configuration for the rules every setting must satisfy.

Step 2: Assign Roles

The Roles you picked in Step 1 are granted when the identity is created, so nothing more is needed for a new identity. To change its roles later, or if the Roles field was not shown because your account cannot set the IAM policy, grant them from the project:
  1. Go to your project’s Settings > Members.
  2. Click Grant Access.
  3. Enter the Workload Identity email (e.g., gitlab-ci-deploy@workload.bytebase.com).
  4. Select the GitOps Service Agent role.
  5. Click Confirm.
The GitOps Service Agent role is designed for automated CI/CD workflows, allowing the identity to create and execute database changes. See Roles and Permissions for details.

Step 3: Configure GitLab CI/CD Pipeline

In your GitLab CI/CD pipeline, add the following configuration:

Request OIDC Token

Add id_tokens configuration to get the JWT token from GitLab:

Complete Example

Here’s a complete GitOps workflow that uses Workload Identity to deploy database migrations:
For more details on GitOps workflows, see GitOps Overview and Migration-Based Workflow.

Self-Hosted GitLab

For a self-hosted GitLab instance, request the token with your instance URL as the audience:
In the workload identity, set GitLab URL under Advanced Settings to the same instance URL, since GitLab signs tokens with the instance as the issuer, and add the URL to the Audience list.

Troubleshooting

Token Exchange Fails

If the token exchange returns an error:
  1. Verify the project path and branch: Check that the pipeline’s project path and ref match the Subject Pattern shown under Advanced Settings.
  2. Check the audience: The aud in your id_tokens configuration must be on the identity’s Audience list. This guide requests the GitLab instance URL; pipelines generated on the project GitOps page request bytebase.
  3. Check the issuer: GitLab URL must equal the token’s iss claim exactly, which is your instance URL for self-hosted GitLab.
  4. Verify OIDC is enabled: GitLab CI/CD OIDC tokens require GitLab 15.7 or later.
  5. Upgraded from 3.22 or earlier: An identity whose pipeline requests an audience that is not listed, or whose subject pattern matches every project (project_path:*), stops authenticating after the upgrade. See the 3.23.0 changelog.

Permission Denied

If API calls return permission errors:
  1. Verify the Workload Identity has the GitOps Service Agent role assigned.
  2. Check that the Workload Identity is a member of the target project.

Debug Token Claims

To inspect the OIDC token claims, decode the JWT:
This shows the token’s claims. Bytebase checks iss, aud, and sub against the identity’s settings; the project path and ref are matched through sub, and the namespace_path, project_path, and ref claims are not read. See Configuration.