logo

Database

Need

Enforce automatic key rotation for KMS service

Context

• Usage of CloudFormation for Infrastructure as Code (IaC)

• Usage of AWS KMS Key for encryption and decryption of data

Description

1. Non compliant code

Resources:
  MyKmsKey:
    Type: AWS::KMS::Key
    Properties:
      Description: "This is my KMS key"
      EnableKeyRotation: false
      KeyPolicy:
        Statement:...

The above CloudFormation code defines an AWS KMS key, but it does not enable automatic key rotation. Without key rotation, the same encryption key is used indefinitely. This increases the risk of compromise, as long-term static keys are more likely to be exposed or brute-forced. Enabling key rotation is a security best practice to limit exposure in case a key is compromised.

2. Steps

• Add or update the `EnableKeyRotation` property in the CloudFormation resource.

• Set the value of `EnableKeyRotation` to `true` to activate yearly key rotation.

• Deploy or update the CloudFormation stack.

3. Secure code example

Resources:
  MyKmsKey:
    Type: AWS::KMS::Key
    Properties:
      Description: "This is my KMS key"
      EnableKeyRotation: true
      KeyPolicy:
        Statement:...

This CloudFormation code enables automatic key rotation for the AWS KMS key using the `EnableKeyRotation` property. With rotation enabled, AWS rotates the key material every year. This reduces the impact of a key compromise and ensures that encryption keys are refreshed regularly to improve the security posture of your infrastructure.