Configure service rate limiting policies

This document describes how to configure service rate limiting policies for Secure Web Proxy to protect your systems from traffic overloads and manage the costs of outbound web traffic.

Before you begin

Set up a service rate limiting policy

To create a service rate limiting policy, define your configuration in a YAML file and then import that file into Secure Web Proxy.

  1. Create the my-rate-limit-policy.yaml file, and then specify the policy parameters.

    The following example limits the number of requests sent to a large language model (LLM) provider (foo.com) to 100 requests per minute for each agent on a Secure Web Proxy gateway for outbound traffic. Each agent is identified by the common name in its client certificate.

      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 "
    

    Replace the following:

    • PROJECT_ID: ID of your Google Cloud project
    • LOCATION: region of your Secure Web Proxy instance; for example, us-central1
    • GATEWAY_NAME: name of your Secure Web Proxy gateway instance
  2. Import the rate limit policy YAML file by using the following command:

    gcloud alpha network-security rate-limit-policies import test-policy \
      --source=my-rate-limit-policy.yaml \
      --location=LOCATION
    

    Replace LOCATION with the region of your Secure Web Proxy instance.

What's next