使用客户管理的加密密钥 (CMEK) 加密数据

本页面介绍如何使用客户管理的加密密钥 (CMEK) 对存储在 AML AI 实例中的数据进行加密。

概览

AML AI 实例中的所有客户数据在静态存储时都使用 CMEK 密钥进行加密。您可以在 Cloud Key Management Service 中管理密钥,并使用 Identity and Access Management 来控制对密钥的访问权限。如果您暂时停用或永久销毁 CMEK 密钥,则无法访问使用该密钥加密的数据。

借助 CMEK,您可以控制密钥生命周期和管理的多个方面,但也会产生 Cloud KMS 服务的额外费用

Cloud KMS 可以在与 AML AI 相同的 Google Cloud 项目中运行,也可以在您集中管理多个项目密钥的单独项目中运行。

您在创建实例时分配 CMEK 密钥。所有实例都必须使用 CMEK 进行配置,并且无法更改为使用 Google 默认加密。

如需大致了解 CMEK(包括其启用时间和原因),请参阅 Cloud KMS 文档

客户数据

由 AML AI 处理的所有客户数据都会使用相应父级实例资源中指定的 CMEK 密钥进行静态加密。这包括与数据集、引擎配置、模型等 AML AI 资源相关的所有客户数据。客户数据的所有临时和永久性存储(包括输入和输出的副本、生成的机器学习功能、日志、模型超参数、模型权重和预测结果)都使用相应实例的 CMEK 密钥进行加密。

AML AI 不负责管理 Google Cloud 项目中输入或输出数据的加密。如果您希望对此数据进行加密,则必须在您的 Google Cloud 项目中设置单独的 CMEK 密钥。实例中的指定 KMS 密钥用于 AML AI 资源及其数据。

创建密钥并授予权限

