-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(@aws-cdk/aws-ecr-assets): DockerImageAsset - can't tell which images are outdated, and where they came from #18629
Comments
Related to aws/aws-cdk-rfcs#64 I am also wondering if there is a way to add some kind of description to the ECR repositories. |
@madeline-k assigning to you as part of your ECR ownership. |
Reading about this, there doesn't seem to be a good solution. I thought I might be able to use Lifecycle Policies to clear down unused images, but it seems that they just delete images, even if they're in use within ECS, which I definitely don't want to happen. In that scenario, a scaling event (e.g. adding another container) would result in loss of service. Is it really the case that ECS isn't checked? 6 years ago https://github.com/trek10inc/ecr-cleaner had this in place, but discontinued it due to the ECR lifecycle feature - I suppose they thought it would be developed more. Seems like I'm going to have to write a Lambda function to periodically check ECS and tag the images that are in use (and de-tag ones that are no longer in use), then use a lifecycle policy to delete images that are no longer in use. What a waste of time. |
Since I'm only using ECS, I wrote a Go program to:
I was able to clean up 1200+ unused images from my testing environment, and then focus on solving the security vulnerabilities in images that are actually in use. |
The RFC @eladb linked (aws/aws-cdk-rfcs#64) would address this issue. Please comment and add +1s there to help us prioritize it! In the meantime, we could definitely add some descriptions to the ECR repos to make manual deletion easier. @a-h , thanks for sharing your tool for cleanup! There is also a community-created construct that can do asset clean up as well: https://github.com/jogold/cloudstructs/blob/master/src/toolkit-cleaner/README.md. Please check that out! (Shout out to @jogold 🎉 🚀) |
I'm estimating this as large effort thinking about the overall asset cleanup problem. But there may be smaller effort things we can do just for ECR. |
Thanks @madeline-k - I've put some detailed notes on how I think the overall problem could be resolved into aws/aws-cdk-rfcs#64 (comment) |
This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled. |
This is still a problem. CDK's DockerImageAsset construct still creates untraceable assets with no mechanism for cleaning them up, or identifying the source of the asset. |
Maybe adding an option to the policy settings to prevent purging image that have been pulled in the last |
@rawpixel-vincent - pull metrics doesn't really work. You might have a monthly scheduled task, and if you delete images which haven't been pulled in the last 14 days, your scheduled task will fail when it does try and pull the image. Ultimately, I don't think |
yes, I definitely agree with that. And what I suggested wouldn't fix this issue. On the issue subject, I had a lambda that stopped working in the past because the image has been deleted by an ECR lifecycle.
I think the new construct should also enforce to use an explicit ECR repository, instead of publishing everything to the same cdk repo |
I'll +1 the suggestion that DockerImageAsset be retired. It makes absolutely zero sense that multiple Stacks can deploy to the same ECR repo with zero indication of where or what the images contained within are. It's not even clear to me how you ensure that you get the right image for each task/service right now aside from hoping that they have independent tags on them. I'd much rather have DockerImageAsset create a new (named) ECR repo, and then upload images to that specific repo. Then we could easily manage images through lifecycle policies on the named ECR repos. |
This is a massive problem for those using AWS Inspector. Firstly, when vulnerabilities are reported, I have no simple way to attribute those vulnerabilities to the component that generated the image and needs updating. Secondly, because there's no cleanup, I'm going to be getting security reports for outdated images that haven't actually been deployed for potentially years. |
Description
I got the results back from a 3rd part security test of our AWS account. The results included this finding:
And it listed the affected assets. They were all CDK assets.
So I went to ECR to take a look.
But I can't see a way to differentiate between the 8 DockerImageAssets for different projects that all deploy to the same AWS account using CDK, and I assume it will just keep all the old stuff lying around and growing.
So clearly this isn't the way to do things:
Perhaps DockerImageAsset needs to be more aggressive about cleaning up after itself, and also to provide information in ECR so that it's possible to find out which CDK project it's related to?
Use Case
Need to find the source of the security issues in the Docker containers without looking into each CDK project build history to find the hash in the CI logs.
Proposed Solution
Also tag the ECR instances with the CloudFormation ID.
Other information
No response
Acknowledge
The text was updated successfully, but these errors were encountered: