本文說明如何為 Secure Web Proxy 設定服務頻率限制政策,保護系統免於流量過載,並管理傳出網路流量的費用。
事前準備
請參閱「Secure Web Proxy 總覽」和「服務頻率限制政策總覽」頁面。
-
- 網路安全 API (
networksecurity.googleapis.com) - Network Services API (
networkservices.googleapis.com)
執行下列指令,啟用 API:
gcloud services enable \ networksecurity.googleapis.com \ networkservices.googleapis.com - 網路安全 API (
請確認您的使用者帳戶具備必要的管理角色和權限,可設定 Secure Web Proxy 資源。
您必須先啟用 Secure Web Proxy 執行個體,才能建立政策。 詳情請參閱「部署 Secure Web Proxy 執行個體」。
選用:如要根據用戶端憑證身分 (例如
CLIENT_CERT_COMMON_NAME) 建立速率限制政策,請務必設定前端相互傳輸層安全標準 (mTLS)。
設定服務頻率限制政策
如要建立服務頻率限制政策,請在 YAML 檔案中定義設定,然後將該檔案匯入 Secure Web Proxy。
建立
my-rate-limit-policy.yaml檔案,然後指定政策參數。以下範例會將傳送至大型語言模型 (LLM) 供應商 (
foo.com) 的要求數量,限制為 Secure Web Proxy 閘道上每個代理每分鐘 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 執行個體的區域。