為虛擬私有雲網路設定 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.

      前往「身分與存取權管理」頁面

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

    5. 在「請選擇角色」清單中,選取角色。
    6. 如要授予其他角色,請按一下 「Add another role」(新增其他角色),然後新增其他角色。
    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.

      前往「身分與存取權管理」頁面

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

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

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

      準備虛擬私有雲網路

      在本節中,您將為 VPC 網路設定私人連線至 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 存取權的 VPC 網路和子網路:

        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

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

      確認輸入政策允許精細的邊界例外狀況

      在本節中,您將驗證入口政策是否允許對外圍進行精細的例外狀況設定。與粗粒度的存取層級相比,精細的入站政策可設定流量來源的其他屬性,並允許存取個別服務或方法。

      架構圖:說明入口政策如何允許精細例外狀況存取範圍內的特定服務

      上圖說明瞭入口政策如何讓已授權的用戶端只存取範圍內的特定服務,而不允許存取其他受限制的服務。

      在後續步驟中,您將透過將存取層級替換為入站政策,驗證這個概念。入站政策可讓已授權的用戶端僅存取 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 值區。

        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 執行個體上,透過 SSH 工作階段執行的指令會使用所附服務帳戶的身分,而從邊界外 Cloud Shell 執行的指令則會使用您自己的身分。按照教學課程中建議的設定方式操作時,即使要求擁有足夠的 IAM 權限,邊界仍會允許或拒絕要求。

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

      確認範圍允許內部流量存取範圍內的受限服務

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

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

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

      在下列步驟中,您將透過建立與邊界內 Compute Engine 執行個體的 SSH 連線,然後向服務提出要求,驗證這個概念。

      1. 在 Cloud Shell 中建立防火牆規則,允許從 IAP 用於 TCP 轉送 服務使用的 35.235.240.0/20 IP 位址範圍,允許進入 VPC 網路的 SSH 流量:

        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 工作階段,確認虛擬機器人無法存取不在虛擬私有雲可存取服務許可清單中的服務。舉例來說,下列指令會使用 Resource Manager 服務,但該服務並未在 VPC 可存取的服務許可清單中設定。

        gcloud projects describe PROJECT_ID

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

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

        Compute Engine 執行個體和其他網路端點只能要求在 VPC 可存取服務許可清單中設定的服務。不過,來自範圍外部的無伺服器資源或服務流量,可能會要求該服務。如要禁止在專案中使用某項服務,請參閱「Restricted Service Resource Usage」政策。

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

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

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

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

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

      1. 在重疊範圍內的 SSH 工作階段中,執行下列指令,即可建立儲存體值區。這項指令有效,是因為 Cloud Storage 服務已在 restricted-servicesaccessible-services 中設定。

        gcloud storage buckets create gs://PROJECT_ID-02

        成功的回應會建立 Storage 儲存桶。這個回應表示您的邊界允許 Cloud Storage 服務的內部流量。

      2. 在邊界內的 SSH 工作階段中,執行下列指令,從邊界外的儲存桶讀取資料。這個公開值區允許 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. 返回分隔區內 VM 的 SSH 工作階段分頁,指令列提示字元開頭為 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."
        

        這個回應表示您的外圍會拒絕外部值區中物件清單的內部流量,這表示外流政策只允許明確指定的方法。

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

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

      您也可能有內部規定或法規要求,只允許在環境中使用個別核准的 API。在這種情況下,您也可以設定「Restricted Service Resource Usage」機構政策服務。在專案中套用機構政策,即可限制在該專案中可建立哪些服務。不過,機構政策不會阻止這個專案中的服務與其他專案中的服務進行通訊。相比之下,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. 返回分隔區內 VM 的 SSH 工作階段分頁,指令列提示字元開頭為 username@demo-vm

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

        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 工作階段中,執行下列指令,查看邊界外由出口政策允許的儲存體值區。

        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."
        

        成功的回應會傳回外部儲存空間儲存桶中的 helloworld.txt 內容。這項回應顯示,在特定限制條件下,您的邊界和輸出政策允許內部流量存取外部儲存空間值區,但無論邊界設定為何,機構政策服務都會拒絕專案中的 Cloud Storage 服務。無論是否有「Restricted Service Resource Usage」機構政策,如果服務範圍允許使用專案外的服務,這些服務仍可能用於資料外洩。

        如要拒絕與範圍外 Cloud Storage 或其他 Google 服務的通訊,單靠「Restricted Service Resource Usage」機構政策服務是不夠的,您必須設定 VPC Service Controls 範圍。VPC Service Controls 可降低資料外洩途徑,而「Restricted Service Resource Usage」則是用來防範在環境中建立未經核准的服務的規定控制項。搭配使用這些控制項,即可封鎖一系列外洩路徑,並有選擇地允許在環境中使用內部核准的服務。

      清除所用資源

      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. 在對話方塊中,再次按一下「刪除」,確認刪除作業。

      後續步驟