將 Secure Web Proxy 部署為 Agent Gateway

本頁面說明如何設定 Secure Web Proxy 執行個體,並部署為 Agent Gateway。

總覽

在 Google Cloud 部署的企業 AI 工作負載需要結構化網路邊界,才能維持資料隱私權法規遵循、防止機密資料外洩,以及防範提示詞注入等新興 AI 威脅。

Agent Gateway 提供集中式安全管理、身分強制執行和內容防護機制,可控管從 AI 代理傳出至大型語言模型 (LLM)、Model Context Protocol (MCP) 工具、外部 API、遠端代理和標準網路目的地的流量。

您可以部署 Google 代管的 Agent Gateway,或將 Secure Web Proxy 執行個體部署為自行管理的 Agent Gateway。這兩種部署模型都提供通用的 Gemini Enterprise Agent Platform 管理解決方案,包括集中式存取政策、Agent Registry 整合和內容護欄。

請根據您的作業偏好,選擇下列其中一種部署選項:

  • Google 代管的 Agent Gateway:如果想享有全代管、免維護的體驗,不必管理網路 Proxy 基礎架構,請選用這個選項。詳情請參閱「Google 代管的 Agent Gateway」。這個模型經過最佳化,適用於在 Gemini Enterprise 或 Gemini Enterprise Agent Platform 的 Agent Runtime 上執行的代理。

  • Secure Web Proxy 做為自行管理的 Agent Gateway:如要完整控管虛擬私有雲網路 perimeter、私人 CA 憑證和 Proxy 轉送,以支援在 Google Kubernetes Engine (GKE) 或 Cloud Run 上執行的代理,請將 Secure Web Proxy 執行個體部署為 Agent Gateway。

優點

將 Secure Web Proxy 部署為 Agent Gateway,可享有下列優點:

  • 客戶控管的基礎架構:您可以在自己的虛擬私有雲 (VPC) 網路中管理 Secure Web Proxy 閘道,完全控管網路路由、IP 位址、私人 CA 憑證和 TLS 檢查。

  • 集中強制執行 AI 政策:您可以在 agentGateway 資源上定義授權政策。這可讓您直接在 Secure Web Proxy 閘道上強制執行這些政策,限制 MCP 工具呼叫、篩選 AI 代理的外部目的地,以及叫用 Model Armor 等內容清理服務。

  • 執行階段支援:您可以透過單一 Proxy 範圍,轉送託管於各種執行階段 (例如 GKE 或 Cloud Run) 的 AI 代理傳出的流量。

  • 代理感知觀測能力:Cloud Logging 中的交易記錄會自動包含 AI 代理執行中繼資料 (agentGatewayInfo),包括 MCP 方法、工具名稱和 Agent Registry 目的地的統一資源名稱 (URN)。

架構

下列步驟說明 Secure Web Proxy 如何做為 Agent Gateway,保護傳出流量:

  1. 代理執行階段:在 GKE 或 Cloud Run 上執行的自主代理,會啟動對外連線,連至外部 API、模型供應商、MCP 工具伺服器、遠端代理或標準網頁目的地。

  2. 傳出流量轉送:代理流量會透過虛擬私有雲內 Proxy 轉送,或跨虛擬私有雲 Private Service Connect (PSC) 服務連結,導向 Secure Web Proxy。

  3. 政策評估和內容清理:Secure Web Proxy 會終止 TLS 連線、強制執行 MCP 授權政策,並叫用 Model Armor 或 Identity-Aware Proxy (IAP) 等擴充功能服務,清理酬載並驗證用戶端身分。

事前準備

將 Secure Web Proxy 執行個體部署為 Agent Gateway 之前,請先完成下列必要條件:

  1. 啟用下列必要 Google Cloud API:

    gcloud services enable \
        networkservices.googleapis.com \
        networksecurity.googleapis.com \
        privateca.googleapis.com \
        certificatemanager.googleapis.com \
        serviceextensions.googleapis.com \
        agentregistry.googleapis.com \
        compute.googleapis.com
    
  2. 確認您具備下列必要的 Identity and Access Management (IAM) 角色:

  3. 為部署作業設定下列環境變數:

    export PROJECT_ID="my-project-id"
    export PROJECT_NUMBER="my-project-number"
    export REGION="us-central1"
    export NETWORK_NAME="swp-vpc"
    export PROXY_SUBNET_NAME="swp-proxy-subnet"
    export PSC_NAT_SUBNET_NAME="swp-psc-nat-subnet"
    export CA_POOL_NAME="swp-ca-pool"
    export ROOT_CA_NAME="swp-root-ca"
    export TLS_INSPECTION_POLICY_NAME="swp-tls-inspection-policy"
    export SECURE_WEB_PROXY_NAME="swp-agent-gateway"
    export SWP_IP_ADDRESS="10.129.0.10"
    export SWP_CERTIFICATE_NAME="swp-cert"
    export SERVER_TLS_POLICY_NAME="swp-server-tls-policy"
    export GATEWAY_SECURITY_POLICY_NAME="swp-security-policy"
    export SERVICE_ATTACHMENT_NAME="swp-service-attachment"
    export AGENT_GATEWAY_NAME="my-agent-gateway"
    
  4. 選用:如果 Agent Runtime 在不同的虛擬私有雲網路或代管環境中運作,例如跨專案 GKE 或 Cloud Run 叢集,則必須透過 Private Service Connect 服務連結公開 Secure Web Proxy:

