生成和存储 SBOM

本文档介绍了如何创建和存储软件物料清单 (SBOM),其中列出了容器映像中的依赖项。

将容器映像存储在 Artifact Registry 中,并使用 Artifact Analysis 扫描这些映像以查找漏洞后,您可以使用 Google Cloud CLI 生成 SBOM。

如需了解如何使用漏洞扫描功能,请参阅自动扫描价格

Artifact Analysis 会将 SBOM 存储在 Cloud Storage 中。如需详细了解 Cloud Storage 费用,请参阅价格

不支持 Container Registry (已弃用)代码库。了解如何从 Container Registry 过渡

准备工作

  1. Sign in to your Google Account.

    If you don't already have one, sign up for a new account.

  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

  4. Enable the Artifact Registry, Container Analysis, Container Scanning APIs.

    Enable the APIs

  5. Install the Google Cloud CLI.

  6. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  7. To initialize the gcloud CLI, run the following command:

    gcloud init
  8. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  9. Make sure that billing is enabled for your Google Cloud project.

  10. Enable the Artifact Registry, Container Analysis, Container Scanning APIs.

    Enable the APIs

  11. Install the Google Cloud CLI.

  12. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  13. To initialize the gcloud CLI, run the following command:

    gcloud init
  14. 在 Artifact Registry 中创建 Docker 代码库,并将容器映像推送到该代码库。如果您不熟悉 Artifact Registry,请参阅 Docker 快速入门
  15. 所需的角色

    如需获得管理 Cloud Storage 存储分区和上传 SBOM 文件所需的权限,请让您的管理员为您授予项目的 Storage Admin (roles/storage.admin) IAM 角色。 如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限

    您也可以通过自定义角色或其他预定义角色来获取所需的权限。

    生成 SBOM 文件

    如需生成 SBOM 文件,请使用以下命令:

    gcloud artifacts sbom export --uri=URI
    

    地点

    • URI 是 SBOM 文件描述的 Artifact Registry 映像 URI,类似于 us-east1-docker.pkg.dev/my-image-repo/my-image。映像可以采用标记格式摘要格式。 以标记格式提供的映像将解析为摘要格式。

    Artifact Analysis 会将您的 SBOM 存储在 Cloud Storage 中。

    您可以使用 Google Cloud 控制台或 gcloud CLI 查看 SBOM。 如果您想找到包含 SBOM 的 Cloud Storage 存储桶,则必须使用 gcloud CLI 搜索 SBOM

    生成不含漏洞扫描结果的 SBOM

    如果您想生成 SBOM,但不想为项目进行持续的漏洞扫描,那么您可以在将映像推送到 Artifact Registry 之前启用 Container Scanning API,这样仍可导出 SBOM。将映像推送到 Artifact Registry 并导出 SBOM 后,您必须停用 Container Scanning API,以免因进一步的漏洞扫描而产生费用。

    后续步骤