客戶代管的加密金鑰 (CMEK)

使用 Managed Service for Apache Spark 時,叢集和工作資料會儲存在與叢集中的 Compute Engine VM 相關聯的永久磁碟,以及 Cloud Storage 暫存值區中。根據預設,系統會使用 Google 產生的資料加密金鑰 (DEK) 和金鑰加密金鑰 (KEK),加密這類永久磁碟和值區資料。

如要控管及管理金鑰加密金鑰 (KEK),可以使用客戶自行管理的加密金鑰 (CMEK) (Google 會繼續控管資料加密金鑰 (DEK))。如要進一步瞭解 Google 資料加密金鑰,請參閱「靜態資料加密」。

CMEK 叢集資料加密

您可以使用客戶自行管理的加密金鑰 (CMEK) 加密下列叢集資料:

  • 附加至 Managed Service for Apache Spark 叢集 VM 的永久磁碟資料
  • 提交至叢集的工作引數資料,例如透過 Spark SQL 工作提交的查詢字串
  • 叢集中繼資料、工作驅動程式輸出內容,以及寫入 Managed Service for Apache Spark 叢集暫存值區的其他資料

事前準備

  1. 登入 Google Cloud 帳戶。如果您是 Google Cloud新手,歡迎 建立帳戶,親自評估產品在實際工作環境中的成效。新客戶還能獲得價值 $300 美元的免費抵免額,可用於執行、測試及部署工作負載。
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the Dataproc, Cloud Key Management Service, Compute Engine, and Cloud Storage APIs.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the APIs

  5. 安裝 Google Cloud CLI。

  6. 若您採用的是外部識別資訊提供者 (IdP),請先使用聯合身分登入 gcloud CLI

  7. 執行下列指令,初始化 gcloud CLI:

    gcloud init
  8. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  9. Verify that billing is enabled for your Google Cloud project.

  10. Enable the Dataproc, Cloud Key Management Service, Compute Engine, and Cloud Storage APIs.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the APIs

  11. 安裝 Google Cloud CLI。

  12. 若您採用的是外部識別資訊提供者 (IdP),請先使用聯合身分登入 gcloud CLI

  13. 執行下列指令,初始化 gcloud CLI:

    gcloud init

建立金鑰

如要使用 CMEK 保護 Managed Service for Apache Spark 資源,您可以自動建立金鑰,也可以手動建立金鑰。

自動建立金鑰

使用 Autokey 自動佈建及指派 CMEK。建立資源時,Autokey 會視需要產生金鑰環和金鑰。服務代理程式會在加密和解密作業中使用金鑰。如有需要,Autokey 會建立代理程式,並授予必要的 Identity and Access Management (IAM) 角色。詳情請參閱「Autokey 總覽」。

手動建立金鑰