設定 TLS 檢查

Secure Web Proxy 會終止 TLS 連線,以檢查 HTTP 標頭、評估 MCP 方法,以及清理酬載。

如要設定 TLS 檢查,請按照下列步驟建立私人憑證授權單位 (CA) 集區、根 CA 和 tlsInspectionPolicy 資源:

  1. 建立私人 CA 集區。

    gcloud privateca pools create CA_POOL_NAME \
        --location=REGION \
        --tier=devops \
        --project=PROJECT_ID
    

    更改下列內容:

    • CA_POOL_NAME:CA 集區名稱
    • REGION:建立 CA 集區的區域
    • PROJECT_ID: Google Cloud 專案 ID
  2. 在私人 CA 集區中建立根 CA。

    gcloud privateca roots create ROOT_CA_NAME \
        --pool=CA_POOL_NAME \
        --location=REGION \
        --subject="CN=Agent Gateway SWP Root CA, O=MyOrganization" \
        --auto-enable \
        --project=PROJECT_ID
    

    更改下列內容:

    • ROOT_CA_NAME:根 CA 的名稱
    • CA_POOL_NAME:CA 集區名稱
    • REGION:根 CA 的建立區域
    • PROJECT_ID: Google Cloud 專案 ID

    注意:如要讓用戶端工作負載 (例如 Cloud Run 或 GKE) 在 TLS 檢查期間信任這個 CA 集區核發的憑證,請匯出根 CA 憑證,然後新增至工作負載的信任存放區。例如,您可以設定 AGENT_GATEWAY_ROOT_CERTIFICATES 環境變數。

  3. 授予網路安全服務帳戶要求憑證的權限。

    gcloud privateca pools add-iam-policy-binding CA_POOL_NAME \
        --location=REGION \
        --member="serviceAccount:service-PROJECT_NUMBER@gcp-sa-networksecurity.iam.gserviceaccount.com" \
        --role="roles/privateca.certificateRequester" \
        --project=PROJECT_ID
    
  4. 在名為 tls-inspection-policy.yaml 的檔案中建立 tlsInspectionPolicy 資源。

    name: projects/PROJECT_ID/locations/REGION/tlsInspectionPolicies/TLS_INSPECTION_POLICY_NAME
    caPool: projects/PROJECT_ID/locations/REGION/caPools/CA_POOL_NAME
    

    更改下列內容:

    • PROJECT_ID: Google Cloud 專案 ID
    • REGION:建立 TlsInspectionPolicy 的區域
    • TLS_INSPECTION_POLICY_NAME:TlsInspectionPolicy 資源的名稱
    • CA_POOL_NAME:CA 集區名稱
  5. 執行 gcloud network-security tls-inspection-policies import 指令來匯入政策。

    gcloud network-security tls-inspection-policies import TLS_INSPECTION_POLICY_NAME \
        --source=tls-inspection-policy.yaml \
        --location=REGION \
        --project=PROJECT_ID
    

部署 Secure Web Proxy

建立已設定相互傳輸層安全性 (mTLS) 的 Secure Web Proxy 閘道。

  1. 請確認虛擬私有雲網路在您要部署閘道的區域中,有 Proxy 專用子網路。

    gcloud compute networks subnets create PROXY_SUBNET_NAME \
        --purpose=REGIONAL_MANAGED_PROXY \
        --role=ACTIVE \
        --region=REGION \
        --network=NETWORK_NAME \
        --range=10.129.0.0/23
    

    更改下列內容:

    • PROXY_SUBNET_NAME:僅限 Proxy 的子網路名稱
    • NETWORK_NAME:虛擬私有雲網路的名稱
    • REGION:建立子網路的區域
  2. 選用:從僅限 Proxy 的子網路範圍中選取可用的 IP 位址 (例如 10.129.0.0/23 內的 10.129.0.10),指派給 SWP_IP_ADDRESS。

    注意:如果您未在 swp.yaml 檔案中新增 addresses 欄位,Secure Web Proxy 會自動從僅限 Proxy 的子網路分配 IP 位址。

  3. 為確保 Secure Web Proxy 閘道能安全接受傳入的用戶端代理連線,請在 Certificate Manager 中建立區域 SSL/TLS 伺服器憑證。

    1. 產生自行管理的憑證和私密金鑰。

      openssl req -x509 -newkey rsa:2048 -nodes \
          -keyout "swp.key" \
          -out "swp.crt" \
          -days 365 \
          -subj "/CN=SWP_IP_ADDRESS"
      

      將 SWP_IP_ADDRESS 替換為 Secure Web Proxy 閘道的 IP 位址。

    2. 如要將憑證上傳至 Certificate Manager,請執行 gcloud certificate-manager certificates create 指令。

      gcloud certificate-manager certificates create SWP_CERTIFICATE_NAME \
          --location=REGION \
          --certificate-file="swp.crt" \
          --private-key-file="swp.key" \
          --project=PROJECT_ID
      

      更改下列內容:

      • SWP_CERTIFICATE_NAME:憑證資源的名稱
      • REGION:建立憑證的區域
      • PROJECT_ID: Google Cloud專案 ID
  4. 如要啟用前端 mTLS,請建立 ServerTlsPolicy 資源。如要允許 Cloud Run 等工作負載將身分憑證傳遞至 IAP 等服務,請使用 clientValidationMode: ALLOW_INVALID_OR_MISSING_CLIENT_CERT 設定政策。

    注意:如果使用 IAP,請勿為 clientValidationTrustConfig 欄位設定任何值,因為系統不支援。

    1. 建立名為 server-tls-policy.yaml 的檔案,然後加入下列內容:

      name: projects/PROJECT_ID/locations/REGION/serverTlsPolicies/SERVER_TLS_POLICY_NAME
      mtlsPolicy:
        clientValidationMode: ALLOW_INVALID_OR_MISSING_CLIENT_CERT
      

      更改下列內容:

      • PROJECT_ID: Google Cloud 專案 ID
      • REGION:建立 ServerTlsPolicy 的區域
      • SERVER_TLS_POLICY_NAME:ServerTlsPolicy 資源的名稱
    2. 執行 gcloud network-security server-tls-policies import 指令來匯入政策。

      gcloud network-security server-tls-policies import SERVER_TLS_POLICY_NAME \
          --source=server-tls-policy.yaml \
          --location=REGION \
          --project=PROJECT_ID
      
  5. 建立閘道安全性政策,以附加 tlsInspectionPolicy。

    1. 建立名為 gateway-security-policy.yaml 的檔案,然後新增下列內容:

      name: projects/PROJECT_ID/locations/REGION/gatewaySecurityPolicies/GATEWAY_SECURITY_POLICY_NAME
      tlsInspectionPolicy: projects/PROJECT_ID/locations/REGION/tlsInspectionPolicies/TLS_INSPECTION_POLICY_NAME
      

      更改下列內容:

      • PROJECT_ID: Google Cloud 專案 ID
      • REGION:建立 GatewaySecurityPolicy 的區域
      • GATEWAY_SECURITY_POLICY_NAME:GatewaySecurityPolicy 資源的名稱
      • TLS_INSPECTION_POLICY_NAME:TlsInspectionPolicy 資源的名稱
    2. 執行 gcloud network-security gateway-security-policies import 指令來匯入政策。

      gcloud network-security gateway-security-policies import GATEWAY_SECURITY_POLICY_NAME \
          --source=gateway-security-policy.yaml \
          --location=REGION \
          --project=PROJECT_ID
      
  6. 建立名為 swp.yaml 的 Secure Web Proxy 規格檔案。

    name: projects/PROJECT_ID/locations/REGION/gateways/SECURE_WEB_PROXY_NAME
    type: SECURE_WEB_GATEWAY
    addresses:
      - "SWP_IP_ADDRESS"
    ports:
      - 443
    routingMode: EXPLICIT_ROUTING_MODE
    certificateUrls:
      - projects/PROJECT_ID/locations/REGION/certificates/SWP_CERTIFICATE_NAME
    serverTlsPolicy: projects/PROJECT_ID/locations/REGION/serverTlsPolicies/SERVER_TLS_POLICY_NAME
    network: projects/PROJECT_ID/global/networks/NETWORK_NAME
    subnetwork: projects/PROJECT_ID/regions/REGION/subnetworks/PROXY_SUBNET_NAME
    gatewaySecurityPolicy: projects/PROJECT_ID/locations/REGION/gatewaySecurityPolicies/GATEWAY_SECURITY_POLICY_NAME
    

    更改下列內容:

    • PROJECT_ID: Google Cloud 專案 ID
    • REGION:建立 Secure Web Proxy 閘道的區域
    • SECURE_WEB_PROXY_NAME:Secure Web Proxy 閘道名稱
    • SWP_IP_ADDRESS:Secure Web Proxy 閘道的 IP 位址
    • SWP_CERTIFICATE_NAME:與 Secure Web Proxy 閘道相關聯的憑證名稱
    • SERVER_TLS_POLICY_NAME:ServerTlsPolicy 資源的名稱
    • NETWORK_NAME:虛擬私有雲網路的名稱
    • PROXY_SUBNET_NAME:僅限 Proxy 的子網路名稱
    • GATEWAY_SECURITY_POLICY_NAME:GatewaySecurityPolicy 資源的名稱
  7. 如要匯入 Secure Web Proxy 閘道,請執行 gcloud network-services gateways import 指令。

    gcloud network-services gateways import SECURE_WEB_PROXY_NAME \
        --source=swp.yaml \
        --location=REGION \
        --project=PROJECT_ID
    

