Skip to main content

Choppr

Choppr is a CLI tool to filter unused components out of an SBOM using strace results.

Choppr refines the components in a Software Bill of Materials (SBOM). It does not replace SBOM generation tools. Mainly, Choppr analyses a build or runtime to verify which components are used, and remove the SBOM components not used. Starting with file accesses, it works backwards from how an SBOM generation tool typically would. For example SBOM generators use the yum database to determine which packages yum installed. Choppr looks at all the files accessed and queries sources like yum to determine the originating package.

Other intended results include:

  • Reducing installed components. Size is optimized. The number of vulnerabilities is reduced. The less tools available to an attacker the better.
  • Creating a runtime container from the build container
  • Detecting files without corresponding SBOM components

Approaches

How to use Choppr depends on your project and needs. Consider the following use cases and their recommended approaches.

Build an SBOM of a software product

The user provides the required content. Choppr determines which components were used during the build. The exclude list tells Choppr to remove components like CMake, because the user is certain no CMake software was built into their product. An list of unused packages is generated that can be used to automate removal. Building again after removing these components verifies no required components were lost.

Create a runtime image and runtime SBOM from a build image

Choppr uses a multistage build to ADD the files used. Optionally metadata such as the yum database can be kept. The additional include list can be used to specify dynamically linked libraries, necessary services, or any other necessary components that were not exercised during build. This will also be reflected in the SBOM components.

Create a runtime SBOM from a runtime image

Similar to analyzing a build, Choppr can analyze a runtime.

If this is used to describe a delivery, it should be merged with the Build SBOM.


References:

Installation

pip install choppr

Usage

Usage: choppr [OPTIONS] OPERATING_MODE:{run|cache}

╭─ Arguments ──────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ *    operating_mode      OPERATING_MODE:{run|cache}  The operating mode to use [required]                            │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Options ────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --config          -f      FILE  The configuration file to use [default: choppr.yml]                                  │
│ --input-sbom      -i      FILE  The SBOM to process and filter the components of                                     │
│ --strace-results  -s      FILE  The output file created when running strace on your build or runtime executable      │
│ --output-sbom     -o      FILE  The file to write the chopped SBOM to                                                │
│ --log             -l      FILE  The log file to write to [default: choppr.log]                                       │
│ --verbose         -v            Enable debug logging                                                                 │
│ --version                                                                                                            │
│ --help                          Show this message and exit.                                                          │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

Configuration

The default path choppr will look for the configuration is choppr.yml in the current working directory.

Example Configuration
---
main_component:
  type: application
  name: ffmpeg
  version: 8.1.2
  url: https://github.com/FFmpeg/FFmpeg.git
  supplier: FFmpeg
  licenses:
    - license:
        name: LGPL-2.1-or-later

input_files:
  sbom: ffmpeg.cdx.json
  strace_results: ffmpeg-strace.txt

repositories:
  rpm:
    - url: https://rocky-linux-us-west4.production.gcp.mirrors.ctrliq.cloud/pub/rocky/8.10/AppStream/x86_64/os/
    - url: http://mirror.siena.edu/rocky/8.10/BaseOS/x86_64/os/
    - url: https://mirrors.iu13.net/rocky/8.10/extras/x86_64/os/

options:
  strace_regex_excludes:
    - ^.*ffmpeg.*$
    - ^.*\.(c|cpp|cxx|h|hpp|o|py|s)$
    - ^/usr/share/pkgconfig$
    - ^/tmp$
    - ^bin$
    - ^.*\.git.*$
    - ^.*(\.\.)+.*$
    - ^.*(CMakeFiles.*|\.cmake)$

Variables

