Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Webhook security between bitbucket cloud and AWS?

Robert Patrick
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 21, 2019

I have a web hook registered to call the Jenkins BitBucket Push and Pull Request Plugin running in Jenkins on AWS.  The EC2 instance on which Jenkins is running is bound to an Elastic IP address (i.e., static IP).  How do I secure the calls to allow legitimate calls from bitbucket cloud through but not expose Jenkins to rogue calls?

The webhook infrastructure in bitbucket does not appear to support the use of credentials and the CIDR list of where these calls could originate is daunting.  Is my only choice to punt and drop back to polling from Jenkins?

1 answer

0 votes
Steffen Opel _Utoolity_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 22, 2019

There does indeed not seem to be an official Bitbucket Cloud approach for this common problem (would assume there is a related feature request, but couldn't find it right away).

I'd consider a workaround along the following lines:

Potential workaround

Your goal is to identify and ideally authenticate the Bitbucket Cloud webhook as early as possible so that rogue traffic doesn't even reach Jenkins or the EC2 instance in the first place.

A common pattern for this is to provide resp. authentication tokens, ideally within the HTTP request headers (as e.g. supported by Jira Service Desk webhooks), or at least as an HTTP query parameter as a fallback, here are two examples:

Now, within AWS you have a couple of edge services that allow you to achieve that one way or another, again just briefly to give you an idea where to start:

  • Amazon API Gateway + AWS Lambda, ideally via API Gateway Lambda Authorizers, or just a custom token (see example below) - "A Lambda authorizer is useful if you want to implement a custom authorization scheme that uses a bearer token authentication strategy such as OAuth or SAML, or that uses request parameters to determine the caller's identity. [emphasis mine]"
  • Amazon CloudFront + AWS Lambda@Edge - "Inspect headers or authorized tokens, inserting a corresponding header and allowing access control before forwarding a request to the origin. [emphasis mine]"

Both approaches already deflect most traffic at the network edge, and you can optionally further refine and control that with AWS WAF (Web Application Firewall (would e.g. allow to still use that daunting CIDR list and only check the token as a secondary line of defense).

I would also assume there are a few OSS projects that already implement those pattern, at least for related scenarios that may be easy to adopt, here's one each:

Good luck, and please share what you come up with!

Robert Patrick
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 22, 2022

We migrated away from BitBucket to GitHub to get a real solution without requiring complex workarounds...

Like Blake Duffey likes this

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events