-
Notifications
You must be signed in to change notification settings - Fork 600
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: add ability to ignore packages on pom properties #1345
Open
jneate
wants to merge
4
commits into
anchore:main
Choose a base branch
from
jneate:ignore-java-test-deps
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
|
@@ -70,19 +70,22 @@ var ( | |
{ | ||
Vulnerability: vulnerability.Vulnerability{ | ||
ID: "CVE-458", | ||
Namespace: "ruby-vulns", | ||
Namespace: "java-vulns", | ||
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. Has the change to this vulnerability test removed the ruby case? Unclear why it should be removed, should this be added back in as another test case? |
||
Fix: vulnerability.Fix{ | ||
State: grypeDb.UnknownFixState, | ||
}, | ||
}, | ||
Package: pkg.Package{ | ||
ID: pkg.ID(uuid.NewString()), | ||
Name: "speach", | ||
Version: "100.0.52", | ||
Language: syftPkg.Ruby, | ||
Type: syftPkg.GemPkg, | ||
Locations: source.NewLocationSet(source.NewVirtualLocation("/real/path/with/speach", | ||
"/virtual/path/that/has/speach")), | ||
Name: "log4j", | ||
Version: "1.1.1", | ||
Language: syftPkg.Java, | ||
Type: syftPkg.JavaPkg, | ||
Metadata: pkg.JavaMetadata{ | ||
PomGroupID: "log4j", | ||
PomArtifactID: "log4j-core", | ||
PomScope: "test", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
@@ -235,6 +238,7 @@ func TestApplyIgnoreRules(t *testing.T) { | |
}, | ||
expectedRemainingMatches: []Match{ | ||
allMatches[0], | ||
allMatches[3], | ||
}, | ||
expectedIgnoredMatches: []IgnoredMatch{ | ||
{ | ||
|
@@ -253,14 +257,6 @@ func TestApplyIgnoreRules(t *testing.T) { | |
}, | ||
}, | ||
}, | ||
{ | ||
Match: allMatches[3], | ||
AppliedIgnoreRules: []IgnoreRule{ | ||
{ | ||
Namespace: "ruby-vulns", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
|
@@ -275,6 +271,7 @@ func TestApplyIgnoreRules(t *testing.T) { | |
}, | ||
expectedRemainingMatches: []Match{ | ||
allMatches[0], | ||
allMatches[3], | ||
}, | ||
expectedIgnoredMatches: []IgnoredMatch{ | ||
{ | ||
|
@@ -297,12 +294,86 @@ func TestApplyIgnoreRules(t *testing.T) { | |
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "ignore matches on pom scope", | ||
allMatches: allMatches, | ||
ignoreRules: []IgnoreRule{ | ||
{ | ||
Pom: IgnoreRulePom{ | ||
Scope: "test", | ||
}, | ||
}, | ||
}, | ||
expectedRemainingMatches: []Match{ | ||
allMatches[0], | ||
allMatches[1], | ||
allMatches[2], | ||
}, | ||
expectedIgnoredMatches: []IgnoredMatch{ | ||
{ | ||
Match: allMatches[3], | ||
AppliedIgnoreRules: []IgnoreRule{ | ||
{ | ||
Package: IgnoreRulePackage{ | ||
Language: string(syftPkg.Ruby), | ||
Pom: IgnoreRulePom{ | ||
Scope: "test", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "ignore matches on pom group id", | ||
allMatches: allMatches, | ||
ignoreRules: []IgnoreRule{ | ||
{ | ||
Pom: IgnoreRulePom{ | ||
GroupID: "log4j", | ||
}, | ||
}, | ||
}, | ||
expectedRemainingMatches: []Match{ | ||
allMatches[0], | ||
allMatches[1], | ||
allMatches[2], | ||
}, | ||
expectedIgnoredMatches: []IgnoredMatch{ | ||
{ | ||
Match: allMatches[3], | ||
AppliedIgnoreRules: []IgnoreRule{ | ||
{ | ||
Pom: IgnoreRulePom{ | ||
GroupID: "log4j", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "ignore matches on pom artifact id", | ||
allMatches: allMatches, | ||
ignoreRules: []IgnoreRule{ | ||
{ | ||
Pom: IgnoreRulePom{ | ||
ArtifactID: "log4j-core", | ||
}, | ||
}, | ||
}, | ||
expectedRemainingMatches: []Match{ | ||
allMatches[0], | ||
allMatches[1], | ||
allMatches[2], | ||
}, | ||
expectedIgnoredMatches: []IgnoredMatch{ | ||
{ | ||
Match: allMatches[3], | ||
AppliedIgnoreRules: []IgnoreRule{ | ||
{ | ||
Pom: IgnoreRulePom{ | ||
ArtifactID: "log4j-core", | ||
}, | ||
}, | ||
}, | ||
|
@@ -346,6 +417,25 @@ var ( | |
} | ||
) | ||
|
||
var ( | ||
exampleJavaMatch = Match{ | ||
Vulnerability: vulnerability.Vulnerability{ | ||
ID: "CVE-2000-1234", | ||
}, | ||
Package: pkg.Package{ | ||
ID: pkg.ID(uuid.NewString()), | ||
Name: "a-pkg", | ||
Version: "1.0", | ||
Type: "java-archive", | ||
Metadata: pkg.JavaMetadata{ | ||
PomGroupID: "example-group", | ||
PomArtifactID: "example-artifact", | ||
PomScope: "test", | ||
}, | ||
}, | ||
} | ||
) | ||
|
||
func TestShouldIgnore(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
|
@@ -450,6 +540,36 @@ func TestShouldIgnore(t *testing.T) { | |
}, | ||
expected: false, | ||
}, | ||
{ | ||
name: "rule applies via pom scope", | ||
match: exampleJavaMatch, | ||
rule: IgnoreRule{ | ||
Pom: IgnoreRulePom{ | ||
Scope: exampleJavaMatch.Package.Metadata.(pkg.JavaMetadata).PomScope, | ||
}, | ||
}, | ||
expected: true, | ||
}, | ||
{ | ||
name: "rule applies via pom group id", | ||
match: exampleJavaMatch, | ||
rule: IgnoreRule{ | ||
Pom: IgnoreRulePom{ | ||
GroupID: exampleJavaMatch.Package.Metadata.(pkg.JavaMetadata).PomGroupID, | ||
}, | ||
}, | ||
expected: true, | ||
}, | ||
{ | ||
name: "rule applies via pom artifact id", | ||
match: exampleJavaMatch, | ||
rule: IgnoreRule{ | ||
Pom: IgnoreRulePom{ | ||
ArtifactID: exampleJavaMatch.Package.Metadata.(pkg.JavaMetadata).PomArtifactID, | ||
}, | ||
}, | ||
expected: true, | ||
}, | ||
} | ||
|
||
for _, testCase := range cases { | ||
|
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
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.
I wonder if this should be nested under a Java ignore rule container? E.g. the configuration would be:
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.
@jneate the team talked about this PR a bit and had a few comments:
The first thing to note is
The simplest change to get this to the finish line: since this is for a package rather than something else we believe this should be nested under the
IgnoreRulePackage
, probably for now asjava
(since the metadata ispkg.JavaMetadata
rather than Maven POM specific), so the configuration would look something like:... I think this would basically just involve moving the
under the
IgnoreRulePackage
, as something more like:--
But... I'd also mention there was another thought that we might like to make this more generic, where we could potentially specify any metadata information, something like:
Do you think either of these options would be something you'd like to do? If not, we could probably help at least get the first change done to get this to the finish line.