如要手動建立金鑰,以透過 CMEK 加密叢集資料,請按照下列步驟操作:

  1. 使用 Cloud KMS 建立一或多個金鑰。您將在後續步驟中使用的資源名稱 (也稱為金鑰的資源 ID) 結構如下:

    projects/PROJECT_ID/locations/REGION/keyRings/KEY_RING_NAME/cryptoKeys/KEY_NAME
    
    金鑰 (CMEK) 必須與加密資源位於相同位置。舉例來說,用於加密 us-central1 區域中資源的 CMEK,也必須位於 us-central1 區域。

  2. 為確保下列服務帳戶 (Compute Engine 服務代理人服務帳戶Cloud Storage 服務代理人服務帳戶Managed Service for Apache Spark 服務代理人服務帳戶) 具備使用 Cloud KMS 金鑰保護資源的必要權限,請管理員在專案中,將 Cloud KMS CryptoKey Encrypter/Decrypter (roles/cloudkms.cryptoKeyEncrypterDecrypter) IAM 角色授予下列服務帳戶:Compute Engine 服務代理人服務帳戶Cloud Storage 服務代理人服務帳戶Managed Service for Apache Spark 服務代理人服務帳戶

    以下範例說明如何使用 Google Cloud CLI,將 Cloud KMS CryptoKey Encrypter/Decrypter 角色指派給 Managed Service for Apache Spark 服務代理人服務帳戶:

    gcloud projects add-iam-policy-binding KMS_PROJECT_ID \
    --member serviceAccount:service-PROJECT_NUMBER@dataproc-accounts.iam.gserviceaccount.com \
    --role roles/cloudkms.cryptoKeyEncrypterDecrypter
    

    更改下列內容:

    KMS_PROJECT_ID: Google Cloud 專案的 ID,其中包含 Cloud KMS 金鑰。

    PROJECT_NUMBER:執行 Managed Service for Apache Spark 資源的專案編號 (不是專案 ID)。 Google Cloud

  3. 如果Managed Service for Apache Spark 服務代理角色未附加至 Managed Service for Apache Spark 服務代理服務帳戶,請將 serviceusage.services.use 權限新增至附加至 Managed Service for Apache Spark 服務代理服務帳戶的自訂角色。

使用 CMEK 建立叢集

建立 Managed Service for Apache Spark 叢集時,請傳遞金鑰的資源 ID。

