Skip to content

Commit cdfa970

Browse files
authored
fix(bootstrap): ECR repository produces Security Hub finding [ECR.3] because of missing lifecycle policy (#24735)
After enabling AWS Foundational Security Best Practices v1.0.0 in the security hub, I am always frustrated when I see failed checks. Similar to #24175 I would like to see a lifecycle rule that does not do much but at least per default resolves the finding. I know that there is an RFC for garbage collection in the works but this is a simple immediate fix. _This is heavily inspired by https://github.com/aws/aws-cdk/pull/24175_ Closes #24723. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 3c98d1e commit cdfa970

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

packages/aws-cdk/lib/api/bootstrap/bootstrap-template.yaml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,24 @@ Resources:
235235
Type: AWS::ECR::Repository
236236
Properties:
237237
ImageTagMutability: IMMUTABLE
238+
# Untagged images should never exist but Security Hub wants this rule to exist
239+
LifecyclePolicy:
240+
LifecyclePolicyText: |
241+
{
242+
"rules": [
243+
{
244+
"rulePriority": 1,
245+
"description": "Untagged images should not exist, but expire any older than one year",
246+
"selection": {
247+
"tagStatus": "untagged",
248+
"countType": "sinceImagePushed",
249+
"countUnit": "days",
250+
"countNumber": 365
251+
},
252+
"action": { "type": "expire" }
253+
}
254+
]
255+
}
238256
RepositoryName:
239257
Fn::If:
240258
- HasCustomContainerAssetsRepositoryName
@@ -615,7 +633,7 @@ Resources:
615633
Type: String
616634
Name:
617635
Fn::Sub: '/cdk-bootstrap/${Qualifier}/version'
618-
Value: '16'
636+
Value: '17'
619637
Outputs:
620638
BucketName:
621639
Description: The name of the S3 bucket owned by the CDK toolkit stack

0 commit comments

Comments
 (0)