You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
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 bitbucket.org from Jenkins?
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:
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:
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!