如何限制从 Internet 直接访问 Azure [=a10=] Load Balancer backend pool VM with NSG

How to restrict direct access from internet to Azure Public LoadBalancer backend pool VM with NSG

如标题中的问题,我在 Azure Cloud 上设置了以下体系结构,但在限制从 Internet 直接访问 VM 时遇到了问题。

架构要求如下:

假设两个虚拟机都在 WebASG(应用程序安全组)中,在应用于虚拟机子网的 NSG 设置中,我添加了一些规则(优先级高于 3 个 Azure NSG 默认规则):

  1. 场景 A(添加 1 个自定义规则):

Port: 80 - Protocol: Tcp - Source: Internet - Destination: WebASG - Action: Allow

使用此 NSG 设置,我可以从 LoadBalancer IP 访问 WebService(满足 #3 要求),但是两个 VM 的端口 80 上的 WebService 将暴露给 Internet(这违反了 #2 要求)

  1. 场景 B(添加 2 个自定义规则):

Port: 80 - Protocol: Tcp - Source: AzureLoadBalancer - Destination: WebASG - Action: Allow

Port: 80 - Protocol: Tcp - Source: Internet - Destination: WebASG - Action: Deny

这个NSG设置满足#2要求,但是访问LoadBalancer IP时无法访问WebService(违反#3要求)

请注意: 使用 AGW(Azure 应用程序网关,我可以通过这些 NSG 配置满足所有要求:

RuleName: AllowSSH Port: 22 - Protocol: Tcp - Source: sys-admin-ip-address - Destination: WebASG - Action: Allow

RuleName: DenyInternet2Web Port: Any - Protocol: Any - Source: Internet - Destination: WebASG - Action: Deny

RuleName: AllowProbe2Web Port: 80 - Protocol: Tcp - Source: VirtualNetwork - Destination: WebASG - Action: Allow

RuleName: AllowProbe2Web Port: 80 - Protocol: Tcp - Source: VirtualNetwork - Destination: WebASG - Action: Allow

我不想使用 AGW,因为它比 Azure LoadBalancer 花费更多(实际上 Basic LoadBalancer 是免费的)。那么,在使用 LoadBalancer 时,如何更改 NSG 以满足所有要求?

在此先感谢您的帮助!

我认为没有满足所有要求的 NSG 规则,因为 #1 和 #2 要求是矛盾的。

如果虚拟机必须有 public 个 IP 地址,它实际上就有机会暴露在互联网上。任何客户端都可以通过 public IP 访问虚拟机。如果你想通过负载均衡器前端 IP 访问虚拟机,它的工作原理是一样的。阅读 https://docs.microsoft.com/en-us/azure/load-balancer/load-balancer-overview#load-balancer-concepts

Load Balancer doesn't terminate or originate flows, interact with the payload of the flow, or provide any application layer gateway function. Protocol handshakes always occur directly between the client and the back-end pool instance. A response to an inbound flow is always a response from a virtual machine. When the flow arrives on the virtual machine, the original source IP address is also preserved.

在这种情况下,您可以删除后端实例 IP 地址,只需将负载均衡器前端用于 Web 流量和 SSH 连接。如果是这样,您可以 configure port forwarding in Azure Load Balancer for the SSH connections to individual instances and a load balancer rule for the web traffic following this quickstart,它适用于标准 LB。您只能允许来自客户端 IP 地址的端口 80 和 22。 NSG 将如下所示,

Port: 80,22 - Protocol: Tcp - Source: 客户端的 IP 列表- 目标:WebASG -操作:允许