Repository navigation
Conversation
Macbet
left a comment
There was a problem hiding this comment.
Looks good overall: HMAC check is constant-time and fails closed, the SSRF/same-origin check covers the diff URL on every redirect hop, and the {} encoding also fixes the v1 deleteWebhook. A few things inline, the Bitbucket Server one being the most important.
One thing outside this diff that is worth a separate issue: PrApplyAuthorizationService.refusalReason has no Bitbucket branch and falls through to default -> Optional.empty(), so with PR apply enabled any user who can comment on the PR can trigger an apply. This already applies to v1, so it is not a regression of this PR.
| || vcsType == io.terrakube.api.rs.vcs.VcsType.AZURE_SP_MI | ||
| || vcsType == io.terrakube.api.rs.vcs.VcsType.AZURE_DEVOPS; | ||
| || vcsType == io.terrakube.api.rs.vcs.VcsType.AZURE_DEVOPS | ||
| || vcsType == io.terrakube.api.rs.vcs.VcsType.BITBUCKET; |
There was a problem hiding this comment.
Bitbucket Server / Data Center connections are also stored as VcsType.BITBUCKET (see the comment in BitbucketRepositoryDiscoveryService, they differ only by apiUrl), but createOrUpdateRepoWebhook builds the Cloud-only {apiUrl}/repositories/{owner}/{repo}/hooks URL and the parser only knows Cloud event keys.
For a Server repo the webhook is saved as migratedV2=true, the background sync fails, and v1 deliveries are ignored for migrated rows, so the workspace ends up with a webhook that never fires. Before this PR the v1 path failed loudly with a 424.
Could we gate this on apiUrl containing api.bitbucket.org (same check discovery uses), here, in the two hook copies of isSharedWebhookProvider, and in SHARED_WEBHOOK_VCS in the UI?
There was a problem hiding this comment.
Bitbucket Cloud is the only supported option for Bitbucket webhooks in Terrakube, so keeping VcsType.BITBUCKET enabled for Webhook v2 without gating on api.bitbucket.org is intentional.
| @@ -129,15 +147,17 @@ private WebhookResult handlePushCommit(String jsonPayload, WebhookResult result, | |||
| BitbucketTokenModel bitbucketTokenModel = new ObjectMapper().readValue(jsonPayload, | |||
| BitbucketTokenModel.class); | |||
| if (bitbucketTokenModel.getPush().getChanges().size() == 1) { | |||
There was a problem hiding this comment.
Pushes with more than one change are dropped: handlePushEvent only looks at changes[0], and here with size() != 1 neither the commit nor the diff URL is set, so checkFileChanges gets nothing and no job is created. git push --follow-tags or git push origin a b produce such payloads, and a tag sitting in changes[1] never marks modules as due.
This is inherited from v1, but v2 now depends on it for every workspace sharing the repo. Iterating over the changes (first branch change, plus each tag change) would cover it.
There was a problem hiding this comment.
Fixed in 8816190bb — BitBucketWebhookService.handlePushEvent now iterates over all entries in push.changes, processing the first branch commit change, recording any accompanying tag name (e.g. git push --follow-tags) on result.setTag(...) for module refresh, and handling tag-only pushes as release events. Added unit tests for multi-change pushes in BitBucketWebhookServiceTest.
| bitbucketTokenModel.getPush().getChanges().get(0).getLinks().getDiff().getHref(), | ||
| result.getWorkspaceId())); | ||
| var change = bitbucketTokenModel.getPush().getChanges().get(0); | ||
| String diffUrl = change.getLinks() != null && change.getLinks().getDiff() != null |
There was a problem hiding this comment.
Not verified against a real delivery, so treat as a question: for the first push to a new branch (old is null) does Bitbucket include links.diff? If it does not, diffUrl is null here, there are no file changes, and the push never matches a workspace path filter. A fallback to the commit diff for new.target.hash would close that gap.
There was a problem hiding this comment.
Fixed in 8816190bb — added resolvePushDiffUrl fallback when change.links.diff.href is omitted: it checks change.new.target.links.diff.href and then derives {repository.links.self.href}/diff/{commit} (still validated by VcsApiUrlValidator.isAllowedForVcs). Added unit tests covering both fallbacks.
|
Addressed the inline feedback on |
|



Summary
Phase 1 of the stacked PR plan to deprecate Webhook v1 and standardize on shared repository webhooks (Webhook v2): adds full Webhook v2 support for Bitbucket (
VcsType.BITBUCKET), the remaining webhook-capable VCS provider without v2 support.Stack Overview
feat/webhook-v2-bitbucketmainfeat/webhook-v1-disable-flagfeat/webhook-v2-bitbucketio.terrakube.webhook.v1.disabledflag, 404/hook enforcement, UI v2-only creationfeat/webhook-v1-to-v2-startup-migrationfeat/webhook-v1-disable-flag@DisallowConcurrentExecutionQuartz migration job + defaultdisabled=trueChanges
BitBucketWebhookService:fetchDiffFileChanges(Vcs, String)shared by v1 and v2.parseBitBucketPayload(String, Map<String, String>)for v2 deliveries (repo:push,pullrequest:created,pullrequest:updated,pullrequest:comment_created, tag pushes) with null-safe event checks andprFilesUrlpopulation.createOrUpdateRepoWebhook(...)(PUTwith404->POSTre-creation fallback) anddeleteRepoWebhook(...).callBitBucketApi&WebhookServiceBase.makeApiRequest(..., URI, ...)to percent-encode{and}in Bitbucket hook UUIDs soRestTemplatedoes not treat them as URI template variables.RepoWebhookService:BitBucketWebhookServiceintocreateOrUpdateSharedWebhook,cleanupIfOrphan,acceptV2Webhook(x-hub-signatureHMAC-SHA256 verification),processClaimedDelivery,processWorkspaceWebhook, andsaveAndScheduleJob(skipping commit status for Bitbucket).VcsType.BITBUCKETtoWebhookService.isSharedWebhookProvider,WebhookManageHook,WebhookEventManageHook,ModuleRefreshTransactions.WEBHOOK_VCS_TYPES, andWebhook.tsx(SHARED_WEBHOOK_VCS).BitBucketWebhookServiceTest,RepoWebhookServiceTest,RepoWebhookJobAuditIntegrationTest,WebhookServiceTest,WebhookManageHookTest,WebhookEventManageHookTest,WebhookV1MigratedSecurityIntegrationTest,ModuleManageHookTest,ModuleRefreshTransactionsIntegrationTest, andWebhook.test.tsx.Verification
BitBucketWebhookServiceTest,RepoWebhookServiceTest,WebhookServiceTest,WebhookManageHookTest,WebhookEventManageHookTest,WebhookSecurityHardeningTest,ModuleManageHookTest): 154 tests passed (0 failures, 0 errors).ModuleRefreshTransactionsIntegrationTest,WebhookV1MigratedSecurityIntegrationTest,RepoWebhookJobAuditIntegrationTest): 33 tests passed (0 failures, 0 errors).Webhook.test.tsx: 27/27 passed;lint:check: 0 errors;format:check&typecheck: passed).