Step 1: Create a Workload Identity in Bytebase
- 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.
- Fill in the configuration:
- Click Create.
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:- Go to your project’s Settings > Members.
- Click Grant Access.
- Enter the Workload Identity email (e.g.,
gitlab-ci-deploy@workload.bytebase.com). - Select the GitOps Service Agent role.
- Click Confirm.
Step 3: Configure GitLab CI/CD Pipeline
In your GitLab CI/CD pipeline, add the following configuration:Request OIDC Token
Addid_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:Self-Hosted GitLab
For a self-hosted GitLab instance, request the token with your instance URL as the audience:Troubleshooting
Token Exchange Fails
If the token exchange returns an error:- Verify the project path and branch: Check that the pipeline’s project path and ref match the Subject Pattern shown under Advanced Settings.
-
Check the audience: The
audin yourid_tokensconfiguration must be on the identity’s Audience list. This guide requests the GitLab instance URL; pipelines generated on the project GitOps page requestbytebase. -
Check the issuer: GitLab URL must equal the token’s
issclaim exactly, which is your instance URL for self-hosted GitLab. - Verify OIDC is enabled: GitLab CI/CD OIDC tokens require GitLab 15.7 or later.
-
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:- Verify the Workload Identity has the
GitOps Service Agentrole assigned. - Check that the Workload Identity is a member of the target project.
Debug Token Claims
To inspect the OIDC token claims, decode the JWT: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.
