為虛擬私有雲網路設定 VPC Service Controls 範圍

瞭解如何使用 VPC Service Controls 設定服務範圍。本教學課程會使用防火牆、Private Service Connect 和 DNS 設定等網路設定,這些設定是有效使用 VPC Service Controls 範圍的必要條件。本教學課程接著會示範如何允許或拒絕服務,以及如何為特定服務的允許清單建立精細的例外狀況。

目標

  • 設定 VPC Service Controls 範圍,並搭配額外的網路控制項,減少資料竊取路徑。
  • 允許或拒絕來自範圍內或範圍外的要求,存取範圍內的服務。
  • 允許或拒絕來自範圍內的要求存取範圍外的服務。
  • 同時使用「限制資源服務用量」機構政策和 VPC Service Controls。

費用

本教學課程使用下列 Google Cloud的計費元件:

如要根據預測用量估算費用,請使用 Pricing Calculator

完成本教學課程後,您可以刪除建立的資源以避免繼續計費。詳情請參閱清除所用資源一節。

事前準備

  1. 本教學課程需要貴機構的專案。如果還沒有 Google Cloud 機構,請參閱建立及管理機構

  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

  4. Enable the Compute Engine, Access Context Manager, and Cloud DNS APIs.

    Enable the APIs

  5. In the Google Cloud console, activate Cloud Shell.

    Activate Cloud Shell

  6. Make sure that you have the following role or roles on the organization: Access Context Manager Admin, Organization Policy Administrator

    Check for the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the organization.
    3. In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.

    4. For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.

    Grant the roles

    1. In the Google Cloud console, go to the IAM page.

      前往「IAM」頁面

    2. 選取機構。
    3. 按一下「授予存取權」
    4. 在「New principals」(新增主體) 欄位中,輸入您的使用者 ID。 這通常是 Google 帳戶的電子郵件地址。

    5. 在「Select a role」(選取角色) 清單中,選取角色。
    6. 如要授予其他角色,請按一下 「新增其他角色」,然後新增每個其他角色。
    7. 按一下 [Save]
  7. Make sure that you have the following role or roles on the project: Compute Admin, DNS Administrator, IAP-Secured Tunnel User, Service Account User, Service Directory Editor

    Check for the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.

    4. For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.

    Grant the roles

    1. In the Google Cloud console, go to the IAM page.

      前往「IAM」頁面

    2. 選取專案。
    3. 按一下「授予存取權」
    4. 在「New principals」(新增主體) 欄位中,輸入您的使用者 ID。 這通常是 Google 帳戶的電子郵件地址。

    5. 在「Select a role」(選取角色) 清單中,選取角色。
    6. 如要授予其他角色,請按一下 「新增其他角色」,然後新增每個其他角色。
    7. 按一下 [Save]
    8. 設定 VPC Service Controls 範圍

      如要為虛擬私有雲網路實作 VPC Service Controls 範圍,您必須實作網路控制項,拒絕連往外部服務的流量。以下各節將詳細說明您必須在邊界內的虛擬私有雲網路中實作的網路設定,以及邊界設定範例。

      準備虛擬私有雲網路

      在本節中,您將設定虛擬私有雲網路的 Google API 和服務私人連線,以減少網際網路的網路輸出路徑。

      1. 在 Cloud Shell 中設定變數:

        gcloud config set project PROJECT_ID
        gcloud config set compute/region REGION
        gcloud config set compute/zone ZONE

        更改下列內容:

        • PROJECT_ID:您要在其中建立資源的專案 ID
        • REGION:靠近您所在位置的區域,例如 us-central1
        • ZONE:靠近您所在位置的可用區,例如 us-central1-a
      2. 建立虛擬私有雲網路和子網路,並啟用私人 Google 存取權:

        gcloud compute networks create restricted-vpc --subnet-mode=custom
        gcloud compute networks subnets create restricted-subnet \
        --range=10.0.0.0/24 \
        --network=restricted-vpc \
        --enable-private-ip-google-access
      3. 建立 Private Service Connect 端點和轉送規則,並設定使用 vpc-sc 套件

        gcloud compute addresses create restricted-psc-endpoint \
        --global \
        --purpose=PRIVATE_SERVICE_CONNECT \
        --addresses=10.0.1.1 \
        --network=restricted-vpc
        
        gcloud compute forwarding-rules create restrictedpsc \
        --global \
        --network=restricted-vpc \
        --address=restricted-psc-endpoint \
        --target-google-apis-bundle=vpc-sc
      4. 設定 Cloud DNS 伺服器政策,將 Google Cloud API 的查詢重新導向至 Private Service Connect 端點:

        gcloud dns managed-zones create restricted-dns-zone \
          --description="Private DNS Zone to map Google API queries to the Private Service Connect endpoint for Google APIs" \
          --dns-name="googleapis.com." \
          --networks=restricted-vpc \
          --visibility=private
        
        gcloud dns record-sets create googleapis.com  \
        --rrdatas=10.0.1.1 \
        --type=A \
        --ttl=300 \
        --zone=restricted-dns-zone
        
        gcloud dns record-sets create *.googleapis.com  \
        --rrdatas="googleapis.com." \
        --type=CNAME \
        --ttl=300 \
        --zone=restricted-dns-zone
      5. 設定低優先順序的防火牆規則,拒絕所有輸出流量:

        gcloud compute firewall-rules create deny-all-egress \
        --priority=65534 \
        --direction=egress \
        --network=restricted-vpc \
        --action=DENY \
        --rules=all \
        --destination-ranges=0.0.0.0/0
      6. 設定優先順序較高的防火牆規則,允許流量連線至 Private Service Connect 端點使用的 IP 位址:

        gcloud compute firewall-rules create allow-psc-for-google-apis \
        --priority=1000 \
        --direction=egress \
        --network=restricted-vpc \
        --action=ALLOW \
        --rules=tcp:443 \
        --destination-ranges=10.0.1.1

        這些防火牆規則會廣泛拒絕輸出流量,然後選擇性地允許輸出至 Private Service Connect 端點。這項設定會拒絕前往預設網域的出站流量,這些網域通常可透過私人 Google 存取權和隱含防火牆規則預設連線。

      建立 VPC Service Controls 範圍

      在本節中,您將建立 VPC Service Controls 範圍。

      1. 在 Cloud Shell 中建立存取權政策,這是建立 VPC Service Controls 範圍的前提:

        gcloud access-context-manager policies create \
        --organization=ORGANIZATION_ID --title "Access policy at organization node"

        輸出結果會與下列內容相似:

        "Create request issued
        Waiting for operation [operations/accessPolicies/123456789/create/123456789] to complete...done."
        

        機構節點只能有一個存取權政策容器。如果貴機構已建立政策,輸出內容會類似下列內容:

        "ALREADY_EXISTS: Policy already exists with parent ContainerKey{containerId=organizations/123456789012, numericId=123456789012}"
        

        如果看到這則訊息,請繼續下一個步驟。

      2. 建立 VPC Service Controls 範圍,限制 Cloud Storage 和 Compute Engine 服務。

        export POLICY_ID=$(gcloud access-context-manager policies list \
        --organization=ORGANIZATION_ID \
        --format="value(name)")
        
        gcloud access-context-manager perimeters create demo_perimeter \
        --title="demo_perimeter" \
        --resources=projects/$(gcloud projects describe PROJECT_ID --format="value(projectNumber)") \
        --restricted-services="storage.googleapis.com,compute.googleapis.com" \
        --enable-vpc-accessible-services \
        --policy=$POLICY_ID \
        --vpc-allowed-services="RESTRICTED-SERVICES"

      確認允許從範圍外部流量存取的服務

      以下各節將說明 VPC Service Controls 範圍如何允許或拒絕範圍外的存取要求,以及如何透過設定存取層級和輸入政策,選擇性允許服務輸入。

      如要模擬來自周邊以外的流量,可以在 Cloud Shell 中執行指令。Cloud Shell 是您專案和邊界外的資源。即使要求具備足夠的 Identity and Access Management 權限,安全防護範圍仍可允許或拒絕要求。

      本教學課程使用 Compute Engine API、Cloud Storage API 和 Cloud Resource Manager API,但同樣的概念也適用於其他服務。

      確認範圍拒絕受限服務的外部流量

      在本節中,您將驗證服務範圍是否拒絕受限服務的外部流量。

      架構圖:說明 VPC Service Controls 範圍如何拒絕存取受限制的服務

      上圖說明已授權的用戶端如何遭拒存取您設定為受限的服務範圍內服務,但可存取您未設定為受限的服務。

      在下列步驟中,您將使用 Cloud Shell 嘗試在 VPC 網路中建立 VM,但由於 VPC Service Controls 範圍的設定,因此會失敗,藉此驗證這個概念。

      1. 在 Cloud Shell 中執行下列指令,在 VPC 網路內建立 VM。

        gcloud compute instances create demo-vm \
            --machine-type=e2-micro \
            --subnet=restricted-subnet \
            --scopes=https://www.googleapis.com/auth/cloud-platform \
            --no-address

        輸出結果會與下列內容相似:

        "ERROR: (gcloud.compute.instances.create) Could not fetch resource:
        - Request is prohibited by organization's policy."
        

        要求失敗,因為 Cloud Shell 超出安全防護範圍,且 Compute Engine 已設定 --restricted-services 旗標。

      2. 在 Cloud Shell 中執行下列指令,存取未在 --restricted-services 旗標中設定的 Resource Manager 服務。

        gcloud projects describe PROJECT_ID

        成功的回應會傳回專案的詳細資料。這項回應表示安全防護範圍允許外部流量存取 Cloud Resource Manager API。

        您已證明安全防護範圍會拒絕流向 --restricted-services 中設定服務的外部流量,並允許流向未在 --restricted-services 中明確設定服務的外部流量。

      下列各節將介紹例外狀況模式,以便存取範圍內受限制的服務。

      確認存取層級允許範圍例外狀況

      在本節中,您會驗證存取層級是否允許範圍例外狀況。如果您想為外部流量建立例外狀況,允許存取範圍內的所有受限服務,且不需要為每個服務或其他屬性建立精細的例外狀況,存取層級就非常實用。

      架構圖:說明存取層級如何為 VPC Service Controls 範圍內的所有服務授予例外狀況

      上圖說明存取層級如何允許授權用戶端存取範圍內的所有受限服務。

      在下列步驟中,您將建立存取層級,然後向 Compute Engine 服務提出要求並成功執行,藉此驗證這個概念。即使您將 Compute Engine 設為受限,系統仍允許這項要求。

      1. 在 Cloud Shell 中,建立說明存取層級設定的 YAML 檔案,並將其套用至安全防護範圍。這個範例會為您目前用來執行教學課程的使用者身分建立存取層級。

        export USERNAME=$(gcloud config list account --format "value(core.account)")
        
        cat <<EOF > user_spec.yaml
        - members:
          - user:$USERNAME
        EOF
        
        gcloud access-context-manager levels create single_user_level \
        --title="single-user access level" \
        --basic-level-spec=user_spec.yaml \
        --policy=$POLICY_ID
        
        gcloud access-context-manager perimeters update demo_perimeter \
        --add-access-levels=single_user_level \
        --policy=$POLICY_ID
      2. 在 Cloud Shell 中再次執行下列指令,嘗試建立 VM:

        gcloud compute instances create demo-vm \
        --machine-type=e2-micro \
        --subnet=restricted-subnet \
        --scopes=https://www.googleapis.com/auth/cloud-platform \
        --no-address

        這次要求成功。您的服務範圍會禁止外部流量使用受限制的服務,但您設定的存取層級允許例外狀況。

      確認輸入政策允許對周邊環境進行精細的例外處理

      在本節中,您會驗證 Ingress 政策是否允許對安全邊界進行細微的例外處理。相較於粗略存取層級,細微連入政策可設定流量來源的其他屬性,並允許存取個別服務或方法。

      架構圖:說明 Ingress 政策如何允許細微的例外狀況,存取範圍內的指定服務

      上圖說明 ingress 政策如何允許授權用戶端僅存取服務範圍內的指定服務,而不允許存取其他受限服務。

      在下列步驟中,您將存取層級替換為僅允許授權用戶端存取 Compute Engine 服務,但不允許存取其他受限服務的連入政策,藉此驗證這個概念。

      1. 在 Cloud Shell 分頁中執行下列指令,移除存取層級。

        gcloud access-context-manager perimeters update demo_perimeter \
        --policy=$POLICY_ID \
        --clear-access-levels
      2. 在 Cloud Shell 分頁中,建立輸入政策,只允許使用者身分輸入 Compute Engine 服務,並將政策套用至服務範圍。

        cat <<EOF > ingress_spec.yaml
        - ingressFrom:
            identities:
            - user:$USERNAME
            sources:
            - accessLevel: '*'
          ingressTo:
            operations:
            - methodSelectors:
              - method: '*'
              serviceName: compute.googleapis.com
            resources:
            - '*'
        EOF
        
        gcloud access-context-manager perimeters update demo_perimeter \
        --set-ingress-policies=ingress_spec.yaml \
        --policy=$POLICY_ID
      3. 在 Cloud Shell 分頁中,執行下列指令,在安全防護範圍內建立 Cloud Storage bucket。

        gcloud storage buckets create gs://PROJECT_ID-01

        輸出結果會與下列內容相似:

        "ERROR: (gcloud.storage.buckets.create) HTTPError 403: Request is prohibited by organization's policy."
        

        Cloud Shell 是範圍外的用戶端,因此 VPC Service Controls 範圍會禁止 Cloud Shell 與範圍內的受限服務通訊。

      4. 在 Cloud Shell 分頁中,執行下列指令,向安全防護範圍內的 Compute Engine 服務提出要求。

        gcloud compute instances describe demo-vm --zone=ZONE

        成功的回應會傳回 demo-vm 的詳細資料。這項回應表示服務範圍允許外部流量進入 Compute Engine 服務,且符合輸入政策的條件。

      確認允許從範圍內流量存取的服務

      以下各節將說明 VPC Service Controls 範圍如何允許或拒絕從範圍內對服務發出的要求,以及如何透過輸出政策選擇性允許輸出至外部服務。

      為示範重疊範圍內外流量的差異,下列各節會同時使用重疊範圍外的 Cloud Shell,以及您在重疊範圍內建立的 Compute Engine 執行個體。您在安全殼層工作階段中,從安全範圍內的 Compute Engine 執行個體執行的指令,會使用附加服務帳戶的身分;而從安全範圍外的 Cloud Shell 執行的指令,則會使用您自己的身分。按照本教學課程的建議設定操作時,即使要求具備足夠的 IAM 權限,可順利完成作業,安全防護範圍仍會允許或拒絕要求。

      本教學課程使用 Compute Engine API、Cloud Storage API 和 Cloud Resource Manager API,但同樣的概念也適用於其他服務。

      確認範圍允許內部流量進入範圍內受限制的服務

      在本節中,如果服務也設定在「VPC 可存取的服務」中,您會驗證服務範圍是否允許來自服務範圍內網路端點的流量。

      架構圖:說明如何設定 vpc-accessible-services,讓服務可從內部網路端點存取

      上圖說明範圍如何允許範圍內的網路端點流量,連至您也設定為可透過虛擬私有雲存取的受限服務。如果服務未設定為可透過虛擬私有雲存取的服務,就無法從範圍內的網路端點連線。

      在下列步驟中,您將建立與安全範圍內 Compute Engine 執行個體的 SSH 連線,然後向服務發出要求,藉此驗證這項概念。

      1. 在 Cloud Shell 中建立防火牆規則,允許 SSH 流量進入虛擬私有雲網路,方法是允許從 35.235.240.0/20 IP 位址範圍 (IAP for TCP forwarding 服務所用) 傳入流量:

        gcloud compute firewall-rules create demo-allow-ssh \
        --direction=INGRESS \
        --priority=1000 \
        --network=restricted-vpc \
        --action=ALLOW \
        --rules=tcp:22 \
        --source-ranges=35.235.240.0/20 
      2. 啟動這個執行個體的 SSH 工作階段:

        gcloud compute ssh demo-vm --zone=ZONE

        確認命令列提示已變更為顯示執行個體的主機名稱,藉此驗證您是否已成功連線至 demo-vm 執行個體:

        username@demo-vm:~$
        

        如果先前的指令失敗,您可能會看到類似以下的錯誤訊息:

        "[/usr/bin/ssh] exited with return code [255]"
        

        在這種情況下,Compute Engine 執行個體可能尚未完成啟動。請稍後再試。

      3. 在範圍內的 SSH 工作階段中,使用 VPC 可存取服務允許清單中設定的 Google Cloud 服務,驗證範圍內部允許的服務。舉例來說,請嘗試使用 Compute Engine 服務的任何指令。

        gcloud compute instances describe demo-vm --zone=ZONE

        成功的回應會傳回 demo-vm 的詳細資料。這項回應表示您的安全防護範圍允許內部流量存取 Compute Engine API。

      4. 在範圍內的 SSH 工作階段中,確認不在虛擬私有雲可存取服務允許清單中的服務,無法從 VM 存取。舉例來說,下列指令會使用 Resource Manager 服務,但該服務並未在虛擬私有雲可存取的服務許可清單中設定。

        gcloud projects describe PROJECT_ID

        輸出結果會與下列內容相似:

        "ERROR: (gcloud.projects.list) PERMISSION_DENIED: Request is prohibited by organization's policy."
        

        Compute Engine 執行個體和其他網路端點只能要求虛擬私有雲可存取服務允許清單中設定的服務。不過,來自服務範圍外的無伺服器資源或服務流量,可能會要求該服務。如要禁止專案使用某項服務,請參閱受限服務資源使用政策

      確認範圍會拒絕範圍外受限服務的內部流量

      在本節中,您將確認服務範圍是否會封鎖範圍內服務與範圍外 Google Cloud 服務之間的通訊。

      架構圖:說明 VPC Service Controls 範圍如何拒絕範圍內流量存取範圍外的受限服務

      上圖說明內部流量無法與範圍外的受限服務通訊。

      在下列步驟中,您會嘗試將內部流量傳送至範圍內的受限服務,以及範圍外的受限服務,藉此驗證這個概念。

      1. 在重疊範圍內的 SSH 工作階段中,執行下列指令,在重疊範圍內建立儲存空間值區。這項指令之所以能運作,是因為 Cloud Storage 服務已在 restricted-servicesaccessible-services 中設定。

        gcloud storage buckets create gs://PROJECT_ID-02

        成功的回應會建立儲存空間 bucket。這項回應表示安全防護範圍允許內部流量連線至 Cloud Storage 服務。

      2. 在周邊內部的 SSH 工作階段中,執行下列指令,從周邊外部的 bucket 讀取資料。這個公開值區允許「allUsers」的唯讀權限,但服務範圍會拒絕來自範圍內,前往範圍外受限服務的流量。

        gcloud storage cat gs://solutions-public-assets/vpcsc-tutorial/helloworld.txt

        輸出結果會與下列內容相似:

        "ERROR: (gcloud.storage.objects.describe) HTTPError 403: Request is prohibited
        by organization's policy."
        

        這項回應顯示您可以在範圍內使用受限服務,但範圍內的資源無法與範圍外的受限服務通訊。

      確認輸出政策允許周邊裝置的例外狀況

      在本節中,您會驗證輸出政策是否允許周邊的例外狀況。

      架構圖:說明輸出政策如何允許特定例外狀況存取範圍外的受限服務

      上圖說明您透過輸出政策授予狹義例外狀況時,內部流量如何與特定外部資源通訊。

      在後續步驟中,您將建立輸出政策,然後存取輸出政策允許的範圍外公開 Cloud Storage 值區,藉此驗證這個概念。

      1. 在 Cloud Shell 中點按「開啟新分頁」,開啟新的 Cloud Shell 工作階段。在後續步驟中,您會在第一個分頁 (內含周邊環境內的 SSH 工作階段),以及第二個分頁 (周邊環境外的 Cloud Shell,指令列提示符號為 username@cloudshell) 之間切換。

      2. 在 Cloud Shell 分頁中,建立允許從 demo-vm 附加服務帳戶身分進行輸出作業的輸出政策,方法是使用 google.storage.objects.get 方法,將資料輸出至外部專案中的公開值區。使用輸出政策更新安全防護範圍。

        export POLICY_ID=$(gcloud access-context-manager policies list \
        --organization=ORGANIZATION_ID \
        --format="value(name)")
        
        export SERVICE_ACCOUNT_EMAIL=$(gcloud compute instances describe demo-vm \
        --zone=ZONE) \
        --format="value(serviceAccounts.email)"
        cat <<EOF > egress_spec.yaml
        - egressFrom:
            identities:
              - serviceAccount:$SERVICE_ACCOUNT_EMAIL
          egressTo:
            operations:
            - methodSelectors:
              - method: 'google.storage.objects.get'
              serviceName: storage.googleapis.com
            resources:
            - projects/950403849117
        EOF
        
        gcloud access-context-manager perimeters update demo_perimeter \
        --set-egress-policies=egress_spec.yaml \
        --policy=$POLICY_ID
      3. 返回 SSH 工作階段的分頁,該工作階段位於周邊網路內的 VM,且指令列提示符號以 username@demo-vm 開頭。

      4. 在周邊內部的 SSH 工作階段中,再次向 Cloud Storage 值區提出要求,並確認要求是否正常運作。

        gcloud storage cat gs://solutions-public-assets/vpcsc-tutorial/helloworld.txt

        輸出結果會與下列內容相似:

        "Hello world!
        This is a sample file in Cloud Storage that is viewable to allUsers."
        

        這項回應表示您的周邊和輸出政策允許特定身分從特定 Cloud Storage 值區傳輸內部流量。

      5. 在周邊的 SSH 工作階段中,您也可以測試其他未明確允許的輸出政策例外狀況方法。舉例來說,下列指令需要 google.storage.buckets.list 權限,但周邊裝置拒絕授予這項權限。

        gcloud storage ls gs://solutions-public-assets/vpcsc-tutorial/*

        輸出結果會與下列內容相似:

        "ERROR: (gcloud.storage.cp) Request is prohibited by organization's policy."
        

        這項回應表示安全防護範圍拒絕列出外部 bucket 中的物件,指出輸出政策僅允許明確指定的方法。

      如要進一步瞭解在服務邊界外共用資料的常見模式,請參閱「透過輸入和輸出規則保護資料交換工作」。

      (選用) 設定「受限服務資源用量」政策

      您可能也有內部或法規遵循方面的需求,只允許在環境中使用個別核准的 API。在這種情況下,您也可以設定「受限服務資源用量」機構政策服務。在專案中套用機構政策,即可限制可在該專案中建立的服務。不過,機構政策不會禁止這個專案中的服務與其他專案中的服務通訊。相較之下,VPC Service Controls 可讓您定義範圍,防止與範圍外的服務通訊。

      舉例來說,如果您定義的機構政策允許 Compute Engine,但禁止專案中的 Cloud Storage,則該專案中的 VM 無法在專案中建立 Cloud Storage 值區。不過,VM 可以向其他專案中的 Cloud Storage 值區發出要求,因此仍有可能透過 Cloud Storage 服務外洩資料。以下步驟說明如何實作及測試這個情境:

      1. 切換到 Cloud Shell 分頁,指令列提示會以 username@cloudshell 開頭。
      2. 在 Cloud Shell 分頁中,建立 YAML 檔案來描述機構政策服務,該服務只允許使用 Compute Engine 服務,並拒絕所有其他服務,然後將其套用至專案。

        cat <<EOF > allowed_services_policy.yaml
        constraint: constraints/gcp.restrictServiceUsage
        listPolicy:
          allowedValues:
          - compute.googleapis.com
          inheritFromParent: true
        EOF
        
        gcloud resource-manager org-policies set-policy allowed_services_policy.yaml \
        --project=PROJECT_ID
      3. 返回 SSH 工作階段的分頁,該工作階段位於周邊網路內的 VM,且指令列提示符號以 username@demo-vm 開頭。

      4. 在周邊內部的 SSH 工作階段中,執行下列指令,查看您先前在這個專案中建立的相同儲存空間 bucket。

        gcloud storage buckets describe gs://PROJECT_ID

        輸出結果會與下列內容相似:

        "ERROR: (gcloud.storage.buckets.create) HTTPError 403: Request is disallowed by organization's constraints/gcp.restrictServiceUsage constraint for 'projects/123456789' attempting to use service 'storage.googleapis.com'."
        

        這項回應表示無論範圍設定為何,組織政策服務都會拒絕專案內的 Cloud Storage 服務。

      5. 在安全防護範圍內的 SSH 工作階段中,執行下列指令,查看安全防護範圍外的儲存空間 bucket,該 bucket 受到輸出政策允許。

        gcloud storage cat gs://solutions-public-assets/vpcsc-tutorial/helloworld.txt

        輸出結果會與下列內容相似:

        "Hello world!
        This is a sample file in Cloud Storage that is viewable to allUsers."
        

        成功的回應會傳回外部儲存空間 bucket 中的 helloworld.txt 內容。這項回應表示您的邊界和輸出政策允許內部流量在特定條件下存取外部儲存空間值區,但無論邊界設定為何,機構政策服務都會拒絕專案中的 Cloud Storage 服務。如果服務範圍允許,即使受限服務資源使用機構政策服務不允許,仍可使用專案外部的服務進行外洩。

        如要拒絕與範圍外的 Cloud Storage 或其他 Google 服務通訊,單獨使用受限服務資源用量機構政策服務並不夠,您必須設定 VPC Service Controls 範圍。VPC Service Controls 可減少資料竊取路徑,而受限服務資源使用是合規性控制項,可防止在環境中建立未經核准的服務。搭配使用這些控制項,即可封鎖一系列外洩路徑,並在環境中選擇性允許核准的服務供內部使用。

      清除所用資源

      Delete a Google Cloud project:

      gcloud projects delete PROJECT_ID

      雖然 VPC Service Controls 範圍不會產生任何額外費用,但仍應清除,以免機構組織中出現雜亂和未使用的資源。

      1. 在 Google Cloud 控制台頂端的專案選取器中,選取您在本教學課程中使用的機構。
      2. 在 Google Cloud 控制台中,前往「VPC Service Controls」頁面。

        前往 VPC Service Controls

      3. 在安全防護範圍清單下方,選取要刪除的安全防護範圍,然後按一下「刪除」

      4. 在對話方塊中,再次按一下「刪除」確認刪除。

      後續步驟