Skip to content

Commit

Permalink
add new ignore and make upstream regex
Browse files Browse the repository at this point in the history
Signed-off-by: github-actions <[email protected]>
  • Loading branch information
github-actions authored and tomersein committed Jan 5, 2025
1 parent 9e54256 commit 5761275
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/grype/cli/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ var ignoreVEXFixedNotAffected = []match.IgnoreRule{

var ignoreLinuxKernelHeaders = []match.IgnoreRule{
{Package: match.IgnoreRulePackage{Name: "kernel-headers", UpstreamName: "kernel", Type: string(syftPkg.RpmPkg)}, MatchType: match.ExactIndirectMatch},
{Package: match.IgnoreRulePackage{Name: "linux-.*-headers-.*", UpstreamName: "linux.*", Type: string(syftPkg.DebPkg)}, MatchType: match.ExactIndirectMatch},
{Package: match.IgnoreRulePackage{Name: "linux(-.*)?-headers-.*", UpstreamName: "linux.*", Type: string(syftPkg.DebPkg)}, MatchType: match.ExactIndirectMatch},
{Package: match.IgnoreRulePackage{Name: "linux-libc-dev", UpstreamName: "linux", Type: string(syftPkg.DebPkg)}, MatchType: match.ExactIndirectMatch},
}

Expand Down
6 changes: 5 additions & 1 deletion grype/match/ignore.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,11 @@ func ifPackageLocationApplies(location string) ignoreCondition {
func ifUpstreamPackageNameApplies(name string) ignoreCondition {
return func(match Match) bool {
for _, upstream := range match.Package.Upstreams {
if name == upstream.Name {
pattern, err := packageNameRegex(name)
if err != nil {
continue
}
if pattern.MatchString(upstream.Name) {
return true
}
}
Expand Down
66 changes: 65 additions & 1 deletion grype/match/ignore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,30 @@ var (
},
},
},
// linux-like match, similar to what we see from debian\ubuntu
{
Vulnerability: vulnerability.Vulnerability{
ID: "CVE-3",

Check failure on line 231 in grype/match/ignore_test.go

View workflow job for this annotation

GitHub Actions / Unit tests

unknown field ID in struct literal of type vulnerability.Vulnerability
Namespace: "fake-linux-vulns",

Check failure on line 232 in grype/match/ignore_test.go

View workflow job for this annotation

GitHub Actions / Unit tests

unknown field Namespace in struct literal of type vulnerability.Vulnerability
Fix: vulnerability.Fix{
State: vulnerability.FixStateUnknown,
},
},
Package: pkg.Package{
ID: pkg.ID(uuid.NewString()),
Name: "linux-azure-headers-generic",
Version: "5.2.1",
Type: syftPkg.DebPkg,
Upstreams: []pkg.UpstreamPackage{
{Name: "linux-azure"},
},
},
Details: []Detail{
{
Type: ExactIndirectMatch,
},
},
},
}

// For testing the match-type and upstream ignore rules
Expand Down Expand Up @@ -540,6 +564,11 @@ func TestApplyIgnoreRules(t *testing.T) {
UpstreamName: "kernel",
},
},
{
Package: IgnoreRulePackage{
UpstreamName: "linux-.*",
},
},
},
expectedRemainingMatches: []Match{
kernelHeadersMatches[1],
Expand All @@ -555,6 +584,16 @@ func TestApplyIgnoreRules(t *testing.T) {
},
},
},
{
Match: kernelHeadersMatches[2],
AppliedIgnoreRules: []IgnoreRule{
{
Package: IgnoreRulePackage{
UpstreamName: "linux-.*",
},
},
},
},
},
},
{
Expand Down Expand Up @@ -595,6 +634,14 @@ func TestApplyIgnoreRules(t *testing.T) {
},
MatchType: ExactIndirectMatch,
},
{
Package: IgnoreRulePackage{
Name: "linux-.*-headers-.*",
UpstreamName: "linux.*",
Type: string(syftPkg.DebPkg),
},
MatchType: ExactIndirectMatch,
},
},
expectedRemainingMatches: []Match{
kernelHeadersMatches[1],
Expand All @@ -613,6 +660,19 @@ func TestApplyIgnoreRules(t *testing.T) {
},
},
},
{
Match: kernelHeadersMatches[2],
AppliedIgnoreRules: []IgnoreRule{
{
Package: IgnoreRulePackage{
Name: "linux-.*-headers-.*",
UpstreamName: "linux.*",
Type: string(syftPkg.DebPkg),
},
MatchType: ExactIndirectMatch,
},
},
},
},
},
{
Expand All @@ -627,6 +687,7 @@ func TestApplyIgnoreRules(t *testing.T) {
},
expectedRemainingMatches: []Match{
kernelHeadersMatches[1],
kernelHeadersMatches[2],
},
expectedIgnoredMatches: []IgnoredMatch{
{
Expand Down Expand Up @@ -677,7 +738,10 @@ func TestApplyIgnoreRules(t *testing.T) {
},
},
},
expectedRemainingMatches: []Match{kernelHeadersMatches[1]},
expectedRemainingMatches: []Match{
kernelHeadersMatches[1],
kernelHeadersMatches[2],
},
expectedIgnoredMatches: []IgnoredMatch{
{
Match: kernelHeadersMatches[0],
Expand Down

0 comments on commit 5761275

Please sign in to comment.