以下说明介绍了如何为实例创建密钥,以及如何授予使用该密钥加密和解密实例数据的权限。您可以使用直接在 Cloud KMS 中创建的密钥,也可以使用通过 Cloud External Key Manager 提供的外部管理的密钥。

  1. 在您要用于管理密钥的 Google Cloud 项目中,执行以下操作:

    1. 启用 Cloud KMS API

    2. 使用 projects.locations.keyRings.create 方法创建密钥环。Cloud KMS 密钥环位置必须与您加密的实例的位置一致。

      REST

      在使用任何请求数据之前,请先进行以下替换:

      • KMS_PROJECT_ID:包含密钥环的项目的 Google Cloud 项目 ID
      • LOCATION:密钥环的位置;请使用受支持的区域之一:
        • us-central1
        • us-east1
        • asia-south1
        • europe-west1
        • europe-west2
        • europe-west4
        • northamerica-northeast1
        • southamerica-east1
      • KEY_RING_ID:用户定义的密钥环标识符

      如需发送请求,请选择以下方式之一:

      curl

      执行以下命令:

      curl -X POST \
      -H "Authorization: Bearer $(gcloud auth print-access-token)" \
      -H "Content-Type: application/json; charset=utf-8" \
      -d "" \
      "https://cloudkms.googleapis.com/v1/projects/KMS_PROJECT_ID/locations/LOCATION/keyRings?key_ring_id=KEY_RING_ID"

      PowerShell

      执行以下命令:

      $cred = gcloud auth print-access-token
      $headers = @{ "Authorization" = "Bearer $cred" }

      Invoke-WebRequest `
      -Method POST `
      -Headers $headers `
      -Uri "https://cloudkms.googleapis.com/v1/projects/KMS_PROJECT_ID/locations/LOCATION/keyRings?key_ring_id=KEY_RING_ID" | Select-Object -Expand Content

      您应该收到类似以下内容的 JSON 响应:

      {
        "name": "projects/KMS_PROJECT_ID/locations/LOCATION/keyRings/KEY_RING_ID",
        "createTime": CREATE_TIME
      }
      

      gcloud

      在使用下面的命令数据之前,请先进行以下替换:

      • LOCATION:密钥环的位置;请使用受支持的区域之一:
        • us-central1
        • us-east1
        • asia-south1
        • europe-west1
        • europe-west2
        • europe-west4
        • northamerica-northeast1
        • southamerica-east1
      • KEY_RING_ID:用户定义的密钥环标识符

      执行以下命令:

      Linux、macOS 或 Cloud Shell

      gcloud kms keyrings create KEY_RING_ID \
        --location LOCATION
      

      Windows (PowerShell)

      gcloud kms keyrings create KEY_RING_ID `
        --location LOCATION
      

      Windows (cmd.exe)

      gcloud kms keyrings create KEY_RING_ID ^
        --location LOCATION
      
      您应该会收到一个空响应:
      $

    3. 使用 projects.locations.keyRings.cryptoKeys 方法创建密钥。

      REST

      在使用任何请求数据之前,请先进行以下替换:

      • KMS_PROJECT_ID:包含密钥环的项目的 Google Cloud 项目 ID
      • LOCATION:密钥环的位置;请使用受支持的区域之一:
        • us-central1
        • us-east1
        • asia-south1
        • europe-west1
        • europe-west2
        • europe-west4
        • northamerica-northeast1
        • southamerica-east1
      • KEY_RING_ID:用户定义的密钥环标识符
      • KEY_ID:用户定义的密钥标识符

      请求 JSON 正文:

      {
        "purpose": "ENCRYPT_DECRYPT"
      }
      

      如需发送请求,请选择以下方式之一:

      curl

      将请求正文保存在名为 request.json 的文件中。在终端中运行以下命令,在当前目录中创建或覆盖此文件:

      cat > request.json << 'EOF'
      {
        "purpose": "ENCRYPT_DECRYPT"
      }
      EOF

      然后,执行以下命令以发送 REST 请求:

      curl -X POST \
      -H "Authorization: Bearer $(gcloud auth print-access-token)" \
      -H "Content-Type: application/json; charset=utf-8" \
      -d @request.json \
      "https://cloudkms.googleapis.com/v1/projects/KMS_PROJECT_ID/locations/LOCATION/keyRings/KEY_RING_ID/cryptoKeys?crypto_key_id=KEY_ID"

      PowerShell

      将请求正文保存在名为 request.json 的文件中。在终端中运行以下命令,在当前目录中创建或覆盖此文件:

      @'
      {
        "purpose": "ENCRYPT_DECRYPT"
      }
      '@  | Out-File -FilePath request.json -Encoding utf8

      然后,执行以下命令以发送 REST 请求:

      $cred = gcloud auth print-access-token
      $headers = @{ "Authorization" = "Bearer $cred" }

      Invoke-WebRequest `
      -Method POST `
      -Headers $headers `
      -ContentType: "application/json; charset=utf-8" `
      -InFile request.json `
      -Uri "https://cloudkms.googleapis.com/v1/projects/KMS_PROJECT_ID/locations/LOCATION/keyRings/KEY_RING_ID/cryptoKeys?crypto_key_id=KEY_ID" | Select-Object -Expand Content

      您应该收到类似以下内容的 JSON 响应:

      {
        "name": "projects/KMS_PROJECT_ID/locations/LOCATION/keyRings/KEY_RING_ID/cryptoKeys/KEY_ID",
        "primary": {
          "name": "projects/KMS_PROJECT_ID/locations/LOCATION/keyRings/KEY_RING_ID/cryptoKeys/KEY_ID/cryptoKeyVersions/1",
          "state": "ENABLED",
          "createTime": CREATE_TIME,
          "protectionLevel": "SOFTWARE",
          "algorithm": "GOOGLE_SYMMETRIC_ENCRYPTION",
          "generateTime": GENERATE_TIME
        },
        "purpose": "ENCRYPT_DECRYPT",
        "createTime": CREATE_TIME,
        "versionTemplate": {
          "protectionLevel": "SOFTWARE",
          "algorithm": "GOOGLE_SYMMETRIC_ENCRYPTION"
        },
        "destroyScheduledDuration": "86400s"
      }
      

      gcloud

      在使用下面的命令数据之前,请先进行以下替换:

      • LOCATION:密钥环的位置;请使用受支持的区域之一:
        • us-central1
        • us-east1
        • asia-south1
        • europe-west1
        • europe-west2
        • europe-west4
        • northamerica-northeast1
        • southamerica-east1
      • KEY_RING_ID:用户定义的密钥环标识符
      • KEY_ID:用户定义的密钥标识符

      执行以下命令:

      Linux、macOS 或 Cloud Shell

      gcloud kms keys create KEY_ID \
        --keyring KEY_RING_ID \
        --location LOCATION \
        --purpose "encryption"
      

      Windows (PowerShell)

      gcloud kms keys create KEY_ID `
        --keyring KEY_RING_ID `
        --location LOCATION `
        --purpose "encryption"
      

      Windows (cmd.exe)

      gcloud kms keys create KEY_ID ^
        --keyring KEY_RING_ID ^
        --location LOCATION ^
        --purpose "encryption"
      
      您应该会收到一个空响应:
      $

  2. 如果您尚未在 AML AI 项目中创建 AML AI 实例,则 AML AI 服务帐号尚不存在。创建服务账号。

    在使用下面的命令数据之前,请先进行以下替换:

    • PROJECT_ID:运行 AML AI 的项目的 Google Cloud 项目 ID

    执行以下命令:

    Linux、macOS 或 Cloud Shell

    gcloud beta services identity create --service=financialservices.googleapis.com --project=PROJECT_ID
    

    Windows (PowerShell)

    gcloud beta services identity create --service=financialservices.googleapis.com --project=PROJECT_ID
    

    Windows (cmd.exe)

    gcloud beta services identity create --service=financialservices.googleapis.com --project=PROJECT_ID
    

    您应该会收到类似如下所示的响应:

    Service identity created: service-PROJECT_NUMBER@gcp-sa-financialservices.iam.gserviceaccount.com

  3. CryptoKey Encrypter/Decrypter IAM 角色 (roles/cloudkms.cryptoKeyEncrypterDecrypter) 授予 AML AI 服务帐号。为您创建的密钥授予此权限。

    在使用下面的命令数据之前,请先进行以下替换:

    • PROJECT_ID:运行 AML AI 的项目的 Google Cloud 项目 ID
    • KEY_ID:用户定义的密钥标识符
    • LOCATION:密钥环的位置;请使用受支持的区域之一:
      • us-central1
      • us-east1
      • asia-south1
      • europe-west1
      • europe-west2
      • europe-west4
      • northamerica-northeast1
      • southamerica-east1
    • KEY_RING_ID:用户定义的密钥环标识符
    • PROJECT_NUMBER:运行 AML AI 的项目的 Google Cloud 项目编号

    执行以下命令:

    Linux、macOS 或 Cloud Shell

    gcloud kms keys add-iam-policy-binding KEY_ID --project=PROJECT_ID \
      --location LOCATION --keyring=KEY_RING_ID \
      --member serviceAccount:service-PROJECT_NUMBER@gcp-sa-financialservices.iam.gserviceaccount.com \
      --role roles/cloudkms.cryptoKeyEncrypterDecrypter
    

    Windows (PowerShell)

    gcloud kms keys add-iam-policy-binding KEY_ID --project=PROJECT_ID `
      --location LOCATION --keyring=KEY_RING_ID `
      --member serviceAccount:service-PROJECT_NUMBER@gcp-sa-financialservices.iam.gserviceaccount.com `
      --role roles/cloudkms.cryptoKeyEncrypterDecrypter
    

    Windows (cmd.exe)

    gcloud kms keys add-iam-policy-binding KEY_ID --project=PROJECT_ID ^
      --location LOCATION --keyring=KEY_RING_ID ^
      --member serviceAccount:service-PROJECT_NUMBER@gcp-sa-financialservices.iam.gserviceaccount.com ^
      --role roles/cloudkms.cryptoKeyEncrypterDecrypter
    

    您应该会收到类似如下所示的响应:

    Updated IAM policy for key KEY_ID.
    bindings:
    - members:
      - serviceAccount:service-PROJECT_NUMBER@gcp-sa-financialservices.iam.gserviceaccount.com
      role: roles/cloudkms.cryptoKeyEncrypterDecrypter
    etag: BwYCq0Sq4Ho=
    version: 1
    

    如需详细了解此命令,请参阅 gcloud kms keys add-iam-policy-binding 文档。

您现在可以创建实例并指定用于加密的密钥。

移除访问权限

您可以通过以下几种方式移除对 CMEK 加密的实例的访问权限:

我们建议您先撤消 AML AI 服务帐号的权限,然后再停用或销毁密钥。对权限所做的更改会在数秒内传播,因此您可以观察停用或销毁密钥的影响。

停用或销毁实例的加密密钥后,您将无法查看或检索实例数据。实例中存储的所有数据都将无法访问,包括数据集、模型、引擎配置、回测结果和预测结果等 API 资源。拥有 AML AI Viewer 角色的用户仍然可以查看实例元数据,如实例名称。

拥有 AML AI Administrator 角色或 Owner 角色的用户可以删除该实例。

CMEK 组织政策

AML AI 不支持 CMEK 组织政策。但是,无论 constraints/gcp.restrictNonCmekServices 组织政策为何,AML AI 始终需要使用 CMEK。

后续步骤