-
Notifications
You must be signed in to change notification settings - Fork 529
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
931: binary cataloger exclusion defaults #1948
Changes from 17 commits
e7513e3
27e19cf
1a5bfce
228b5f5
a8bd32e
b67898a
1a0df53
d45458e
439f48e
aca6e56
f227e5a
a87fd40
7fb0f52
a31c03e
14263d3
2ede303
58f6d69
dfd2446
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -8,23 +8,14 @@ import ( | |||||||||||||||||||
) | ||||||||||||||||||||
|
||||||||||||||||||||
// TODO: these field naming vs helper function naming schemes are inconsistent. | ||||||||||||||||||||
|
||||||||||||||||||||
type Config struct { | ||||||||||||||||||||
Search SearchConfig | ||||||||||||||||||||
Golang golang.GoCatalogerOpts | ||||||||||||||||||||
LinuxKernel kernel.LinuxCatalogerConfig | ||||||||||||||||||||
Python python.CatalogerConfig | ||||||||||||||||||||
Catalogers []string | ||||||||||||||||||||
Parallelism int | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
func DefaultConfig() Config { | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why delete the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function was only used as a part of syft/test/integration/utils_test.go Lines 57 to 65 in c7272fd
Apologies for the boy scout change on an unrelated PR - my IDE was yelling about this being |
||||||||||||||||||||
return Config{ | ||||||||||||||||||||
Search: DefaultSearchConfig(), | ||||||||||||||||||||
Parallelism: 1, | ||||||||||||||||||||
LinuxKernel: kernel.DefaultLinuxCatalogerConfig(), | ||||||||||||||||||||
Python: python.DefaultCatalogerConfig(), | ||||||||||||||||||||
} | ||||||||||||||||||||
Search SearchConfig | ||||||||||||||||||||
Golang golang.GoCatalogerOpts | ||||||||||||||||||||
LinuxKernel kernel.LinuxCatalogerConfig | ||||||||||||||||||||
Python python.CatalogerConfig | ||||||||||||||||||||
Catalogers []string | ||||||||||||||||||||
Parallelism int | ||||||||||||||||||||
ExcludeBinaryOverlapByOwnership bool | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
func (c Config) Java() java.Config { | ||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package cataloger | ||
|
||
import ( | ||
"golang.org/x/exp/slices" | ||
|
||
"github.com/anchore/syft/syft/artifact" | ||
"github.com/anchore/syft/syft/pkg" | ||
"github.com/anchore/syft/syft/pkg/cataloger/alpm" | ||
"github.com/anchore/syft/syft/pkg/cataloger/apkdb" | ||
"github.com/anchore/syft/syft/pkg/cataloger/binary" | ||
"github.com/anchore/syft/syft/pkg/cataloger/deb" | ||
"github.com/anchore/syft/syft/pkg/cataloger/nix" | ||
"github.com/anchore/syft/syft/pkg/cataloger/rpm" | ||
) | ||
|
||
type CategoryType string | ||
|
||
const ( | ||
OsCatalogerType CategoryType = "os" | ||
BinaryCatalogerType CategoryType = "binary" | ||
) | ||
|
||
var CatalogerTypeIndex = map[CategoryType][]string{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could these just be simplified into 2 variables? something like: var parentCatalogerTypes = []string { .... }
var childCatalogerTypes = []string { .... } There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! Yea that would be a good simplification here. My only hesitancy to change it back to that is the original config object we had discussed on the issue: I think keeping this as is has two advantages:
WDYT? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the concern is that we want to be explicit about OS and binary cataloger types, these could be named var osCatalogerTypes = []string { .... }
var binaryCatalogerTypes = []string { .... }
I'm all for forward-thinking such as being open to more configuration. The suggestion was more that since we're not doing that at the moment, we don't necessarily know what that would look like (although you had an option originally), so it might be better to just make whatever changes at such time as we do change the feature. Again, this is not a blocker and I'll leave it to your discernment.
kzantow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
OsCatalogerType: { | ||
apkdb.CatalogerName, | ||
alpm.CatalogerName, | ||
deb.CatalogerName, | ||
nix.CatalogerName, | ||
rpm.DBCatalogerName, | ||
rpm.FileCatalogerName, | ||
}, | ||
BinaryCatalogerType: { | ||
binary.CatalogerName, | ||
}, | ||
} | ||
|
||
// Exclude will remove packages from a collection given the following properties are true | ||
// 1) the relationship between packages is OwnershipByFileOverlap | ||
// 2) the parent is an "os" package | ||
// 3) the child is a synthetic package generated by the binary cataloger | ||
// 4) the package names are identical | ||
// This exclude was implemented as a way to help resolve: https://github.com/anchore/syft/issues/931 | ||
func Exclude(r artifact.Relationship, c *pkg.Collection) bool { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this function seems very specific, but has a very generic name. I think the name should probably be tweaked to be a little more specific. |
||
parent := c.Package(r.From.ID()) | ||
if parent == nil { | ||
return false | ||
} | ||
child := c.Package(r.To.ID()) | ||
if child == nil { | ||
return false | ||
} | ||
|
||
if artifact.OwnershipByFileOverlapRelationship != r.Type { | ||
return false | ||
} | ||
kzantow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
parentInExclusion := slices.Contains(CatalogerTypeIndex[OsCatalogerType], parent.FoundBy) | ||
if !parentInExclusion { | ||
return false | ||
} | ||
|
||
return slices.Contains(CatalogerTypeIndex[BinaryCatalogerType], child.FoundBy) | ||
} |
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.
the code has
exclude-binary-overlap-by-ownership
https://github.com/anchore/syft/pull/1948/files#diff-9dd8956cf9479ebf46ae7743d82d2d89bd81661bd13cd239651ff31f414f10b5R226