AWS Secrets Manager: Tutorial & best practices
AWS Secrets Manager vs KMS: Differences & synergies
AWS Secrets Manager vs. Parameter Store: Features, cost & more
AWS CLI Secrets Manager: In-depth tutorial with examples
AWS Secrets Manager with Terraform: Tutorial & examples
AWS KMS key rotation: Tutorial & best practices
AWS Secrets Manager for Kubernetes: Tutorial & best practices
AWS Secrets Manager alternatives: A comprehensive analysis
AWS Lambda Secrets Manager best practices
AWS Vault: Tutorial, best practices & limitations
AWS CDK Secrets Manager tutorial & best practices
SSM Parameter Store: Tutorial & best practices
As DevOps engineers, we're no strangers to the paramount importance of cloud security. And, as the 10 immutable laws of security tell us: “encrypted data is only as secure as the decryption key”. In other words, effective key management is a crucial aspect of overall security posture. For the Amazon Web Services (AWS) platform, AWS KMS is a popular native key management solution, and AWS Key Management Service (KMS) key rotation is a key component in keeping keys on the platform secure.
This article delves into AWS KMS key rotation's fundamentals, its principles and outlines the best practices to ensure your data remains secure. By the end, you'll clearly understand how to implement key rotation effectively within your AWS environment.
The table below summarizes the AWS KMS key rotation concepts this article will explore in more detail.
Key rotation regularly replaces an encryption key with a new one. This practice enhances security by reducing the risk associated with long-lived keys. AWS KMS facilitates this process by automating your key rotation.
Key rotation primarily serves two critical purposes:
There are multiple reasons teams use AWS KMS key rotation. Let’s take a look at ten common use cases.
As of this writing, each AWS KMS key you create in AWS KMS costs $1/month (prorated hourly). The $1 per month charge is the same for symmetric, asymmetric, HMAC, and multi-region keys (each primary and each replica multi-region key). Suppose you enable automatic key rotation; each newly generated backing key costs an additional $1 per month (prorated hourly). This fee covers the cost to AWS KMS for retaining all versions of the key material. For more information, you can view the latest AWS KMS prices here.
AWS KMS is a native solution that offers teams several advantages and can help simplify the overall key management lifecycle. Here are five AWS KMS advantages to consider:
While AWS KMS is a powerful tool for managing encryption keys and securing data, it does have some limitations and constraints that users should be aware of:
Getting key rotation right requires a mix of strategy and tactics. In this section, we’ll explore five practical key rotation best practices, including specific AWS KMS key rotation examples, that can help organizations improve their overall data security.
AWS managed KMS keys automatically rotate every 365 days. This setting can not be disabled. You can use the enable-key-rotation command to enable key rotation for an AWS Customer Managed KMS key using the AWS Command Line Interface (CLI). Here's the syntax for enabling key rotation:
Replace <your-key-id> with the Amazon Resource Name (ARN) of the KMS key for which you want to enable key rotation.
You can also use the AWS console to accomplish this task. This link provides details for console use.
For example, if your key ID is arn:aws:kms:us-west-2:123456789012:key/abcd1234-a123-456a-a12b-a123b4cd56ef, the command would be:
After running this command, rotation will be enabled for the specified KMS key. Remember that you need the necessary permissions to perform this operation. Ensure your AWS CLI user has the required IAM permissions to enable key rotation on the specified KMS key.
Key rotation is specified in key policies as part of key rotation configuration. Here's an example of defining a key rotation policy for a KMS key using the AWS Command Line Interface (CLI): Replace <your-key-id> with the ID of your KMS key and <your-key-arn> with the Amazon Resource Name (ARN) of your KMS key.
In this example, the "Action": "kms: EnableKeyRotation" statement enables key rotation for the specified KMS key for the service principal kms.amazonaws.com. You can customize the policy JSON to fit your specific use case and security requirements.
Make sure you have the necessary permissions to modify the key policy. Adjust the policy document to include other statements or conditions for your specific scenario. Also, be cautious when changing key policies, as they directly affect the security and access control of your KMS keys.
You can use the get-key-rotation-status command to check the key rotation status of an AWS KMS key using the AWS Command Line Interface (CLI). Here's the syntax for checking the key rotation status:
Replace <your-key-id> with the Amazon Resource Name (ARN) or key ID of the KMS key for which you want to check the rotation status.
For example, if your key ID is arn:aws:kms:us-west-2:123456789012:key/abcd1234-a123-456a-a12b-a123b4cd56ef, the command would be:
This command will return the key rotation status for the specified KMS key, indicating whether the key rotation is enabled (Enabled) or disabled (Disabled).
Key rotation defaults to annually. These instructions can guide you if you need to rotate keys more frequently.
To automate key rotation with AWS KMS using the AWS Command Line Interface (CLI), you can use AWS CloudWatch Events and AWS Lambda. CloudWatch Events can be set up to detect the scheduled key rotation event, and a Lambda function can be triggered to handle the key rotation process. Here's an example of how you can set this up:
First, create a CloudWatch Events rule that triggers based on a schedule. For example, you can create a rule that triggers every day at a specific time.
This command creates a CloudWatch Events rule named "RotateKMSKeys" that triggers every day at midnight (UTC).
Next, create a Lambda function that handles the key rotation logic. You must create a ZIP archive containing your function code and any dependencies. Here is a sample lambda function implemented in Python:
Assuming you have a file named lambda_function.zip containing your Lambda code (lambda_function.py), you can create the Lambda function using the following command:
Replace <your-lambda-role-arn> with the ARN of the IAM role that your Lambda function will assume.
Give your Lambda function permission to invoke KMS key rotation. You can attach a policy to the Lambda function's execution role.
Example policy (lambda-kms-policy.json):
Apply the policy to the Lambda function's execution role:
Replace <your-lambda-role-name> with the name of your Lambda execution role and <your-kms-key-arn> with the ARN of the KMS key you want to rotate.
Associate the CloudWatch Events rule with your Lambda function as a target.
Replace <your-lambda-function-arn> with the ARN of your Lambda function.
Your CloudWatch Events rule will trigger the Lambda function at the specified schedule, enabling key rotation for your KMS key. Ensure your Lambda function logic includes the code to allow key rotation for the KMS key.
Please note that you need appropriate IAM permissions to perform these actions. Be careful when configuring automated key rotation, as it directly affects the security and access controls of your data.
KMS is one component of a robust data security program. Securing our data environments requires more robust tooling as they become more complex. Integrating KMS with tools like Doppler can create robust and resilient security controls to manage increasingly complex environments.
Doppler is a secrets management solution that integrates into your AWS environment to enhance the security and management of secrets, including API keys, passwords, and other sensitive information.
Here's how you can incorporate Doppler into your holistic approach to KMS and secrets management in AWS:
By integrating Doppler into your AWS environment following these guidelines, you can create a robust and secure secrets management system. This approach ensures that sensitive information is protected, access is controlled, and auditability is maintained, thereby enhancing the overall security posture of your AWS infrastructure.
Key management is an essential aspect of cybersecurity, and AWS KMS key rotation is an important security practice for the AWS cloud. Organizations can establish a robust and secure data security program by following key rotation best practices and effectively integrating the right tools. This approach ensures that sensitive information is protected, access is controlled, and auditability is maintained, thereby enhancing the overall security posture of AWS infrastructures.
Trusted by the world’s best DevOps and security teams. Doppler is the secrets manager developers love.