透過輸入和輸出規則保護資料交換工作

本文說明安全資料交換的常見用途,以及允許用戶端和資源在服務安全防護範圍之間存取資料的設定範例。

如要瞭解輸入和輸出規則,請參閱輸入和輸出規則

如需如何設定輸入和輸出規則政策的操作說明,請參閱「設定輸入和輸出政策」。

安全資料交換用途的設定範例

本節提供範例使用案例,說明如何在服務範圍之間安全地交換資料。

存取 Google Cloud 服務範圍外的資源

下圖顯示服務範圍內的 Compute Engine 資源需要存取範圍外的 Cloud Storage 資源:

從一個安全防護範圍輸出

假設您已定義下列周邊範圍:

 name: accessPolicies/222/servicePerimeters/Example status:   resources:   - projects/111   restrictedServices:   - bigquery.googleapis.com   - containerregistry.googleapis.com   - storage.googleapis.com title: Example 

您需要授予不同機構中的 Cloud Storage 值區讀取權限。project 999接著,請在檔案中定義下列輸出規則,並將檔案儲存為 gcs.yaml

 echo """ - egressTo:     operations:       - serviceName: storage.googleapis.com         methodSelectors:         - method: google.storage.objects.get     resources:     - projects/999   egressFrom:     identityType: ANY_IDENTITY """ > gcs.yaml 

執行下列指令,套用輸出規則:

 gcloud beta access-context-manager perimeters update Example --set-egress-policies=gcs.yaml 

如要進一步瞭解 gcloud access-context-manager perimeters update 指令,請參閱 gcloud access-context-manager perimeters update

在兩個使用 VPC Service Controls 的機構之間,透過 Pub/Sub 共用資料

下圖顯示兩個機構 Org1Org2,這兩個機構使用 VPC Service Controls,並透過 Pub/Sub 主題共用資料:

從一個範圍輸出,並輸入至另一個範圍

假設您已定義下列周邊範圍:

 # Org 1 Perimeter Definition name: accessPolicies/222/servicePerimeters/Example1 status:   resources:   - projects/111   restrictedServices:   - pubsub.googleapis.com title: Example1 
  # Org 2 Perimeter Definition name: accessPolicies/333/servicePerimeters/Example2 status:   resources:   - projects/222   restrictedServices:   - pubsub.googleapis.com title: Example2 

如要啟用資料交換,Org1 必須定義下列輸出規則,允許訂閱並將檔案儲存為 org1egress.yaml

 # Org1: Org1's perimeter must allow a Pub/Sub subscription to project 222.  echo """ - egressTo:     operations:     - serviceName: pubsub.googleapis.com       methodSelectors:       - method: Subscriber.CreateSubscription     resources:     - projects/222   egressFrom:     identityType: ANY_IDENTITY """ > org1egress.yaml  

Org2 必須定義對應的輸入規則,允許訂閱並將檔案儲存為 org2ingress.yaml

 # Org 2: Org2's perimeter must allow a Pub/Sub subscription from network project 111 in Org1.  echo """ - ingressFrom:     identityType: ANY_IDENTITY     sources:     - resource: projects/111   ingressTo:     operations:     - serviceName: pubsub.googleapis.com       methodSelectors:       - method: Subscriber.CreateSubscription     resources:     - \"*\" """ > org2ingress.yaml 

執行下列指令,套用輸入和輸出規則:

 gcloud beta access-context-manager perimeters update Example2 1--set-egress-policies=org1egress.yaml 
 gcloud beta access-context-manager perimeters update Example1 1--set-ingress-policies=org2ingress.yaml 

與合作夥伴機構分享去識別化的 PHI 資料

下圖顯示受保護健康資訊 (PHI) 資料區隔周圍的邊界、匿名資料區隔周圍的第二個邊界,以及個別合作夥伴機構。PHI 區隔可以操控去識別化資料區隔中的資料,並與合作夥伴機構分享去識別化資料區隔中的資料。

