-
Notifications
You must be signed in to change notification settings - Fork 2.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
feat(image): prevent scanning oversized container images #8178
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: nikpivkin <[email protected]>
f188f2d
to
84689dd
Compare
Signed-off-by: nikpivkin <[email protected]>
72f3146
to
eddcbf8
Compare
Signed-off-by: nikpivkin <[email protected]>
Signed-off-by: nikpivkin <[email protected]>
Signed-off-by: nikpivkin <[email protected]>
@knqyf263 I was thinking that we could download the compressed layer and then decompress it ourselves. I saw that downloader.Download is used for decompression. Does it support all the compression types that |
This is what was in my mind.
|
@knqyf263 Then we can't display the progress bar correctly, because we don't know the size of the uncompressed layer. |
Can't we use the progress in ggcr? |
If it doesn't work, we can use |
@knqyf263 I kept the old behavior, if no flag is passed, to avoid unnecessary disk operations. But then the progress bar will be displayed only when the flag is passed. What do you think? |
@nikpivkin I got an idea. |
This might be better.
|
Even better
|
@knqyf263 Ok, I'll think about how to use this with the progress bar pool otherwise there is flickering in the terminal when loading in parallel |
@nikpivkin Actually, the progress bar should be discussed in #8186. I'll re-post it there. |
Signed-off-by: nikpivkin <[email protected]>
Signed-off-by: nikpivkin <[email protected]>
Signed-off-by: nikpivkin <[email protected]>
BTW, Trivy also supports VM images. I'm unsure, but users may want to introduce the same functionality in the future. Do you think we want to rename |
I think that I think Also i suggest to add this flag for VM scan in another PR. |
I performed a quick test on Azure, which has a stable network. The current approach (without |
Signed-off-by: knqyf263 <[email protected]>
pkg/fanal/artifact/image/image.go
Outdated
if err := os.RemoveAll(a.layerCacheDir); err != nil { | ||
log.Error("Failed to remove layer cache", log.Err(err)) | ||
} | ||
return artifact.Reference{}, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can delete the cache directory if checkImageSize
returns an error, but how about other errors? If I understand correctly, Artifact.Clean()
will not be called.
So, should we call the defer function before handling the error?
Lines 160 to 165 in ec124bd
defer func() { | |
if err := s.artifact.Clean(artifactInfo); err != nil { | |
log.Warn("Failed to clean the artifact", | |
log.String("artifact", artifactInfo.Name), log.Err(err)) | |
} | |
}() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clean
takes artifactInfo, and if we call it before the error is checked, the artifactInfo will not be valid. Maybe we should clear the cache inside Inspect
if any error occurred?
defer func() {
if err != nil {
if rerr := os.RemoveAll(a.layerCacheDir); rerr != nil {
log.Error("Failed to remove layer cache", log.Err(rerr))
}
}
}()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought using Clean()
is more straightforward, but you're actually right. We don't need this cache after Inspect
is complete. It makes more sense to delete it in the method.
Signed-off-by: nikpivkin <[email protected]>
Description
This PR adds the
--max-image-size
flag. If the flag is specified and the uncompressed image size exceeds the maximum size, Trivy exits with an error. If the flag is not specified, the behaviour does not change.For more implementation details, see #8176
Related issues
Checklist