我如何在 GCP 中的负载均衡器旁边阻止我的 VM 的流量

How I block the traffic of my VM's beside the Load Balancers in GCP

我在 GCP 中遇到来自中国和美洲的流量影响我的 VM 的问题,我已经设置 GCP Cloud Armor 以阻止来自智利以外的任何流量。但这只是通过网站 url 输入的流量,但如果您输入 ip,您仍然可以输入。这推高了云费用。

我如何设置我的虚拟机只接受来自负载均衡器的流量? 谢谢!

编辑: 我正在使用非托管实例组。

Google Cloud Armor 安全策略有一个拒绝规则,阻止来自 IP 地址和特定区域的流量。

您可以使用 Google Cloud Console、Google Cloud CLI 或 REST API 配置 Google Cloud Armor 安全策略、规则和表达式.当您使用 gcloud CLI 创建安全策略时,使用 --type 标志指定安全策略是后端安全策略还是边缘安全策略。

以下命令添加规则以阻止来自指定 IP 范围内的中国和美国区域的请求:

gcloud compute security-policies rules create 1000 \
 --security-policy my-policy \
 --expression ("origin.region_code == 'CN' || 'US') &&  inIpRange(origin.ip, '1.2.3.0/24')" \
 --action "deny-403" \
 --description "country and IP block"

请参阅此 documentation for more information on blocking traffic from specific regions using Google Cloud Armor and refer to this documentation 区域代码。