在 Ingress 和 Egress 規則中使用身分群組和第三方身分的範例

本頁說明如何在 Ingress 和 Egress 規則中使用身分群組和第三方身分

本頁包含下列範例,說明如何在輸入和輸出規則中使用身分群組:

  • 允許 Cloud Run 透過網際網路存取身分群組的成員,並允許來自允許清單 IP 位址範圍的特定服務帳戶存取。

允許 Cloud Run 存取身分群組的成員和特定服務帳戶

下圖顯示特定身分群組和允許的 IP 位址範圍內的使用者,如何存取服務邊界內的 Cloud Run:

假設您已定義下列服務範圍:

name: accessPolicies/222/servicePerimeters/Example
status:
  resources:
  - projects/111
  restrictedServices:
  - run.googleapis.com
  - artifactregistry.googleapis.com
  vpcAccessibleServices:
    enableRestriction: true
    allowedServices:
    - RESTRICTED_SERVICES
title: Example

如要查看貴機構現有服務範圍的詳細資料,請使用 gcloud CLI 指令說明服務範圍

在本範例中,我們也假設您已定義下列資源:

  • 名為 allowed-users@example.com 的身分識別群組,內含您想在安全範圍內授予 Cloud Run 存取權的使用者。
  • 與服務範圍位於相同存取權政策中的存取層級,名稱為「CorpDatacenters」。CorpDatacenters 包含公司資料中心的允許清單 IP 位址範圍,服務帳戶的要求可從這些範圍發出。

下列輸入政策 ingress.yaml 允許 Cloud Run 存取特定人員帳戶 (屬於 allowed-users@example.com 群組) 和特定服務帳戶,但僅限於允許的 IP 位址範圍:

- ingressFrom:
    identities:
    - serviceAccount:my-sa@my-project.s3ns-system.iam.gserviceaccount.com
    sources:
    - accessLevel: accessPolicies/222/accessLevels/CorpDatacenters
  ingressTo:
    operations:
    - serviceName: run.googleapis.com
      methodSelectors:
      - method: "*"
    resources:
    - "*"
- ingressFrom:
    identities:
    - group:allowed-users@example.com
    sources:
    - accessLevel: "*"
  ingressTo:
    operations:
    - serviceName: run.googleapis.com
      methodSelectors:
      - method: "*"
    resources:
    - "*"

如要套用 Ingress 規則,請執行下列指令:

gcloud access-context-manager perimeters update Example --set-ingress-policies=ingress.yaml

後續步驟