Skip to content

feat(bitbucket-cloud): add HMAC webhook secret validation - #2870

Merged
zakisk merged 1 commit into
tektoncd:mainfrom
zakisk:SRVKP-12223-bb-cloud-hmac-validation
Aug 3, 2026
Merged

feat(bitbucket-cloud): add HMAC webhook secret validation#2870
zakisk merged 1 commit into
tektoncd:mainfrom
zakisk:SRVKP-12223-bb-cloud-hmac-validation

Conversation

@zakisk

@zakisk zakisk commented Jul 21, 2026

Copy link
Copy Markdown
Member

📝 Description of the Change

Implement X-Hub-Signature / X-Hub-Signature-256 HMAC validation for Bitbucket Cloud webhooks, matching the existing GitHub and Bitbucket Data Center pattern. PaC first checks IP-Based validation if it's disabled then fallback to webhook secret validation and checks if a webhook_secret is configured on the Repository CR, incoming payloads are verified against the signature header.

Assisted-by: Claude Opus 4.6 (via Claude Code)

🔗 Linked GitHub Issue

Fixes #

🧪 Testing Strategy

  • Unit tests
  • Integration tests
  • End-to-end tests
  • Manual testing
  • Not Applicable

🤖 AI Assistance

AI assistance can be used for various tasks, such as code generation,
documentation, or testing.

Please indicate whether you have used AI assistance
for this PR and provide details if applicable.

  • I have not used any AI assistance for this PR.
  • I have used AI assistance for this PR.

Important

Slop will be simply rejected, if you are using AI assistance you need to make sure you
understand the code generated and that it meets the project's standards. you
need at least know how to run the code and deploy it (if needed). See
startpaac to make it easy
to deploy and test your code changes.

If the majority of the code in this PR was generated by an AI, please add a Co-authored-by trailer to your commit message.
For example:

Co-authored-by: Claude noreply@anthropic.com

✅ Submitter Checklist

  • 📝 My commit messages are clear, informative, and follow the project's How to write a git commit message guide. The Gitlint linter ensures in CI it's properly validated
  • ✨ I have ensured my commit message prefix (e.g., fix:, feat:) matches the "Type of Change" I selected above.
  • ♽ I have run make test and make lint locally to check for and fix any
    issues. For an efficient workflow, I have considered installing
    pre-commit and running pre-commit install to
    automate these checks.
  • 📖 I have added or updated documentation for any user-facing changes.
  • 🧪 I have added sufficient unit tests for my code changes.
  • 🎁 I have added end-to-end tests where feasible. See README for more details.
  • 🔎 I have addressed any CI test flakiness or provided a clear reason to bypass it.
  • If adding a provider feature, I have filled in the following and updated the provider documentation:
    • GitHub App
    • GitHub Webhook
    • Gitea/Forgejo
    • GitLab
    • Bitbucket Cloud
    • Bitbucket Data Center

@zakisk

zakisk commented Jul 21, 2026

Copy link
Copy Markdown
Member Author

e2e test would fail on it waiting for #2869 to be merged.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces webhook secret validation for Bitbucket Cloud using HMAC-SHA256/SHA1 signatures, updating both the documentation and the provider implementation. The review feedback highlights a critical backward compatibility issue: the new validation logic blocks webhooks when no secret is configured, rather than falling back to IP-based validation. To resolve this, the reviewer suggests returning early with no error when the secret is empty and adjusting the corresponding unit tests.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread pkg/provider/bitbucketcloud/bitbucket.go
Comment thread pkg/provider/bitbucketcloud/bitbucket_test.go

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 webhook HMAC signature validation to the Bitbucket Cloud provider to align with the existing signature-validation patterns used by other providers, and updates docs/tests accordingly.

Changes:

  • Implement HMAC signature validation in bitbucket-cloud provider Validate().
  • Add unit tests covering signature validation scenarios for Bitbucket Cloud.
  • Update Bitbucket Cloud provider documentation to describe configuring a webhook secret.

Reviewed changes

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

File Description
pkg/provider/bitbucketcloud/bitbucket.go Adds signature-header extraction and HMAC verification in Validate().
pkg/provider/bitbucketcloud/bitbucket_test.go Introduces unit tests for Bitbucket Cloud webhook validation.
docs/content/docs/providers/bitbucket-cloud.md Documents webhook secret configuration and reframes IP-checking as defense-in-depth.

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

Comment thread pkg/provider/bitbucketcloud/bitbucket.go
Comment thread pkg/provider/bitbucketcloud/bitbucket_test.go
Comment thread docs/content/docs/providers/bitbucket-cloud.md Outdated
@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.43%. Comparing base (c42a902) to head (6cbe058).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2870      +/-   ##
==========================================
- Coverage   68.45%   68.43%   -0.02%     
==========================================
  Files         197      197              
  Lines       16766    16777      +11     
==========================================
+ Hits        11477    11482       +5     
- Misses       4417     4423       +6     
  Partials      872      872              
