首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将Atlassian/Bitbucket in加入AWS EC2安全组白名单?

如何将Atlassian/Bitbucket in加入AWS EC2安全组白名单?
EN

Stack Overflow用户
提问于 2021-01-21 19:43:08
回答 2查看 459关注 0票数 1

我们希望Bitbucket webhooks触发我们的CI工具,该工具在亚马逊网络服务EC2实例上运行,受入口规则保护,不受一般访问的影响。

Bitbucket提供了一个页面,列出了他们在https://support.atlassian.com/bitbucket-cloud/docs/what-are-the-bitbucket-cloud-ip-addresses-i-should-use-to-configure-my-corporate-firewall/上的IP地址

他们还在https://ip-ranges.atlassian.com/上为亚特兰大的in提供了一个机器可用的版本。

我想知道,在亚马逊网络服务EC2安全组中添加和维护此列表的有效方法是什么,例如通过terraform。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-01-21 19:47:10

我最终从他们的页面中删除了机器可用的json,剩下的让terraform来管理。获取json的步骤保留为手动任务。

代码语言:javascript
复制
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
          )
}
票数 2
EN

Stack Overflow用户

发布于 2021-01-28 04:26:11

我改进了Richard的回答,并希望添加TF的http提供程序可以为您获取JSON,并且对jsondecode()调用稍作调整后,仍然可以使用相同的for循环。

代码语言:javascript
复制
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
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65826698

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档