本頁面說明如何設定 Secure Web Proxy 的授權政策。
事前準備
查看「Secure Web Proxy 總覽」和「授權政策總覽」頁面。
-
- Network Security API
- Network Services API
- Certificate Manager API
確認您具備適當的角色和權限。
您必須部署有效的 Secure Web Proxy 執行個體,並與
GatewaySecurityPolicy建立關聯。詳情請參閱「部署 Secure Web Proxy 執行個體」。如要設定 Secure Web Proxy 授權政策,您必須啟用 TLS 檢查政策。
建立授權政策
您可以針對兩種不同的用途設定授權政策:
控管代理流量:如要保護從 AI 代理傳送至 Model Context Protocol (MCP) 伺服器、工具和模型的傳出流量,請參閱「設定代理目的地的授權政策」。您可以在
agentGateway資源上設定政策和擴充功能繫結,強制執行 MCP 工具限制、mTLS 代理身分和酬載清理。保護非代理式網路流量:如要保護非代理式企業工作負載的傳出網路流量,請參閱後續章節的範例。您可以直接在 Secure Web Proxy
Gateway資源上設定政策,強制執行 mTLS 用戶端憑證身分、服務帳戶、安全標記或自訂授權擴充功能。
如要為 Secure Web Proxy 建立授權政策,請按照下列步驟操作:
- 設定 YAML 檔案,定義目標和規則。
- 如要匯入 YAML 檔案,請執行
gcloud network-security authz-policies import指令。
設定代理目的地授權政策
將 Secure Web Proxy 部署為 Agent Gateway 後,即可定義授權政策,檢查及限制導向 MCP 工具伺服器和 AI 代理目的地的流量。
您可以設定規則,在下列要求層強制執行存取控管:
網路規則:略過特定信任外部模型或代理端點的 TLS 檢查或深層酬載分析。
擴充功能繫結:使用 Service Extensions 中的
ExtensionBinding資源,附加外部管理和安全處理器,例如用於代理身分驗證的 Identity-Aware Proxy (IAP),以及用於提示和回覆清理的 Model Armor。HTTP MCP 方法和工具篩選:對特定 MCP 動作 (例如
tools/list或tools/call) 實施精細控管,並驗證引數,限制代理可叫用的工具。
授權規則的評估順序
透過 Agent Gateway 處理傳出的 AI 代理流量時,系統會按照下列順序評估規則:
網路 (L4) 授權規則:最先評估。如果適用 SNI 比對規則 (例如允許與外部模型端點直接通訊),流量就會略過 TLS 攔截。
TLS 攔截:未略過的流量會遭到攔截,並使用閘道的 TLS 檢查政策解密。
擴充功能繫結規則:要求會由設定的擴充功能服務 (例如 IAP) 評估,驗證要求標頭中的呼叫端身分,並由 Model Armor 檢查解密的酬載,確保提示詞安全,並防止回覆中發生資料外洩。
HTTP (L7) 授權規則:評估 HTTP 層級的授權政策,例如 MCP 工具限制和方法篩選。
範例 1:限制 MCP 工具執行
以下範例顯示附加至 agentGateway 資源的授權政策,允許代理探索工具 (tools/list),並僅執行核准的工具 (tools/call 適用於 get_weather 和 get_location):
建立名為
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更改下列內容:
PROJECT_ID: Google Cloud 專案 IDLOCATION:部署 Agent Gateway 和 Secure Web Proxy 執行個體的區域AGENT_GATEWAY_NAME:與 Secure Web Proxy 閘道相關聯的agentGateway資源名稱
執行
gcloud network-security authz-policies import指令,匯入授權政策。gcloud network-security authz-policies import authz-policy-restrict-tools \ --source=authz-policy-mcp.yaml \ --location=LOCATION
範例 2:使用 SNI 比對略過 TLS 攔截
如果特定外部模型供應商或代理 API 使用憑證固定,或不需要檢查酬載,您可以使用網路規則比對伺服器名稱指示 (SNI),並允許連線,而不解密工作階段。
建立名為
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更改下列內容:
PROJECT_ID: Google Cloud 專案 IDLOCATION:部署 Agent Gateway 和 Secure Web Proxy 執行個體的區域AGENT_GATEWAY_NAME:與 Secure Web Proxy 閘道相關聯的agentGateway資源名稱
執行
gcloud network-security authz-policies import指令,匯入授權政策。gcloud network-security authz-policies import authz-policy-skip-interception \ --source=authz-policy-sni.yaml \ --location=LOCATION
範例 3:使用擴充功能繫結,透過 Model Armor 啟用深度酬載檢查
如要防範提示詞注入、有害輸出內容或敏感資料外洩,您可以使用 Service Extensions 中的擴充功能繫結,將流量處理作業卸載至 Model Armor 或自訂 ext_proc 處理器。
這個模型會以下列方式區分擴充功能供應商和消費者:
- Google 服務 (1P):Model Armor 和 IAP 等內建 Google 服務的基礎架構由 Google 管理。您可以使用預先定義的端點 URI (
modelarmor.googleapis.com或iap.googleapis.com) 直接繫結服務。 - 自訂和合作夥伴擴充功能 (2P/3P):如果是自訂內部處理器或第三方資安供應商,供應商會發布指向其 Private Service Connect 服務連結的
ProducerExtension資源,而消費者會繫結該資源 URI。
如要進一步瞭解如何評估 agentGateway 資源的授權政策和擴充功能,請參閱「使用 Service Extensions 委派授權」和「Agent Gateway 的可擴充政策」。
如要設定 Model Armor 的擴充功能繫結,請按照下列步驟操作:
啟用 Service Extensions API。
gcloud services enable serviceextensions.googleapis.com
建立名為
extension-binding-model-armor.yaml的設定檔,指定agentGateway資源、設定檢查範本,並攔截傳送至 MCP 伺服器的流量。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"更改下列內容:
PROJECT_ID: Google Cloud 專案 IDLOCATION:部署 Agent Gateway 和 Secure Web Proxy 執行個體的區域AGENT_GATEWAY_NAME:agentGateway資源的名稱TEMPLATE_PROJECT_ID:建立 Model Armor 範本的專案 IDREQUEST_TEMPLATE_ID:用於檢查傳入要求的範本 IDRESPONSE_TEMPLATE_ID:用於檢查傳出回應的範本 ID
注意:
- 如果無法連上擴充功能服務,
failOpen: false會封鎖流量。如要在服務中斷期間允許流量未經檢查即通過,請設定failOpen: true。 - 如要繫結自訂內部或第三方擴充功能,而非 Model Armor,請將
producerExtension設為供應商的資源路徑,格式如下:projects/PRODUCER_PROJECT_ID/locations/LOCATION/producerExtensions/PRODUCER_EXTENSION_NAME。
如要匯入擴充功能繫結,請執行
gcloud beta service-extensions extension-bindings import指令。gcloud beta service-extensions extension-bindings import ext-binding-model-armor \ --source=extension-binding-model-armor.yaml \ --location=LOCATION
如要進一步瞭解如何繫結 IAP 進行身分驗證,請參閱「將擴充功能繫結附加至 Agent Gateway」。
以 mTLS 身分為基礎的授權政策
Secure Web Proxy 支援根據雙向 TLS (mTLS) 憑證衍生的身分,強制執行安全性規則。在零信任環境中,用戶端與 Proxy 之間的流量會受到 mTLS 保護,因此根據這些身分強制執行規則特別實用。詳情請參閱「依據主體的授權政策」。
以下範例顯示名為 swp1 的 Secure Web Proxy 執行個體授權政策。本範例假設傳送至 Proxy 的流量使用 HTTPS 通訊協定。
具有 REQUEST_AUTHZ 設定檔的政策會強制規定,所有傳送至 example.com/mcp 的流量都必須先通過特定主體的 mTLS 驗證,才能通過。這項政策也會拒絕所有非傳送至 example.com/mcp 的傳出流量。
建立授權政策 YAML 檔案。
以下範例會建立
authz-policy.yaml檔案。只有在用戶端出示與定義的SPIFFE ID主體相符的憑證時,政策才會允許流量傳送至指定的主機和路徑。$ 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更改下列內容:
PROJECT_ID: Google Cloud 專案 IDLOCATION:Secure Web Proxy 執行個體的區域
使用
gcloud network-security authz-policies import指令建立授權政策並匯入 YAML 檔案。gcloud beta network-security authz-policies import my-authz-policy-allow --source=authz-policy.yaml --location= LOCATION將
LOCATION替換為 Secure Web Proxy 執行個體的區域。
依據服務帳戶或標記設定授權政策
您可以根據附加至各種 Google Cloud 資源的服務帳戶或標記,套用授權政策。
本範例假設您已完成下列事項:
建立標記,並以鍵/值組合的形式附加至 Google Cloud 資源。建立標記時,請將
--purpose旗標設為GCE_FIREWALL。授權政策規定需要GCE_FIREWALL目的才能套用標記。
服務帳戶
建立授權政策 YAML 檔案,允許特定要求。
下列範例會為名為
swp1的 Secure Web Proxy 執行個體建立authz-policy.yaml檔案。這項政策設定為允許來自 Compute Engine 虛擬機器 (VM) 執行個體 (具有服務帳戶my-sa-123@56788.) 的要求,連至 example1.com/url1 路徑。$ 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更改下列內容:
PROJECT_ID: Google Cloud 專案 IDLOCATION:Secure Web Proxy 執行個體的區域
使用
gcloud network-security authz-policies import指令建立授權政策並匯入 YAML 檔案。下列範例指令說明如何匯入先前建立的政策檔案,並建立授權政策:
gcloud network-security authz-policies import my-authz-policy-allow --source=authz-policy.yaml --location= LOCATION將
LOCATION替換為 Secure Web Proxy 執行個體的區域。
標記
建立授權政策 YAML 檔案,允許特定要求。
以下範例會為名為
swp1的 Secure Web Proxy 執行個體建立authz-policy-tag.yaml檔案。這項政策只允許來自 Google Cloud資源且標記值為TAG_VALUE_PERMANENT_ID的要求,存取example1.com/url1網址路徑。$ 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更改下列內容:
PROJECT_ID: Google Cloud 專案 IDLOCATION:Secure Web Proxy 執行個體的區域GATEWAY_NAME:Secure Web Proxy 閘道名稱TAG_VALUE_PERMANENT_ID:標記值的永久 ID,例如tagValues/123456789012
使用
gcloud network-security authz-policies import指令建立授權政策並匯入 YAML 檔案。下列範例指令會匯入先前建立的政策檔案,並在指定的 Google Cloud 區域中建立授權政策:
gcloud network-security authz-policies import my-authz-policy-tag-allow --source=authz-policy-tag.yaml --location= LOCATION將
LOCATION替換為 Secure Web Proxy 執行個體的區域。
委派授權決策的授權政策
如果授權決策過於複雜,無法使用標準 ALLOW 或 DENY 規則表示,您可以建立具有 CUSTOM 動作的授權政策。接著,您可以將授權決策委派給授權擴充功能 (Service Extensions)。
使用 CUSTOM 動作設定政策時,Secure Web Proxy 會將要求中繼資料或酬載卸載至 Service Extensions。視 Service Extensions 的回應而定,Proxy 會允許或拒絕流量。
Secure Web Proxy 支援下列委派類型:
將要求授權決策委派給 Service Extensions:您可以使用設定
CUSTOM動作和REQUEST_AUTHZ設定檔的授權政策,根據要求中繼資料和標頭委派決策。在這個模式中,存取權決策會委派給授權擴充功能。您可以使用這個模式驗證身分和權限。將內容授權決策委派給 Service Extensions:您可以使用具有
CUSTOM動作和CONTENT_AUTHZ設定檔的授權政策,根據要求的實際資料酬載,將決策委派給授權擴充功能。這個模式可讓您啟用深度內容檢查和安全防護措施,並整合 Model Armor 等服務,掃描私密資訊或惡意模式。
限制
為 Secure Web Proxy 導入授權政策時,須遵守下列限制:
目標和連線限制:Secure Web Proxy 的授權擴充功能不支援將 IAP 做為直接目標。
政策衝突和相容性:如果閘道安全性政策已有安全性規則,則不需移除。當您將授權政策套用至執行個體時,Secure Web Proxy 會忽略這些規則。
通訊協定和檢查需求:如要設定 Secure Web Proxy 授權政策,您必須啟用 TLS 檢查。