除非允许所有流量,否则无法访问 Aws Application Load Balancer

Aws Application Load Balancer not accessible unless All traffic is allowed

我有这样的设置。

  1. Application Load Balancer(面向互联网)LB1,Route 53 中的条目为 loadbalancer1.com

  2. LB1 在安全组 sg1 中,该安全组具有接受所有 Https 请求的入站规则。

  3. LB1 附加了目标组,它有一个属于安全组 sg2 的 EC2 实例 instance1

  4. sg2 有入站规则指定流量只能来自 sg1

  5. 我在安全组 sg3 中有另一个 EC2 实例 instance2。此实例要访问​​ instance1。它通过调用负载均衡器 loadbalancer1.com(在端口 443 上,即 Https)

    来实现

此设置有效。现在我想改进一下。因为 loadbalancer1.com 只能从 instance2 访问。我想更改安全组 sg1 的入站规则以仅接受来自安全组 sg3 的流量。如果我这样做,loadbalancer1.com 将无法从 instance2 访问。

知道为什么吗?

这是个很好的问题。 TL;DR:它仅适用于不离开 VPC 的内部流量。

以下是详细情况:

当 instance2 访问面向互联网的负载均衡器时,流量首先离开您的 VPC 并转到 public 互联网。然后流量通过一些网络路由到达ELB,ELB将流量转发给instance1。

当流量离开 AWS VPC 并重新进入它时,与流量关联的源 SG 元数据“消失”了。从ELB的SG来看,它只知道流量来自instance2的public IP地址。

根据 Security group rules 文档:

When you specify a security group as the source or destination for a rule, the rule affects all instances that are associated with the security group. Incoming traffic is allowed based on the private IP addresses of the instances that are associated with the source security group (and not the public IP or Elastic IP addresses).