将 CMEK 与 Managed Service for Apache Spark 搭配使用

默认情况下,Managed Service for Apache Spark 会静态加密客户内容, Managed Service for Apache Spark 会为您处理加密,您无需执行任何 其他操作。此选项称为“Google 默认加密”。

如果您想要控制加密密钥,则可以将 Cloud KMS 中客户管理的加密密钥 (CMEK) 与集成 CMEK 的服务(包括 Managed Service for Apache Spark)搭配使用。使用 Cloud KMS 密钥时,您可以控制其保护级别、位置、轮替时间表、使用和访问权限以及加密边界。 使用 Cloud KMS 还可让您跟踪密钥使用情况、查看审核日志以及控制密钥生命周期。 这样您就可以在 Cloud KMS 中控制和管理用于保护数据的对称 密钥加密密钥 (KEK),而不是由 Google 拥有和管理这些密钥。

使用 CMEK 设置资源后,访问您的 Managed Service for Apache Spark 资源的体验与使用 Google 默认加密功能类似。 如需详细了解加密 选项,请参阅客户管理的加密密钥 (CMEK)

使用 CMEK

按照本部分中的步骤操作,使用 CMEK 加密 Managed Service for Apache Spark 写入永久性磁盘和 Managed Service for Apache Spark 暂存存储桶的数据。

您可以使用 Cloud Key Management Service 创建和管理密钥环和密钥,也可以使用 Cloud KMS Autokey 简化 密钥环和密钥的自动创建。

使用 Cloud KMS Autokey

  1. 在包含项目的文件夹中启用 Autokey
  2. 创建密钥句柄。 创建密钥句柄时,请指定 dataproc.googleapis.com/Batchdataproc.googleapis.com/Session 作为 --resource-type。Autokey 会生成密钥并将其分配给密钥句柄。
  3. 按照手动创建和使用密钥部分中的第 4 步和第 5 步,向服务账号授予权限并配置批量或会话工作负载。 提交工作负载时,请在 kmsKey 字段中指定密钥句柄资源名称,而不是密钥资源名称。

手动创建和使用密钥

按照以下步骤手动创建 Cloud KMS 密钥,并将其与 Managed Service for Apache Spark 搭配使用。

  1. 使用 Cloud Key Management Service (Cloud KMS)创建密钥。

  2. 复制资源名称。

    复制资源名称。
    资源名称的构造方式如下:
    projects/PROJECT_ID/locations/REGION/keyRings/KEY_RING_NAME/cryptoKeys/KEY_NAME
    

  3. 启用 Compute Engine、Managed Service for Apache Spark 和 Cloud Storage Service Agent 服务账号以使用您的密钥:

    1. 如需向 Compute Engine Service Agent 服务账号分配 Cloud KMS CryptoKey Encrypter/Decrypter 角色,请参阅 使用 Cloud KMS 密钥保护资源> 必需的角色。如果此服务帐号未列在控制台的 IAM 页面上 ,请点击 包括 Google 提供的角色授予 以列出该服务账号。 Google Cloud
    2. Cloud KMS CryptoKey Encrypter/Decrypter 角色分配给 Managed Service for Apache Spark Service Agent 服务账号。 您可以使用 Google Cloud 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 的项目的 ID。 Google Cloud 此项目也可以是运行 Managed Service for Apache Spark 资源的项目。

      PROJECT_NUMBER:运行 Managed Service for Apache Spark 资源的项目的项目编号(不是项目 ID)。 Google Cloud

    3. 在运行 Managed Service for Apache Spark 资源的项目中启用 Cloud KMS API。

    4. 如果 Managed Service for Apache Spark Service Agent 角色 未附加到 Managed Service for Apache Spark Service Agent 服务账号, 请将 serviceusage.services.use 权限添加到附加到 Managed Service for Apache Spark Service Agent 服务帐号的自定义 角色。如果 Managed Service for Apache Spark Service Agent 角色已附加到 Managed Service for Apache Spark Service Agent 服务帐号,则可以跳过此步骤。

    5. 按照步骤在存储桶中 添加密钥

  4. 提交批量工作负载时

    1. 在批次的 kmsKey 参数中指定密钥。
    2. 在批次的 stagingBucket 参数中指定 Cloud Storage 存储桶的名称。
  5. 创建交互式会话或会话模板时

    1. 在会话的 kmsKey 参数中指定密钥。
    2. 在会话的 stagingBucket 参数中指定 Cloud Storage 存储桶的名称。