阻止来自 Google 计算实例的违规 IP

Block offending IP from Google Compute Instance

Google Compute Engine 实例是否具有网络级 IP 地址 blocking/blacklist 功能?例如,一个站点托管在 GCE 实例上以允许 public 用户访问。但是,恶意脚本会运行多个 times/second,这不是合法流量。理想情况下,可以将违规用户的 IP 放在阻止列表中,这样流量就不会被路由到实例,而不仅仅是服务器端的机制(apache 模块、IPtables 等)仍然需要 CPU/RAM/disk 资源。

GCP 本身不提供 WAF。您可以使用市场 WAF(如 Brocade WAF)来阻止 IP。

https://cloud.google.com/launcher/solution/brocade-public-1063/stm-csub-1000-h-saf?q=brocade

您可以为您的实例设置一个 HTTP 负载平衡器,并只允许从 LB IP 地址到您的实例的流量。可以在 Help Center article.

中找到更多信息

是的,您可以使用 Gcloud 防火墙阻止它。

尝试从命令行或登录 Google Cloud 创建防火墙规则。

示例:

gcloud compute firewall-rules create tcp-deny --network example-network --source-ranges 10.0.0.0/8 --allow !tcp:80

以上规则将阻止从 10.0.0.0/8 到端口 80 (tcp) 的范围。 可以通过 tcp 和 udp 阻止其他 IP 范围。

有关更多信息,请查看:glcoud network config

这绝对不是管理防火墙黑名单的推荐方法。

然而...

在计算 GUI 中,您可以创建防火墙规则集操作以匹配 "deny" 以及协议和端口 "deny all"。然后设置源IP。

compute GUI

然后您可以 运行 一个 cron 作业来通过 gcloud compute firewall-rules update 更新您的防火墙,以便在您的列表发生变化时更新源 IP。

注(来自Google - https://cloud.google.com/vpc/docs/using-firewalls):

gcloud compute firewall-rules update is used to update firewall rules that allow/deny incoming/outgoing traffic. The firewall rule will only be updated for arguments that are specifically passed. Other attributes will remain unaffected. The action flag (whether to allow or deny matching traffic) cannot be defined when updating a firewall rule