如要變更現有 Secure Web Proxy 閘道的這些欄位,且不造成工作負載停機,請按照下列步驟操作:

  1. 建立另一個 Secure Web Proxy 閘道,並指定新名稱和必要設定。

  2. 更新 agentGateway 資源 (selfManaged.resourceUris),參照新的 Secure Web Proxy 閘道。

  3. 更新 EgressRouting 資源,指向新的 Secure Web Proxy 閘道。

  4. 確認新閘道成功管理流量路由後,請從 agentGateway 資源中移除舊的 Secure Web Proxy 閘道,然後刪除舊閘道資源。

將 Secure Web Proxy 執行個體與 Agent Gateway 建立關聯

如要將 Secure Web Proxy 執行個體與 agentGateway 資源建立關聯,請按照下列步驟操作:

  1. 建立名為 agent-gateway.yaml 的設定檔。

    name: projects/PROJECT_ID/locations/REGION/agentGateways/AGENT_GATEWAY_NAME
    selfManaged:
      resourceUris:
        - //networkservices.googleapis.com/projects/PROJECT_ID/locations/REGION/gateways/SECURE_WEB_PROXY_NAME
    registries:
      - //agentregistry.googleapis.com/projects/PROJECT_ID/locations/REGION
    

    更改下列內容:

    • PROJECT_ID: Google Cloud 專案 ID
    • REGION:建立 Agent Gateway 的區域
    • AGENT_GATEWAY_NAME:Agent Gateway 的名稱
    • SECURE_WEB_PROXY_NAME:Secure Web Proxy 執行個體的名稱

    選用:registries 欄位會將 Agent Gateway 與 Agent Registry 建立關聯。如果不想使用 Agent Registry 解析目的地或工具,請勿指定 registries 欄位。

  2. 如要匯入 agentGateway 資源,請執行 gcloud beta network-services agent-gateways import 指令。

    gcloud beta network-services agent-gateways import AGENT_GATEWAY_NAME \
        --source=agent-gateway.yaml \
        --location=REGION \
        --project=PROJECT_ID
    

設定擴充功能繫結和授權政策

如要控管 AI 代理的傳出流量,請在 agentGateway 資源上設定擴充功能繫結和授權政策。Proxy 會忽略直接附加至基礎 Secure Web Proxy Gateway 資源的所有政策。

Agent Gateway 支援下列兩個管理層:

  • 擴充功能繫結:使用 Service Extensions,將 IAP 和 Model Armor 等外部安全性和管理服務,直接附加至 Agent Gateway。

  • 授權政策:強制執行 L7 MCP 方法限制和 L4 網路規則。

將擴充功能繫結附加至 Agent Gateway

在 Service Extensions 中使用擴充功能繫結,將代管服務繫結至 Agent Gateway,以便檢查、驗證及控管代理互動。

步驟 1:將 Identity-Aware Proxy (IAP) 繫結至 Agent Gateway

