anchore/grype-db

GitHub: anchore/grype-db

用于从多个上游漏洞数据源拉取、处理并构建 Grype 漏洞数据库的工具,支持离线分发与多 Schema 版本管理。

Stars: 66 | Forks: 35

# grype-db **用于从上游漏洞数据源创建 [Grype](https://github.com/anchore/grype) 漏洞数据库的应用程序。** [![GitHub release](https://img.shields.io/github/release/anchore/grype-db.svg)](https://github.com/anchore/grype-db/releases/latest) [![License: Apache-2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/anchore/grype-db/blob/main/LICENSE) [![Join our Discourse](https://img.shields.io/badge/Discourse-Join-blue?logo=discourse)](https://anchore.com/discourse) ## 安装 **注意**:目前,Grype-DB 仅支持在 Linux 和 macOS 上构建。 ### 推荐安装方式 ``` curl -sSfL https://raw.githubusercontent.com/anchore/grype-db/main/install.sh | sh -s -- -b /usr/local/bin ``` ... 或者,你可以指定安装的发行版本和目标目录: ``` curl -sSfL https://raw.githubusercontent.com/anchore/grype-db/main/install.sh | sh -s -- -b ``` ## 用法 `grype-db` 接受以下选项: ``` grype-db [-g] [--dir=DIR] [--schema=SCHEMA] [--skip-validation] [--publish-base-url=URL] [-p PROVIDER ...] ``` ### 拉取数据并构建数据库 要从一个或多个特定的 provider 拉取数据并一步完成数据库构建,请带上 `-g` 标志运行 `grype-db`,并使用 `-p` 标志指定 providers: ``` grype-db -g -p nvd ``` 此示例将为 `nvd` provider 构建数据库。可以指定多个 providers。 如果未指定任何 providers,`grype-db` 默认使用由 `vunnel list` 生成的所有可用 providers。但是请注意,访问 GitHub provider 数据需要使用 token 进行 GitHub API 身份验证。有关添加 GitHub token 的更多信息,请参见 [分步入门指南](https://github.com/anchore/grype-db#getting-started-step-by-step)。) 要下载所有 provider 数据并构建 `vulnerability.db` 数据库,请运行: ``` grype-db -g ``` 默认情况下,`grype-db` 将下载 provider 数据并构建数据库。要单独运行这些步骤,请使用 `build` 和 `pull` 子命令。 ### 拉取 Provider 数据 要在不构建数据库的情况下拉取 provider 数据: ``` grype-db pull -g -p nvd ``` 省略 `-p` 标志可针对所有可用的 providers。 请注意,如果您已经有本地漏洞数据缓存(例如通过 `make download-all-provider-cache` 获取),则可以跳过 `pull` 步骤。 ### 构建数据库 下载 provider 数据后,运行以下命令来构建数据库: ``` grype-db build -g -p nvd ``` build 命令可以接受以下选项: ``` grype-db build [-g] [--dir=DIR] [--schema=SCHEMA] [--skip-validation] [-p PROVIDER ...] ``` ### 打包数据库 您可以对 `vulnerability.db` 进行打包,例如用于提供数据服务或在 CI 中使用。请注意,您的系统上需要安装 zstd 工具才能使用 `package` 子命令。 要打包已构建的数据库,请运行: ``` grype-db package ``` 这将会打包 `build` 文件夹中存在的任何数据库。 `package` 子命令接受以下选项: ``` grype-db package [--dir=DIR] [--publish-base-url=URL] ``` `package` 命令会将 `vulnerability.db` 文件归档为 `tar.zstd` 文件。此外,还会生成一个 `latest.json` 文件,以辅助提供一个或多个数据库归档供下游使用,其中使用方应用程序应 使用该清单文件来发现可供下载的归档。用于为每个数据库归档创建下载 URL 的基础 URL 由 `package.base-url` 配置选项控制。 ### 关于缓存的说明 `pull` 命令从上游来源(例如 NIST、redhat、github、canonical 等)下载漏洞数据并将其缓存到 一个缓存目录中。缓存位置取决于平台的 XDG 目录,不过,可以通过 `cache.dir` 配置选项覆盖该位置。 `build` 命令处理缓存的漏洞数据以生成 `vulnerability.db` sqlite3 文件。此外,还会创建一个 `metadata.json` 文件, 用于数据库文件的打包和管理工作。另外还会创建一个 `provider-metadata.json` 文件,其中包含每个 provider 上次成功运行的日期。 ### 缓存命令 要显示整个漏洞数据缓存或特定 `PROVIDER` 的当前状态: ``` grype-db cache status [--provider-name=PROVIDER ...] ``` 要将所有缓存的漏洞数据或特定的 PROVIDER 备份到 tar.gz 文件 (`PATH`) 中: ``` grype-db cache backup [--path=PATH] [--provider-name=PROVIDER] ``` 要删除所有缓存的漏洞数据或特定的 `PROVIDER`: ``` grype-db cache delete [--provider-name=PROVIDER] ``` 要从 tar.gz 文件 (`PATH`) 还原漏洞缓存 ``` grype-db cache restore [--path=PATH] [--delete-existing] ``` ## 分步入门指南 如果您是第一次运行 `grype-db`,可以按照以下步骤进行设置。 首先,[创建一个 GitHub 访问令牌](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens) 以进行 GitHub API 身份验证。(可以在[此 GitHub 设置页面](https://github.com/settings/tokens)上生成令牌。)不需要特定权限。强烈建议使用限制性权限设置并创建短期有效的令牌。 将您的令牌设置为环境变量: ``` GITHUB_TOKEN=ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ``` 创建并设置一个工作目录: ``` mkdir -p ~/vulnerability-data && cd $_ ``` 创建一个 Python 虚拟环境并激活它: ``` python -m venv venv && source venv/bin/activate ``` 安装 [vunnel](https://github.com/anchore/vunnel): ``` pip install vunnel ``` 现在,在工作目录中将 `grype-db` 作为二进制文件安装。(请注意,这不会将 `grype-db` 放到您的 PATH 中。) ``` curl -sSfL https://raw.githubusercontent.com/anchore/grype-db/main/install.sh | sh -s -- -b . ``` 使用以下 here document 为 `grype-db` 创建配置文件。该命令会自动将您之前设置的 GitHub token 添加到配置中,因此无需手动替换。 ``` cat << EOF > ~/vulnerability-data/.grype-db.yaml provider: vunnel: executor: local generate-configs: true env: GITHUB_TOKEN: $GITHUB_TOKEN EOF ``` 从所有 providers 构建数据库。(请注意,此命令可能需要相当长的时间才能完成。) ``` ./grype-db -g ``` 此命令完成后,您应该会拥有包含下载数据的 `data` 文件夹和包含已构建的 `vulnerability.db` 文件的 `build` 文件夹,以及其他内容。 ## 数据库模式 此仓库支持为所有受支持的 grype 版本构建数据库,即使数据结构已发生更改。 对于随着时间推移数据结构发生的每一次更改,都会创建一个新的模式(有关如何更新模式的详细信息,请参见 DEVELOPING.md)。 **对于 grype-db 支持的每种模式,我们都会在每晚构建相应的 DB。为了减少每晚 DB 的维护工作,请尽量在开发过程中将模式更新保持在最低限度。** 一旦创建了新模式,旧模式就应被视为已锁定,除非是进行与 [vunnel](https://github.com/anchore/vunnel) 相关的错误修复或更新,或者是其他上游数据结构更改。 如果正在进行的开发需要以下任何一项,则**必须创建一个新模式**(而不是继续在当前模式上进行开发): - 如果使用相同模式的旧版 grype 无法在新更改下正常运行 - 如果当前版本的 grype 使用以前发布的数据库(但仍使用相同的模式)无法在新更改下正常运行 此处“无法正常运行”是指 grype 在处理过程中出错,或者结果受到其他方面的损害(例如,丢失了本来可以/应该被找到并报告的数据)。 以下类型的更改**不一定需要新模式**: - 添加新数据源 - 移除现有数据源(只要 grype 匹配器不要求其存在) 在这些情况之间存在着许多灰色地带(例如,更改字段预期的值集,或更改列的语义)——请运用您的最佳判断。 此仓库负责每日为所有受支持的模式发布包含最新漏洞数据的 DB。 这是通过 [Daily Data Sync](https://github.com/anchore/grype-db/actions/workflows/daily-data-sync.yaml) 和 [Daily DB Publisher](https://github.com/anchore/grype-db/actions/workflows/daily-db-publisher.yaml) GitHub Actions 工作流实现的。 构建哪些模式以及使用哪些 grype 版本来验证功能,由此仓库根目录中的 `grype-schema-version-mapping.json` 文件控制 (有关更多详细信息,请参见 DEVELOPING.md)。 ## 配置 ``` # 抑制所有输出 # 与 -q 相同 ; GRYPE_DB_QUIET 环境变量 quiet: false log: # the log level; note: detailed logging suppress the ETUI # same as GRYPE_DB_LOG_LEVEL env var level: "error" # location to write the log file (default is not to have a log file) # same as GRYPE_DB_LOG_FILE env var file: "" provider: # where to read and write all provider data. The state must be oriented as described # in https://github.com/anchore/vunnel/tree/main/schema/provider-workspace-state . # Note: all location references under `providers` should be relative to this directory # same as GRYPE_DB_PROVIDER_ROOT env var root: ./data # names of providers to filter down to while running # same as -p include-filter: [] vunnel: # how to execute vunnel. Options are: # - "docker" (default): execute vunnel in a docker container # - "local": execute vunnel on the host from what is in your $PATH executor: docker # the docker image to use when executing vunnel with executor=docker docker-tag: latest docker-image: ghcr.io/anchore/vunnel # generate additional provider configuration files based on the "vunnel list" command # same as -g ; GRYPE_DB_GENERATE_CONFIGS env var generate-configs: true # providers to exclude from the "vunnel list" command (only applies when generate-configs=true) exclude-providers: - centos # environment variables to set when executing vunnel env: {} # manually crafted provider configurations. (advanced use only) configs: [] pull: # the number of concurrent workers to use when pulling and processing data parallelism: 1 build: # where to place the built SQLite DB that is built from the "build" command # same as --dir; GRYPE_DB_BUILD_DIR env var dir: "./build" # the DB schema version to build # same as --schema-version; GRYPE_DB_BUILD_SCHEMA_VERSION env var schema-version: 5 # skip validation of the provider state skip-validation: false package: # this is the base URL that is referenced in the listing file created during the "package" command # same as GRYPE_DB_PACKAGE_PUBLISH_BASE_URL env var publish-base-url: "https://localhost:8080/grype/databases" # limit the providers to pull based off of this list. (empty list means pull all providers) provider-names: [] ```
标签:Anchore, Angular, CVE, DevSecOps, Go语言, GPT, Grype, NVD, 上游代理, 安全扫描, 数字签名, 数据库构建, 数据聚合, 日志审计, 时序注入, 测试覆盖率, 漏洞数据源, 漏洞管理, 程序破解, 请求拦截, 逆向工具