-
Notifications
You must be signed in to change notification settings - Fork 17
libs: Add envoy.dependency.check[cves]
#186
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
Merged
htuch
merged 1 commit into
envoyproxy:main
from
phlax:envoy.dependency.check-rename_cve-scanner
Jan 26, 2022
Merged
Changes from all commits
Commits
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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
|
|
||
| pytooling_package("envoy.dependency.check") |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
|
|
||
| envoy.dependency.check | ||
| ====================== | ||
|
|
||
| Dependency checker used in Envoy proxy's CI |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 0.0.1-dev |
16 changes: 10 additions & 6 deletions
16
....cve_scan/envoy/dependency/cve_scan/BUILD → ...ndency.check/envoy/dependency/check/BUILD
This file contains hidden or 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 |
|---|---|---|
| @@ -1,23 +1,27 @@ | ||
|
|
||
| pytooling_library( | ||
| "envoy.dependency.cve_scan", | ||
| "envoy.dependency.check", | ||
| dependencies=[ | ||
| "//deps:abstracts", | ||
| "//deps:aio.core", | ||
| "//deps:aio.run.checker", | ||
| "//deps:envoy.base.utils", | ||
| "//deps:aiohttp", | ||
| "//deps:jinja2", | ||
| "//deps:aiohttp", | ||
| "//deps:packaging", | ||
| ], | ||
| sources=[ | ||
| "abstract/__init__.py", | ||
| "abstract/checker.py", | ||
| "abstract/cpe.py", | ||
| "abstract/cve.py", | ||
| "abstract/cves/__init__.py", | ||
| "abstract/cves/cpe.py", | ||
| "abstract/cves/cve.py", | ||
| "abstract/cves/cves.py", | ||
| "abstract/cves/version_matcher.py", | ||
| "abstract/dependency.py", | ||
| "abstract/typing.py", | ||
| "abstract/version_matcher.py", | ||
| "checker.py", | ||
| "cmd.py", | ||
| "exceptions.py", | ||
| "typing.py", | ||
| ], | ||
| ) |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
|
|
||
| from . import abstract, exceptions, typing | ||
| from .abstract import ( | ||
| ADependency, | ||
| ADependencyChecker, | ||
| ADependencyCPE, | ||
| ADependencyCVE, | ||
| ADependencyCVEs, | ||
| ADependencyCVEVersionMatcher) | ||
| from .checker import ( | ||
| Dependency, | ||
| DependencyChecker, | ||
| DependencyCPE, | ||
| DependencyCVE, | ||
| DependencyCVEs, | ||
| DependencyCVEVersionMatcher) | ||
| from .cmd import run, main | ||
| from . import checker | ||
|
|
||
|
|
||
| __all__ = ( | ||
| "abstract", | ||
| "ADependency", | ||
| "ADependencyChecker", | ||
| "ADependencyCPE", | ||
| "ADependencyCVE", | ||
| "ADependencyCVEs", | ||
| "ADependencyCVEVersionMatcher", | ||
| "checker", | ||
| "Dependency", | ||
| "DependencyChecker", | ||
| "DependencyCPE", | ||
| "DependencyCVE", | ||
| "DependencyCVEs", | ||
| "DependencyCVEVersionMatcher", | ||
| "exceptions", | ||
| "main", | ||
| "run", | ||
| "typing") |
17 changes: 17 additions & 0 deletions
17
envoy.dependency.check/envoy/dependency/check/abstract/__init__.py
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
|
|
||
| from .checker import ADependencyChecker | ||
| from .cves import ( | ||
| ADependencyCPE, | ||
| ADependencyCVE, | ||
| ADependencyCVEs, | ||
| ADependencyCVEVersionMatcher) | ||
| from .dependency import ADependency | ||
|
|
||
|
|
||
| __all__ = ( | ||
| "ADependency", | ||
| "ADependencyChecker", | ||
| "ADependencyCPE", | ||
| "ADependencyCVE", | ||
| "ADependencyCVEs", | ||
| "ADependencyCVEVersionMatcher") |
107 changes: 107 additions & 0 deletions
107
envoy.dependency.check/envoy/dependency/check/abstract/checker.py
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| """Abstract dependency checker.""" | ||
|
|
||
| import abc | ||
| import argparse | ||
| import json | ||
| import pathlib | ||
| from functools import cached_property | ||
| from typing import Tuple, Type | ||
|
|
||
| import aiohttp | ||
|
|
||
| import abstracts | ||
|
|
||
| from aio.run import checker | ||
|
|
||
| from envoy.dependency.check import abstract, exceptions, typing | ||
|
|
||
|
|
||
| class ADependencyChecker( | ||
| checker.Checker, | ||
| metaclass=abstracts.Abstraction): | ||
| """Dependency checker.""" | ||
|
|
||
| checks = ("cves", ) | ||
|
|
||
| @property | ||
| def cve_config(self): | ||
| return self.args.cve_config | ||
|
|
||
| @cached_property | ||
| def cves(self): | ||
| return self.cves_class( | ||
| self.dependencies, | ||
| config_path=self.cve_config, | ||
| session=self.session) | ||
|
|
||
| @property # type:ignore | ||
| @abstracts.interfacemethod | ||
| def cves_class(self) -> "abstract.ADependencyCVEs": | ||
| """CVEs class.""" | ||
| raise NotImplementedError | ||
|
|
||
| @cached_property | ||
| def dependencies(self) -> Tuple["abstract.ADependency", ...]: | ||
| """Tuple of dependencies.""" | ||
| deps = [] | ||
| for k, v in self.dependency_metadata.items(): | ||
| deps.append(self.dependency_class(k, v)) | ||
| return tuple(sorted(deps)) | ||
|
|
||
| @property # type:ignore | ||
| @abstracts.interfacemethod | ||
| def dependency_class(self) -> Type["abstract.ADependency"]: | ||
| """Dependency class.""" | ||
| raise NotImplementedError | ||
|
|
||
| @property | ||
| @abc.abstractmethod | ||
| def dependency_metadata(self) -> typing.DependenciesDict: | ||
| """Dependency metadata (derived in Envoy's case from | ||
| `repository_locations.bzl`).""" | ||
| return json.loads(self.repository_locations_path.read_text()) | ||
|
|
||
| @property | ||
| def repository_locations_path(self) -> pathlib.Path: | ||
| return pathlib.Path(self.args.repository_locations) | ||
|
|
||
| @cached_property | ||
| def session(self) -> aiohttp.ClientSession: | ||
| """HTTP client session.""" | ||
| return aiohttp.ClientSession() | ||
|
|
||
| def add_arguments(self, parser: argparse.ArgumentParser) -> None: | ||
| super().add_arguments(parser) | ||
| parser.add_argument('--repository_locations') | ||
| parser.add_argument('--cve_config') | ||
|
|
||
| async def check_cves(self) -> None: | ||
| """Scan for CVEs in a parsed NIST CVE database.""" | ||
| for dep in self.dependencies: | ||
| await self.dep_cve_check(dep) | ||
|
|
||
| async def dep_cve_check( | ||
| self, | ||
| dep: "abstract.ADependency") -> None: | ||
| if not dep.cpe: | ||
| self.log.info(f"No CPE listed for: {dep.id}") | ||
| return | ||
| warnings = [] | ||
| async for failing_cve in self.cves.dependency_check(dep): | ||
| warnings.append( | ||
| f'{failing_cve.format_failure(dep)}') | ||
| if warnings: | ||
| self.warn("cves", warnings) | ||
| else: | ||
| self.succeed("cves", [f"No CVEs found for: {dep.id}"]) | ||
|
|
||
| async def on_checks_complete(self) -> int: | ||
| await self.session.close() | ||
| return await super().on_checks_complete() | ||
|
|
||
| @checker.preload( | ||
| when=["cves"], | ||
| catches=[exceptions.CVECheckError]) | ||
| async def preload_cves(self) -> None: | ||
| async for download in self.cves.downloads: | ||
| self.log.debug(f"Preloaded cve data: {download}") | ||
|
Member
Author
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 is the debug log that was previously a |
||
12 changes: 12 additions & 0 deletions
12
envoy.dependency.check/envoy/dependency/check/abstract/cves/__init__.py
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
|
|
||
| from .cpe import ADependencyCPE | ||
| from .cve import ADependencyCVE | ||
| from .cves import ADependencyCVEs | ||
| from .version_matcher import ADependencyCVEVersionMatcher | ||
|
|
||
|
|
||
| __all__ = ( | ||
| "ADependencyCPE", | ||
| "ADependencyCVE", | ||
| "ADependencyCVEs", | ||
| "ADependencyCVEVersionMatcher") |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
this is the
newlog.infosaying that the dep has no cve - im just wondering what this did before...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.
it did https://github.com/envoyproxy/pytooling/blob/main/envoy.dependency.cve_scan/tests/integration/outcome/no_fail.json#L12