進入範圍和離開範圍

您想定義輸入和輸出規則,以便與合作夥伴機構共用匿名資料,並允許 PHI 區隔操控匿名資料區隔中的資料。

假設您已定義下列周邊範圍:

 # PhiPerimeter name: accessPolicies/222/servicePerimeters/PhiPerimeter status:   resources:   - projects/111   restrictedServices:   - storage.googleapis.com   - bigquery.googleapis.com   vpcAccessibleServices:     enableRestriction: true     allowedServices:     - RESTRICTED_SERVICES title: PhiPerimeter 
 # AnonPerimeter name: accessPolicies/222/servicePerimeters/AnonPerimeter status:   resources:   - projects/222   restrictedServices:   - storage.googleapis.com   vpcAccessibleServices:     enableRestriction: true     allowedServices:     - RESTRICTED_SERVICES title: AnonPerimeter 

您也可以假設合作夥伴機構專案為 999。您可以定義下列輸入和輸出規則:

 # Anon Perimeter  echo """ - ingressFrom:     identityType: ANY_IDENTITY     sources:     - resource: projects/111   ingressTo:     operations:     - serviceName: storage.googleapis.com       methodSelectors:       - method: google.storage.Write       - method: google.storage.objects.create     resources:     - \"*\" """ > anoningress.yaml 
  echo """ - egressTo:     operations:     - serviceName: storage.googleapis.com       methodSelectors:       - method: google.storage.Write       - method: google.storage.objects.create     resources:     - projects/999   egressFrom:     identityType: ANY_IDENTITY """ > anonegress.yaml 
 # PHI Perimeter  echo """ - egressTo:     operations:     - serviceName: storage.googleapis.com       methodSelectors:       - method: \"*\"     resources:     - projects/222   egressFrom:     identityType: ANY_IDENTITY """ > phiegress.yaml 

執行下列指令,套用輸入和輸出規則:

 gcloud beta access-context-manager perimeters update AnonPerimeter --set-ingress-policies=anoningress.yaml --set-egress-policies=anonegress.yaml 
 gcloud beta access-context-manager perimeters update PhiPerimeter --set-egress-policies=phiegress.yaml 

授予第三方 Compute Engine 磁碟映像檔的存取權

下圖顯示服務範圍內的 Compute Engine 資源需要存取範圍外的第三方映像檔專案中的 Compute Engine 磁碟映像檔:

輸出至映像檔專案

假設您已定義下列周邊範圍:

 name: accessPolicies/222/servicePerimeters/Example status:   resources:   - projects/111   - projects/222   restrictedServices:   - compute.googleapis.com   - containerregistry.googleapis.com title: Example 

您現在需要授予 project 999 中磁碟映像檔的讀取權限,該映像檔位於其他機構。接著,在檔案中定義下列輸出規則,並將檔案儲存為 compute.yaml

 echo """ - egressTo:     operations:     - serviceName: compute.googleapis.com       methodSelectors:       - method: InstancesService.Insert     resources:     - projects/999   egressFrom:     identityType: ANY_IDENTITY """ > compute.yaml 

執行下列指令,套用輸出規則:

 gcloud beta access-context-manager perimeters update Example --set-egress-policies=compute.yaml 

允許從範圍外的 VPC 網路進行私人存取,藉此讀取 BigQuery 資料集

下圖顯示範圍外的多個合作夥伴虛擬私有雲網路,需要從範圍內的 BigQuery 資源讀取資料:

輸出至映像檔專案

您可以假設您使用的周邊裝置與範例 1 相同:

 name: accessPolicies/222/servicePerimeters/Example status:   resources:   - projects/111   restrictedServices:   - bigquery.googleapis.com   - containerregistry.googleapis.com title: Example 

