This document describes how to create and store a software bill of materials
(SBOM) listing the dependencies in your container images.

When you store container images in Artifact Registry and scan them for
vulnerabilities with Artifact Analysis, you can then generate an SBOM using
the Google Cloud CLI.

For information on using vulnerability scanning, see
[Automatic scanning](https://docs.cloud.google.com/artifact-analysis/docs/artifact-analysis#automatic_scanning)
and [Pricing](https://cloud.google.com/artifact-analysis/pricing).

Artifact Analysis stores SBOMs in Cloud Storage. For more information on
Cloud Storage costs, see [Pricing](https://cloud.google.com/storage/pricing).

## Before you begin

1. Create a Docker repository in Artifact Registry and push a container image to the repository. If you are not familiar with Artifact Registry, see the [Docker
   quickstart](https://docs.cloud.google.com/artifact-registry/docs/docker/store-docker-container-images).

<br />

### Required roles


To get the permissions that
you need to manage Cloud Storage buckets and upload SBOM files,

ask your administrator to grant you the
[Storage Admin](https://docs.cloud.google.com/iam/docs/roles-permissions/storage#storage.admin) (`roles/storage.admin`) IAM role on the project.


For more information about granting roles, see [Manage access to projects, folders, and organizations](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access).


You might also be able to get
the required permissions through [custom
roles](https://docs.cloud.google.com/iam/docs/creating-custom-roles) or other [predefined
roles](https://docs.cloud.google.com/iam/docs/roles-overview#predefined).

## Generate an SBOM file

To generate an SBOM file, use the following command:

    gcloud artifacts sbom export --uri=LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE_NAME

Where

- <var translate="no">LOCATION</var> is the location of the Artifact Registry repository.
- <var translate="no">PROJECT_ID</var> is the ID of the project that contains the Artifact Registry repository.
- <var translate="no">REPOSITORY</var> is the name of the Artifact Registry repository that contains the image.
- <var translate="no">IMAGE_NAME</var> is the name of the image. Images can be in either [tag format](https://docs.cloud.google.com/artifact-registry/docs/container-concepts#tags), or [digest format](https://docs.cloud.google.com/artifact-registry/docs/container-concepts#manifests). Images provided in tag format will be resolved into digest format.

Artifact Analysis stores your SBOM in Cloud Storage. If you don't
yet have a Cloud Storage bucket for the same region as your image,
Cloud Storage creates one for you with a name of
`artifactanalysis-<var>REGION</var>-<var>PROJECT_NUMBER</var>` and sends your
SBOM to that bucket. Additional SBOMs in that region are sent to the same
bucket.

You can view SBOMs by using the Google Cloud console or the gcloud CLI.
If you want to locate the Cloud Storage bucket that contains your
SBOMs, you must
[search for SBOMs using the gcloud CLI](https://docs.cloud.google.com/artifact-analysis/docs/view-sboms-dependencies#gcloud).

> [!NOTE]
> **Note:** If you're using images with `gcr.io` domain names, SBOMs might not appear immediately. SBOM generation takes at least 24 hours from the time when you set up hostname redirection.

## Generate an SBOM without vulnerability scanning

If you want to generate an SBOM, but you don't want ongoing vulnerability
scanning for your project, you can still export an SBOM if you enable the
Container Scanning API before you push the image to Artifact Registry. After
your image is pushed to Artifact Registry, and you have exported an SBOM, you
must disable the Container Scanning API to prevent being billed for further
vulnerability scanning.

## What's next

- [Upload your own SBOM](https://docs.cloud.google.com/artifact-analysis/docs/upload-sbom)
- [View SBOMs and dependencies](https://docs.cloud.google.com/artifact-analysis/docs/view-sboms-dependencies)