如何设置防火墙规则以仅允许从 Google Cloud 控制台通过 ssh 访问实例

rra*_*tam 4 ssh firewall google-cloud-platform

我可以允许 Bastian 主机的 IP,但如何在防火墙规则中允许 Google Cloud Console 的 IP?

meb*_*s99 6

1.如果您使用默认网络配置,Compute Engine 会创建防火墙规则,允许通过端口 22 进行 TCP 连接。您可以在 GCP Console 中看到它们:

GCP Console => VPC network => Firewall rules
Run Code Online (Sandbox Code Playgroud)

默认网络具有预配置的防火墙规则,允许网络中的所有实例相互通信。特别是,这些防火墙规则允许来自任何地方的 ICMP、RDP 和 SSH 入口流量 ( 0.0.0.0/0)。应该有 SSH 的入口防火墙规则:default-allow-ssh

2.如果您使用自定义网络,则应手动创建 SSH 的防火墙规则。

使用云控制台

GCP Console => VPC network => Firewall rules => Create Firewall Rule 
    Name:   mynet-allow-ssh
    Network:    mynet
    Targets:    All instances in the network
    Source filter:  IP Ranges
    Source IP ranges:   0.0.0.0/0 
    Protocols and ports:    Specified protocols and ports
        tcp: ports 22 
Run Code Online (Sandbox Code Playgroud)

使用命令行

$ gcloud compute --project=myproject firewall-rules create mynet-allow-ssh --direction=INGRESS --priority=1000 --network=mynet --action=ALLOW --rules=tcp:22 --source-ranges=0.0.0.0/0
Run Code Online (Sandbox Code Playgroud)

有关更多详细信息,请参阅计算引擎 => 文档 => 连接到实例

当您在 Cloud Console 中按下“SSH”按钮时,谈到将“Google Cloud Console IP”列入白名单,这是相当不可行的,因为 SSH 连接是通过 HTTPS 通过中继服务器建立的,该中继服务器可能具有不可预测的地址Google 的外部 IP 池。从这个角度来看,使用具有单个静态 IP 的堡垒主机更为合理。