您的目標是允許來自週邊以外虛擬私有雲網路的讀取存取權,在檔案中定義下列 Ingress 規則,然後將檔案儲存為 partneringress.yaml

 echo """ - ingressFrom:     identityType: ANY_IDENTITY     sources:     - resource: projects/888     - resource: projects/999   ingressTo:     operations:     - serviceName: bigquery.googleapis.com       methodSelectors:       - permission: bigquery.datasets.get       - permission: bigquery.tables.list       - permission: bigquery.tables.get       - permission: bigquery.tables.getData       - permission: bigquery.jobs.create     resources:     - \"*\"  """ > partneringress.yaml 

執行下列指令來套用 Ingress 規則:

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

為了提供更靈活的彈性和控制權,BigQuery 使用 - permission: methodSelectors,而非大多數服務使用的 - method: methodSelectors。單一 BigQuery 方法 (RunQuery) 可對多種不同資源執行不同作業,而與權限模型保持一致,可提供更大的彈性和控制權。

允許從範圍外的 VPC 網路進行私密存取,將資料載入 Cloud Storage 值區 (寫入)

您可以假設您使用的周邊與範例 1 相同:

 name: accessPolicies/222/servicePerimeters/Example status:   resources:   - projects/111   restrictedServices:   - storage.googleapis.com   - containerregistry.googleapis.com title: Example 

您的目標是允許範圍外的 VPC 網路存取,讓合作夥伴能將資料寫入範圍內的值區。定義輸入規則,並將檔案儲存為 partneringress.yaml

 echo """ - ingressFrom:     identityType: ANY_IDENTITY     sources:     - resource: projects/222   ingressTo:     operations:     - serviceName: storage.googleapis.com       methodSelectors:       - method: google.storage.objects.create     resources:     - \"*\" """ > partneringress.yaml 

執行下列指令來套用 Ingress 規則:

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

在獨立範圍中分享記錄,允許多個範圍的專案共用記錄

在本例中,假設企業有一個共用專案,可從整個 Google Cloud 部署作業收集記錄資料。企業必須能夠將多個不同 VPC Service Controls 範圍的資料記錄到共用記錄專案 (位於自有範圍內)。記錄專案不應存取記錄檔以外的任何資源。

假設您已定義下列三個周邊:

 # Sensitive 1 name: accessPolicies/222/servicePerimeters/Sensitive1 status:   resources:   - projects/111   restrictedServices:   - bigquery.googleapis.com   - containerregistry.googleapis.com   - logging.googleapis.com   vpcAccessibleServices:     enableRestriction: true     allowedServices:     - RESTRICTED_SERVICES title: Sensitive Data 1 
 # Sensitive 2 name: accessPolicies/222/servicePerimeters/Sensitive2 status:   resources:   - projects/222   restrictedServices:   - bigquery.googleapis.com   - containerregistry.googleapis.com   - logging.googleapis.com   vpcAccessibleServices:     enableRestriction: true     allowedServices:     - RESTRICTED_SERVICES title: Sensitive Data 2 
 #Logs name: accessPolicies/222/servicePerimeters/Logs status:   resources:   - projects/777   restrictedServices:   - logging.googleapis.com   vpcAccessibleServices:     enableRestriction: true     allowedServices:     - RESTRICTED_SERVICES title: Logs Perimeter 

如要允許 Sensitive1Sensitive2 將記錄寫入記錄周邊,請在檔案中定義下列輸出規則,並將檔案儲存為 logsegress.yaml

 echo """ - egressTo:     operations:     - serviceName: logging.googleapis.com       methodSelectors:       - method: LoggingServiceV2.WriteLogEntries       - method: LoggingService.WriteLogEntries     resources:     - projects/777   egressFrom:     identityType: ANY_IDENTITY """ > logsegress.yaml 

執行下列指令,套用輸出規則:

 gcloud beta access-context-manager perimeters update Sensitive1 --set-egress-policies=logsegress.yaml 
 gcloud beta access-context-manager perimeters update Sensitive2 --set-egress-policies=logsegress.yaml 

對於需要寫入記錄周邊的任何其他機密資料周邊,都可以指定類似的設定。

後續步驟