Description

Ensure that no Amazon Elastic Container Registry (ECR) private repository is set to fully mutable image tags (MUTABLE). Repositories set to IMMUTABLE, IMMUTABLE_WITH_EXCLUSION or MUTABLE_WITH_EXCLUSION pass. With immutable tags, once an image is pushed with a tag, that tag cannot be moved to a different image, so each tag always refers to the same image.

Rationale

When tags are mutable, anyone with push access can replace the image behind a trusted tag, such as a release version, without changing the deployment configuration. This enables supply-chain attacks, backdoored deployments and unintended rollouts of untested code, and makes it hard to know which image is actually running. Enabling tag immutability, together with unique versioned tags for each build and least-privilege push permissions, keeps each tag tied to a single image.

Impact

  • Guarantees that a tag always points to the same image, improving release integrity and traceability

  • Pushes that reuse an existing tag (for example, latest) are rejected, so build pipelines must use a unique tag for each build

  • Already pushed images are not changed

Default Value

New ECR repositories are created with mutable image tags unless immutability is selected at creation.

Pre-Requisites

  • IAM permissions: ecr:DescribeRepositories and ecr:PutImageTagMutability

  • Confirmation that the build pipelines pushing to the repository use a unique tag for each image

Test Plan

Console:

  1. Sign in to the AWS Management Console at https://console.aws.amazon.com.

  2. Open the Amazon ECR console and select Repositories under Private registry.

  3. Check the tag immutability (or tag mutability) setting shown for each repository.

  4. Repeat for each region in use.

  5. If any repository shows tags as mutable, follow the implementation steps.

CLI:

List all repositories with their tag mutability setting:

aws ecr describe-repositories --region <REGION> --query "repositories[].[repositoryName,imageTagMutability]" --output table

A repository fails only if imageTagMutability is MUTABLE. The values IMMUTABLE, IMMUTABLE_WITH_EXCLUSION and MUTABLE_WITH_EXCLUSION pass.

Implementation Steps

Console:

  1. Sign in to the AWS Management Console at https://console.aws.amazon.com.

  2. Open the Amazon ECR console and select Repositories under Private registry.

  3. Select the repository, then choose Actions and Edit.

  4. Set the image tag mutability setting to Immutable.

  5. Choose Save.

  6. Repeat for each affected repository in each region in use.

CLI:

Enable tag immutability for a repository:

aws ecr put-image-tag-mutability --repository-name <REPOSITORY_NAME> --image-tag-mutability IMMUTABLE --region <REGION>

Backout Plan

  1. Sign in to the AWS Management Console at https://console.aws.amazon.com.

  2. Open the Amazon ECR console and select Repositories under Private registry.

  3. Select the repository, then choose Actions and Edit.

  4. Set the image tag mutability setting to Mutable.

  5. Choose Save.

CLI:

aws ecr put-image-tag-mutability --repository-name <REPOSITORY_NAME> --image-tag-mutability MUTABLE --region <REGION>

Note: rolling back allows existing tags to be overwritten with different images again.

Reference

  • https://docs.aws.amazon.com/AmazonECR/latest/userguide/image-tag-mutability.html

  • https://docs.aws.amazon.com/securityhub/latest/userguide/ecr-controls.html

  • https://docs.aws.amazon.com/cli/latest/reference/ecr/put-image-tag-mutability.html