By using customer-managed encryption keys (CMEK), you have control over your keys. This gives you control over their protection level, location, rotation schedule, usage and access permissions, and cryptographic boundaries. Instead of Google owning and managing the symmetric key encryption keys (KEKs) that protect your data, you control and manage these keys in Cloud Key Management Service (KMS).
To set up CMEK, do one of the following:
- Create a key, and then use the key when you create an instance by using the gcloud CLI. For more information, see Workflow to create an instance that uses CMEK.
- To create keys on demand when you create an instance, use Cloud KMS Autokey. For more information, see Use Cloud KMS Autokey.
Before you begin
Make sure that you have the Memorystore Admin role on your user account.
Workflow to create an instance that uses CMEK
Create a key ring and key in the location where you want the Memorystore for Valkey instance to be.
Copy or write down the key name (
KEY_NAME), the location of the key, and the name of the key ring (KEY_RING). You need this information when granting the service account access to the key.Grant the Memorystore for Valkey service agent access to the key.
Go to a project and create a Memorystore for Valkey instance with CMEK enabled in the same region as the key ring and key.
Your Memorystore for Valkey instance is now enabled with CMEK.
Create a key ring and key
Create a key ring and key. Both must be in the same region as your Memorystore for Valkey instance. The key can be from a different project, as long as the key is in the same region. Also, the key must use the symmetric encryption algorithm.
After you create the key ring and key, copy or write down the KEY_NAME, the
key location, and the KEY_RING. You need this information when you grant the
service account access to the key.
Grant the Memorystore for Valkey service agent access to the key
Before you can create a Memorystore for Valkey instance that uses CMEK, you must grant a specific Memorystore for Valkey service account access to the key.
You can grant the service account access to the key by using the gcloud CLI. To grant access to the service account, use the following format:
service-PROJECT_NUMBER@gcp-sa-memorystore.iam.gserviceaccount.com
gcloud
To grant the service account access to the key, use the gcloud kms keys add-iam-policy-binding
command.
gcloud kms keys add-iam-policy-binding \ projects/PROJECT_ID/locations/REGION_ID/keyRings/KEY_RING/cryptoKeys/KEY_NAME \ --member=serviceAccount:service-PROJECT_NUMBER@gcp-sa-memorystore.iam.gserviceaccount.com \ --role=roles/cloudkms.cryptoKeyEncrypterDecrypter
Make the following replacements:
- PROJECT_ID: the ID or number of the project that contains the key ring
- REGION_ID: the region where the key ring is located
- KEY_RING: the name of the key ring that contains the key
- KEY_NAME: the name of the key that you're granting access to the service account
- PROJECT_NUMBER: the ID or number of the project that contains the service account
Use Cloud KMS Autokey
To request a key when you create an instance, instead of creating a key ring and key yourself, use Cloud KMS Autokey. Autokey creates the key in the same region as the instance. Autokey also creates the Memorystore for Valkey service agent if it doesn't exist and grants the service agent the required role on the key. As a result, you can skip the steps in Create a key ring and key and Grant the Memorystore for Valkey service account access to the key.
Before you request a key, enable Cloud KMS Autokey for the folder or project where you create the instance.
To request a key from Autokey, use one of the following methods:
Console
- When you create an instance, in the Encryption section, select Cloud KMS key.
- In the Key management type list, select Cloud KMS with Autokey, and then click Request a key.
gcloud
- Create a key handle in the
same region as the instance. For the resource type of the key handle,
specify
memorystore.googleapis.com/Instance. For instructions, see Create protected resources using Cloud KMS Autokey. - When you create the instance, specify the key from the key handle. Use
the
--kms-keyflag in the gcloud CLI, thekms_keyargument in Terraform, or thekmsKeyfield in the REST API.
Create a Memorystore for Valkey instance that uses CMEK
You can create an instance that uses CMEK by using the gcloud CLI.
gcloud
To create an instance that uses CMEK, use the gcloud memorystore instances create command.
gcloud memorystore instances create INSTANCE_ID \
--project=PROJECT_NAME \
--location=REGION_ID \
--endpoints='[{"connections": [{"pscAutoConnection": {"network": "projects/PROJECT_NAME/global/networks/NETWORK_ID", "projectId": "PROJECT_NAME"}}]}]' \
--kms-key=projects/PROJECT_NAME/locations/REGION_ID/keyRings/KEY_RING/cryptoKeys/KEY_NAME \
--shard-count=SHARD_NUMBER \
--persistence-config-mode=PERSISTENCE_CONFIG_MODE
Make the following replacements:
- INSTANCE_ID: the ID of the instance that you're creating.
- PROJECT_NAME: the name of the project where you want to create the instance.
- REGION_ID: the ID of the region where you want the instance to be located.
- NETWORK_ID: the ID of the network that you want to use to create the instance.
- KEY_RING: the name of the key ring that contains the key.
- KEY_NAME: the name of the key.
- SHARD_NUMBER: the number of shards that you want to have for the instance.
- PERSISTENCE_CONFIG_MODE: the persistence mode for the instance.
You can set this mode to one of the following values:
aof: you enable Append-Only File (AOF)-based persistence for the instance.disabled: you deactivate persistence for the instance.rdb: you enable Redis Database (RDB)-based persistence for the instance.
View key information for a CMEK-enabled instance
You can view information about your CMEK-enabled instance by using the gcloud CLI. This information includes whether CMEK is enabled for your instance and the active key.
gcloud
To verify if CMEK is enabled and to see the key reference, use the
gcloud memorystore instances describe
command to view the encryptionInfo and kmsKey fields.
gcloud memorystore instances describe INSTANCE_ID \ --project=PROJECT_NAME \ --location=REGION_ID
Make the following replacements:
- INSTANCE_ID: the ID of the instance about which you want to view information
- PROJECT_NAME: the name of the project that contains the instance
- REGION_ID: the ID of the region where the instance is located
Manage key versions
For information about what happens when you disable, destroy, rotate, enable, and restore a key version, see Behavior of a CMEK key version.
For instructions on how to disable and re-enable key versions, see Enable and disable key versions.
For instructions on how to destroy and restore key versions, see Destroy and restore key versions.
What's next
- Learn more about backups.
- Learn more about persistence.