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
- 1Set ImageTagMutability to IMMUTABLE
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' } }],
}),
},
});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::RepositoryIntentional? 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 scanCDK Insights runs this and 118+ other rules locally against your synthesised CDK app โ free, no account, your code never leaves your machine.