[英]How to whitelist Atlassian/Bitbucket IPs in AWS EC2 security group?
我們希望 Bitbucket webhook 觸發我們的 CI 工具,該工具在 AWS EC2 實例上運行,受到一般訪問的入口規則的保護。
Bitbucket 提供了一個頁面,列出了他們的 IP 地址https://support.atlassian.com/bitbucket-cloud/docs/what-are-my-bitbucket-cloud-ipto-config -企業防火牆/
他們在https://ip-ranges.atlassian.com/上也有一個機器消耗版本,通常用於 Atlassian IP。
我想知道,在 AWS EC2 安全組中添加和維護此列表的有效方法是什么,例如通過 terraform。
我最終從他們的頁面上抓取了機器消耗品 json,並讓 terraform 管理 rest。 獲取 json 的步驟留作手動任務。
resource "aws_security_group_rule" "bitbucket-ips-sgr" {
security_group_id = "your-security-group-id"
type = "ingress"
from_port = 443
to_port = 443
protocol = "TCP"
cidr_blocks = local.bitbucket_cidrs_ipv4
ipv6_cidr_blocks = local.bitbucket_cidrs_ipv6
}
locals {
bitbucket_cidrs_ipv4 = [for item in local.bitbucket_ip_ranges_source.items:
# see https://stackoverflow.com/q/47243474/1242922
item.cidr if length(regexall(":", item.cidr)) == 0
]
bitbucket_cidrs_ipv6 = [for item in local.bitbucket_ip_ranges_source.items:
# see https://stackoverflow.com/q/47243474/1242922
item.cidr if length(regexall(":", item.cidr)) > 0
]
# the list originates from https://ip-ranges.atlassian.com/
bitbucket_ip_ranges_source = jsondecode(
<<JSON
the json output from the above URL
JSON
)
}
我改進了 Richard 的回答並想補充一點,TF 的 http 提供程序可以為您獲取 JSON,並且對jsondecode()
調用稍作調整,同樣for
循環仍然可以播放。
provider "http" {}
data "http" "bitbucket_ips" {
url = "https://ip-ranges.atlassian.com/"
request_headers = {
Accept = "application/json"
}
}
locals {
bitbucket_ipv4_cidrs = [for c in jsondecode(data.http.bitbucket_ips.body).items : c.cidr if length(regexall(":", c.cidr)) == 0]
bitbucket_ipv6_cidrs = [for c in jsondecode(data.http.bitbucket_ips.body).items : c.cidr if length(regexall(":", c.cidr)) > 0]
}
output "ipv4_cidrs" {
value = local.bitbucket_ipv4_cidrs
}
output "ipv6_cidrs" {
value = local.bitbucket_ipv6_cidrs
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.