-
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): Add image-src flag to specify which runtime(s) to use #4047
Conversation
216d947
to
93fc695
Compare
@DmitriyLewen I think we may want to replace your PR with this approach. Can you take a look? Also, I suggested as below. |
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.
@pmengelbert Thanks for your work!
Looks good. I added some comments. Can you take a look?
8ced0ca
to
38b9de1
Compare
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.
LGTM
I added some comments.
Take a look, please.
Also i think we need add some information about this in docs - https://github.com/aquasecurity/trivy/blob/main/docs/docs/target/container_image.md#supported
i mean default value, priority, etc...
Signed-off-by: Peter Engelbert <pmengelbert@gmail.com>
Signed-off-by: Peter Engelbert <pmengelbert@gmail.com>
Signed-off-by: Peter Engelbert <pmengelbert@gmail.com>
Signed-off-by: Peter Engelbert <pmengelbert@gmail.com>
Signed-off-by: Peter Engelbert <pmengelbert@gmail.com>
Signed-off-by: Peter Engelbert <pmengelbert@gmail.com>
Signed-off-by: Peter Engelbert <pmengelbert@gmail.com>
Signed-off-by: Peter Engelbert <pmengelbert@gmail.com>
Also, update docs to reflect the change. Signed-off-by: Peter Engelbert <pmengelbert@gmail.com>
Signed-off-by: Peter Engelbert <pmengelbert@gmail.com>
Signed-off-by: Peter Engelbert <pmengelbert@gmail.com>
f047a25
to
8a24085
Compare
Signed-off-by: Peter Engelbert <pmengelbert@gmail.com>
I added some docs in diff --git a/docs/docs/target/container_image.md b/docs/docs/target/container_image.md
index 7350a6a93..108c667a9 100644
--- a/docs/docs/target/container_image.md
+++ b/docs/docs/target/container_image.md
@@ -224,6 +224,23 @@ GitHub Personal Access Token
You can see environment variables with `docker inspect`.
## Supported
+
+Trivy will look for the specified image in a series of locations. By default, it
+will first look in the local Docker Engine, then Containerd, Podman, and
+finally container registry.
+
+This behavior can be modified with the `--runtimes` flag. For example, the
+command
+
+```bash
+trivy image --runtimes podman,containerd alpine:3.7.3
+```
+
+Will first search in Podman. If the image is found there, it will be scanned
+and the results returned. If the image is not found in Podman, then Trivy will
+search in Containerd. If the image is not found there either, the scan will
+fail and no more runtimes will be searched.
+
### Docker Engine
Trivy tries to looks for the specified image in your local Docker Engine.
It will be skipped if Docker Engine is not running locally. |
Signed-off-by: Peter Engelbert <pmengelbert@gmail.com>
This reverts commit b5c82bb.
Signed-off-by: Peter Engelbert <pmengelbert@gmail.com>
Good work! Can you resolve conflicts? |
Signed-off-by: Peter Engelbert <pmengelbert@gmail.com>
Signed-off-by: Peter Engelbert <pmengelbert@gmail.com>
Signed-off-by: Peter Engelbert <pmengelbert@gmail.com>
pkg/types/target.go
Outdated
type Runtime string | ||
|
||
// Runtimes is a slice of runtimes | ||
type Runtimes []Runtime |
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.
It should be defined under ImageOptions.
trivy/pkg/fanal/types/image.go
Lines 17 to 22 in 9bc3269
type ImageOptions struct { | |
RegistryOptions RegistryOptions | |
DockerOptions DockerOptions | |
PodmanOptions PodmanOptions | |
ContainerdOptions ContainerdOptions | |
} |
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.
done
pkg/types/target.go
Outdated
type Runtime string | ||
|
||
// Runtimes is a slice of runtimes | ||
type Runtimes []Runtime |
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.
It should be defined under ImageOptions.
trivy/pkg/fanal/types/image.go
Lines 17 to 22 in 9bc3269
type ImageOptions struct { | |
RegistryOptions RegistryOptions | |
DockerOptions DockerOptions | |
PodmanOptions PodmanOptions | |
ContainerdOptions ContainerdOptions | |
} |
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.
done
pkg/fanal/image/image.go
Outdated
opts.podman = false | ||
} | ||
} | ||
func WithRuntimes(runtimes ftypes.Runtimes) ([]RuntimeFunc, error) { |
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 think it can be done in NewContainerImage. Is there any benefit in exporting this function?
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 moved this to NewContainerImage
, and made the function private. The function was also renamed
Signed-off-by: Peter Engelbert <pmengelbert@gmail.com>
Signed-off-by: Peter Engelbert <pmengelbert@gmail.com>
Signed-off-by: Peter Engelbert <pmengelbert@gmail.com>
Signed-off-by: Peter Engelbert <pmengelbert@gmail.com>
Signed-off-by: Peter Engelbert <pmengelbert@gmail.com>
Signed-off-by: Peter Engelbert <pmengelbert@gmail.com>
Renamed to |
@knqyf263 Is there anything else that this PR needs to be accepted? |
Signed-off-by: Peter Engelbert <pmengelbert@gmail.com>
Signed-off-by: Peter Engelbert <pmengelbert@gmail.com>
@pmengelbert I'm back from vacation. We plan to take another look at this PR next week. Thanks for your patience. |
Signed-off-by: Peter Engelbert <pmengelbert@gmail.com>
Signed-off-by: Peter Engelbert <pmengelbert@gmail.com>
Signed-off-by: Peter Engelbert <pmengelbert@gmail.com>
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've added some tweaks, such as comments, formatting, etc., but it looks great to me! Thanks for your contribution.
Description
Enable a new trivy image
--image-src
flag. For examplebefore:
trivy image alpine:3.7.3 # tries docker, containerd, podman, remote in that order (hardcoded)
after:
Related issues
trivy image
. #4044Related PRs
Remove this section if you don't have related PRs.
Checklist
=======
Description
Related issues
@knqyf263 This is what I got done today on the socket selection. Feel free to use this as a starting point for your future work to include this feature in 0.41.0
Opening as a draft PR since I have not written tests or docs for this yet.