为 Secure Web Proxy 设置授权政策

本页介绍了如何为 Secure Web Proxy 设置授权政策。

准备工作

创建授权政策

本部分介绍了如何创建附加到 Secure Web Proxy 实例的不同类型的授权政策。

如需为 Secure Web Proxy 创建授权政策,请执行以下操作:

基于 mTLS 身份的授权政策

Secure Web Proxy 支持根据从双向 TLS (mTLS) 证书派生的身份强制执行安全规则。在零信任环境中,根据这些身份强制执行规则特别有用,因为在零信任环境中,客户端与代理之间的流量由 mTLS 保护。如需了解详情,请参阅基于正文的授权政策

以下示例展示了名为 swp1 的 Secure Web Proxy 实例的授权政策。此示例假设代理的流量使用 HTTPS 协议。

具有 REQUEST_AUTHZ 配置文件的政策会强制执行以下操作:所有流向 example.com/mcp 的流量都必须通过来自特定主账号的 mTLS 身份验证,然后才能通过。该政策还会拒绝所有不打算流向 example.com/mcp 的出站流量。

  1. 创建授权政策 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 项目的 ID
    • LOCATION:Secure Web Proxy 实例的区域
  2. 使用 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 资源的服务账号或标记来应用授权政策

此示例假定您已完成以下操作:

服务账号

  1. 创建一个授权政策 YAML 文件以允许某些请求。

    以下示例为名为 swp1 的 Secure Web Proxy 实例创建了一个 authz-policy.yaml 文件。该政策配置为允许来自服务账号为 my-sa-123@56788.iam.gserviceaccount.com 的 Compute Engine 虚拟机 (VM) 实例的请求到达 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.iam.gserviceaccount.com"
      to:
        operations:
        - hosts:
            - exact: "example1.com"
        paths:
        - prefix: "/url1"
    action: ALLOW
    EOF
    

    替换以下内容:

    • PROJECT_ID:您的 Google Cloud 项目的 ID
    • LOCATION:Secure Web Proxy 实例的区域
  2. 使用 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 实例的区域。

标记

  1. 创建一个授权政策 YAML 文件以允许某些请求。

    以下示例为名为 swp1 的 Secure Web Proxy 实例创建了一个 authz-policy-tag.yaml 文件。该政策仅允许源自标记值为 TAG_VALUE_PERMANENT_ID 的 Google Cloud资源的请求访问 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 项目的 ID
    • LOCATION:Secure Web Proxy 实例的区域
    • GATEWAY_NAME:Secure Web Proxy 网关的名称
    • TAG_VALUE_PERMANENT_ID:标记值的永久 ID,例如 tagValues/123456789012
  2. 使用 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 实例的区域。

用于委托授权决策的授权政策

对于无法使用标准 ALLOWDENY 规则表达的复杂授权决策,您可以创建包含 CUSTOM 操作的授权政策。然后,您可以将授权决策委托给Service Extensions(Service Extensions)。

当您配置具有 CUSTOM 操作的政策时,Secure Web Proxy 会将请求元数据或载荷分流到 Service Extensions。根据 Service Extensions 的响应,代理会允许或拒绝相应流量。

Secure Web Proxy 支持以下类型的委托:

  • 将请求授权决策委托给 Service Extensions:您可以使用配置了 CUSTOM 操作和 REQUEST_AUTHZ 配置文件的授权政策,根据请求元数据和标头委托决策。在此模式下,访问决策会委托给授权扩展程序。您可以使用此模式来验证身份和权限。

  • 将内容授权决策委托给服务扩展程序:您可以将授权政策与 CUSTOM 操作和 CONTENT_AUTHZ 配置文件搭配使用,以根据请求的实际数据载荷将决策委托给授权扩展程序。借助此模式,您可以启用深度内容检查和安全强制执行,从而通过与 Model Armor 等服务集成来扫描敏感信息或恶意模式。

限制

为 Secure Web Proxy 实现授权政策时,会受到以下限制:

  • 目标和连接限制:Secure Web Proxy 的授权扩展程序不支持将 Identity-Aware Proxy (IAP) 作为直接目标。

  • 政策冲突和兼容性:如果您有包含现有安全规则的网关安全政策,则无需移除这些规则。当您将授权政策应用于实例时,Secure Web Proxy 会忽略这些规则。

  • 协议和检查要求:如需配置 Secure Web Proxy 授权政策,您必须启用 TLS 检查

后续步骤