feat(cloud-agent-next) bitbucket outbound creds injection - #4868
Conversation
capability issue/redeem
credential injection wiring
validator + use canonical clone URL
divergence from GitLab validator
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Executive SummaryIncremental review: the only change since the last review is a mechanical test-file update ( Files Reviewed (1 file)
Previous Review Summary (commit ffc9e3b)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit ffc9e3b)Status: No Issues Found | Recommendation: Merge Executive SummaryReviewed the new Bitbucket outbound credential-injection capability flow (issue/redeem, path-traversal/origin validation, and containment wiring) across git-token-service and cloud-agent-next; found no high-confidence security, correctness, or logic issues in the changed lines. Files Reviewed (13 files)
Reviewed by claude-sonnet-5 · Input: 14 · Output: 2.2K · Cached: 243.4K Review guidance: REVIEW.md from base branch |
expected credentialContainment
Summary
Adds Bitbucket outbound credential injection for contained code-review
sessions, matching the existing GitHub and GitLab capability model. A
contained Bitbucket session no longer receives the raw workspace token.
Instead git-token-service mints an opaque, encrypted, container-bound
capability (
kbb1.prefix) and the cloud-agent-next sandbox outboundinterceptor redeems it per request, attaching the real credential as a Basic
x-token-authheader. This lets Bitbucket use the same containment sandbox asGitHub and GitLab.
The path is gated per organization by a new
BITBUCKET_TOKEN_CONTAINMENT_ORG_IDSallow-list and is off by default, so merging this ships the code dormant with no
behavior change until an org is enabled.
Changes
git-token-service (mint and redeem):
bitbucket-session-capability.ts: capability codec (kbb1.prefix,encrypted claims, 4h TTL, sha256 token digest, container and workspace/repo
binding) with tests.
index.ts:issueBitbucketSessionCapabilityandredeemBitbucketSessionCapability, plusvalidateBitbucketCapabilityUpstream,which restricts redemption to
https://bitbucket.org/<repo>.gitand rejectscross-repo and path-traversal requests (single and nested percent-encoded).
Redeem re-resolves the token and compares digests, so a rotated token stops
working.
bitbucket-runtime-token-resolver.ts:resolveBitbucketCapabilitySubjectreturns the canonical workspace/repo identity (resolved by UUID) and current
token.
cloud-agent-next (wiring and interceptor):
sandbox-outbound.ts:handleManagedBitbucketOutboundrecognizeskbb1.capabilities on
bitbucket.org, matches thex-token-authgit-auth surface,and injects the redeemed credential, dispatched alongside the GitHub and
GitLab handlers.
session-service.ts: whencredentialContainment.bitbucketis set, issue acapability instead of resolving the raw token, capture the canonical clone URL
returned by issuance, and use it at every clone-URL site.
session-registration.tsandsession-metadata.ts: add thebitbucketcontainment dimension, gated by
BITBUCKET_TOKEN_CONTAINMENT_ORG_IDSand repotype, and route contained Bitbucket sessions to the containment sandbox.
types.tsandgit-token-service-client.ts: RPC method signatures, resulttypes, the new env binding, and the client wrapper.
wrangler.jsonc: dev default for the new var (empty, off).Verification
No manual end-to-end run was performed. The feature ships dormant behind the
org allow-list, so a live Bitbucket review will be smoke-tested after an org is
enabled post-deploy. Automated coverage: git-token-service unit tests
(issue/redeem, cross-repo rejection, single and double-encoded traversal
rejection, rotated-token rejection) and cloud-agent-next sandbox-outbound tests
(capability recognition and header injection).
Visual Changes
N/A
Reviewer Notes
BITBUCKET_TOKEN_CONTAINMENT_ORG_IDSis empty by default, so noBitbucket session changes behavior until an org is added. GitHub and GitLab
paths are untouched.
validateBitbucketCapabilityUpstreamis the security boundary. Itdeliberately rejects
%2f(Bitbucket repo paths never encode slashes) wherethe GitLab validator must allow it (GitLab addresses projects by encoded
path); see the inline comment. Both decode the path iteratively and re-check
for traversal.
re-cased workspace does not mismatch the redeem-side repo check.
follow-up PR.