Step 1: Create a Workload Identity in Bytebase
- Go to IAM & Admin > Users & Groups.
- Click Add User in the upper-right corner.
- Select Workload Identity as the Type.
- Fill in the configuration:
| Field | Description | Example |
|---|---|---|
| Name | Display name for this identity | GitLab Deploy |
Unique email prefix (automatically appended with @workload.bytebase.com) | gitlab-deploy | |
| Platform | Select GitLab CI | GitLab CI |
| Group / Username | GitLab group or username (required) | my-group |
| Project | Project name (leave empty to allow all projects) | my-project |
| Allowed Branches/Tags | Select branch/tag restrictions | All branches and tags |
| Roles | Assign workspace roles | GitOps Service Agent |
- Click Confirm to create the Workload Identity.
Step 2: Assign Roles
After creating the Workload Identity, assign theGitOps Service Agent role to enable automated CI/CD workflows:
- Go to your project’s Settings > Members.
- Click Grant Access.
- Enter the Workload Identity email (e.g.,
[email protected]). - 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 self-hosted GitLab instances, update the audience (aud) to match your GitLab instance URL:
Troubleshooting
Token Exchange Fails
If the token exchange returns an error:- Verify the project path and branch: Check that your pipeline’s project path and branch match the configured values in Bytebase.
-
Check the audience: Ensure the
audin yourid_tokensconfiguration matches your GitLab instance URL (e.g.,https://gitlab.comfor GitLab.com). - Verify OIDC is enabled: GitLab CI/CD OIDC tokens require GitLab 15.7 or later.
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:sub, aud, namespace_path, project_path, and ref that Bytebase validates.
