nikstur/bombon

GitHub: nikstur/bombon

为 Nix 包自动生成符合国际合规标准的 CycloneDX 软件物料清单(SBOM),助力软件供应链透明化与安全审计。

Stars: 140 | Forks: 12

# Bombon 为 Nix 包自动构建 CycloneDX 软件物料清单 (SBOM)! Bombon 生成旨在符合以下标准的 CycloneDX v1.5 SBOM: - 德国联邦信息安全办公室 (BSI) 的[技术指南 TR-03183 v2.0.0][] - 美国[第 14028 号行政命令][] 如果您发现它们在任何方面不符合标准,请提交 issue! ## 入门指南 ### Flakes ``` nix flake init -t github:nikstur/bombon ``` 或者,手动将此内容复制到您仓库中的 `flake.nix` 中: ``` # 文件:flake.nix { inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; bombon.url = "github:nikstur/bombon"; bombon.inputs.nixpkgs.follows = "nixpkgs"; }; outputs = { self, nixpkgs, bombon }: let system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; in { packages.${system}.default = bombon.lib.${system}.buildBom pkgs.hello { }; }; } ``` ### Niv ``` niv init niv add nikstur/bombon ``` ``` # 文件:default.nix let sources = import ./nix/sources.nix { }; pkgs = import sources.nixpkgs { }; bombon = import sources.bombon { inherit pkgs; }; in bombon.buildBom pkgs.hello { } ``` ## 第三方打包的依赖项 Nixpkgs 中的某些语言生态系统(最显著的是 Rust 和 Go)会对依赖项进行 vendor(本地化打包)。这意味着并非每个依赖项都是独立的 derivation,因此 bombon 无法像记录“常规” Nix 依赖项那样记录它们的信息。不过,bombon 可以自动从名为 `bombonVendoredSbom` 的 passthru derivation 中,读取由其他工具(如 `cargo-cyclonedx`)为这些第三方打包的依赖项生成的 SBOM。 您可以使用 `passthruVendoredSbom.rust` 函数将 `bombonVendoredSbom` passthru derivation 添加到 Rust 包中: ``` myPackageWithSbom = bombon.passthruVendoredSbom.rust myPackage { inherit pkgs; }; ``` 或者使用 Flakes: ``` myPackageWithSbom = bombon.lib.${system}.passthruVendoredSbom.rust myPackage { inherit pkgs; }; ``` 基于这个新 derivation 构建的 SBOM 现在将包含第三方打包的依赖项。 ## 选项 `buildBom` 接受一个属性集作为选项。所有属性都是可选的: - `extraPaths`:一个 store 路径列表,用于额外包含进 SBOM 的考量中。当您构建镜像并丢弃其引用(例如使用 [`unsafeDiscardReferences`](https://nixos.org/manual/nix/stable/language/advanced-attributes#adv-attr-unsafeDiscardReferences)但仍希望其内容出现在 SBOM 中时,这非常有用。`extraPaths` 将作为主 derivation 的组件出现。 - `includeBuildtimeDependencies`:布尔标志,用于在输出中包含构建时的依赖项。 - `excludes`:一个正则表达式模式列表,用于从最终 SBOM 中排除匹配的 store 路径。 示例: ``` bombon.lib.${system}.buildBom pkgs.hello { extraPaths = [ pkgs.git ]; includeBuildtimeDependencies = true; excludes = [ "service" ]; } ``` `passthruVendoredSbom.rust` 也接受 `includeBuildtimeDependencies` 作为可选属性。 示例: ``` myPackageWithSbom = bombon.passthruVendoredSbom.rust myPackage { inherit pkgs; includeBuildtimeDependencies = true; }; ``` ## 贡献 在开发过程中,Nix Repl 是测试更改的一种便捷且快速的方法。 启动 repl,加载您的本地版 nixpkgs。 ``` nix repl ``` 在 repl 内部,加载 bombon flake 并为您感兴趣的包构建 BOM。 ``` :l . :b lib.x86_64-linux.buildBom python3 { } ``` 请记住,每次对任何源代码进行更改后,都要重新加载 bombon flake。 ## 致谢 使用 Nix 检索依赖项的方式深受 [Nicolas Mattia 的这篇博客文章](https://www.nmattia.com/posts/2019-10-08-runtime-dependencies.html)的影响。
标签:BSI TR-03183, CycloneDX, DevSecOps, EO 14028, Flakes, Go, GPT, Nix, NixOS, Nixpkgs, Ruby工具, Rust, SBOM, 上游代理, 人工智能安全, 合规性, 漏洞管理, 硬件无关, 网络流量审计, 自动化生成, 跌倒检测, 软件物料清单, 通知系统