|
| 1 | +<!-- |
| 2 | + SPDX-License-Identifier: Apache-2.0 |
| 3 | + SPDX-FileCopyrightText: 2021 The Elixir Team |
| 4 | +--> |
| 5 | + |
| 6 | +# Software Bill of Materials |
| 7 | + |
| 8 | +A Software Bill of Materials (SBoM) is a structured inventory of the components that make up a software system. This guide explains what SBoMs are, why they matter, and how to generate them for Elixir projects. |
| 9 | + |
| 10 | +## What is an SBoM? |
| 11 | + |
| 12 | +An SBoM is a formal, machine-readable record of all components in a piece of software. Think of it as a detailed ingredient list for your application. A typical SBoM includes: |
| 13 | + |
| 14 | + * **Dependencies**: all libraries and packages your project uses |
| 15 | + * **Versions**: the exact version of each component |
| 16 | + * **Source locations**: where each component was obtained (Hex, GitHub, etc.) |
| 17 | + * **Checksums**: cryptographic hashes to verify integrity |
| 18 | + * **Licensing information**: the license under which each component is distributed |
| 19 | + |
| 20 | +Two widely adopted standards exist for SBoM formats: |
| 21 | + |
| 22 | + * [CycloneDX](https://cyclonedx.org/): a lightweight standard designed for security contexts |
| 23 | + * [SPDX](https://spdx.dev/): a more comprehensive standard originally focused on licensing |
| 24 | + |
| 25 | +Both formats are machine-readable (JSON, XML) and designed to be consumed by automated tooling. |
| 26 | + |
| 27 | +> #### SBoM is an inventory, not a certification {: .info} |
| 28 | +> |
| 29 | +> An SBoM does not claim that software is secure, compliant, or free of vulnerabilities. |
| 30 | +> It simply provides a detailed inventory that enables further analysis. Security and |
| 31 | +> compliance assessments are performed by separate tools that consume the SBoM. |
| 32 | +
|
| 33 | +## Why generate SBoMs? |
| 34 | + |
| 35 | +There are three main reasons to generate SBoMs for your projects. |
| 36 | + |
| 37 | +### Vulnerability analysis |
| 38 | + |
| 39 | +When a security vulnerability (CVE) is discovered in a library, you need to quickly determine if your projects are affected. SBoMs make this possible by providing a complete inventory of your dependencies. |
| 40 | + |
| 41 | +Tools like [OWASP Dependency-Track](https://dependencytrack.org/) continuously monitor your SBoMs against vulnerability databases. When a new CVE is published, you get notified if any of your projects use the affected component. |
| 42 | + |
| 43 | +Without an SBoM, answering "are we affected by CVE-2024-XXXXX?" means manually checking each project, which is time-consuming and error-prone. |
| 44 | + |
| 45 | +### Regulatory requirements |
| 46 | + |
| 47 | +SBoMs are required by some regulations and procurement policies: |
| 48 | + |
| 49 | + * **US Executive Order 14028** (2021) requires SBoMs for certain software supplied to the U.S. federal government, particularly for designated critical software |
| 50 | + * **EU Cyber Resilience Act** introduces requirements for component inventories (commonly fulfilled using SBoMs) for products with digital elements placed on the EU market |
| 51 | + * **Safety-critical industries** (medical devices, automotive, aerospace) often require detailed component inventories as part of certification |
| 52 | + |
| 53 | +Customers and partners may also request SBoMs as part of their own compliance efforts. |
| 54 | + |
| 55 | +### License compliance |
| 56 | + |
| 57 | +Every dependency in your project comes with a license. An SBoM provides a starting point for license review by listing the declared license for each package. This helps you: |
| 58 | + |
| 59 | + * Get an overview of licenses in your dependency tree |
| 60 | + * Flag packages that may need closer review |
| 61 | + * Support due diligence for acquisitions, audits, or legal review |
| 62 | + |
| 63 | +Note that package-level license information (as provided by mix_sbom) reflects what the package declares, not necessarily all licenses present in its source files. For thorough license compliance, file-level scanning tools like ORT provide deeper analysis. |
| 64 | + |
| 65 | +## Generating SBoMs with mix_sbom |
| 66 | + |
| 67 | +[mix_sbom](https://github.com/erlef/mix_sbom) is an EEF project that generates CycloneDX SBoMs for Elixir projects. |
| 68 | + |
| 69 | +### Installation |
| 70 | + |
| 71 | +There are several ways to install mix_sbom: |
| 72 | + |
| 73 | + * **As a project dependency**: add `sbom` to your `mix.exs` |
| 74 | + * **As a global escript**: run `mix escript.install hex sbom` (requires Elixir 1.19.4+) |
| 75 | + * **As a standalone binary**: download from the [releases page](https://github.com/erlef/mix_sbom/releases) |
| 76 | + |
| 77 | +The standalone binary is useful for CI environments or when you don't want to modify your project's dependencies. It requires no local Elixir or Erlang installation. |
| 78 | + |
| 79 | +### Basic usage |
| 80 | + |
| 81 | +To generate an SBoM for your project using the standalone binary: |
| 82 | + |
| 83 | +```console |
| 84 | +$ mix_sbom cyclonedx /path/to/your/project |
| 85 | +``` |
| 86 | + |
| 87 | +This creates a `bom.cdx.json` file in CycloneDX format containing your project's complete dependency tree. |
| 88 | + |
| 89 | +### Common options |
| 90 | + |
| 91 | +The most useful options are: |
| 92 | + |
| 93 | + * `-o, --output PATH`: specify the output file (default: `bom.cdx.json`) |
| 94 | + * `-t, --format FORMAT`: output format (`json`, `xml`, or `protobuf`) |
| 95 | + * `-s, --schema VERSION`: CycloneDX schema version |
| 96 | + |
| 97 | +For example, to generate an XML format SBoM: |
| 98 | + |
| 99 | +```console |
| 100 | +$ mix_sbom cyclonedx --format xml --output sbom.xml /path/to/project |
| 101 | +``` |
| 102 | + |
| 103 | +## CI integration |
| 104 | + |
| 105 | +For automated SBoM generation, mix_sbom provides a GitHub Action: |
| 106 | + |
| 107 | +```yaml |
| 108 | +name: Generate SBoM |
| 109 | +on: |
| 110 | + release: |
| 111 | + types: [published] |
| 112 | + |
| 113 | +jobs: |
| 114 | + sbom: |
| 115 | + runs-on: ubuntu-latest |
| 116 | + steps: |
| 117 | + - uses: actions/checkout@v4 |
| 118 | + - uses: erlef/mix_sbom@v0 |
| 119 | + with: |
| 120 | + path: "." |
| 121 | + format: "json" |
| 122 | + - uses: actions/upload-artifact@v4 |
| 123 | + with: |
| 124 | + name: sbom |
| 125 | + path: bom.cdx.json |
| 126 | +``` |
| 127 | +
|
| 128 | +This workflow generates an SBoM whenever you publish a release and uploads it as a build artifact. See the [action's documentation](https://github.com/erlef/mix_sbom) for additional options. |
| 129 | +
|
| 130 | +## Deeper analysis with ORT |
| 131 | +
|
| 132 | +mix_sbom provides package-level license information based on what each dependency declares. However, some compliance workflows require file-level scanning. A package might declare an MIT license but contain individual files under different licenses, or include vendored code with its own licensing terms. |
| 133 | +
|
| 134 | +The [OSS Review Toolkit (ORT)](https://oss-review-toolkit.org/) addresses this by scanning actual source files for license headers and copyright notices. ORT supports Mix projects and provides: |
| 135 | +
|
| 136 | + * **File-level license detection**: scans source code for license texts and SPDX identifiers |
| 137 | + * **Copyright holder identification**: extracts copyright notices from files |
| 138 | + * **Policy enforcement**: define rules for allowed and denied licenses |
| 139 | + * **Multi-ecosystem support**: analyze projects that span multiple package managers |
| 140 | +
|
| 141 | +For organizations with strict compliance requirements, ORT complements mix_sbom by providing the deeper analysis needed for thorough license audits. |
| 142 | +
|
| 143 | +See the [ORT Mix plugin documentation](https://oss-review-toolkit.org/ort/docs/plugins/package-managers/Mix) for details. |
| 144 | +
|
| 145 | +## Next steps |
| 146 | +
|
| 147 | + * [CycloneDX Specification](https://cyclonedx.org/specification/overview/): learn more about the SBoM format |
| 148 | + * [OWASP Dependency-Track](https://dependencytrack.org/): continuous SBoM analysis platform |
| 149 | + * [mix_sbom documentation](https://hexdocs.pm/sbom): full documentation and advanced options |
0 commit comments