gcloud CLI

  • 如要使用金鑰加密叢集永久磁碟資料,請在建立叢集時,將金鑰的資源 ID 傳送至 --gce-pd-kms-key 旗標。
    gcloud dataproc clusters create CLUSTER_NAME \
        --region=REGION \
        --gce-pd-kms-key='projects/PROJECT_ID/locations/REGION/keyRings/KEY_RING_NAME/cryptoKeys/KEY_NAME' \
        other arguments ...
        

    您可以使用 gcloud 指令列工具驗證金鑰設定。

    gcloud dataproc clusters describe CLUSTER_NAME \
        --region=REGION
        

    指令輸出片段:

    ...
    configBucket: dataproc- ...
      encryptionConfig:
        gcePdKmsKeyName: projects/project-id/locations/region/keyRings/key-ring-name/cryptoKeys/key-name
    ...
        
  • 如要使用金鑰加密叢集永久磁碟資料和工作引數資料,請在建立叢集時,將金鑰的資源 ID 傳遞至 --kms-key 標記。如需使用 `--kms-key` 標記加密的工作類型和引數清單,請參閱 [Cluster.EncryptionConfig.kmsKey](/managed-spark/docs/reference/rest/v1/ClusterConfig#EncryptionConfig.FIELDS.kms_key)。
    gcloud dataproc clusters create CLUSTER_NAME \
        --region=REGION \
        --kms-key='projects/PROJECT_ID/locations/REGION/keyRings/KEY_RING_NAME/cryptoKeys/KEY_NAME' \
        other arguments ...
          

    您可以使用 gcloud CLI dataproc clusters describe 指令驗證金鑰設定。金鑰資源 ID 會在 gcePdKmsKeyNamekmsKey 上設定,以便使用金鑰加密叢集永久磁碟和工作引數資料。

    gcloud dataproc clusters describe CLUSTER_NAME \
        --region=REGION
          

    指令輸出片段:

    ...
    configBucket: dataproc- ...
      encryptionConfig:
      gcePdKmsKeyName: projects/PROJECT_ID/locations/REGION/keyRings/KEY_RING_NAME/cryptoKeys/KEY_NAME
      kmsKey: projects/PROJECT_ID/locations/REGION/keyRings/KEY_RING_NAME/cryptoKeys/KEY_NAME
    ...
        
  • 如要加密叢集中繼資料、工作驅動程式,以及寫入 Cloud Storage 中 Managed Service for Apache Spark 暫存 bucket 的其他輸出資料,請按照下列步驟操作:
    gcloud dataproc clusters create CLUSTER_NAME \
        --region=REGION \
        --bucket=CMEK_BUCKET_NAME \
        other arguments ...
            

    如果工作採用值區引數,您還可以將啟用 CMEK 功能的值區傳送至 `gcloud dataproc jobs submit` 指令,如下列 `cmek-bucket` 範例所示:

    gcloud dataproc jobs submit pyspark gs://cmek-bucket/wordcount.py \
        --region=region \
        --cluster=cluster-name \
        -- gs://cmek-bucket/shakespeare.txt gs://cmek-bucket/counts
          

REST API

  • 如要使用您的金鑰加密叢集 VM 永久磁碟資料,請在 cluster.create 要求中加入 ClusterConfig.EncryptionConfig.gcePdKmsKeyName 欄位。

    您可以使用 gcloud CLI dataproc clusters describe 指令驗證金鑰設定。

    gcloud dataproc clusters describe CLUSTER_NAME \
        --region=REGION
        

    指令輸出片段:

    ...
    configBucket: dataproc- ...
      encryptionConfig:
        gcePdKmsKeyName: projects/PROJECT_ID/locations/REGION/keyRings/KEY_RING_NAME/cryptoKeys/KEY_NAME
    ...
        
  • 如要使用金鑰加密叢集 VM 永久磁碟資料和工作引數資料,請在 cluster.create 要求中加入 Cluster.EncryptionConfig.kmsKey 欄位。如需使用 --kms-key 欄位加密的工作類型和引數清單,請參閱 Cluster.EncryptionConfig.kmsKey

    您可以使用 gcloud CLI dataproc clusters describe 指令驗證金鑰設定。金鑰資源 ID 會在 gcePdKmsKeyNamekmsKey 上設定,以便使用金鑰加密叢集永久磁碟和工作引數資料。

    gcloud dataproc clusters describe CLUSTER_NAME \
        --region=REGION
        

    指令輸出片段:

    ...
    configBucket: dataproc- ...
      encryptionConfig:
        gcePdKmsKeyName: projects/PROJECT_ID/locations/REGION/keyRings/KEY_RING_NAME/cryptoKeys/KEY_NAME
        kmsKey: projects/PROJECT_ID/locations/REGION/keyRings/KEY_RING_NAME/cryptoKeys/KEY_NAME
    ...
        
  • 如要加密叢集中繼資料、工作驅動程式,以及寫入 Cloud Storage 中 Managed Service for Apache Spark 暫存 bucket 的其他輸出資料,請按照下列步驟操作:
    gcloud dataproc clusters create CLUSTER_NAME \
        --region=REGION \
        --bucket=CMEK_BUCKET_NAME \
        other arguments ...
        

    如果工作採用值區引數,您還可以將啟用 CMEK 功能的值區傳送至 `gcloud dataproc jobs submit` 指令,如下列 `cmek-bucket` 範例所示:

    gcloud dataproc jobs submit pyspark gs://cmek-bucket/wordcount.py \
        --region=region \
        --cluster=cluster-name \
        -- gs://cmek-bucket/shakespeare.txt gs://cmek-bucket/counts
          

搭配工作流程範本資料使用 CMEK

您可以使用 CMEK 加密 Managed Service for Apache Spark 工作流程範本工作引數資料,例如 Spark SQL 工作的查詢字串。請按照本節的步驟 1、2 和 3,將 CMEK 用於 Managed Service for Apache Spark 工作流程範本。如要查看啟用這項功能後,使用 CMEK 加密的工作流程範本工作類型和引數清單,請參閱 WorkflowTemplate.EncryptionConfig.kmsKey

  1. 使用 Cloud KMS 建立金鑰。您將在後續步驟中使用金鑰的資源名稱,該名稱的建構方式如下:
    projects/project-id/locations/region/keyRings/key-ring-name/cryptoKeys/key-name
    
  2. 如要讓 Managed Service for Apache Spark 服務帳戶使用您的金鑰,請按照下列步驟操作:

    1. 將 Cloud KMS CryptoKey Encrypter/Decrypter 角色指派給 Managed Service for Apache Spark 服務代理人服務帳戶。您可以使用 gcloud CLI 指派角色:

       gcloud projects add-iam-policy-binding KMS_PROJECT_ID \
       --member serviceAccount:service-PROJECT_NUMBER@dataproc-accounts.iam.gserviceaccount.com \
       --role roles/cloudkms.cryptoKeyEncrypterDecrypter
      

      更改下列內容:

      KMS_PROJECT_ID:執行 Cloud KMS 的 Google Cloud 專案 ID。這個專案也可以是執行 Managed Service for Apache Spark 資源的專案。

      PROJECT_NUMBER:執行 Managed Service for Apache Spark 資源的專案編號 (不是專案 ID)。 Google Cloud

    2. 在執行 Managed Service for Apache Spark 資源的專案中啟用 Cloud KMS API。

    3. 如果Managed Service for Apache Spark 服務代理角色未附加至 Managed Service for Apache Spark 服務代理服務帳戶,請將 serviceusage.services.use 權限新增至附加至 Managed Service for Apache Spark 服務代理服務帳戶的自訂角色。如果 Managed Service for Apache Spark 服務代理角色已附加至 Managed Service for Apache Spark 服務代理服務帳戶,可以略過這個步驟。

  3. 您可以使用 gcloud CLI 或 Dataproc API,在工作流程中設定您在步驟 1 中建立的金鑰。在工作流程中設定金鑰後,系統會使用該金鑰,加密 WorkflowTemplate.EncryptionConfig.kmsKey 中列出的所有工作類型和引數,以及工作流程工作引數和查詢。

    gcloud CLI

    使用 gcloud dataproc workflow-templates create 指令建立工作流程範本時,請將金鑰的資源 ID 傳遞至 --kms-key 旗標。

    範例:

    gcloud dataproc workflow-templates create my-template-name \
        --region=region \
        --kms-key='projects/project-id/locations/region/keyRings/key-ring-name/cryptoKeys/key-name' \
        other arguments ...
    
    您可以使用 gcloud 指令列工具驗證金鑰設定。
    gcloud dataproc workflow-templates describe TEMPLATE_NAME \
        --region=REGION
    
    ...
    id: my-template-name
    encryptionConfig:
    kmsKey: projects/PROJECT_ID/locations/REGION/keyRings/KEY_RING_NAME/cryptoKeys/KEY_NAME
    ...
    

    REST API

    workflowTemplates.create 要求中,使用 WorkflowTemplate.EncryptionConfig.kmsKey

    您可以發出 workflowTemplates.get 要求來驗證金鑰設定。傳回的 JSON 包含 kmsKey

    ...
    "id": "my-template-name",
    "encryptionConfig": {
      "kmsKey": "projects/project-id/locations/region/keyRings/key-ring-name/cryptoKeys/key-name"
    },
    

Cloud External Key Manager

Cloud External Key Manager (Cloud EKM) 可讓您使用支援的外部金鑰管理合作夥伴代管的金鑰,保護 Managed Service for Apache Spark 資料。在 Managed Service for Apache Spark 中使用 Cloud EKM 的步驟,與設定 CMEK 金鑰的步驟相同,但金鑰會指向外部管理的金鑰的 URI (請參閱「Cloud EKM 總覽」)。

Cloud EKM 錯誤

使用 Cloud EKM 時,如果輸入內容、Cloud EKM、外部金鑰管理合作夥伴系統發生錯誤,或是 Cloud EKM 與外部系統之間的通訊發生錯誤,建立叢集作業可能會失敗。如果您使用 REST API 或 Google Cloud 控制台,系統會在 Cloud Logging 中記錄錯誤。您可以透過「查看記錄」分頁,檢查失敗叢集的錯誤。