Repository navigation
tidb-cloud: add CMEK documentation for Google Cloud #24792
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,197 @@ | ||||||||||
| --- | ||||||||||
| title: Encryption at Rest Using Customer-Managed Encryption Keys on Google Cloud | ||||||||||
| summary: Learn how to use Customer-Managed Encryption Key (CMEK) to encrypt data in TiDB Cloud clusters hosted on Google Cloud. | ||||||||||
| --- | ||||||||||
|
|
||||||||||
| # Encryption at Rest Using Customer-Managed Encryption Keys on Google Cloud | ||||||||||
|
|
||||||||||
| Customer-Managed Encryption Key (CMEK) enables you to secure your static data in a TiDB Cloud Dedicated cluster by utilizing a symmetric encryption key that is under your complete control. This key is referred to as the CMEK key. | ||||||||||
|
|
||||||||||
| Once CMEK is enabled for a project, all clusters created within that project encrypt their static data using the CMEK key. Additionally, any backup data generated by these clusters is encrypted using the same key. If CMEK is not enabled, TiDB Cloud employs an escrow key to encrypt all data in your TiDB Cloud Dedicated cluster when it is at rest. | ||||||||||
|
|
||||||||||
| > **Note:** | ||||||||||
| > | ||||||||||
| > CMEK is similar to Bring Your Own Key (BYOK). With BYOK, you typically generate the key locally and upload it. However, TiDB Cloud supports keys generated within [Cloud KMS](https://cloud.google.com/kms/docs). | ||||||||||
|
|
||||||||||
| ## Restrictions | ||||||||||
|
|
||||||||||
| - To use CMEK, you need to enable CMEK when creating a Dedicated project and complete the CMEK configuration before creating a cluster. You cannot enable CMEK for existing projects. | ||||||||||
| - In CMEK-enabled projects, you can only create [TiDB Cloud Dedicated](/tidb-cloud/select-cluster-tier.md#tidb-cloud-dedicated) clusters. | ||||||||||
| - In CMEK-enabled projects, [dual region backup](/tidb-cloud/backup-and-restore-concepts.md#dual-region-backup) is not supported. | ||||||||||
| - For each cloud provider, you can configure one unique encryption key per region. Once created, the CMEK configuration of a Dedicated project cannot be removed or changed. If the configuration is incorrect, you need to create a new Dedicated project. | ||||||||||
| - You can create clusters only in the regions where you have configured an encryption key. | ||||||||||
| - A CMEK key can only be used by clusters hosted on the same cloud provider and in the same region as the key. | ||||||||||
| - The key ring of the CMEK key must be in the same region as your clusters. `global` and multi-region key ring locations are not supported. | ||||||||||
|
|
||||||||||
| ## Prerequisites | ||||||||||
|
|
||||||||||
| - You are in the `Organization Owner` role of your organization. | ||||||||||
| - You have a Dedicated project with CMEK enabled. If you do not have one, see [Step 1](#step-1-create-a-cmek-enabled-dedicated-project). | ||||||||||
|
|
||||||||||
| ## Enable CMEK | ||||||||||
|
|
||||||||||
| If you want to encrypt your data using the key owned by your account, take the following steps. | ||||||||||
|
|
||||||||||
| ### Step 1. Create a CMEK-enabled Dedicated project | ||||||||||
|
|
||||||||||
| If you are in the `Organization Owner` role of your organization, you can create a CMEK-enabled project by performing the following steps: | ||||||||||
|
|
||||||||||
| 1. In the [TiDB Cloud console](https://tidbcloud.com), navigate to the [**My TiDB**](https://tidbcloud.com/tidbs) page of your organization, and then click **Create Project**. | ||||||||||
| 2. In the displayed dialog, enter a project name. | ||||||||||
| 3. Select the **Create for Dedicated Cluster** option. | ||||||||||
| 4. Choose to enable the CMEK capability of the project. | ||||||||||
| 5. Click **Confirm** to complete the project creation. | ||||||||||
|
|
||||||||||
| ### Step 2. Add the CMEK configuration | ||||||||||
|
|
||||||||||
| > **Note:** | ||||||||||
| > | ||||||||||
| > Make sure that the key is configured correctly and is free from errors such as insufficient permissions or a location mismatch. These errors can cause clusters to be incorrectly created using this key. | ||||||||||
|
|
||||||||||
| 1. In the [TiDB Cloud console](https://tidbcloud.com), go to **Organization Settings** > **CMEK**. | ||||||||||
|
|
||||||||||
| 2. Select the **Dedicated** key scope, and then click **Add CMEK** in the upper-right corner. | ||||||||||
|
|
||||||||||
| > **Note:** | ||||||||||
| > | ||||||||||
| > Only Dedicated projects with CMEK enabled are available in the project list. | ||||||||||
|
|
||||||||||
| 3. On the **Add CMEK** page, select your target **Project**, set **Cloud Provider** to **Google Cloud**, and then select the **Region** where you will create your clusters. | ||||||||||
|
|
||||||||||
| 4. In the **Key Name** area, enter a key name prefix, and then click the copy icon next to the generated suffix to copy the **full key name**. | ||||||||||
|
|
||||||||||
| > **Warning:** | ||||||||||
| > | ||||||||||
| > For enhanced security, TiDB Cloud adds a unique suffix to your key name. Use the full key name (prefix plus suffix) when creating the key in Cloud KMS. The full key name is sensitive information. Do not share or forward it outside your organization. | ||||||||||
|
|
||||||||||
| 5. In your Google Cloud project, create a key ring and a symmetric key using the full key name copied in the previous step. The key ring must be in the region selected in step 3. | ||||||||||
|
|
||||||||||
| <SimpleTab groupId="method"> | ||||||||||
| <div label="Use Google Cloud console" value="console"> | ||||||||||
|
|
||||||||||
| To create a key ring and a key, take the following steps: | ||||||||||
|
|
||||||||||
| 1. In the [Google Cloud console](https://console.cloud.google.com/), navigate to **Security** > **Key Management**. | ||||||||||
| 2. Click **Create key ring**, enter a name for the key ring, select the region selected in step 3, and then click **Create**. | ||||||||||
| 3. In the created key ring, click **Create key**. | ||||||||||
| 4. For **Key name**, enter the full key name copied from the TiDB Cloud console. | ||||||||||
| 5. For **Protection level**, select **Software** or **HSM** (both are supported). | ||||||||||
| 6. For **Key material**, keep **Generated key**. | ||||||||||
| 7. For **Purpose**, select **Symmetric encrypt/decrypt**. | ||||||||||
| 8. Click **Create**. | ||||||||||
|
|
||||||||||
| </div> | ||||||||||
| <div label="Use gcloud CLI" value="cli"> | ||||||||||
|
|
||||||||||
| Run the following commands. Replace `<PROJECT_ID>`, `<KEY_RING>`, `<FULL_KEY_NAME>`, and `<REGION>` with your own values. The `--project` flag makes sure that the key is created in the same Google Cloud project that you reference in step 7, and `--purpose=encryption` creates a symmetric key for encrypt and decrypt operations. | ||||||||||
|
|
||||||||||
| ```shell | ||||||||||
| gcloud kms keyrings create <KEY_RING> --location=<REGION> --project=<PROJECT_ID> | ||||||||||
|
|
||||||||||
| gcloud kms keys create <FULL_KEY_NAME> \ | ||||||||||
| --keyring=<KEY_RING> \ | ||||||||||
| --location=<REGION> \ | ||||||||||
| --project=<PROJECT_ID> \ | ||||||||||
| --purpose=encryption \ | ||||||||||
| --protection-level=software | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| </div> | ||||||||||
| </SimpleTab> | ||||||||||
|
|
||||||||||
| 6. Grant both TiDB Cloud service agents the **Cloud KMS CryptoKey Encrypter/Decrypter** (`roles/cloudkms.cryptoKeyEncrypterDecrypter`) role on the key. Both grants are required: the cluster disks and the backup data are handled by two different Google service agents. | ||||||||||
|
|
||||||||||
| The two identities are displayed on the **Add CMEK** page of the TiDB Cloud console: | ||||||||||
|
|
||||||||||
| - **Compute Engine Service Agent (Cluster Disks)**: `service-<PROJECT_NUMBER>@compute-system.iam.gserviceaccount.com` | ||||||||||
| - **Cloud Storage Service Agent (Backups)**: `service-<PROJECT_NUMBER>@gs-project-accounts.iam.gserviceaccount.com` | ||||||||||
|
|
||||||||||
| `<PROJECT_NUMBER>` is the number of the Dedicated project where your clusters run. Use the values displayed in the TiDB Cloud console rather than copying the preceding patterns, because the format of service agent emails is subject to change. | ||||||||||
|
|
||||||||||
| <SimpleTab groupId="method"> | ||||||||||
| <div label="Use Google Cloud console" value="console"> | ||||||||||
|
|
||||||||||
| To grant the role, take the following steps: | ||||||||||
|
|
||||||||||
| 1. In the [Google Cloud console](https://console.cloud.google.com/), navigate to **Security** > **Key Management**, and then open the key created in step 5. | ||||||||||
| 2. In the **Permissions** tab, click **Add principal**. | ||||||||||
| 3. For **New principals**, paste the **Compute Engine Service Agent** identity copied from the TiDB Cloud console. | ||||||||||
| 4. For **Role**, select **Cloud KMS CryptoKey Encrypter/Decrypter**. | ||||||||||
| 5. Click **Save**. | ||||||||||
| 6. Repeat steps 2 to 5 for the **Cloud Storage Service Agent** identity. | ||||||||||
|
|
||||||||||
| </div> | ||||||||||
| <div label="Use gcloud CLI" value="cli"> | ||||||||||
|
|
||||||||||
| Run the following commands. Replace `<PROJECT_ID>`, `<KEY_RING>`, `<FULL_KEY_NAME>`, `<REGION>`, and `<PROJECT_NUMBER>` with your own values. | ||||||||||
|
|
||||||||||
| ```shell | ||||||||||
| gcloud kms keys add-iam-policy-binding <FULL_KEY_NAME> \ | ||||||||||
| --keyring=<KEY_RING> \ | ||||||||||
| --location=<REGION> \ | ||||||||||
| --project=<PROJECT_ID> \ | ||||||||||
| --member=serviceAccount:service-<PROJECT_NUMBER>@compute-system.iam.gserviceaccount.com \ | ||||||||||
| --role=roles/cloudkms.cryptoKeyEncrypterDecrypter | ||||||||||
|
|
||||||||||
| gcloud kms keys add-iam-policy-binding <FULL_KEY_NAME> \ | ||||||||||
| --keyring=<KEY_RING> \ | ||||||||||
| --location=<REGION> \ | ||||||||||
| --project=<PROJECT_ID> \ | ||||||||||
| --member=serviceAccount:service-<PROJECT_NUMBER>@gs-project-accounts.iam.gserviceaccount.com \ | ||||||||||
| --role=roles/cloudkms.cryptoKeyEncrypterDecrypter | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| </div> | ||||||||||
| </SimpleTab> | ||||||||||
|
|
||||||||||
| 7. Back on the **Add CMEK** page in the TiDB Cloud console, enter the full resource name of the key in the **Cloud KMS Key Resource Name** field. The resource name has the following format: | ||||||||||
|
|
||||||||||
| ``` | ||||||||||
| projects/<PROJECT_ID>/locations/<REGION>/keyRings/<KEY_RING>/cryptoKeys/<FULL_KEY_NAME> | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| - `<PROJECT_ID>` is the ID of the Google Cloud project that contains the key ring. | ||||||||||
| - `<REGION>` is the region of the key ring. It must be the same as the region selected in step 3. | ||||||||||
| - `<KEY_RING>` is the name of the key ring. | ||||||||||
| - `<FULL_KEY_NAME>` is the full key name copied in step 4. | ||||||||||
|
|
||||||||||
| 8. Click **Verify and Add**. TiDB Cloud verifies the key and saves the configuration. | ||||||||||
|
|
||||||||||
| ### Step 3. Create a cluster | ||||||||||
|
|
||||||||||
| Under the project configured in [Step 2](#step-2-add-the-cmek-configuration), create a TiDB Cloud Dedicated cluster hosted on Google Cloud. For detailed steps, refer to [Create a TiDB Cloud Dedicated Cluster](/tidb-cloud/create-tidb-cluster.md). | ||||||||||
|
|
||||||||||
| When you select a cloud provider and region, the appropriate encryption key is automatically matched. If no key is available for your provider and region, the console displays a tip to help you create one. | ||||||||||
|
|
||||||||||
| > **Note:** | ||||||||||
| > | ||||||||||
| > When CMEK is enabled, TiDB Cloud encrypts both the persistent disks used by the cluster nodes and the Cloud Storage bucket used for the cluster backups with the CMEK key. | ||||||||||
|
|
||||||||||
| ## Rotate CMEK | ||||||||||
|
|
||||||||||
| You can configure [automatic key rotation](https://cloud.google.com/kms/docs/key-rotation) in Cloud KMS. With this rotation enabled, you do not need to update the CMEK configuration in TiDB Cloud. | ||||||||||
|
|
||||||||||
| ## Revoke and restore CMEK | ||||||||||
|
|
||||||||||
| If you need to temporarily revoke TiDB Cloud's access to the CMEK key, follow these steps: | ||||||||||
|
|
||||||||||
| > **Note:** | ||||||||||
| > | ||||||||||
| > Step 2 pauses the affected clusters. You cannot pause a cluster that has [changefeeds](/tidb-cloud/changefeed-overview.md) or [Point-in-Time Restore (PITR)](/tidb-cloud/backup-and-restore.md#turn-on-point-in-time-restore) enabled, so delete the changefeeds or turn off PITR first. For details, see [Limitations](/tidb-cloud/pause-or-resume-tidb-cluster.md#limitations). | ||||||||||
|
|
||||||||||
| 1. In the [Google Cloud console](https://console.cloud.google.com/), remove the `roles/cloudkms.cryptoKeyEncrypterDecrypter` role bindings that you granted in [Step 2](#step-2-add-the-cmek-configuration). | ||||||||||
|
|
||||||||||
| > **Note:** | ||||||||||
| > | ||||||||||
| > Removing the key-level role bindings revokes access to all versions of the key at once, provided that neither service agent also holds a decrypt-capable role granted at the key ring or project level. If such an inherited grant exists, remove it at that level as well. Alternatively, disable every enabled version of the key, not only the current one. Data and backups written before a rotation are still protected by the earlier versions, so disabling only the newest version leaves them decryptable. Record which versions you disable so that you can re-enable them when you restore access. | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check all effective decrypt grants. A service agent can have another decrypt-capable grant directly on the key or inherit one from a folder or organization. Removing the Step 2 bindings and checking only the key ring and project leaves that access intact. Instruct readers to check and remove all applicable grants, or disable every enabled key version. (docs.cloud.google.com) Revocation takes time to become effective. Disabling a key version and removing a role binding are both eventually consistent. A disabled key version can stay usable for up to 1 minute, and in exceptional cases for several hours. A removed IAM role binding can take about 2 minutes, and 7 minutes or longer in some cases. Pausing the clusters in Step 2 does not confirm that the change has taken effect. Wait for the change to take effect before you treat access as revoked. Suggested note
Committable suggestion
|
||||||||||
|
|
||||||||||
| 2. In the TiDB Cloud console, pause the clusters that use this key, that is, the clusters in the region of the key. Clusters in other regions use their own regional keys and are not affected. | ||||||||||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||||||||||
|
|
||||||||||
| > **Note:** | ||||||||||
| > | ||||||||||
| > After you revoke TiDB Cloud's access to the CMEK key, Compute Engine disks attached to running VMs remain accessible until the VMs shut down. After you pause the clusters that use this key, TiDB Cloud can no longer decrypt their data. As a result, operations that require access to the key, such as resuming a paused cluster, creating a backup, and restoring a backup, fail until you restore the access. | ||||||||||
|
|
||||||||||
| After revoking TiDB Cloud's access to the CMEK key, if you need to restore the access, follow these steps: | ||||||||||
|
|
||||||||||
| 1. In the [Google Cloud console](https://console.cloud.google.com/), re-enable the key versions that you disabled, and restore the role bindings for both service agents. | ||||||||||
| 2. In the TiDB Cloud console, resume the clusters that you paused. | ||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Restore the features disabled for the pause.
After restoration, the procedure resumes the clusters but does not restore PITR or the deleted changefeeds. PITR and replication therefore remain disabled. Ask readers to record the affected settings before revocation and restore them after the clusters resume. (raw.githubusercontent.com)