Skip to content

feat: add webhook v1 disable flag and default UI to v2-only creation - #4065

Open
alfespa17 wants to merge 2 commits into
feat/webhook-v2-bitbucketfrom
feat/webhook-v1-disable-flag
Open

alfespa17 wants to merge 2 commits into
feat/webhook-v2-bitbucketfrom
feat/webhook-v1-disable-flag

Conversation

@alfespa17

@alfespa17 alfespa17 commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Summary

Phase 2 of the stacked PR plan to deprecate Webhook v1 and standardize on shared repository webhooks (Webhook v2): introduces the io.terrakube.webhook.v1.disabled property, enforces 404 / v2-only creation on the API when enabled, and updates the UI so new setups exclusively create Webhook v2 and cannot revert v2 webhooks back to v1.

Note: io.terrakube.webhook.v1.disabled defaults to false in this PR so main remains safe if #4065 merges before #4066; #4066 flips the default to true alongside the startup v1→v2 Quartz migration job.

Stack Overview

PR Branch Base Scope Status
#4064 feat/webhook-v2-bitbucket main Bitbucket Webhook v2 support (API + UI) Open
#4065 (This PR) feat/webhook-v1-disable-flag feat/webhook-v2-bitbucket io.terrakube.webhook.v1.disabled flag, 404/hook enforcement, UI v2-only creation Open
#4066 feat/webhook-v1-to-v2-startup-migration feat/webhook-v1-disable-flag Startup @DisallowConcurrentExecution Quartz migration job + default disabled=true Open

Changes

  • API Configuration (application.properties, WebhookProperties):
    • Added io.terrakube.webhook.v1.disabled=${WebhookV1Disabled:false} (webhookProperties.getV1().isDisabled()).
  • Controller & Elide Hook (WebHookController, WebhookManageHook):
    • POST /webhook/v1/{webhookId} returns 404 Not Found immediately when v1.disabled=true.
    • WebhookManageHook automatically sets migratedV2=true on CREATE and rejects UPDATE attempts reverting migratedV2 to false with HTTP 400 when v1.disabled=true.
  • UI (Webhook.tsx):
    • Removed the opt-in "Share one webhook across this repository" checkbox; new webhook setups for shared-webhook VCS providers always create with migratedV2: true.
    • Removed the "Switch to a webhook for this workspace" (v2 → v1 downgrade) action while retaining the one-way "Migrate to shared webhook" action for existing v1 workspaces.
  • Tests:
    • Added WebHookControllerTest and WebhookV1DisabledIntegrationTest.
    • Updated WebhookManageHookTest and Webhook.test.tsx.

Verification

  • API unit tests (WebHookControllerTest, WebhookManageHookTest, WebhookEventManageHookTest, WebhookServiceTest, RepoWebhookServiceTest, BitBucketWebhookServiceTest): 141 tests passed (0 failures, 0 errors).
  • API integration tests (WebhookV1DisabledIntegrationTest, WebhookV1MigratedSecurityIntegrationTest, WebhookTests): 13 tests passed (0 failures, 0 errors).
  • UI tests & checks (Webhook.test.tsx: 27/27 passed; lint:check: 0 errors; format:check & typecheck: passed).

@Macbet Macbet 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.

The 404 check runs before any DB work and the property binding is fine. The main problem is the UPDATE guard, which blocks every save of a not-yet-migrated webhook once the flag is on. Details inline.

switch (phase) {
case PRECOMMIT:
try {
if (isWebhookV1Disabled() && isSharedWebhookProvider(elideEntity)

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.

This guard only looks at the new value (!elideEntity.isMigratedV2()), not at whether the value actually changed from true to false. The hook runs for any UPDATE of the webhook, and the UI save always sends an update op for it (with the events relationship).

So with WebhookV1Disabled=true, a workspace whose webhook is still migratedV2=false cannot save anything: editing a trigger branch fails with 400 "switching to webhook v1 is not allowed", which is also a misleading message for that case.

Suggestion: reject only when the original value was true and the new one is false (changes.get().getOriginal() for migratedV2, or the persisted row), and let untouched v1 rows through.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 75956322f — moved the revert guard to a field-level PRECOMMIT hook (WebhookV1RevertGuardHook) bound directly to Webhook.migratedV2 (UPDATE). It inspects ChangeSpec so only true -> false transitions are rejected with HTTP 400, allowing trigger edits and other updates on untouched migratedV2=false rows to pass.

}

@Test
void execute_update_whenV1Disabled_rejectsRevertToV1() {

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.

This test passes Optional.empty() and an entity that is simply migratedV2=false, so it exercises "update that does not touch migratedV2" rather than a revert, and currently pins the behaviour described on the guard. It would be good to have two cases: true -> false is rejected, and an update of an existing v1 row that leaves migratedV2 alone is accepted.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Updated in 75956322f — added WebhookV1RevertGuardHookTest covering true -> false (rejected with 400), untouched false -> false / Optional.empty() (allowed), and v1.disabled=false (allowed), updated WebhookLifeCycleHookBindingTest for the field-level binding, and updated WebhookManageHookTest to verify untouched migratedV2=false updates succeed.

...(!webhookId && createShared && { attributes: { migratedV2: true } }),
...(!webhookId &&
vcsProvider &&
SHARED_WEBHOOK_VCS.includes(vcsProvider) && { attributes: { migratedV2: true } }),

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.

This is unconditional, while the flag defaults to false in this PR. SHARED_WEBHOOK_VCS covers every type except PUBLIC, so after this change the UI can no longer create a v1 webhook or switch back to one, even though the API still allows both. Is that intended as the new default for everyone regardless of the flag? If yes, worth stating in the PR description / release notes; if not, the UI needs to know the flag value.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, making the UI always create Webhook v2 for new setups (and removing the v2 -> v1 downgrade button) is intentional regardless of the flag. With #4064 adding Bitbucket Cloud v2 support, all supported webhook providers now work with v2, and once the full stack (#4064 + #4065 + #4066) is merged, #4066 enables v1.disabled=true by default and automatically migrates any remaining v1 workspaces on startup.

io.terrakube.webhook.pr-base-branch-filter=${WebhookPrBaseBranchFilter:false}
# When true, the legacy per-workspace /webhook/v1/{webhookId} endpoint returns 404
# and new webhooks for supported VCS providers are always created as shared v2 webhooks.
io.terrakube.webhook.v1.disabled=${WebhookV1Disabled:false}

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.

Turning this on makes every existing v1 hook return 404 while the remote hooks stay registered, and nothing in this PR migrates them (that comes in #4066). Could the comment say that existing workspaces have to be migrated first? Also WebhookV1Disabled is not mentioned anywhere in the docs yet.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Updated the application.properties comment in 75956322f to note that existing v1 workspaces must be migrated first (automated on startup in #4066 once the full stack is merged).


@PostMapping("/webhook/v1/{webhookId}")
public ResponseEntity<String> processWebhook(@PathVariable String webhookId,@RequestBody Map<String, Object> payload,@RequestHeader Map<String, String> headers) {
if (webhookProperties != null && webhookProperties.getV1().isDisabled()) {

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.

Nit: @RequestBody is still deserialized before this check, so a malformed body gets 400 instead of 404 when v1 is disabled. Not a problem functionally, just noting the endpoint still parses bodies.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Acknowledged — keeping @RequestBody as-is since it does not affect valid webhook callers.

@alfespa17
alfespa17 force-pushed the feat/webhook-v1-disable-flag branch from 7878c86 to 7595632 Compare November 30, 2026 14:43
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author/maintainer Authored by a maintainer size/L 250-999 lines changed terrakube-api terrakube-ui type/feature New functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants