-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
refactor(report): Replacing source_location
in github
report when scanning an image
#5999
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
458a30b
replacing `source_location` in github report when scanning an image
Maxim-Durand 054833e
Update pkg/report/github/github.go
Maxim-Durand 3c2d602
added test for image export to github using the full image_name and t…
Maxim-Durand b65ef00
Using `<image_registry>/<image_name>:<tag>@sha256:<image_hash>` forma…
Maxim-Durand 077f52f
added comments about `RepoDigests` and `RepoTag` parsing and concaten…
Maxim-Durand dffe603
adding "source_location" of each package into their metadata field
Maxim-Durand c43fd98
Apply suggestions from DmitriyLewen review
Maxim-Durand fc53d37
lint fix
Maxim-Durand File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,6 +164,73 @@ func TestWriter_Write(t *testing.T) { | |
}, | ||
}, | ||
}, | ||
{ | ||
name: "pypi from image", | ||
report: types.Report{ | ||
SchemaVersion: 2, | ||
ArtifactName: "fake_repo.azurecr.io/image_name", | ||
ArtifactType: "container_image", | ||
Metadata: types.Metadata{ | ||
RepoDigests: []string{"fake_repo.azurecr.io/image_name@sha256:a7c92cdcb3d010f6edeb37ddcdbacab14981aa31e7f1140e0097dc1b8e834c49"}, | ||
RepoTags: []string{"fake_repo.azurecr.io/image_name:latest"}, | ||
}, | ||
Results: types.Results{ | ||
{ | ||
Target: "Python", | ||
Class: "lang-pkgs", | ||
Type: "python-pkg", | ||
Packages: []ftypes.Package{ | ||
{ | ||
Name: "jwcrypto", | ||
Version: "0.7", | ||
Licenses: []string{ | ||
"LGPLv3+", | ||
}, | ||
Layer: ftypes.Layer{ | ||
Digest: "sha256:ddc612ba4e74ea5633a93e19e7c32f61f5f230073b21a070302a61ef5eec5c50", | ||
DiffID: "sha256:12935ef6ce21a266aef8df75d601cebf7e935edd01e9f19fab16ccb78fbb9a5e", | ||
}, | ||
FilePath: "opt/pyenv/versions/3.11.2/lib/python3.11/site-packages/jwcrypto-0.7.dist-info/METADATA", | ||
}, | ||
{ | ||
Name: "matplotlib", | ||
Version: "3.5.3", | ||
Licenses: []string{ | ||
"PSF", | ||
}, | ||
Layer: ftypes.Layer{ | ||
Digest: "sha256:ddc612ba4e74ea5633a93e19e7c32f61f5f230073b21a070302a61ef5eec5c50", | ||
DiffID: "sha256:12935ef6ce21a266aef8df75d601cebf7e935edd01e9f19fab16ccb78fbb9a5e", | ||
}, | ||
FilePath: "opt/pyenv/versions/3.11.2/lib/python3.11/site-packages/matplotlib-3.5.3.dist-info/METADATA", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
want: map[string]github.Manifest{ | ||
"Python": { | ||
Name: "python-pkg", | ||
File: &github.File{ | ||
SrcLocation: "fake_repo.azurecr.io/image_name:latest@sha256:a7c92cdcb3d010f6edeb37ddcdbacab14981aa31e7f1140e0097dc1b8e834c49", | ||
}, | ||
Resolved: map[string]github.Package{ | ||
"jwcrypto": { | ||
PackageUrl: "pkg:pypi/[email protected]", | ||
Relationship: "direct", | ||
Scope: "runtime", | ||
Metadata: github.Metadata{"source_location": "opt/pyenv/versions/3.11.2/lib/python3.11/site-packages/jwcrypto-0.7.dist-info/METADATA"}, | ||
}, | ||
"matplotlib": { | ||
PackageUrl: "pkg:pypi/[email protected]", | ||
Relationship: "direct", | ||
Scope: "runtime", | ||
Metadata: github.Metadata{"source_location": "opt/pyenv/versions/3.11.2/lib/python3.11/site-packages/matplotlib-3.5.3.dist-info/METADATA"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 aggregate some packages to 1 result -
trivy/pkg/fanal/applier/docker.go
Lines 263 to 291 in fb36c4e
But we can find path from Results.Packages.FilePath:
Maybe we just use FilePath for these packages?
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.
Although I agree with you it's an interesting change as it would make the manifest more precise.
Nonetheless, I think the full
FilePath
would be too much to render in Github Dependency and would bloat the UI.I can do a test with that change if you want and show the results here ?
Otherwise we could try to extract important values from the
FilePath
and adding them toresult.Target
, but that seems complex and prone to errors.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.
For other languages we already use filePath (filePath is stored in
target
):And we didn't get issues about UI.
Yes please. If you have time, check it out.
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.
So I have a few things to report:
As you pointed out trivy aggregates multiple packages in the same "App" (for instance
Python
orNode
) into one result.The issue is that in the sbom format, the
source_location
is set at themanifest
level not at the package level (resolved
key in sbom format). Meaning, if we keep the default trivy aggregation then we have to use only one of all the packagesFilePath
. How to define that value is either arbitrary, or we need some sort of heuristic ?In terms of UI it isn't as bloated as I expected, so I think you're right and it's ok to use.
The
source_location
used in the above screenshot is simply theFilePath
of the last package inresult.Packages
so it's not even correct.In the case trivy is scanning an image I think it's still pretty useless to replace the
manifest
'ssource_location
with thisFilePath
value and we should instead reference the image's name and tag.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 have already seen cases where it is necessary to remove aggregation, but this requires large changes and we are not sure about it.
I created a small function to get filePath for each package - DmitriyLewen@8431664
Can you take a look?
This makes sense for UI. But what worries me is case where user only knows that image contains vulnerable package, but doesn't have filePath to find and update that package. It would be great to add filePath somehow.
e.g. we can use
<image_name>:<tag> - <filePath>
format for manifest map key. Is it possible to seegsbom
file after uploading to GitHub?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.
Not that I can see in Github Dependency UI no, see screenshot below to see how it looks.
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.
So user can only get package metadata when taking snapshot, right?
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.
If they use trivy then there's no issue as the user will now be able to find the file path for each package by parsing the JSON report before sending it to GitHub.
But if they use trivy-action then the report is sent automatically and the user doesn't have access to the original report hence he wouldn't be able to parse it.
Maybe if the user then export it from GitHub, the metadata tag with each package file path will still be there, I'll test that.
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.
This is what I got from github export to SBOM for the same package as in #5999 (comment):
As you can see the
metadata
tag doesn't show up in the exported SBOM.Important
Conclusion: users of
trivy-action
would currently have no way of finding out thefilePath
of each package when using thegithub
format.As this issue only involves
trivy-action
and nottrivy
itself anymore, I think we should continue this discussion once this PR is merged to find a solution fortrivy-action
users at aquasecurity/trivy-action#286(I would recommend to add an option for upload as an artifact so that user can easily fetch the report).
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 created aquasecurity/trivy-action#307 to make sure users of
trivy-action
will know where to find the missing details from Github Dependency.@DmitriyLewen and @knqyf263 do you agree with this compromise ?
If so, can you review this PR code ?