Flag Coverage Δ
unit-tests 68.43% <100.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread pkg/provider/bitbucketcloud/bitbucket.go
Comment thread pkg/provider/bitbucketcloud/bitbucket_test.go
func (v *Provider) Validate(_ context.Context, _ *params.Run, _ *info.Event) error {
return nil
func (v *Provider) Validate(_ context.Context, _ *params.Run, event *info.Event) error {
signature := event.Request.Header.Get(github.SHA256SignatureHeader)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The docs suggest PaC validates X-Hub-Signature but github.SHA256SignatureHeader = X-Hub-Signature-256

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Bitbucket Cloud sends SHA-256 signatures as X-Hub-Signature: sha256=. The current tests cover X-Hub-Signature-256 with SHA-256 and X-Hub-Signature with SHA-1, but not the format Bitbucket actually sends. Please update the docs and add a positive test for X-Hub-Signature with SHA-256.

See the doc: https://support.atlassian.com/bitbucket-cloud/docs/manage-webhooks/

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.

yeah, this is weird bb cloud send X-Hub-Signature with sha256 prefix and calculated as sha256

Comment thread pkg/provider/bitbucketcloud/bitbucket_test.go Outdated
Comment thread pkg/provider/bitbucketcloud/bitbucket_test.go
Comment thread pkg/provider/bitbucketcloud/bitbucket.go
@zakisk
zakisk force-pushed the SRVKP-12223-bb-cloud-hmac-validation branch 2 times, most recently from b606f5d to 1e2dd36 Compare July 22, 2026 14:54
@zakisk

zakisk commented Jul 24, 2026

Copy link
Copy Markdown
Member Author

Paco Review ⚠️

This PR adds HMAC webhook signature validation to the Bitbucket Cloud provider by checking the X-Hub-Signature-256 (falling back to X-Hub-Signature) header and comparing it against a configured webhook secret using go-github's ValidateSignature helper. It also updates the Bitbucket Cloud docs to describe the new webhook-secret-based validation alongside the existing IP-based checks, and adds a table-driven test suite covering the new Validate logic.

Reviewed commit: 1e2dd36

@zakisk zakisk left a comment

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.

Paco inline comments -- see the Paco Review summary comment for the overview.

Comment thread pkg/provider/bitbucketcloud/bitbucket.go Outdated
Comment thread pkg/provider/bitbucketcloud/bitbucket_test.go Outdated
@zakisk
zakisk force-pushed the SRVKP-12223-bb-cloud-hmac-validation branch 3 times, most recently from ad70d85 to 248d89e Compare July 28, 2026 09:20
Comment thread pkg/provider/bitbucketcloud/bitbucket.go Outdated
Comment thread pkg/provider/bitbucketcloud/bitbucket.go
Comment thread docs/content/docs/providers/bitbucket-cloud.md Outdated
Comment thread docs/content/docs/providers/bitbucket-cloud.md Outdated
@zakisk
zakisk force-pushed the SRVKP-12223-bb-cloud-hmac-validation branch from 248d89e to 734b7cb Compare July 28, 2026 12:54

@theakshaypant theakshaypant left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Minor suggestions for docs.

Comment thread docs/content/docs/providers/bitbucket-cloud.md Outdated
Comment thread docs/content/docs/providers/bitbucket-cloud.md Outdated
Comment thread docs/content/docs/providers/bitbucket-cloud.md Outdated
@chmouel

chmouel commented Jul 29, 2026

Copy link
Copy Markdown
Member

all good for me but please consider fix the spelling as highlighted by akshay

@zakisk
zakisk force-pushed the SRVKP-12223-bb-cloud-hmac-validation branch 3 times, most recently from 9b04119 to a849d4a Compare July 31, 2026 10:12
@zakisk

zakisk commented Jul 31, 2026

Copy link
Copy Markdown
Member Author

/retest

1 similar comment
@zakisk

zakisk commented Jul 31, 2026

Copy link
Copy Markdown
Member Author

/retest

Implement X-Hub-Signature / X-Hub-Signature-256 HMAC validation
for Bitbucket Cloud webhooks, matching the existing GitHub and
Bitbucket Data Center pattern. When a webhook_secret is configured
on the Repository CR, incoming payloads are verified against the
signature header. Repositories without a webhook_secret continue
to rely on IP-based validation for backward compatibility.

Signed-off-by: Zaki Shaikh <zashaikh@redhat.com>
Assisted-by: Claude Opus 4.6 (via Claude Code)
@zakisk
zakisk force-pushed the SRVKP-12223-bb-cloud-hmac-validation branch from a849d4a to 6cbe058 Compare August 3, 2026 06:11
@zakisk

zakisk commented Aug 3, 2026

Copy link
Copy Markdown
Member Author

I think last week doc-deployment was failing due to cluster issue

@zakisk

zakisk commented Aug 3, 2026

Copy link
Copy Markdown
Member Author

/retest

@theakshaypant theakshaypant left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, all earlier review comments have been addressed.

@zakisk
zakisk merged commit a5b9155 into tektoncd:main Aug 3, 2026
17 checks passed
@zakisk
zakisk deleted the SRVKP-12223-bb-cloud-hmac-validation branch August 3, 2026 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants