Set up authorization policies for Secure Web Proxy

This page describes how to configure authorization policies for Secure Web Proxy.

Before you begin

Create an authorization policy

You can configure authorization policies for two distinct use cases:

  • Govern agentic traffic: to secure outbound traffic from AI agents to Model Context Protocol (MCP) servers, tools, and models, see Configure authorization policies for agentic destinations. You can configure policies and extension bindings on the agentGateway resource to enforce MCP tool restrictions, mTLS agent identities, and payload sanitization.

  • Secure non-agentic web traffic: to secure outbound web traffic from non-agentic enterprise workloads, see the examples in the subsequent sections. You can configure policies directly on the Secure Web Proxy Gateway resource to enforce mTLS client certificate identities, service accounts, secure tags, or custom authorization extensions.

To create an authorization policy for Secure Web Proxy, do the following:

Configure authorization policies for agentic destinations

When you deploy Secure Web Proxy as an Agent Gateway, you can define authorization policies to inspect and restrict the traffic that's directed to MCP tool servers and AI agent destinations.

You can configure rules that enforce access control at the following request layers:

  • Network rules: skip TLS inspection or deep payload analysis for specific trusted external model or agent endpoints.

  • Extension bindings: use ExtensionBinding resources in Service Extensions to attach external governance and security processors, such as Identity-Aware Proxy (IAP) for agent identity verification and Model Armor for prompt and response sanitization.

  • HTTP MCP method and tool filtering: enforce fine-grained controls over specific MCP actions, such as tools/list or tools/call, and validate arguments to restrict the tools that an agent can invoke.

Order of evaluation for authorization rules

When processing outbound AI agent traffic through an Agent Gateway, rules are evaluated in the following sequence:

  1. Network (L4) authorization rules: evaluated first. If an SNI match rule applies, such as allowing direct communication to an external model endpoint, traffic bypasses TLS interception.

  2. TLS interception: traffic that isn't bypassed is then intercepted and decrypted by using the gateway's TLS inspection policy.

  3. Extension binding rules: requests are evaluated by configured extension services, such as IAP, to verify the caller identity on request headers and Model Armor to inspect decrypted payloads for prompt safety and prevent sensitive data leaks in responses.

  4. HTTP (L7) authorization rules: HTTP-level authorization policies, such as MCP tool restrictions and method filtering, are evaluated.

Example 1: Restrict MCP tool execution

The following example shows an authorization policy attached to an agentGateway resource that allows agents to discover tools (tools/list) and run only approved tools (tools/call for get_weather and get_location):

  1. Create a file named authz-policy-mcp.yaml.

    name: authz-policy-restrict-tools
    target:
      resources:
      - "projects/PROJECT_ID/locations/LOCATION/agentGateways/AGENT_GATEWAY_NAME"
    policyProfile: REQUEST_AUTHZ
    httpRules:
    - to:
        operations:
        - mcp:
            baseProtocolMethodsOption: MATCH_BASE_PROTOCOL_METHODS
            methods:
            - name: "tools/list"
            - name: "tools/call"
              params:
              - exact: "get_weather"
              - exact: "get_location"
    action: ALLOW
    

    Replace the following:

    • PROJECT_ID: ID of your Google Cloud project
    • LOCATION: region where your Agent Gateway and Secure Web Proxy instances are deployed
    • AGENT_GATEWAY_NAME: name of the agentGateway resource that's associated with your Secure Web Proxy gateway
  2. To import the authorization policy, run the gcloud network-security authz-policies import command.

    gcloud network-security authz-policies import authz-policy-restrict-tools \
        --source=authz-policy-mcp.yaml \
        --location=LOCATION
    

Example 2: Bypass TLS interception by using SNI matching

If certain external model providers or agentic APIs use certificate pinning or don't require payload inspection, then you can use network rules to match the Server Name Indication (SNI) and allow the connection without decrypting the session.

  1. Create a file named authz-policy-sni.yaml.

    name: authz-policy-skip-interception
    target:
      resources:
      - "projects/PROJECT_ID/locations/LOCATION/agentGateways/AGENT_GATEWAY_NAME"
    policyProfile: REQUEST_AUTHZ
    networkRules:
    - to:
        operations:
        - snis:
          - exact: "api.example-model-provider.com"
    action: ALLOW
    

    Replace the following:

    • PROJECT_ID: ID of your Google Cloud project
    • LOCATION: region where your Agent Gateway and Secure Web Proxy instances are deployed
    • AGENT_GATEWAY_NAME: name of the agentGateway resource that's associated with your Secure Web Proxy gateway
  2. To import the authorization policy, run the gcloud network-security authz-policies import command.

    gcloud network-security authz-policies import authz-policy-skip-interception \
        --source=authz-policy-sni.yaml \
        --location=LOCATION
    

Example 3: Enable deep payload inspection with Model Armor by using extension bindings

