Description
ECR encrypts images at rest with AES256 by default. Selecting KMS without a key uses an AWS managed key.
Potential impact
Use a customer managed KMS key when your organization needs direct control over the key policy and lifecycle.
Remediation
On a new repository, set encryption_type = "KMS" and supply the ARN of a customer managed key in the same Region. ECR fixes the encryption configuration at creation.
Examples
Both excerpts use the same Terraform resource and repository name, bar. Keep the original and add a separate resource with a different repository name. Copy the images and test a pull as the deployment role before switching deployment references.
Before
hcl
resource "aws_ecr_repository" "example" {
name = "bar"
image_tag_mutability = "IMMUTABLE"
encryption_configuration {
encryption_type = "AES256"
}
}
After
hcl
resource "aws_ecr_repository" "example" {
name = "bar"
image_tag_mutability = "IMMUTABLE"
encryption_configuration {
encryption_type = "KMS"
kms_key = "arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab"
}
}