main_component:
  type: str # required - default: library
  name: str # required
  version: str # required
  url: HttpUrl # required - project website or repository URL, used only for PURL inference
  supplier: str # required
  namespace: str # optional - used for purl generation
  bom_ref: str # optional - auto-generated from purl if not supplied
  purl: str # optional - auto-generated if not supplied (format: pkg:<purl_type>/<namespace>/<name>@<version>)
  cpe: str # optional - auto-generated for non-common purl types if not supplied
  licenses: # list[DisjunctiveLicense] required - list of licenses
    - license:
        name: str # optional - license name (required if id not provided)
        id: str # optional - SPDX license ID (required if name not provided)
        url: str # optional - URL to license text

input_files:
  sbom: Path
  strace_results: Path | None
  cache_archive: Path | None

repositories:  # dict[PurlType, list[Repository]]
  _purl_type_:  # PurlType
    - url: HttpUrl | None
      urls:  # list[HttpUrl] | None
        - ...
      credentials:  # Credentials | None
        username: str | None
        user_env: str | None
        pass_env: str | None
      certificate: Path | None
    ...
  deb: # Debian repositories have extra configuration beyond the standard configuration above
    - url: ...
      credentials: ...
      certificate: ...
      distributions:
        - name: str
          components:  # list[str]
            - main
            - security

output_files:  # OutputFiles | None
  cache_archive: Path | None
  excluded_components: # dict[PurlType, ExcludedPackageFile] | None
    _purl_type_: # PurlType
      file: Path
      component_format: str | None
    ...
  sbom: Path | None

options:
  allow_partial_filename_match: bool
  allow_version_mismatch: bool
  allowlist:  # dict[PurlType, PackagePattern]
    _purl_type_:  # PurlType
      - name: regex
        version: regex
  archive_cache: bool
  cache_dir: Path
  cache_timeout: timedelta | bool
  clear_cache: bool
  delete_excluded: bool
  denylist:  # dict[PurlType, PackagePattern]
    _purl_type_:  # PurlType
      - name: regex
        version: regex
  http_limits:
    retries: PositiveInt
    retry_interval: PositiveFloat
    timeout: PositiveFloat
  keep_essential_os_components: bool
  recursion_limit: PositiveInt
  sort_sbom: bool
  strace_regex_excludes: list[regex]

Common Types

PurlType

The purl type, as defined in the package URL specification.

The list of available options can be found here.

Type: str

Input Files

sbom

The SBOM to process and filter the components of with Choppr.

This file is expected to be a JSON file in the CycloneDX format.

Type: Path

Example Usage:

imput_files:
  sbom: my-awesome-sbom.cdx.json
strace_results

The path to the output file created when running strace on your build or runtime executable.

This must be provided when operating_mode is set to run.

This file can be creating using the following command to wrap your build script or runtime executable. The strace tool must be installed on your system separately from choppr.

strace -f -e trace=file -o "strace_output.txt" <build script/runtime executable>

Type: Path | None

Default: None

Example Usage:

input_files:
  strace_results: strace_output.txt
cache_archive

The path for the cache archive to load to avoid pulling cache data again, or when offline.

Type: Path | None

Default: None

Example Usage:

input_files:
  cache_archive: /backup/choppr-cache.tar.gz

Repositories

Type: dict[PurlType, list[Repository]]

To obtain the list of repositories on your system, use one of the following commands:

# For RHEL 8 and later
dnf repolist --verbose

# For RHEL 7 and earlier
yum repolist --verbose

