操作失败:由于组织策略,访问被拒绝:constraint/compute.vmExternalIpAccess 违反了项目 <project-id>
Operation failed: Access denied due to organization policy: constraint/compute.vmExternalIpAccess violated for project <project-id>
ID: policy/gcp-org-policy-restrict-vm-external-ip
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| Google Cloud SDK 450.0.0 | active | — | — | — |
| Compute Engine API v1 | active | — | — | — |
| Organization Policy Service | active | — | — | — |
根因分析
GCP 组织策略 'compute.vmExternalIpAccess' 阻止创建具有外部 IP 的 VM;该约束在组织、文件夹或项目级别强制执行。
English
GCP organization policy 'compute.vmExternalIpAccess' blocks creating VMs with external IPs; the constraint is enforced at the organization, folder, or project level.
官方文档
https://cloud.google.com/compute/docs/ip-addresses/reserve-static-external-ip-address#organization_policy解决方案
-
创建没有外部 IP 的 VM:gcloud compute instances create <instance-name> --no-address --zone=<zone>。然后使用 Cloud NAT 或堡垒主机进行出站连接。
-
向 GCP 管理员请求组织策略的例外:让他们通过组织策略控制台将你的项目添加到允许列表。
-
使用具有允许外部 IP 的代理子网的共享 VPC,然后在该子网中启动 VM,不直接分配外部 IP。
无效尝试
常见但无效的做法:
-
80% 失败
Setting VM to use an ephemeral external IP manually in gcloud still fails because the policy blocks all external IP assignment.
-
70% 失败
Removing the VM and recreating without specifying --no-address still triggers the policy if the default network has external IP.
-
60% 失败
Creating a VM in a different project without checking its policy may still fail if the organization policy applies across projects.