如要驗證代理呼叫端身分,並在流量到達目標工具前強制執行存取權政策,請按照下列步驟將 IAP 繫結至 Agent Gateway:

  1. 建立名為 ext-binding-iap.yaml 的設定檔。

    name: ext-binding-iap
    target:
      resources:
      - "//networkservices.googleapis.com/projects/PROJECT_ID/locations/REGION/agentGateways/AGENT_GATEWAY_NAME"
    failOpen: false
    producerExtension: iap.googleapis.com
    matchConditions:
    - to:
        destination:
          resources:
          - prefix: "urn:mcp"
        notDestinations:
          hosts:
          - suffix: ".googleapis.com"
    

    更改下列內容:

    • PROJECT_ID: Google Cloud 專案 ID
    • REGION:建立擴充功能繫結的區域
    • AGENT_GATEWAY_NAME:Agent Gateway 的名稱
  2. 如要匯入擴充功能繫結,請執行 gcloud beta service-extensions extension-bindings import 指令。

    gcloud beta service-extensions extension-bindings import ext-binding-iap \
        --source=extension-binding-iap.yaml \
        --location=REGION
    

詳情請參閱「將授權委派給 IAP」。

步驟 2:繫結 Model Armor,清理提示詞和回覆

為防範提示詞注入、有害內容和敏感資料外洩,請按照下列步驟將 Model Armor 繫結至 Agent Gateway:

  1. 建立名為 ext-binding-model-armor.yaml 的設定檔。

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

    更改下列內容:

    • PROJECT_ID: Google Cloud 專案 ID
    • REGION:建立擴充功能繫結的區域
    • AGENT_GATEWAY_NAME:Agent Gateway 的名稱
    • REQUEST_TEMPLATE_ID:Model Armor 要求範本的 ID
    • RESPONSE_TEMPLATE_ID:Model Armor 回覆範本的 ID
  2. 如要匯入擴充功能繫結,請執行 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=REGION
    

詳情請參閱「將授權委派給 Model Armor」,以及「設定 Secure Web Proxy 的授權政策」中的「範例 3:使用擴充功能繫結,透過 Model Armor 啟用深層酬載檢查」。

使用授權政策限制 MCP 工具

如要限制代理工具探索和執行,僅限核准的工具,請按照下列步驟建立及匯入授權政策:

  1. 建立名為 authz-policy-restrict-mcp-tools.yaml 的設定檔。

    name: authz-policy-restrict-mcp-tools
    target:
      resources:
      - "projects/PROJECT_ID/locations/REGION/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 專案 ID
    • REGION:建立授權政策的區域
    • AGENT_GATEWAY_NAME:Agent Gateway 的名稱
  2. 執行 gcloud network-security authz-policies import 指令,匯入授權政策。

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

透過 Agent Gateway 轉送代理

設定 Agent Gateway 並附加授權政策後,必須設定代理執行階段環境,將傳出流量導向 Secure Web Proxy 執行個體。傳出流量轉送會在網路層透明運作,將要求重新導向至閘道,而不修改代理應用程式程式碼。

請根據 AI 工作負載的執行位置,參閱下列說明文件,瞭解如何設定傳出轉送:

遙測、記錄和監控

Secure Web Proxy 閘道與 Agent Gateway 資源建立關聯後,交易記錄會以標準 Secure Web Proxy networkservices.googleapis.com/Gateway 受監控資源的形式發出。記錄功能預設為啟用,取樣率為 1.0。

記錄

Cloud Logging 中的記錄項目採用 LoadBalancerLogEntry 格式,並包含下列 AI 代理和安全性酬載欄位:

  • agentGatewayInfo:包含代理交易的中繼資料:

    • agentRegistryResource:相符 Agent Registry 目標的完整資源名稱,例如 MCP 伺服器或技能
    • destinationUrn:目的地 URN 的相關資訊
    • mcpInfo:MCP JSON-RPC 呼叫詳細資料,包括 tools/call 或 resources/read 等方法,以及工具名稱或資源 URI
  • authzPolicyInfo:授權評估結果 (ALLOWED 或 DENIED) 和相符政策的名稱

  • tls:TLS 協商詳細資料和加密用戶端憑證 (mTLS) 驗證屬性,例如 clientCertPresent 和 clientCertSha256Fingerprint

監控指標

Agent Gateway 會將下列指標匯出至 Cloud Monitoring:

  • MCP 期間:

    • gcp.mcp.server.operation.duration:MCP 工具伺服器執行作業的延遲時間
    • gcp.mcp.client.operation.duration:MCP 用戶端呼叫的端對端來回時間
  • HTTP 延遲時間:

    • http.server.request.duration:閘道處理傳入代理要求時的執行延遲時間
    • http.client.request.duration:從 Proxy 傳出要求至外部目的地的延遲時間
  • 流量處理量:

    • gcp.server.request.total_size 和 gcp.server.response.total_size:閘道接收及傳送的要求和回應大小 (以位元組為單位)
    • gcp.client.request.total_size 和 gcp.client.response.total_size:閘道傳送至外部目的地的要求和回應大小 (以位元組為單位)

後續步驟