Skip to main content
MEDIUMECRSecurity

ECR Mutable Image Tags

ecr-mutable-tags

What this rule checks

Detects ECR repositories that allow image tags to be overwritten.

How to fix it

  1. 1Set ImageTagMutability to IMMUTABLE
FlaggedImageTagMutability is unset, so it defaults to MUTABLE: an existing tag can be overwritten by a new push. That breaks deployment consistency and lets a supply-chain change slip in under a trusted tag.
import { App, Stack } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as ecr from 'aws-cdk-lib/aws-ecr';

// FLAGGED: ImageTagMutability defaults to MUTABLE.
new ecr.CfnRepository(this, 'Repo', {
  repositoryName: 'app',
  lifecyclePolicy: {
    lifecyclePolicyText: JSON.stringify({
      rules: [{ rulePriority: 1, selection: { tagStatus: 'untagged', countType: 'sinceImagePushed', countUnit: 'days', countNumber: 14 }, action: { type: 'expire' } }],
    }),
  },
});
FixedSetting ImageTagMutability to IMMUTABLE prevents any tag from being overwritten once pushed, guaranteeing that a given tag always resolves to the same image.
import { App, Stack } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as ecr from 'aws-cdk-lib/aws-ecr';

// FIXED: tags are immutable and cannot be overwritten.
new ecr.CfnRepository(this, 'Repo', {
  repositoryName: 'app',
  imageTagMutability: 'IMMUTABLE',
  lifecyclePolicy: {
    lifecyclePolicyText: JSON.stringify({
      rules: [{ rulePriority: 1, selection: { tagStatus: 'untagged', countType: 'sinceImagePushed', countUnit: 'days', countNumber: 14 }, action: { type: 'expire' } }],
    }),
  },
});

CDK Insights pinpoints the exact file and line in your CDK source for every finding, so you can jump straight to the fix.

Affected resource types

AWS::ECR::Repository

Compliance frameworks

SOC2PCI-DSSNIST

AWS documentation

Read the AWS guidance

Intentional? Suppress this finding

Sometimes a flag is deliberate โ€” a genuinely public endpoint, say. You can dismiss ecr-mutable-tags and the reason is kept in the report, not silently hidden.

In .cdk-insights.json:

{
  "ignoreRules": [
    { "id": "ecr-mutable-tags", "reason": "Why this is intentional" }
  ]
}

Or inline in your CDK code:

Validations.of(scope).acknowledge({
  id: 'cdk-insights::ecr-mutable-tags',
  reason: 'Why this is intentional',
});

Use the rule ID ecr-mutable-tags shown above โ€” not the CDK-* ID from SARIF / GitHub code scanning. To dismiss every finding on one construct instead, use ignorePaths. Suppression docs โ†’

Catch this in your stack

$ npx cdk-insights scan

CDK Insights runs this and 118+ other rules locally against your synthesised CDK app โ€” free, no account, your code never leaves your machine.

More ECR rules