設定可信映像檔政策


根據預設,您的專案使用者可以使用任何公開映像檔,以及實體可透過身分與存取權管理角色存取的任何映像檔,來建立永久磁碟或複製映像檔。不過在某些情況下,您可能會想要限制使用者權限,讓他們在建立開機磁碟時,只能利用有符合您政策及安全性需求之受核准軟體的映像檔。

請使用「可信映像檔」功能來定義機構政策,讓使用者只能利用特定專案中的映像檔建立永久磁碟。

如要限制可以使用映像檔的位置,請參閱限制使用共用映像檔、磁碟與快照的說明。

事前準備

  • 請參閱「使用限制」頁面,瞭解如何管理機構層級的政策。
  • 參閱「瞭解階層評估」頁面,瞭解機構政策的生效方式。
  • 如果尚未設定,請先設定驗證機制。驗證是指驗證身分,以便存取 Google Cloud 服務和 API 的程序。如要在本機開發環境中執行程式碼或範例,您可以選取下列任一選項,向 Compute Engine 進行驗證:

    Select the tab for how you plan to use the samples on this page:

    Console

    When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.

    gcloud

    1. After installing the Google Cloud CLI, initialize it by running the following command:

      gcloud init

      If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

    2. Set a default region and zone.

    REST

    To use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.

      After installing the Google Cloud CLI, initialize it by running the following command:

      gcloud init

      If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

    For more information, see Authenticate for using REST in the Google Cloud authentication documentation.

限制

  • 可信映像檔政策無法限制下列映像檔的存取權:

    • 您本機專案的自訂映像檔

    • Cloud Storage 值區中的映像檔。

  • 可信映像檔政策無法限制使用者在當地專案中建立映像檔資源。

設定圖片存取限制

在您的專案、資料夾或機構組織上設定 compute.trustedImageProjects 限制來制定映像檔存取權政策。您必須擁有修改機構政策的權限才能設定限制條件。舉例來說,roles/orgpolicy.policyAdmin 就有權設定這類限制條件。如要進一步瞭解如何管理專案、資料夾或機構層級的政策,請參閱「使用限制」一文。

您可以為 Compute Engine 提供的所有公開映像檔設定限制。如需圖片專案名稱清單,請參閱「作業系統詳細資訊」。您也可以使用 ml-images 專案,限制 Compute Engine 上可用的機器學習 (ML) 映像檔。如果您使用Serverless VPC Access,請授予專案權限,以便從 serverless-vpc-access-images 專案中使用 Compute Engine VM 映像檔。

使用 Google Cloud 控制台或 Google Cloud CLI 設定圖片存取限制。

主控台

舉例來說,如要在專案層級設定限制,請按照下列步驟操作:

  1. 前往「機構政策」頁面。

    前往「機構政策」

  2. 在政策清單中,點選「Define trusted image projects」。系統會顯示「政策詳細資料」頁面。

  3. 在「政策詳細資料」頁面中,按一下「管理政策」。畫面上會顯示「Edit policy」頁面。

  4. 在「Edit policy」(編輯政策) 頁面中,選取「Customize」(自訂)

  5. 在「政策強制執行」部分,選取強制執行選項。如要進一步瞭解繼承和資源階層,請參閱「瞭解階層評估」。

  6. 按一下 [新增規則]

  7. 在「Policy values」清單中,您可以選取這項機構政策是否應允許存取所有圖片專案、拒絕存取所有圖片專案,或是指定一組自訂專案來允許或拒絕存取權。

    如要設定政策規則,請完成下列任一選項:

    • 如要允許使用者從所有公開映像檔建立開機磁碟,請選取「全部允許」
    • 如要限制使用者無法從所有公開映像檔建立開機磁碟,請選取「全部拒絕」
    • 如要指定使用者可用來建立開機磁碟的公開映像檔,請選取「自訂」。系統會顯示「政策類型」和「自訂值」欄位。

      1. 在「政策類型」清單中,選取「允許」或「拒絕」
      2. 在「自訂值」欄位中,使用 projects/IMAGE_PROJECT 格式輸入圖片專案的名稱。

        IMAGE_PROJECT 替換為要設定限制的圖片專案。

        您可以新增多個圖片專案。針對每個要新增的圖片專案,按一下「新增」並輸入圖片專案名稱。

  8. 如要儲存規則,請按一下「完成」

  9. 如要儲存並套用機構政策,請按一下「儲存」

如要進一步瞭解如何建立機構政策,請參閱「建立及管理機構政策」。

gcloud

舉例來說,如要在專案層級設定限制,請按照下列步驟操作:

  1. 使用 resource-manager org-policies describe 指令,取得專案現有的政策設定。

    gcloud resource-manager org-policies describe \
       compute.trustedImageProjects --project=PROJECT_ID \
       --effective > policy.yaml
    

    PROJECT_ID 替換為您的專案 ID。

  2. 在文字編輯器中開啟 policy.yaml 檔案,並修改 compute.trustedImageProjects 限制條件。新增需要的限制條件或移除不再需要的限制條件。完成檔案編輯後,請儲存變更。以下是您可能會在政策檔案中設定的限制條件項目範例:

    constraint: constraints/compute.trustedImageProjects
    listPolicy:
     allowedValues:
        - projects/debian-cloud
        - projects/cos-cloud
     deniedValues:
        - projects/IMAGE_PROJECT
    

    IMAGE_PROJECT 替換為您要在專案中限制的圖片專案名稱。

    或者,可能除了專案中的自訂映像檔以外,您想要拒絕其他映像檔的存取權。針對該情況,請使用下列範例:

    constraint: constraints/compute.trustedImageProjects
    listPolicy:
     allValues: DENY
    

  3. policy.yaml 檔案套用至您的專案。如果您的機構組織或資料夾已有限制條件,這些限制條件可能會與您設定的專案層級限制條件發生衝突。如要套用限制條件,請使用 resource-manager org-policies set-policy 指令。

    gcloud resource-manager org-policies set-policy \
       policy.yaml --project=PROJECT_ID
    

    PROJECT_ID 替換為您的專案 ID。

完成限制條件設定後,請進行測試,確定建立的限制條件是您需要的。

後續步驟