You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过编程将GCP Cloud Armor托管防护设置为Plus层级?

解决GCP Cloud Armor Tier变更脚本编写建议
  • 不推荐模拟网页点击的方式,优先使用GCP官方提供的API/工具,稳定性和可靠性更高:
    • 使用gcloud命令行工具:直接通过命令修改安全策略的Tier,脚本中可直接调用该命令:
      gcloud compute security-policies update 你的安全策略名称 --set-tier=plus
      
    • 使用编程语言客户端库:GCP为主流语言都提供了客户端库,以Python为例,使用google-cloud-compute库实现:
      from google.cloud import compute_v1
      
      def upgrade_cloud_armor_tier(project_id, policy_name):
          client = compute_v1.SecurityPoliciesClient()
          # 获取目标安全策略
          policy = client.get(project=project_id, security_policy=policy_name)
          # 设置为Plus Tier
          policy.tier = "PLUS"
          # 提交更新
          operation = client.update(
              project=project_id,
              security_policy=policy_name,
              security_policy_resource=policy
          )
          # 等待操作完成
          operation.result()
      
      # 替换为你的项目ID和安全策略名称
      upgrade_cloud_armor_tier("你的项目ID", "你的安全策略名称")
      
  • 前置条件:确保执行脚本的账号拥有compute.securityPolicies.update权限,并且已完成GCP认证配置(本地可通过gcloud auth application-default login配置,服务器可使用服务账号密钥)。

内容的提问来源于stack exchange,提问作者Noam Galoz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 11:17:04