使用 specific IP 范围更新安全组以仅允许 gitlab-ci 与自定义运行程序通信

Update security group with specific IP range to only allow gitlab-ci to communicate with custom runner

我已经按照 https://docs.gitlab.com/runner/configuration/runner_autoscale_aws_fargate/ 创建了一个自定义运行器,它附加了 public IP 并与“私有”资源一起位于 VPC 中。 runner 用于使用 gitlab ci/cd.

应用迁移

ALLOW 22 0.0.0.0/0已在安全组内申请;但它很容易受到攻击。我需要添加什么 IP 范围以仅允许 gitlab ci/cd runners 通过 SSH 访问?我暂时删除了该规则,所以我们收到了连接错误,但是连接到端口 22 的 IP 全部来自 AWS(假设 gitlab runners 也在 AWS 上)。

有什么我遗漏或不理解的地方吗?

我看了教程。您应该只允许 EC2 实例能够通过 SSH 进入 Fargate 任务。

一种方法是,您可以将 EC2 实例的安全组定义为 Fargate 任务安全组中的源,而不是使用 IP 地址(或 CIDR 块)。您不必明确提及任何 ip 范围。这是我的首选方法。

When you specify a security group as the source for a rule, traffic is allowed from the network interfaces that are associated with the source security group for the specified protocol and port. Incoming traffic is allowed based on the private IP addresses of the network interfaces that are associated with the source security group (and not the public IP or Elastic IP addresses).specify a security group as the source

第二种方法是,正如@samtoddler 提到的,您可以允许整个 VPC 网络,也可以将其限制在一个子网内。

我被误解了; gitlab-runner 与 gitlab 对话,而不是相反,我的理解是 gitlab 通过 SSH 与跑步者对话。

我的直接解决方案是两件事:

  • 将 EC2 实例移动到私有子网中
  • 根据@Aruk Ks 的回答,只允许 EC2 通过 SSH 与 ECS Fargate 任务通信

这也回答了我的问题https://forum.gitlab.com/t/gitlab-runner-on-private-ip/19673