-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement provider for Chainguard Linux (#132)
* Implement provider for Chainguard Linux Signed-off-by: Dan Luhring <[email protected]> * Fix tests Signed-off-by: Dan Luhring <[email protected]> * wip: configs.yaml Signed-off-by: Dan Luhring <[email protected]> * Fix failing test Signed-off-by: Dan Luhring <[email protected]> * Use main branch of Grype for quality gate Signed-off-by: Dan Luhring <[email protected]> * Use latest grype and grype-db Signed-off-by: Dan Luhring <[email protected]> --------- Signed-off-by: Dan Luhring <[email protected]>
- Loading branch information
Showing
16 changed files
with
1,060 additions
and
154 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
from __future__ import annotations | ||
|
||
import os | ||
from dataclasses import dataclass, field | ||
from typing import TYPE_CHECKING | ||
|
||
from vunnel import provider, result, schema | ||
from vunnel.providers.wolfi.parser import Parser | ||
|
||
if TYPE_CHECKING: | ||
import datetime | ||
|
||
|
||
@dataclass | ||
class Config: | ||
runtime: provider.RuntimeConfig = field( | ||
default_factory=lambda: provider.RuntimeConfig( | ||
result_store=result.StoreStrategy.SQLITE, | ||
existing_results=provider.ResultStatePolicy.DELETE_BEFORE_WRITE, | ||
), | ||
) | ||
request_timeout: int = 125 | ||
|
||
|
||
class Provider(provider.Provider): | ||
_url = "https://packages.cgr.dev/chainguard/security.json" | ||
_namespace = "chainguard" | ||
|
||
def __init__(self, root: str, config: Config | None = None): | ||
if not config: | ||
config = Config() | ||
super().__init__(root, runtime_cfg=config.runtime) | ||
self.config = config | ||
|
||
self.logger.debug(f"config: {config}") | ||
|
||
self.schema = schema.OSSchema() | ||
self.parser = Parser( | ||
workspace=self.workspace, | ||
url=self._url, | ||
namespace=self._namespace, | ||
download_timeout=self.config.request_timeout, | ||
logger=self.logger, | ||
) | ||
|
||
# this provider requires the previous state from former runs | ||
provider.disallow_existing_input_policy(config.runtime) | ||
|
||
@classmethod | ||
def name(cls) -> str: | ||
return "chainguard" | ||
|
||
def update(self, last_updated: datetime.datetime | None) -> tuple[list[str], int]: | ||
with self.results_writer() as writer: | ||
# TODO: tech debt: on subsequent runs, we should only write new vulns (this currently re-writes all) | ||
for release, vuln_dict in self.parser.get(): | ||
for vuln_id, record in vuln_dict.items(): | ||
writer.write( | ||
identifier=os.path.join(f"{self._namespace.lower()}:{release.lower()}", vuln_id), | ||
schema=self.schema, | ||
payload=record, | ||
) | ||
|
||
return [self._url], len(writer) |
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
Oops, something went wrong.