Skip to content

feat: add Bitbucket Pipelines OIDC detector#303

Merged
cloudsmith-iduffy merged 1 commit into
masterfrom
worktree-bitbucket-oidc
Jun 10, 2026
Merged

feat: add Bitbucket Pipelines OIDC detector#303
cloudsmith-iduffy merged 1 commit into
masterfrom
worktree-bitbucket-oidc

Conversation

@cloudsmith-iduffy

Copy link
Copy Markdown
Contributor

What

Adds an OIDC environment detector for Bitbucket Pipelines, following the same pattern as the existing GitHub Actions / Azure DevOps / GitLab CI detectors.

Bitbucket injects an OIDC JWT into BITBUCKET_STEP_OIDC_TOKEN when a pipeline step sets oidc: true. The detector reads that variable and hands it to the standard Cloudsmith token exchange (/openid/{org}/ with service_slug); no audience handling is needed since Bitbucket sets the audience itself.

  • bitbucket_pipelines.pydetect() checks the env var, get_token() returns it (clear error when absent)
  • Registered in the detector chain ahead of AWS (cheap, specific env-var match before boto3 credential discovery)
  • 5 unit tests (TDD), full core suite green, all pre-commit hooks pass

Live validation

Verified end-to-end against a real Bitbucket pipeline (org iduffy-demo, service bitbucket-y3j7) — build succeeded on a hosted runner, exercising detection → token fetch → Cloudsmith exchange → authenticated API call.

Token claims minted by Bitbucket:

iss = https://api.bitbucket.org/2.0/workspaces/cloudsmith-iduffy/pipelines-config/identity/oidc
aud = ari:cloud:bitbucket::workspace/<workspace-uuid>   (Bitbucket-set, not "cloudsmith")
sub = {repo-uuid}:{step-uuid}

cloudsmith whoami --verbose in the pipeline:

User: bitbucket (slug: bitbucket-y3j7)
Authentication Method: OIDC Auto-Discovery
Source: OIDC via Bitbucket Pipelines (org: iduffy-demo, service: bitbucket-y3j7)

cloudsmith list repos iduffy-demo then returned repositories — confirming the exchanged token authenticates real API calls.

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings June 8, 2026 21:52
@cloudsmith-iduffy cloudsmith-iduffy requested a review from a team as a code owner June 8, 2026 21:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

  • Adds a Bitbucket Pipelines OIDC environment detector to the existing OIDC auto-discovery flow so the CLI can exchange Bitbucket-provided step OIDC JWTs for Cloudsmith API tokens.

Changes:

  • Introduces BitbucketPipelinesDetector that reads BITBUCKET_STEP_OIDC_TOKEN from the environment.
  • Registers the new detector in the OIDC detector chain ahead of AWS detection.
  • Adds unit tests covering detect/get_token behavior for the Bitbucket detector.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
cloudsmith_cli/core/tests/test_bitbucket_pipelines_detector.py Adds unit tests for Bitbucket Pipelines detection and token retrieval.
cloudsmith_cli/core/credentials/oidc/detectors/bitbucket_pipelines.py Implements the Bitbucket Pipelines OIDC environment detector.
cloudsmith_cli/core/credentials/oidc/detectors/init.py Registers Bitbucket Pipelines detector in the auto-discovery chain.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cloudsmith_cli/core/tests/test_bitbucket_pipelines_detector.py
@cloudsmith-iduffy cloudsmith-iduffy force-pushed the worktree-bitbucket-oidc branch from aa06d95 to eb841f1 Compare June 8, 2026 22:46
Add Bitbucket Pipelines to OIDC credential auto-discovery. When a pipeline
step sets `oidc: true`, the CLI reads the OIDC token from the
BITBUCKET_STEP_OIDC_TOKEN environment variable and exchanges it for a
Cloudsmith access token. Works out of the box with no extra dependencies.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@cloudsmith-iduffy cloudsmith-iduffy force-pushed the worktree-bitbucket-oidc branch from 9bf5c96 to 8774dfa Compare June 10, 2026 17:33
@cloudsmith-iduffy cloudsmith-iduffy merged commit 894bf81 into master Jun 10, 2026
45 of 46 checks passed
@cloudsmith-iduffy cloudsmith-iduffy deleted the worktree-bitbucket-oidc branch June 10, 2026 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants