Skip to content

Add --enrich flag to expose syft's metadata enrichment during scan - #319

Merged
alex-vulncheck merged 3 commits into
mainfrom
2823-sbom-enrich-flag
Jul 24, 2026
Merged

Add --enrich flag to expose syft's metadata enrichment during scan#319
alex-vulncheck merged 3 commits into
mainfrom
2823-sbom-enrich-flag

Conversation

@alex-vulncheck

@alex-vulncheck alex-vulncheck commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • New --enrich flag on vulncheck scan that mirrors syft's own --enrich directive: a comma-separated scope list drawn from {all, golang, java, javascript, python} with syft's +scope / -scope prefix conventions. Off by default, so existing behaviour is preserved and no unexpected network calls happen.
  • When set, syft's per-language cataloger configs get the same fields flipped that syft's own CLI flips for --enrich, letting syft fetch license and package metadata from proxy.golang.org, Maven Central, NPM, and PyPI.
  • Hard-fail when --enrich is combined with --sbom-input-file (enrichment only applies during SBOM generation) or --offline (enrichment requires network access). Matches the "explicit error over silent no-op" pattern used elsewhere in scan.
  • Unit tests cover the config-building (empty → nil, all flips every scope, single scopes stay isolated, all,-scope excludes only that scope, none disables everything) and the scope-precedence rules (+scope / -scope beat all / none).
  • Flag help text and the scan flag table in README.md updated.

Why

Customers asked for a way to include richer package metadata (licenses in particular) in generated SBOMs. Syft already supports this via its --enrich directive; the CLI just wasn't exposing it. Adding a flag rather than always-on keeps the default offline-safe and avoids the extra runtime cost when the extra metadata isn't needed.

Test plan

  • go test ./pkg/bill/... passes (includes TestBuildSBOMConfig, TestEnrichmentScope)
  • go build ./... clean
  • vulncheck scan <dir> --sbom-only --enrich all --sbom-output-file out.json on a Go module populates .components[].licenses where a plain run does not
  • vulncheck scan -i <sbom> --enrich all prints --enrich has no effect when reading a pre-built SBOM via --sbom-input-file and exits non-zero
  • vulncheck scan <dir> --enrich all --offline prints --enrich requires network access and cannot be combined with --offline and exits non-zero
  • vulncheck scan --help shows the new flag with the mutual-exclusion notes

Adds an --enrich flag to `vulncheck scan` that mirrors syft's own
--enrich directive: a comma-separated scope list drawn from
{all, golang, java, javascript, python}, with the `+scope` / `-scope`
prefixes syft accepts. Off by default.

When set, syft's per-language cataloger configs get the same fields
flipped that syft's own CLI flips for --enrich, letting syft fetch
license and metadata info from proxy.golang.org, Maven Central,
NPM, and PyPI. This closes the customer ask for richer SBOM metadata
while keeping the default behaviour offline-safe (no network calls
unless the flag is set).

Implementation:

- New bill.SBOMOptions struct threaded through bill.GetSBOM so future
  toggles don't churn every caller.
- bill.buildSBOMConfig converts SBOMOptions.Enrich into a
  syft.CreateSBOMConfig with a customised pkgcataloging.Config.
  Returns nil when Enrich is empty so syft's own defaults still apply.
- bill.enrichmentScope reproduces syft's own precedence
  (explicit `+scope`/`-scope` beats `all`/`none`). Syft keeps the
  equivalent under an internal/ package we can't import.
- --enrich has no meaning when reading an existing SBOM via
  --sbom-input-file; scan hard-fails on the combination rather than
  silently no-op'ing (same pattern as the existing --include-cpes
  online-mode check).
- New i18n.C.FlagEnrich entry keeps the help text where every other
  scan flag's help text lives.

Testing:

- TestBuildSBOMConfig locks in the mapping: empty Enrich yields nil,
  `all` flips every language, single scopes stay isolated, `all,-java`
  excludes only Java, `none` disables everything.
- TestEnrichmentScope covers the precedence rules exhaustively.
- Manually verified end-to-end: scanning a tiny go module without
  --enrich returns 0 licenses; with --enrich all, syft fetches
  license data remotely and populates it. Also verified the
  --enrich + --sbom-input-file mutual-exclusion errors correctly.
Enrichment fetches metadata over the network (proxy.golang.org, Maven
Central, NPM, PyPI); --offline exists so the CLI can run without any
network access. Combining the two silently produces an SBOM missing
the metadata the user opted in for. Hard-fail the combination with a
clear message, matching the pattern used for the existing --enrich +
--sbom-input-file check.

Updates the flag's help text to state both mutual-exclusion rules
inline. Adds the flag to the scan command's flag table in README.md.
Syft accepts additional scope names per language beyond the ones its
--help publicises: `go` alongside `golang`, `node` and `npm` alongside
`javascript`, `maven` alongside `java` (internal/task/package_tasks.go).
The previous implementation only matched the primary names, so a user
typing `--enrich node` or `--enrich maven` got a silent no-op even
though syft would have honoured either.

Refactors enrichmentScope to accept a variadic alias list and updates
the per-language dispatch in buildSBOMConfig to pass every alias syft
accepts. Also picks up golang.UsePackagesLib, which syft flips under
--enrich golang and which we were previously missing (a no-op in
practice because syft's default is already true, but included for
completeness).

Extends TestBuildSBOMConfig with alias assertions and a UsePackagesLib
check.
@alex-vulncheck
alex-vulncheck merged commit b6d0c7f into main Jul 24, 2026
12 checks passed
@alex-vulncheck
alex-vulncheck deleted the 2823-sbom-enrich-flag branch July 24, 2026 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants