For AI agents: a documentation index is available at https://www.mongodb.com/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.

Create a Customer Master Key

In this guide, you will learn how to generate a Customer Master Key in your Key Management System of choice. Generate a Customer Master Key before creating your Queryable Encryption-enabled application.

Tip

Customer Master Keys

To learn more about the Customer Master Key, see Encryption Keys and Key Vaults

Complete the preceding tasks before continuing:

Select the tab for your key provider below.

1
  1. Navigate to the AWS KMS Console.

  2. Create your Customer Master Key

    Create a new symmetric key by following the official AWS documentation on Creating symmetric KMS keys. The key you create is your Customer Master Key. Choose a name and description that helps you identify it; these fields do not affect the functionality or configuration of your CMK.

    In the Usage Permissions step of the key generation process, apply the following default key policy that enables Identity and Access Management (IAM) policies to grant access to your Customer Master Key:

    { "Version": "2012-10-17", "Statement": [ { "Sid": "Enable IAM User Permissions", "Effect": "Allow", "Principal": { "AWS": "<ARN of your AWS account principal>" }, "Action": "kms:*", "Resource": "*" } ]}

    Important

    Record the Amazon Resource Name (ARN) and Region of your Customer Master Key. You will use these in later steps of this guide.

    Tip

    Key Policies

    To learn more about key policies, see Key Policies in AWS KMS in the official AWS documentation.

2
  1. Navigate to the AWS IAM Console.

  2. Create an IAM User

    Create a new programmatic IAM user in the AWS management console by following the official AWS documentation on Adding a User. You will use this IAM user as a service account for your Queryable Encryption-enabled application. Your application authenticates with AWS KMS using the IAM user to encrypt and decrypt your Data Encryption Keys (DEKs) with your Customer Master Key (CMK).

    Important

    Record your Credentials

    Ensure you record the following IAM credentials in the final step of creating your IAM user:

    • access key ID

    • secret access key

    You have one opportunity to record these credentials. If you do not record these credentials during this step, you must create another IAM user.

  3. Grant Permissions

    Grant your IAM user kms:Encrypt and kms:Decrypt permissions for your remote master key.

    Important

    The new client IAM user should not have administrative permissions for the master key. To keep your data secure, follow the principle of least privilege.

    The following inline policy allows an IAM user to encrypt and decrypt with the Customer Master Key with the least privileges possible:

    Note

    Remote Master Key ARN

    The following policy requires the ARN of the key you generate in the Create the Master Key step of this guide.

    { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": ["kms:Decrypt", "kms:Encrypt"], "Resource": "<the Amazon Resource Name (ARN) of your remote master key>" } ]}

    To apply the preceding policy to your IAM user, follow the Adding IAM identity permissions guide in the AWS documentation.

    Important

    Authenticate with IAM Roles in Production

    When deploying your Queryable Encryption-enabled application to a production environment, authenticate your application by using an IAM role instead of an IAM user.

    To learn more about IAM roles, see the following pages in the official AWS documentation:

After installing drivers and dependencies and creating a Customer Master Key, you can create your Queryable Encryption enabled application.