To guard against prompt injection, toxic output, or sensitive data leakage, you can offload traffic processing to Model Armor or a custom ext_proc processor by using extension bindings in Service Extensions.

This model separates the extension provider from the consumer in the following way:

  • Google services (1P): for built-in Google services, such as Model Armor and IAP, Google manages the underlying infrastructure. You can directly bind the service by using predefined endpoint URIs (modelarmor.googleapis.com or iap.googleapis.com).
  • Custom and partner extensions (2P/3P): for custom internal processors or third-party security vendors, the producer publishes a ProducerExtension resource that points to their Private Service Connect service attachment and the consumer binds that resource URI.

For more information about how authorization policies and extensions are evaluated on an agentGateway resource, see Delegate authorization with Service Extensions and Extensible policies on Agent Gateway.

To configure an extension binding for Model Armor, do the following:

  1. Enable the Service Extensions API.

    gcloud services enable serviceextensions.googleapis.com
    
  2. Create a configuration file named extension-binding-model-armor.yaml that targets your agentGateway resource, sets your inspection templates, and intercepts the traffic destined for MCP servers.

    name: ext-binding-model-armor
    target:
      resources:
      - "//networkservices.googleapis.com/projects/PROJECT_ID/locations/LOCATION/agentGateways/AGENT_GATEWAY_NAME"
    failOpen: false
    producerExtension: modelarmor.googleapis.com
    producerMetadata:
      model_armor_settings: '[
        {
          "request_template_id": "projects/TEMPLATE_PROJECT_ID/locations/LOCATION/templates/REQUEST_TEMPLATE_ID",
          "response_template_id": "projects/TEMPLATE_PROJECT_ID/locations/LOCATION/templates/RESPONSE_TEMPLATE_ID"
        }
      ]'
    matchConditions:
    - to:
        destination:
          resources:
          - prefix: "urn:mcp"
    

    Replace the following:

    • PROJECT_ID: ID of your Google Cloud project
    • LOCATION: region where your Agent Gateway and Secure Web Proxy instances are deployed
    • AGENT_GATEWAY_NAME: name of your agentGateway resource
    • TEMPLATE_PROJECT_ID: project ID where your Model Armor templates are created
    • REQUEST_TEMPLATE_ID: ID of the template that's used to inspect incoming requests
    • RESPONSE_TEMPLATE_ID: ID of the template that's used to inspect outgoing responses

    Note:

    • failOpen: false blocks traffic if the extension service is unreachable. To allow traffic to pass through uninspected during service disruptions, set failOpen: true.
    • To bind a custom internal or third-party extension instead of Model Armor, set producerExtension to the producer's resource path in the following format: projects/PRODUCER_PROJECT_ID/locations/LOCATION/producerExtensions/PRODUCER_EXTENSION_NAME.
  3. To import the extension binding, run the gcloud beta service-extensions extension-bindings import command.

    gcloud beta service-extensions extension-bindings import ext-binding-model-armor \
        --source=extension-binding-model-armor.yaml \
        --location=LOCATION
    

For more information about binding IAP for identity verification, see Attach extension bindings to Agent Gateway.

Authorization policy based on mTLS identity

Secure Web Proxy supports enforcing security rules based on identities derived from mutual TLS (mTLS) certificates. Enforcing rules based on these identities is particularly useful in zero-trust environments, where the traffic between clients and the proxy is secured by mTLS. For more information, see Authorization policy based on principals.

The following example shows an authorization policy for a Secure Web Proxy instance named swp1. This example assumes that the traffic to the proxy uses HTTPS protocol.

The policy with the REQUEST_AUTHZ profile enforces that all traffic to example.com/mcp requires mTLS authentication from a specific principal before the traffic is allowed to pass through. The policy also denies all outbound traffic that isn't intended to go to example.com/mcp.

  1. Create the authorization policy YAML file.

    The following example creates an authz-policy.yaml file. The policy allows traffic to the specified host and path only if the client presents a certificate that matches the defined SPIFFE ID principal.

    $ cat >authz-policy.yaml <<EOF
    name: test-authz-policy-mtls
    target:
      resources:
      - "projects/ PROJECT_ID /locations/ LOCATION /gateways/swp1"
    policyProfile: REQUEST_AUTHZ
    httpRules:
    - to:
      operations:
      - hosts:
          - exact: "example.com"
        paths:
          - exact: "/mcp"
      from:
        sources:
        - principals:
          - principalSelector: CLIENT_CERT_URI_SAN
            principal:
              exact: "spiffe:// PROJECT_ID .global.123.workload.id.goog/ns/ns1/sa/hellomcp"
    action: ALLOW
    EOF
    

    Replace the following:

    • PROJECT_ID: ID of your Google Cloud project
    • LOCATION: region of your Secure Web Proxy instance
  2. Create an authorization policy and import the YAML file by using the gcloud network-security authz-policies import command.

    gcloud beta network-security authz-policies import my-authz-policy-allow
        --source=authz-policy.yaml
        --location= LOCATION 
    

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

