This page describes how to configure authorization policies for Secure Web Proxy.
Before you begin
Review the Secure Web Proxy overview and Authorization policy overview pages.
-
- Network Security API
- Network Services API
- Certificate Manager API
Make sure that you have the appropriate roles and permissions.
You must have an active Secure Web Proxy instance deployed and associated with a
GatewaySecurityPolicy. For more information, see Deploy a Secure Web Proxy instance.To configure Secure Web Proxy authorization policies, you must enable a TLS inspection policy.
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
agentGatewayresource 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
Gatewayresource 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 a YAML file that defines the target and rules.
- To import the YAML file, run the
gcloud network-security authz-policies importcommand.
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
ExtensionBindingresources 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/listortools/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:
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.
TLS interception: traffic that isn't bypassed is then intercepted and decrypted by using the gateway's TLS inspection policy.
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.
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):
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: ALLOWReplace the following:
PROJECT_ID: ID of your Google Cloud projectLOCATION: region where your Agent Gateway and Secure Web Proxy instances are deployedAGENT_GATEWAY_NAME: name of theagentGatewayresource that's associated with your Secure Web Proxy gateway
To import the authorization policy, run the
gcloud network-security authz-policies importcommand.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.
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: ALLOWReplace the following:
PROJECT_ID: ID of your Google Cloud projectLOCATION: region where your Agent Gateway and Secure Web Proxy instances are deployedAGENT_GATEWAY_NAME: name of theagentGatewayresource that's associated with your Secure Web Proxy gateway
To import the authorization policy, run the
gcloud network-security authz-policies importcommand.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.comoriap.googleapis.com). - Custom and partner extensions (2P/3P): for custom internal processors or
third-party security vendors, the producer publishes a
ProducerExtensionresource 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:
Enable the Service Extensions API.
gcloud services enable serviceextensions.googleapis.com
Create a configuration file named
extension-binding-model-armor.yamlthat targets youragentGatewayresource, 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 projectLOCATION: region where your Agent Gateway and Secure Web Proxy instances are deployedAGENT_GATEWAY_NAME: name of youragentGatewayresourceTEMPLATE_PROJECT_ID: project ID where your Model Armor templates are createdREQUEST_TEMPLATE_ID: ID of the template that's used to inspect incoming requestsRESPONSE_TEMPLATE_ID: ID of the template that's used to inspect outgoing responses
Note:
failOpen: falseblocks traffic if the extension service is unreachable. To allow traffic to pass through uninspected during service disruptions, setfailOpen: true.- To bind a custom internal or third-party extension instead of
Model Armor, set
producerExtensionto the producer's resource path in the following format:projects/PRODUCER_PROJECT_ID/locations/LOCATION/producerExtensions/PRODUCER_EXTENSION_NAME.
To import the extension binding, run the
gcloud beta service-extensions extension-bindings importcommand.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.
Create the authorization policy YAML file.
The following example creates an
authz-policy.yamlfile. The policy allows traffic to the specified host and path only if the client presents a certificate that matches the definedSPIFFE IDprincipal.$ 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 EOFReplace the following:
PROJECT_ID: ID of your Google Cloud projectLOCATION: region of your Secure Web Proxy instance
Create an authorization policy and import the YAML file by using the
gcloud network-security authz-policies importcommand.gcloud beta network-security authz-policies import my-authz-policy-allow --source=authz-policy.yaml --location= LOCATIONReplace
LOCATIONwith 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:
Created a service account and attached it to a Google Cloud resource.
Created a tag and attached it to a Google Cloud resource as a key-value pair. When you create a tag, set its
--purposeflag toGCE_FIREWALL. Authorization policies require theGCE_FIREWALLpurpose to apply the tag.
Service account
Create an authorization policy YAML file to allow certain requests.
The following example creates an
authz-policy.yamlfile for the Secure Web Proxy instance namedswp1. The policy is configured to allow requests from a Compute Engine virtual machine (VM) instance with the service accountmy-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 EOFReplace the following:
PROJECT_ID: ID of your Google Cloud projectLOCATION: region of your Secure Web Proxy instance
Create an authorization policy and import the YAML file by using the
gcloud network-security authz-policies importcommand.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= LOCATIONReplace
LOCATIONwith the region of your Secure Web Proxy instance.
Tag
Create an authorization policy YAML file to allow certain requests.
The following example creates an
authz-policy-tag.yamlfile for the Secure Web Proxy instance namedswp1. The policy allows only the requests that originate from a Google Cloud resource with a tag value ofTAG_VALUE_PERMANENT_IDto 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 EOFReplace the following:
PROJECT_ID: ID of your Google Cloud projectLOCATION: region of your Secure Web Proxy instanceGATEWAY_NAME: name of your Secure Web Proxy gatewayTAG_VALUE_PERMANENT_ID: permanent ID of a tag value, such astagValues/123456789012
Create an authorization policy and import the YAML file by using the
gcloud network-security authz-policies importcommand.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= LOCATIONReplace
LOCATIONwith 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
CUSTOMaction and aREQUEST_AUTHZprofile 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
CUSTOMaction and aCONTENT_AUTHZprofile 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.