-
Notifications
You must be signed in to change notification settings - Fork 591
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 all 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 |
---|---|---|
|
@@ -24,7 +24,7 @@ func TestCataloger_Catalog(t *testing.T) { | |
Version: "2.34-210", | ||
PURL: "pkg:nix/[email protected]?output=bin&outputhash=h0cnbmfcn93xm5dg2x27ixhag1cwndga", | ||
Locations: file.NewLocationSet(file.NewLocation("nix/store/h0cnbmfcn93xm5dg2x27ixhag1cwndga-glibc-2.34-210-bin")), | ||
FoundBy: catalogerName, | ||
FoundBy: CatalogerName, | ||
Type: pkg.NixPkg, | ||
MetadataType: pkg.NixStoreMetadataType, | ||
Metadata: pkg.NixStoreMetadata{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
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" | ||
) | ||
|
||
var ( | ||
osCatalogerTypes = []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. I think the filtering should be based on the package type, not the cataloger names. |
||
apkdb.CatalogerName, | ||
alpm.CatalogerName, | ||
deb.CatalogerName, | ||
nix.CatalogerName, | ||
rpm.DBCatalogerName, | ||
rpm.FileCatalogerName, | ||
} | ||
binaryCatalogerTypes = []string{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. |
||
if artifact.OwnershipByFileOverlapRelationship != r.Type { | ||
return false | ||
} | ||
|
||
parent := c.Package(r.From.ID()) | ||
if parent == nil { | ||
return false | ||
} | ||
|
||
parentInExclusion := slices.Contains(osCatalogerTypes, parent.FoundBy) | ||
if !parentInExclusion { | ||
return false | ||
} | ||
|
||
child := c.Package(r.To.ID()) | ||
if child == nil { | ||
return false | ||
} | ||
|
||
return slices.Contains(binaryCatalogerTypes, child.FoundBy) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package cataloger | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/anchore/syft/syft/artifact" | ||
"github.com/anchore/syft/syft/pkg" | ||
"github.com/anchore/syft/syft/pkg/cataloger/apkdb" | ||
"github.com/anchore/syft/syft/pkg/cataloger/binary" | ||
) | ||
|
||
func TestExclude(t *testing.T) { | ||
packageA := pkg.Package{Name: "package-a", Type: pkg.ApkPkg, FoundBy: apkdb.CatalogerName} | ||
packageB := pkg.Package{Name: "package-a", Type: pkg.PythonPkg, FoundBy: "language-cataloger"} | ||
packageC := pkg.Package{Name: "package-a", Type: pkg.BinaryPkg, FoundBy: binary.CatalogerName} | ||
packageD := pkg.Package{Name: "package-d", Type: pkg.BinaryPkg, FoundBy: binary.CatalogerName} | ||
for _, p := range []*pkg.Package{&packageA, &packageB, &packageC, &packageD} { | ||
p := p | ||
p.SetID() | ||
} | ||
|
||
tests := []struct { | ||
name string | ||
relationship artifact.Relationship | ||
packages *pkg.Collection | ||
shouldExclude bool | ||
}{ | ||
{ | ||
name: "no exclusions from os -> python", | ||
relationship: artifact.Relationship{ | ||
Type: artifact.OwnershipByFileOverlapRelationship, | ||
From: packageA, | ||
To: packageB, | ||
}, | ||
packages: pkg.NewCollection(packageA, packageB), | ||
shouldExclude: false, | ||
}, | ||
{ | ||
name: "exclusions from os -> binary", | ||
relationship: artifact.Relationship{ | ||
Type: artifact.OwnershipByFileOverlapRelationship, | ||
From: packageA, | ||
To: packageC, | ||
}, | ||
packages: pkg.NewCollection(packageA, packageC), | ||
shouldExclude: true, | ||
}, | ||
{ | ||
name: "no exclusions from python -> binary", | ||
relationship: artifact.Relationship{ | ||
Type: artifact.OwnershipByFileOverlapRelationship, | ||
From: packageB, | ||
To: packageC, | ||
}, | ||
packages: pkg.NewCollection(packageB, packageC), | ||
shouldExclude: false, | ||
}, | ||
{ | ||
name: "no exclusions for different package names", | ||
relationship: artifact.Relationship{ | ||
Type: artifact.OwnershipByFileOverlapRelationship, | ||
From: packageA, | ||
To: packageD, | ||
}, | ||
packages: pkg.NewCollection(packageA, packageD), | ||
shouldExclude: false, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
if !Exclude(test.relationship, test.packages) && test.shouldExclude { | ||
t.Errorf("expected to exclude relationship %+v", test.relationship) | ||
} | ||
}) | ||
|
||
} | ||
} |
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