本文档介绍如何为 Secure Web Proxy 配置 服务速率限制 政策 ,以保护您的系统免受流量过载的影响,并管理出站 Web 流量的 费用。
准备工作
查看 Secure Web 代理概览 和 服务速率限制政策概览 页面。
-
- Network Security API (
networksecurity.googleapis.com) - Network Services API (
networkservices.googleapis.com)
如需启用 API,请运行以下命令:
gcloud services enable \ networksecurity.googleapis.com \ networkservices.googleapis.com - Network Security API (
确保您的用户账号具有配置 Secure Web Proxy 资源所需的管理 角色和权限。
您必须先激活 Secure Web Proxy 实例,然后才能创建政策。如需了解详情,请参阅部署 Secure Web Proxy 实例。
可选:如需根据客户端证书 身份(例如
CLIENT_CERT_COMMON_NAME)创建速率限制政策,请确保您 配置了前端双向 TLS (mTLS)。
设置服务速率限制政策
如需创建服务速率限制政策,请在 YAML 文件中定义配置,然后将该文件导入 Secure Web Proxy。
创建
my-rate-limit-policy.yaml文件,然后指定政策参数。以下示例将发送给大型语言模型 (LLM) 提供商 (
foo.com) 的请求数限制为:对于出站流量,Secure Web 代理网关上的每个代理每分钟 100 个请求。每个代理都由其客户端证书中的通用名称标识。name: "projects/ PROJECT_ID /locations/ LOCATION /rateLimitPolicies/test-policy" description: "Simple agent for LLM rate limiting." httpRules: # Match on the provider host name. - to: destination: hosts: - exact: "foo.com" # default RPM bucket rateLimitActions: - rateLimitBucket: "rl_default_rpm_limit" rateLimitBuckets: - name: "rl_default_rpm_limit" # Identify client by its client cert name keys: - keyType: PRINCIPAL principalType: CLIENT_CERT_COMMON_NAME defaultLimit: countLimit: count: 100 interval: 1 intervalUnit: MINUTES targets: - resource: "projects/ PROJECT_ID /locations/ LOCATION /gateways/ GATEWAY_NAME "替换以下内容:
PROJECT_ID:您的 Google Cloud 项目的 IDLOCATION:Secure Web Proxy 实例的区域;例如,us-central1GATEWAY_NAME:Secure Web Proxy 网关实例的名称
使用以下命令导入速率限制政策 YAML 文件:
gcloud alpha network-security rate-limit-policies import test-policy \ --source=my-rate-limit-policy.yaml \ --location=LOCATION
将
LOCATION替换为 Secure Web Proxy 实例的区域。