# For Debian
cat /etc/apt/sources.list /etc/apt/sources.list.d/*

With the output from one of these commands, you should be able to find the URLs to the repositories used on your system.

Repository

The URL for a repository, or multiple repository URLs, paired with optional credentials and/or a certificate.

Debian repositories have an extra distributions keyword.

Type:

# You must provide a url or a list of urls using one or both of the following keys
url: HttpUrl | None
urls: list[HttpUrl] | None
credentials: Credentials | None
certificate: Path | None
# Debian ONLY
distributions: list[DebianDistribution]

Example Usage:

repositories:
  rpm:
    - url: http://public.repo.com
    - url: http://private.repo.com
      credentials:
        username: repouser
        pass_env: PRIVATE_REPO_PASSWORD
      certificate: /my/private/repo/cert.pem
    - urls:
        - http://private.repo.com/base
        - http://private.repo.com/updates
        - http://private.repo.com/security
      credentials:
        username: repouser
        pass_env: PRIVATE_REPO_PASSWORD
    ...
  deb:
    - url: http://archive.ubuntu.com/ubuntu
      distributions:
        - name: jammy
          components:
            - main
            - security
            ...
        ...
    ...
  ...
Credentials

The credentials to use when accessing the repository.

If you provide user_env, it will override the value of username. You only need to provide one or the other.

Type:

username: str
user_env: str
pass_env: str
DebianDistribution

Distribution information for a Debian repository.

Type:

name: str
components: list[str]

Default:

name:  # This is required, and has no default
components:
  - main
  - restricted
  - universe
  - multiverse

Output Files

cache_archive

The path to write the cache archive to that can be used later as an input.

Type: Path | None

Default: None

Example Usage:

output_files:
  cache_archive: /backup/choppr-cache.tar.gz
excluded_components

The paths to write excluded components to using the optionally provided format when writing components to the list.

Type: dict[PurlType, ExcludedComponentsFile]

Default:

_purl_type_:
  file: "choppr-excluded-components-<purl_type>.txt"
  component_format: "<excluded_component_format>"
...

For excluded_component_format the default value is {name}={version} except for NPM, and RPM. Those are as follows:

NPM: "{name}@{version}"
RPM: "{name}-{version}"

Example Usage:

output_files:
  excluded_components:
    deb:
      file: excluded_deb_components.csv
      component_format: "{name},{version}
sbom

The path to write the chopped SBOM to.

By default it outputs to the same folder as the input sbom, using the same filename, with chopped prepended.

Type: Path

Default: chopped-<input_sbom>

Example Usage:

output_files:
  sbom: chopped-sbom.cdx.json

Options

allow_partial_filename_match

Allow partial matching for filenames when comparing strace files to files provided by remote repository packages.

This may be useful when symlinks are used for libraries. This is currently only implemented for RPMs.

Type: bool

Default: false

Example Usage:

options:
  allow_partial_filename_match: true
allow_version_mismatch

Allow version numbers to be mismatched when comparing SBOM packages to remote repository packages.

Type: bool

Default: false

Example Usage:

options:
  allow_version_mismatch: true
allowlist

A dictionary with packages to always keep in the SBOM.

The keys are purl types, and the values are a list of packages. A package has two members, name and version, both are regex patterns.

Type:

allowlist: # dict[PurlType, list[PackagePattern]]
  _purl_type_: # str (deb, npm, rpm, ...)
    - name: regex
      version: regex
    ...
  ...

Default: {}

Example Usage:

options:
  allowlist:
    deb:
      - name: ".*"
        version: ".*"
    generic:
      - name: "^python$"
        version: "^3.10"
archive_cache

Enable archive_cache to archive the cache directory when Choppr finishes running in run mode.

This has no effect in cache mode, as the archive will always be created in that mode.

Type: bool

Default: false

Example Usage:

options:
  archive_cache: true
cache_dir

The path for the cache directory where Choppr will output temporary and downloaded files.

Type: Path

Default: ./.cache/choppr

Example Usage:

options:
  cache_dir: /tmp/choppr
cache_timeout

The timeout for local cache files, like DEB packages, that aren't traced to a checksum, like RPM packages.

Expects a number followed by a unit (d = days, h = hours, m = minutes, s = seconds).

Type: str | bool

Default: 7d

Example Usage:

options:
  cache_timeout: 24h
clear_cache

Enable clear_cache to delete the cache directory when Choppr finishes running.

Type: bool

Default: false

Example Usage:

options:
  clear_cache: true
delete_excluded

Disable delete_excluded to keep components that are discovered to be unnecessary and marked as excluded.

Type: bool

Default: true

Example Usage:

options:
  delete_excluded: false
denylist

A dictionary with packages to always remove from the SBOM.

The keys are purl types, and the values are a list of packages. A package has two members, name and version, both are regex patterns.

Type:

denylist: # dict[PurlType, list[PackagePattern]]
  _purl_type_: # str (deb, npm, rpm, ...)
    - name: regex
      version: regex
    ...
  ...

Default: {}

Example Usage:

options:
  denylist:
    deb:
      - name: "cmake"
        version: "3.22"
    npm:
      - name: ".*"
        version: ".*"
http_limits

Limits to enforce when performing HTTP requests within Choppr.

  • retries - The number of times to retry the request if it fails
  • retry_interval - The number of seconds to wait before retrying the request
  • timeout - The number of seconds to wait for a request to complete before timing out

Type:

http_limits:  # HttpLimits
  retries: PositiveInt
  retry_interval: PositiveFloat
  timeout: PositiveFloat

Default:

http_limits:
  retries: 3
  retry_interval: 5
  timeout: 60

Example Usage:

options:
  http_limits:
    retries: 10
    retry_interval: 30
    timeout: 300
keep_essential_os_components

Keep components that are essential to the operating system, to include the operating system component.

Type: bool

Default: false

Example Usage:

options:
  keep_essential_os_components: true
recursion_limit

A positive integer that will limit the number of recursive calls to use when checking for nested package dependencies.

Type: PositiveInt

Default: 10

Example Usage:

options:
  recursion_limit: 20
sort_sbom

Sort the output SBOM so that the elements are in the order defined in the schema.

Type: bool

Default: false

Example Usage:

options:
  sort_sbom: true
strace_regex_excludes

An array of regex strings, used to filter the strace input. The example below shows some of the recommended regular expressions.

Type: list[str]

Default: []

Example Usage:

options:
  strace_regex_excludes:
    - "^.*project-name.*$"              # Ignore all files containing the project name to exclude source files
    - "^.*\.(c|cpp|cxx|h|hpp|o|py|s)$"  # Ignore source, header, object, and script files
    - "^/usr/share/pkgconfig$"          # Ignore pkgconfig, which is included/modified by several RPMs
    - "^/tmp$"                          # Ignore the tmp directory
    - "^bin$"                           # Ignore overly simple files, that will be matched by most RPMs
    - "^.*\.git.*$"                     # Ignore all hidden git directories and files
    - "^.*(\.\.)+.*$"                   # Ignore all relative paths containing '..'
    - "^.*(CMakeFiles.*|\.cmake)$"      # Ignore all CMake files

Specificaitons for developers

Metadata

Release files for choppr 1.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for choppr 1.4.0
File Size Uploaded Provenance Actions
choppr-1.4.0.tar.gz 57.4 kB Without provenance Details for choppr-1.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for choppr 1.4.0
File Interpreter ABI Platform Actions
choppr-1.4.0-py3-none-any.whl Python 3 none any Details for choppr-1.4.0-py3-none-any.whl

Total release size: 132.0 kB

Release files / choppr-1.4.0.tar.gz

Download URL choppr-1.4.0.tar.gz
Size 57.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c50b1fd849d5c123af0a5e2e034bdc92be44e6a80af323132f47065c29842aa7
BLAKE2b-256 checksum
How to use checksums
affab2a3d90f83e0ed2dec0e0ab8619f7df2e122ef7d518b17f120cf1afbcc12
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / choppr-1.4.0-py3-none-any.whl

Download URL choppr-1.4.0-py3-none-any.whl
Size 74.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
810f2f1b52efc1da5bcc30d0383e28a141b6a634194af699ba63adda3e461a85
BLAKE2b-256 checksum
How to use checksums
22c634c0465e07b4cd47bff038014a32594822fc9277a84414b63544528e0b76
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for choppr 1.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page