-
Notifications
You must be signed in to change notification settings - Fork 3
docs: add Workload Identity documentation for GitLab CI/CD #984
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,199 @@ | ||||||
| --- | ||||||
| title: Workload Identity for GitLab CI/CD | ||||||
| --- | ||||||
|
|
||||||
| 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** > **Users & Groups**. | ||||||
| 2. Click **Add User** in the upper-right corner. | ||||||
| 3. Select **Workload Identity** as the Type. | ||||||
| 4. Fill in the configuration: | ||||||
|
|
||||||
| | Field | Description | Example | | ||||||
| |-------|-------------|---------| | ||||||
| | **Name** | Display name for this identity | `GitLab Deploy` | | ||||||
| | **Email** | 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` | | ||||||
|
|
||||||
| 5. Click **Confirm** to create the Workload Identity. | ||||||
|
|
||||||
| ## Step 2: Assign Roles | ||||||
|
|
||||||
| After creating the Workload Identity, assign the `GitOps Service Agent` role to enable automated CI/CD workflows: | ||||||
|
|
||||||
| 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**. | ||||||
|
|
||||||
| <Tip> | ||||||
|
|
||||||
| 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](/administration/roles) for details. | ||||||
|
|
||||||
| </Tip> | ||||||
|
|
||||||
| ## 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: | ||||||
|
|
||||||
| ```yaml | ||||||
| stages: | ||||||
| - deploy | ||||||
|
|
||||||
| deploy-database: | ||||||
| stage: deploy | ||||||
| image: alpine:latest | ||||||
| id_tokens: | ||||||
| GITLAB_OIDC_TOKEN: | ||||||
| aud: https://gitlab.com | ||||||
| variables: | ||||||
| BYTEBASE_URL: https://bytebase.example.com | ||||||
| WORKLOAD_IDENTITY_EMAIL: gitlab-ci-deploy@workload.bytebase.com | ||||||
| before_script: | ||||||
| - apk add --no-cache curl jq | ||||||
| script: | ||||||
| - | | ||||||
| # Exchange GitLab OIDC token for Bytebase API token | ||||||
| RESPONSE=$(curl -s -X POST "${BYTEBASE_URL}/v1/auth:exchangeToken" \ | ||||||
| -H "Content-Type: application/json" \ | ||||||
| -d "{\"token\": \"${GITLAB_OIDC_TOKEN}\", \"email\": \"${WORKLOAD_IDENTITY_EMAIL}\"}") | ||||||
|
|
||||||
| ACCESS_TOKEN=$(echo $RESPONSE | jq -r '.accessToken') | ||||||
| if [ "$ACCESS_TOKEN" = "null" ] || [ -z "$ACCESS_TOKEN" ]; then | ||||||
| echo "Failed to get access token" | ||||||
| echo $RESPONSE | ||||||
| exit 1 | ||||||
| fi | ||||||
|
|
||||||
| # Verify the token by calling the user info API | ||||||
| USER_INFO=$(curl -s "${BYTEBASE_URL}/v1/users/me" \ | ||||||
| -H "Authorization: Bearer $ACCESS_TOKEN") | ||||||
| echo "Authenticated as: $USER_INFO" | ||||||
| rules: | ||||||
| - if: $CI_COMMIT_BRANCH == "main" | ||||||
| ``` | ||||||
|
|
||||||
| ## Complete Example | ||||||
|
|
||||||
| Here's a complete GitOps workflow that uses Workload Identity to deploy database migrations: | ||||||
|
|
||||||
| ```yaml | ||||||
| # .gitlab-ci.yml | ||||||
| stages: | ||||||
| - review | ||||||
| - deploy | ||||||
|
|
||||||
| variables: | ||||||
| BYTEBASE_URL: https://bytebase.example.com | ||||||
| WORKLOAD_IDENTITY_EMAIL: gitlab-deploy@workload.bytebase.com | ||||||
|
|
||||||
| # SQL Review on merge requests | ||||||
| sql-review: | ||||||
| stage: review | ||||||
| image: bytebase/sql-review-action:latest | ||||||
|
||||||
| image: bytebase/sql-review-action:latest | |
| image: bytebase/bytebase-action:latest |
Copilot
AI
Jan 15, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect command for SQL review. Based on the bytebase-action Docker image usage in other GitLab CI examples (e.g., docs/gitops/migration-based-workflow/sql-review-ci.mdx line 69), the correct command should be bytebase-action check instead of sql-review. The command format should match the established pattern used in GitLab CI pipelines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The email field description is inconsistent with the GitHub Actions documentation. In the GitHub Actions guide (line 17), it states 'Unique email for this identity (must end with
@workload.bytebase.com)' suggesting users should provide the full email. However, this documentation suggests users provide only the prefix. This inconsistency could confuse users. Please clarify whether users should provide the full email or just the prefix.