Aditya Sirish A YelgundhalliandAlex Goodman ceba249724 Add support for programmatically listing catalogers (#5046)
* refactor(task): describe catalogers before/without construction

- add names and selectors to task factories
- separate cataloger creation from task creation
- add explicit names to cataloger registrations
- verify factory metadata matches created tasks

Signed-off-by: Aditya Sirish A Yelgundhalli <ayelgundhall@bloomberg.net>

* feat(exp): expose package cataloger capabilities

Add experimental public types for package cataloger capability data.

Add PackageCatalogerCapabilities to load, sort, and return the embedded capability descriptions. Copy mutable data before returning it.

Cache the parsed internal capability document to avoid repeated YAML parsing.

Signed-off-by: Aditya Sirish A Yelgundhalli <ayelgundhall@bloomberg.net>

* feat(exp): add selectable package cataloger tasks

Add an internal model that describes and selects package catalogers before construction.

Expose experimental APIs that list selected catalogers and their capabilities from CreateSBOMConfig.

Delay cataloger construction until task execution.

Signed-off-by: Aditya Sirish A Yelgundhalli <ayelgundhall@bloomberg.net>

* refactor: share one cataloger selection path between CreateSBOM and exp

- drop `CreateSBOMConfig.CatalogerTasks()` and `CatalogerSelectionRequest()`, which leaked `internal/task` types through the stable `syft` API
- `syft/exp` now reaches config selection through an internal hook instead
- `exp.ListCatalogers` / `exp.CatalogerInfo` take a `source.Description` and go through the same source-aware selection as a scan, so listings match what would run (previously a source-less listing returned every cataloger and removal-only selections returned none)

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* refactor: run package catalogers through a single construct-and-run path

- `task.CatalogPackages` constructs the cataloger, runs it, and applies the usual post-processing (FoundBy, CPEs, license content rules, compliance)
- `NewPackageTask(cfg, CatalogerTask)` is the only scan task constructor, used by both the default factories and `CreateSBOM`; `NewPackageTaskFromFactory` is removed
- `exp.Task.Catalog` now returns the same post-processed packages a scan would, instead of raw cataloger output
- a nil constructed cataloger is an error on every path (previously silently skipped on the factory path), and a constructed name that differs from the task name is logged

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* refactor: package cataloger decorators and a single capabilities model

- `CatalogerTask` is replaced by unexported `pkg.Cataloger` decorators: `SelectablePackageCataloger`, `LazyPackageCataloger`, and `AlwaysEnabled`
- CreateSBOM and exp share one selection path (`task.SelectPackageCatalogers`)
- the capabilities.yaml model moves to `syft/exp/capabilities` and is used by `internal/capabilities` directly (`Parser.ParserFunction` is now `Parser.Function`)
- `exp.CatalogerInfo` returns capabilities entries as written in the YAML; catalogers without an entry are omitted

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* refactor(exp): return package catalogers instead of tasks

- `exp.Task` and its options are replaced by `pkg.Cataloger` decorators: `SelectablePackageCataloger`, `LazyPackageCataloger`, and `AlwaysEnabled`
- `SelectCatalogerTasks` is now `SelectPackageCatalogers`, and `SelectedPackageCatalogers(cfg, src)` returns what a scan would run
- `CatalogPackages(ctx, cfg, resolver, c)` applies CreateSBOM's post-processing using the given config; previously exp always used syft's default config, so settings like CPE generation and compliance were ignored
- calling `Catalog` directly still returns raw results, same as any syft cataloger

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* feat(exp): describe catalogers via capabilities.Provider, route cataloger info through exp

- add `capabilities.Provider` so a package cataloger can describe itself without being constructed; selectable catalogers answer it from capabilities.yaml for built-ins
- `exp.PackageCatalogerCapabilities(c)` describes one cataloger, the all-entries listing is now `AllPackageCatalogerCapabilities`
- `exp.CatalogerInfo` describes the selected catalogers rather than joining names against the yaml
- `syft cataloger info` selection goes through `exp.CatalogerInfo`, so it uses the same selection path as a scan

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* refactor(exp): narrow to listing and describing what a scan would run

- drop `exp.CatalogPackages`: scan-equivalent results depend on what `CreateSBOM` does around each cataloger (context setup, panic recovery, unknowns, cross-cataloger post-processing), so run a subset via the config selection + `CreateSBOM` instead
- drop `exp.SelectPackageCatalogers`, `SelectablePackageCataloger` and `AlwaysEnabled`; custom catalogers go through `CreateSBOMConfig.WithCatalogers`, so there is one selection path and one meaning per selection request
- `ListCatalogers` -> `ListPackageCatalogers`, `CatalogerInfo` -> `SelectedPackageCatalogerCapabilities` (documented as raw definitions, conditions not evaluated)
- only syft's own catalogers are described from capabilities.yaml; custom catalogers need `capabilities.Provider`, even if they reuse a built-in name. Reported selectors are the selection tags
- the capabilities lookup and deep copy live in `internal/capabilities`, which no longer imports `internal/task`, so the lookup hook is gone
- fix: selecting catalogers for a config no longer rewrites the config's `CatalogerSelection` slices, which made a list-then-scan with `-default` remove the wrong catalogers

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* refactor(exp): keep the capabilities document model internal

- `Document`, `CatalogerConfigEntry`, `CatalogerConfigFieldEntry` and `ApplicationConfigField` move from `syft/exp/capabilities` to `internal/capabilities`; nothing in `syft/exp` returns them, they only describe the yaml file and the generator
- `syft/exp/capabilities` is now just `CatalogerEntry` (and its parts) plus `Provider`

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* fix(task): construct each package cataloger once per scan task

Nested archive cataloging re-runs every package task per extracted archive, so lazily constructed
catalogers were being built again for each archive, resetting per-instance state and repeating
construction warnings and errors.

- `NewPackageTask` now memoizes lazy construction: the first run builds the cataloger, later runs
  reuse it (or the same construction error)
- selection and listing still never construct anything

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* docs(exp): note that the archive task is not listed

When nested archive cataloging is on, the scan also runs an archive task that re-runs the listed package catalogers inside archives. Say so in the `SelectedPackageCatalogers` and `ListPackageCatalogers` docs.

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* fix(exp): let a cataloger reference decide always-enabled

A cataloger returned by `SelectedPackageCatalogers` carries its always-enabled mark, so passing it
back through `WithCatalogers` could turn always-enabled on but never off.

- the reference's `AlwaysEnabled` now sets the mark either way (`task.AlwaysEnabled` takes the value)
- `SelectedPackageCatalogers` docs note returned catalogers are bound to the config they were
  selected from and are meant for listing and describing, not for adding to another config

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* docs(exp): say which catalogers implement capabilities.Provider

Only catalogers returned by `exp.SelectedPackageCatalogers` implement it; `exp.LazyPackageCataloger` does not.

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* refactor(exp): check the capabilities load error without copying entries

`SelectedPackageCatalogerCapabilities` only needs to know whether capabilities.yaml loads, so call `LoadDocument` instead of `Packages`, which deep-copies every entry.

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* refactor(task): word lazy cataloger errors as package cataloger errors

Construction errors and the name mismatch warning still referred to a cataloger task. They now name the package cataloger and log it under a `cataloger` field like the surrounding logs.

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* fix(exp): apply the scan's config checks when selecting catalogers

`SelectedPackageCatalogers` went straight to selection, so it could list catalogers for a config that
`CreateSBOM` would reject, and errored on a nil config that `CreateSBOM` treats as the defaults.

- a nil config now means `DefaultCreateSBOMConfig()`
- invalid configs return the same `invalid configuration` error as a scan
- a selection that leaves no package or file catalogers returns `no catalogers selected`

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* style(task): fix import order in package task factory test

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* feat(exp): let a lazy package cataloger describe itself

- `exp.LazyPackageCataloger` takes an optional `capabilities.CatalogerEntry`, so a lazy custom cataloger can be described without wrapping it (a wrapper hid it from construct-once and brought back per-archive construction)
- the doc now says a scan constructs it once and reuses it for nested archives

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* refactor: check the scan config and empty selection in one place

`CreateSBOM` and the `syft/exp` bridge share `checkedConfig`, and `selectCatalogers` returns the "no catalogers selected" error, replacing the three copies of that check.

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* refactor(exp): take optional lazy cataloger settings as a config

`exp.LazyPackageCataloger(name, factory, cfg *LazyPackageCatalogerConfig)` replaces the variadic entry. nil means nothing set; `DefaultLazyPackageCatalogerConfig().WithCapabilities(entry)` describes the cataloger. The config is read once at construction, so later changes don't reach the cataloger, and new optional settings become builder methods instead of new constructors.

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

---------

Signed-off-by: Aditya Sirish A Yelgundhalli <ayelgundhall@bloomberg.net>
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
Co-authored-by: Alex Goodman <wagoodman@users.noreply.github.com>
2026-12-03 16:36:46 -05:00
2025-12-17 18:00:38 +00:00
2020-06-24 14:37:00 -04:00
2026-05-18 11:59:55 -04:00
2024-10-11 05:17:01 -04:00

Cute pink owl syft logo

Syft

A CLI tool and Go library for generating a Software Bill of Materials (SBOM) from container images and filesystems. Exceptional for vulnerability detection when used with a scanner like Grype.

 Validations   GitHub release   GitHub go.mod Go version   License: Apache-2.0   Join our Discourse   Follow on Mastodon 

syft-demo

Features

Tip

New to Syft? Check out the Getting Started guide for a walkthrough!

Installation

The quickest way to get up and going:

curl -sSfL https://get.anchore.io/syft | sudo sh -s -- -b /usr/local/bin

Tip

See Installation docs for more ways to get Syft, including Homebrew, Docker, Scoop, Chocolatey, Nix, and more!

The basics

See the packages within a container image or directory:

# container image
syft alpine:latest

# directory
syft ./my-project

To get an SBOM, specify one or more output formats:

# SBOM to stdout
syft <image> -o cyclonedx-json

# Multiple SBOMs to files
syft <image> -o spdx-json=./spdx.json -o cyclonedx-json=./cdx.json

Local containers-storage images

On Linux, syft can scan images from a local containers-storage store (e.g. built with Buildah or Podman) when asked explicitly; plain image references never look there:

syft --from containers-storage localhost/myimage:latest

# rootless stores must be read from inside the builder's user namespace
podman unshare syft --from containers-storage localhost/myimage:latest

This is included in the Linux release binaries. When building from source, add -tags containers_image_openpgp,exclude_graphdriver_btrfs.

Tip

Check out the Getting Started guide to explore all of the capabilities and features.

Want to know all of the ins-and-outs of Syft? Check out the CLI docs, configuration docs, and JSON schema.

Contributing

We encourage users to help make these tools better by submitting issues when you find a bug or want a new feature. Check out our contributing overview and developer-specific documentation if you are interested in providing code contributions.

Syft development is sponsored by Anchore, and is released under the Apache-2.0 License. The Syft logo by Anchore is licensed under CC BY 4.0

For commercial support options with Syft or Grype, please contact Anchore.

Come talk to us!

The Syft Team holds regular community meetings online. All are welcome to join to bring topics for discussion.

S
Description
A CLI tool and Go library for generating a Software Bill of Materials (SBOM) from container images and filesystems.
Readme Apache-2.0
198 MiB
Languages
Go 98.6%
Shell 0.9%
Python 0.4%