Bitbucket Cloud — Integration Setup
CMDash reads the branch restrictions on each repository in a Bitbucket Cloud workspace to show, per repository, whether the main branch is protected and how many approvals a merge needs. This is the change-management evidence SOC 2 CC8.1 and ISO 27001 A.8.32 ask for, in the same form as the GitHub and GitLab connectors.
Prerequisites
- A Bitbucket Cloud workspace.
- A workspace admin, to create a workspace access token (or an account that can create an API token).
- Any CMDash plan. The connection uses one of your plan's integrations.
Step 1: Create a token
Either of these works.
Workspace access token (recommended). In the workspace settings, create an access token with these scopes:
- Repositories: Read (
repository), to list repositories. - Repositories: Admin (
repository:admin), because Bitbucket places branch restrictions under repository admin. CMDash only reads them.
API token. Create an API token for an Atlassian account that has admin access to the repositories, with the same read and admin repository access. You will also enter that account's Atlassian email in CMDash.
Least privilege: CMDash sends only
GETrequests. It never changes a repository, a restriction or a member.
Step 2: Connect in CMDash
- Go to Integrations and find Bitbucket Cloud.
- Enter:
- API key: the token.
- Bitbucket workspace: the workspace ID, as in
bitbucket.org/<workspace>. - Atlassian account email: only for an API token. Leave it blank for a workspace access token.
- Select Save & Test Connection.
A workspace access token is sent as Authorization: Bearer. An API token is sent with HTTP Basic, as email:token, as Atlassian documents.
What syncs
| Data | Bitbucket API | When it cannot be read |
|---|---|---|
| Repositories and their main branch | GET /2.0/repositories/{workspace}, every page by next | The sync fails on the first page. A failed later page keeps what was read and marks the sync partial. |
| Branch restrictions | GET /2.0/repositories/{workspace}/{repo}/branch-restrictions | A 403 fails the sync: the token lacks repository admin, and CMDash will not report an unreadable branch as unprotected. Any other failure leaves that repository out and marks the sync partial. |
| Branching model | GET /2.0/repositories/{workspace}/{repo}/branching-model, only for a repository with a branching-model rule | That repository is left out and the sync is partial. |
How the numbers are computed
- A rule applies to the main branch when its glob pattern matches the branch name (
*matches anything), or when it targets the branching model's development or production branch and that branch is the main branch. - Protected: at least one rule applies to the main branch.
- Requires review: a rule of kind require approvals to merge or require default reviewer approvals to merge applies, with at least one approval. Approvals is the highest such number.
- Admins bound by the rule: not read, so it is shown as unknown rather than "admins can bypass".
- Bitbucket has no archived flag, so every repository counts.
- Up to 300 repositories are read per sync. A larger workspace is marked partial.
Troubleshooting
- 403 on branch restrictions: add Repositories: Admin to the token.
- 401: the token was revoked or expired, or the email does not match the API token's account.
Credential rotation
Create the new token first, update the connection in CMDash, confirm a sync, then revoke the old token in Bitbucket.