Amazon ECR supports immutable tags, preventing image tags from being overwritten. In the past, ECR tags could have been overwritten, this could be overcome by requiring users to uniquely identify an image using a naming convention.
Tag Immutability enables users can rely on the descriptive tags of an image as a mechanism to track and uniquely identify images. By setting an image tag as immutable, developers can use the tag to correlate the deployed image version with the build that produced the image.
Fix - Runtime
AWS Console
To change the policy using the AWS Console, follow these steps:
To create a repository with immutable tags configured:
aws ecr create-repository
–repository-name name
–image-tag-mutability IMMUTABLE
–region us-east-2
Fix - Buildtime
Terraform
Resource: aws_ecr_repository
Arguments: image_tag_mutability – (Optional) The tag mutability setting for the repository. Must be one of: MUTABLE or IMMUTABLE. Defaults to MUTABLE.
resource “aws_ecr_repository” “example” {
…
name = “bar”
+ image_tag_mutability = “IMMUTABLE”
}
CloudFormation
Resource: AWS::ECR::Repository
Arguments: Properties.ImageTagMutability – (Optional) The tag mutability setting for the repository. Must be one of: MUTABLE or IMMUTABLE. Defaults to MUTABLE.