sbomgen

Introduction

This tutorial illustrates how to create SBOMs from containers using the tern CLI.

Requirements & Dependencies

Installation

Install tern by running:

pip install tern

Verify installation by running:

tern -h

You should see:

usage: Tern [-h] [-q] [-l FILE] [-c] [-k] [-r] [-wd PATH] [-dr DRIVER_OPTION]
            [-v]
            {report,lock,debug} ...

    Tern is a container image component curation tool. Tern retrieves
    information about packages that are installed in a container image.
    Learn more at https://github.com/tern-tools/tern

positional arguments:
  {report,lock,debug}   Subcommands
    report              Create a BoM report. Run 'tern report -h' for report format options.
    lock                Create an annotated Dockerfile that will pin the information it finds. Use this option to help achieve a more repeatable container image build.
    debug               Debug pieces of operation by themselves. This is useful when debugging scripts entered into the command library or drivers used for mounting the container image layers.

optional arguments:
  -h, --help            show this help message and exit
  -q, --quiet           Silences the output to the terminal;Useful when logging behaviour unnecessary
  -l FILE, --log-file FILE
                        Provide a custom file to write logs to.
                        Useful when writing logs to a different location.
  -c, --clear-cache     Clear the cache before running
  -k, --keep-wd         Keep the working directory after execution. Useful when debugging container images
  -r, --redo            Repopulate the cache for found layers
  -wd PATH, --working-dir PATH
                        Change default working directory to specified absolute path.
  -dr DRIVER_OPTION, --driver DRIVER_OPTION
                        Choose from the following storage drivers: 
                        overlay2: Use the kernel's overlay2 storage driver
                        fuse: Use the fuse-overlayfs system tool
                        If no option is given, the default method of applying container layers in userspace will be used.
  -v, --version         show program's version number and exit

Usage

From Images

Create an SBOM file with tern by running:

tern report -o <output.file> -i <container:image> -f <output-format>

with the <output-format> being one of:

You can create raw outputs to terminal by running:

tern report -i <container:image>

You can create SBOM formatted outputs to terminal by running:

tern report -i <container:image> -f <output-format>

This raw output can be saved to a file by running:

tern report -i <container:image> -o <output.file>

From Dockerfiles

To create outputs SBOMs from Dockerfiles, run:

tern report -d <path/to/Dockerfile> -f <output-format> -o <output-file>

For raw output to terminal:

tern report -d <path/to/Dockerfile>

For SBOM formatted output to terminal:

tern report -d <path/to/Dockerfile> -f <output-format>

For raw output to file

tern report -d <path/to/Dockerfile> -o <output-file>

Notes

References