【问题标题】:Allow firewall rules for a GCP instance (port:8080) from CLI从 CLI 允许 GCP 实例(端口:8080)的防火墙规则
【发布时间】:2022-01-05 13:17:18
【问题描述】:

是否允许来自 CLI 的端口?
我在 GCP 中有一个实例,并且我安装了一个默认在 Port:8080 上运行的服务。我知道有一个选项可以更改防火墙规则以允许来自 GCP 仪表板的端口,但我想知道是否有任何方法可以允许来自 CLI 的所需端口
就我而言,我使用的是 Git Bash 而不是原生的 GCP Cloud Console
我已经看过允许来自命令行GCP Firewall-rules-from CLI 的端口的文档,但这会抛出ERROR,因为我使用的是Git Bash
这是错误日志:

[mygcp@foo~]$ gcloud compute firewall-rules create FooService --allow=tcp:8080 --description="Allow incoming traffic on TCP port 8080" --direction=INGRESS
Creating firewall...failed.
ERROR: (gcloud.compute.firewall-rules.create) Could not fetch resource:
 - Request had insufficient authentication scopes.

[mygcp@foo~]$ gcloud compute firewall-rules list
ERROR: (gcloud.compute.firewall-rules.list) Some requests did not succeed:
 - Request had insufficient authentication scopes.

是否有任何选项可以直接从 Git Bash CLI 允许所需的端口?

【问题讨论】:

  • 您是如何设置 gcloud 的?任何 gcloud 命令都有效吗? gcloud 可以在 PowerShell 上运行吗?
  • 您是否在 Compute Engine 上运行该命令?
  • @guillaumeblaquiere 是的,那个是 E2 虚拟机。但我已经从 Git Bash 连接到该 VM。

标签: linux google-cloud-platform virtual-machine git-bash google-cloud-iam


【解决方案1】:

默认情况下,Compute Engine 使用默认服务帐号 + scopes 来处理权限。

即使您的默认计算引擎服务帐户具有编辑者角色,默认范围也会限制 API 访问(顺便说一下,角色太宽,永远不要使用它!)。


要解决您的问题,有 2 个解决方案:

  • 在您的 Compute Engine 上使用自定义服务帐号

  • 将所需的范围添加到您当前使用的默认计算引擎服务帐户的计算引擎中。

在这两种情况下,您都必须停止 VM 以更新该安全配置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-11
    • 1970-01-01
    • 2019-06-26
    • 2021-02-24
    • 2022-11-14
    • 2015-06-17
    • 2020-01-30
    相关资源
    最近更新 更多