Skip to content

Add istio importer and tests - #336

Merged
sbs2001 merged 5 commits into
aboutcode-org:mainfrom
tushar912:istio
Mar 14, 2021
Merged

Add istio importer and tests#336
sbs2001 merged 5 commits into
aboutcode-org:mainfrom
tushar912:istio

Conversation

@tushar912

@tushar912 tushar912 commented Feb 5, 2021

Copy link
Copy Markdown
Contributor

Description

Added importer and tests for istio
Also added test files in test_data/istio

Fixes #302

Comment thread vulnerabilities/importers/istio.py Outdated
Comment thread vulnerabilities/importers/istio.py Outdated
Comment thread vulnerabilities/importers/istio.py Outdated

@pombredanne pombredanne left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this! I have added a few comments for your consideration.

Comment thread vulnerabilities/importer_yielder.py Outdated
Comment thread vulnerabilities/importers/istio.py
Comment thread vulnerabilities/importers/istio.py
Comment thread vulnerabilities/importers/istio.py Outdated
Comment thread vulnerabilities/importers/istio.py Outdated

safe_pkg_versions = []
vuln_pkg_versions = []
all_version_list = self.version_api.get("istio/istio")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you gain from suffixing your variable names with a type? Would not versions or all_version be better than all_version_list?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I would change them.

Comment thread vulnerabilities/importers/istio.py Outdated
cve_id = cve_id

safe_purls = {
PackageURL(name="istio", type="golang", version=version)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the logical order of fields, type would go first

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

Comment thread vulnerabilities/importers/istio.py Outdated
}

vuln_purls = {
PackageURL(name="istio", type="golang", version=version)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about also creating github type purls?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pombredanne I am still unable to understand how to create two package types for a single purl. Can you explain it a bit.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tushar912 sorry if I was not clear: I meant to have multiple purls: one pkg:/golang and one pkg:github since the project has both personalities

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh Ok

Comment thread vulnerabilities/tests/test_data/istio/test_file.md
Comment thread vulnerabilities/importers/istio.py Outdated
Comment thread vulnerabilities/tests/test_istio.py
@tushar912

Copy link
Copy Markdown
Contributor Author

@pombredanne @sbs2001 I have made some changes as per the suggestions made by you. Please review again.

@tushar912 tushar912 changed the title [WIP] Add istio importer and tests Add istio importer and tests Feb 10, 2021
Comment thread vulnerabilities/importer_yielder.py Outdated
Comment thread vulnerabilities/importers/istio.py Outdated
safe_pkg_versions = []
vuln_pkg_versions = []
all_version_list = self.version_api.get("istio/istio")
if not version_range_list:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the condition and all_version should be at top. We don't want to create objects just to have them destroyed.

Comment thread vulnerabilities/importers/istio.py Outdated
all_version_list = self.version_api.get("istio/istio")
if not version_range_list:
return all_version_list, []
version_ranges = {RangeSpecifier(r) for r in version_range_list}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pombredanne The codebase has (over) use of sets all over the place mostly because we were paranoid of duplicates and order didn't matter.

@tushar912 use a list, if that's ok ?

Comment thread vulnerabilities/importers/istio.py
Comment thread vulnerabilities/importers/istio.py
Comment thread vulnerabilities/importers/istio.py Outdated
Comment thread vulnerabilities/importers/istio.py Outdated
ubound = "<=" + release[2]
releases.append(lbound + "," + ubound)

data["releases"] = releases

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This a list of string version ranges now, change the key name here to something that reflects that

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

Comment thread vulnerabilities/importers/istio.py Outdated
safe_purls = []
vuln_purls = []

cve_id = cve_id

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I should remove this

Comment thread vulnerabilities/importers/istio.py
Comment thread vulnerabilities/importers/istio.py
@tushar912
tushar912 force-pushed the istio branch 7 times, most recently from 73b81f6 to e2ad923 Compare February 17, 2021 11:43
@tushar912
tushar912 requested a review from sbs2001 February 17, 2021 11:43
@tushar912

Copy link
Copy Markdown
Contributor Author

@sbs2001 I have made the changes.

Comment thread vulnerabilities/importers/istio.py Outdated
safe_pkg_versions, vuln_pkg_versions = self.get_versions_for_pkg_from_range_list(
data["release_ranges"])

safe_purls = []

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a need to declare this here, since you are assigning them the union below ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should remove it.

Comment thread vulnerabilities/importers/istio.py Outdated
advisories.extend(processed_data)
return self.batch_advisories(advisories)

def get_versions_for_pkg_from_range_list(self, version_range_list):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function name is too verbose. How about get_pkg_versions_from_ranges ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

Comment thread vulnerabilities/importers/istio.py Outdated
@tushar912

Copy link
Copy Markdown
Contributor Author

@sbs2001 I have made the changes, also can you answer #336 (comment).

Comment thread vulnerabilities/importers/istio.py Outdated
ubound = "<=" + release[2]
releases.append(lbound + "," + ubound)
# If it is a single release
elif isinstance(release, int):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you point me to an example of this ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be done without using isinstance ? This is going to fail in case the release is of form 1.x.y . Maybe some string check ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I use a regex check?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would try to avoid regex unless absolutely needed, because those are very cryptic when reading.

If there's no other way could you do something like https://github.com/nexB/vulnerablecode/blob/f81816fcd95d00736dc17c9aaad20e91cb6ce201/vulnerabilities/helpers.py#L81 ?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That way atleast, it would be easy to understand what the regex is trying to do without going into the details.

@sbs2001 sbs2001 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tushar912 thanks this almost at a stage to be merged, please see my comments inline.

Comment thread vulnerabilities/importers/istio.py Outdated
@sbs2001

sbs2001 commented Feb 23, 2021

Copy link
Copy Markdown
Collaborator

@tushar912 Due to recent model changes, you would need to rename Advisory.cve_id ->Advisory.vulnerability_id

@tushar912
tushar912 force-pushed the istio branch 3 times, most recently from d90ab42 to b1f563a Compare February 24, 2021 12:45
@tushar912
tushar912 requested a review from sbs2001 February 24, 2021 13:07
Comment thread vulnerabilities/importers/istio.py Outdated
as parameter and returns a tuple of safe package versions and
vulnerable package versions"""
all_version = self.version_api.get("istio/istio")
# if not version_range_list:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this can be removed now ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I missed this. I will remove it.

@sbs2001 sbs2001 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment of usage of isinstance and remove the commented code and we're good to merge :)

Signed-off-by: Tushar912 <tushar.912u@gmail.com>
Signed-off-by: Tushar912 <tushar.912u@gmail.com>
Also add github as package type

Signed-off-by: Tushar912 <tushar.912u@gmail.com>
@tushar912
tushar912 force-pushed the istio branch 3 times, most recently from d8e4ec3 to 5b6c5dd Compare March 11, 2021 07:00
@tushar912

Copy link
Copy Markdown
Contributor Author

@sbs2001 Sorry for the delay. I have added a better check for single release using regex.

@tushar912
tushar912 requested a review from sbs2001 March 11, 2021 07:02
assign cve to empty string if its
N/A

Signed-off-by: Tushar912 <tushar.912u@gmail.com>
ubound = "<=" + release[2]
releases.append(lbound + "," + ubound)
# If it is a single release
elif is_release(release):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@sbs2001 sbs2001 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @tushar912 for your patience and I'm merging this.

@sbs2001
sbs2001 merged commit a3e98c2 into aboutcode-org:main Mar 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Collect Istio

3 participants