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.
repo:my-org/my-repo:ref:refs/heads/main. Leaving the branch empty gives repo:my-org/my-repo:*, and leaving the repository empty gives repo:my-org/*. Advanced Settings shows the pattern and the Issuer URL (https://token.actions.githubusercontent.com); edit the pattern there to match other refs, such as a tag or an environment. See Configuration for the rules every setting must satisfy.
On GitHub Enterprise Server, the token issuer and the default audience differ from GitHub.com. Set Issuer URL under Advanced Settings to your server’s issuer, and list the audience your
getIDToken() call requests.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.,
github-actions-deploy@workload.bytebase.com). - Select the GitOps Service Agent role.
- Click Confirm.
Step 3: Configure GitHub Actions Workflow
In your GitHub Actions workflow, add the following configuration:Request OIDC Token
Addid-token: write permission and use the actions/github-script action to get the token:
Complete Example
Here’s a complete workflow that creates a database change using Workload Identity:Troubleshooting
Token Exchange Fails
If the token exchange returns an error:- Verify the repository and branch: Check that the workflow’s repository and branch match the Subject Pattern shown under Advanced Settings.
-
Check the audience: The
audyourgetIDToken()call requests must be on the identity’s Audience list. This guide requestshttps://github.com/{owner}; workflows generated on the project GitOps page requestbytebase. -
Upgraded from 3.22 or earlier: An identity whose pipeline requests an audience that is not listed, or whose subject pattern matches every repository (
repo:*), 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; see Configuration.