Authorization policy based on service accounts or tags

You can apply an authorization policy based on service accounts or tags attached to various Google Cloud resources.

This example assumes that you have completed the following:

Service account

  1. Create an authorization policy YAML file to allow certain requests.

    The following example creates an authz-policy.yaml file for the Secure Web Proxy instance named swp1. The policy is configured to allow requests from a Compute Engine virtual machine (VM) instance with the service account my-sa-123@56788. to reach the example1.com/url1 path.

    $ cat >authz-policy.yaml <<EOF
    name: my-authz-policy-allow
    target:
        resources:
        - "projects/PROJECT_ID/locations/ LOCATION /gateways/swp1"
    policyProfile: REQUEST_AUTHZ
    httpRules:
    - from:
        sources:
            - resources:
                - iamServiceAccount:
                    exact: "my-sa-123@56788."
      to:
        operations:
        - hosts:
            - exact: "example1.com"
        paths:
        - prefix: "/url1"
    action: ALLOW
    EOF
    

    Replace the following:

    • PROJECT_ID: ID of your Google Cloud project
    • LOCATION: region of your Secure Web Proxy instance
  2. Create an authorization policy and import the YAML file by using the gcloud network-security authz-policies import command.

    The following example command shows how to import the previously created policy file and create an authorization policy:

    gcloud network-security authz-policies import my-authz-policy-allow
    
        --source=authz-policy.yaml
        --location= LOCATION 
    

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

Tag

  1. Create an authorization policy YAML file to allow certain requests.

    The following example creates an authz-policy-tag.yaml file for the Secure Web Proxy instance named swp1. The policy allows only the requests that originate from a Google Cloud resource with a tag value of TAG_VALUE_PERMANENT_ID to access the example1.com/url1 URL path.

    $ cat >authz-policy-tag.yaml <<EOF
    name: my-authz-policy-tag-allow
    target:
        resources:
        - "projects/PROJECT_ID/locations/ LOCATION /gateways/ GATEWAY_NAME "
    policyProfile: REQUEST_AUTHZ
    httpRules:
    - from:
        sources:
        - resources:
            - tagValueIdSet:
                ids: ["TAG_VALUE_PERMANENT_ID"]
      to:
        operations:
        - hosts:
            - exact: "example1.com"
            paths:
            - exact: "/url1"
    action: ALLOW
    EOF
    

    Replace the following:

    • PROJECT_ID: ID of your Google Cloud project
    • LOCATION: region of your Secure Web Proxy instance
    • GATEWAY_NAME: name of your Secure Web Proxy gateway
    • TAG_VALUE_PERMANENT_ID: permanent ID of a tag value, such as tagValues/123456789012
  2. Create an authorization policy and import the YAML file by using the gcloud network-security authz-policies import command.

    The following example command imports the previously created policy file and creates an authorization policy in the specified Google Cloud region:

    gcloud network-security authz-policies import my-authz-policy-tag-allow
        --source=authz-policy-tag.yaml
        --location= LOCATION 
    

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

Authorization policy to delegate authorization decisions

For complex authorization decisions that can't be expressed by using standard ALLOW or DENY rules, you can create an authorization policy with a CUSTOM action. You can then delegate your authorization decisions to authorization extensions (Service Extensions).

When you configure a policy with a CUSTOM action, Secure Web Proxy offloads the request metadata or payload to Service Extensions. Depending on the response from Service Extensions, the proxy either allows or rejects the traffic.

Secure Web Proxy supports the following types of delegations:

  • Delegate request authorization decisions to Service Extensions: you can use an authorization policy that's configured with a CUSTOM action and a REQUEST_AUTHZ profile to delegate decisions based on request metadata and headers. In this mode, the access decision is delegated to an authorization extension. You can use this mode to verify identities and permissions.

  • Delegate content authorization decisions to Service Extensions: you can use an authorization policy with a CUSTOM action and a CONTENT_AUTHZ profile to delegate decisions to an authorization extension based on the actual data payload of the request. This mode lets you enable deep content inspection and security enforcement, letting you scan for sensitive information or malicious patterns by integrating with services like Model Armor.

Limitations

When you implement authorization policies for Secure Web Proxy, the following limitations apply:

  • Target and connectivity constraints: authorization extensions for Secure Web Proxy don't support IAP as a direct target.

  • Policy conflict and compatibility: if you have a gateway security policy with existing security rules, then you don't need to remove them. Secure Web Proxy ignores these rules when you apply an authorization policy to your instance.

  • Protocol and inspection requirements: to configure Secure Web Proxy authorization policies, you must enable TLS inspection.

What's next