上传 SBOM

本页介绍了如何将软件物料清单 (SBOM) 文件上传到 Cloud Storage,以帮助跟踪和证明您存储在 Artifact Registry 中的容器映像的组件。

如需了解 Cloud Storage 价格,请参阅价格

准备工作

  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 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 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 代码库,其中包含您的 SBOM 所描述的容器映像。如果您不熟悉 Artifact Registry,请参阅 Docker 快速入门
  15. 准备好要上传的 SBOM 文件,该文件必须采用支持的格式
  16. 所需的角色

    如需获得创建和管理 Cloud Storage 存储分区和 SBOM 文件所需的权限,请让管理员向您授予项目的以下 IAM 角色:

    • 如果您使用的是默认 Cloud Storage 存储桶,则需要以下权限才能管理存储分区: Storage Admin(roles/storage.admin)
    • 如果您指定的是 Cloud Storage 存储桶,则需要以下权限才能管理存储分区: Storage Object Admin(roles/storage.objectAdmin)
    • 如果 SBOM 参考的备注已存在: Container Analysis Notes Attacher (roles/containeranalysis.notes.attacher)
    • 如需在当前项目中为 SBOM 参考发生实例创建新备注,请执行以下操作: Container Analysis Notes Editor((roles/containeranalysis.notes.editor)
    • 如需创建 SBOM 参考发生实例,请执行以下操作: Container Analysis Occurrences Editor(roles/containeranalysis.occurrences.editor)

    如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限

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

    支持的格式

    您的 SBOM 文件必须是 JSON 文件,且采用以下某种格式:

    上传您的 SBOM

    使用以下命令上传您的 SBOM:

    gcloud artifacts sbom load /
        --source SOURCE /
        --uri URI
    

    其中:

    • SOURCE:要上传的 SBOM 文件的路径。
    • URI:SBOM 文件所描述的 Docker 映像的 URI。图片可以是标记格式,也可以是摘要格式。以标记格式提供的映像将解析为摘要格式。

    可选标志

    • --destination:指定要使用的 Cloud Storage 存储桶(而非默认存储分区)。
    • --kms-key-version:提供用于对 SBOM 参考发生载荷进行签名的密钥版本。您可以使用此密钥来验证 SBOM 的来源。

    例如,以下命令会上传从已标记映像 us-east1-docker.pkg.dev/my-image-repo/my-image 生成的 JSON 文件 my-sbom.bom.json,并使用以 my-key/cryptoKeyVersions/1 结尾的 KMS 密钥版本对 SBOM 参考发生情况进行签名。

    gcloud artifacts sbom load /
    --source=my-sbom.bom.json
    --uri=us-east1-docker.pkg.dev/my-image-repo/my-image
    --kms-key-version=projects/my-project/locations/us/keyRings/my-key-ring/cryptoKeys/my-key/cryptoKeyVersions/1
    

    以下命令会上传与映像摘要 my-local-image@sha256:abcxyz 关联的 JSON 文件 my-sbom.spdx.json,并将该文件存储在 Cloud Storage 存储桶 gs://my-sbom-bucket 中。

    gcloud artifacts sbom load /
        --source=my-sbom.spdx.json /
        --uri=my-local-image@sha256:abcxyz /
        --destination=gs://my-sbom-bucket
    

    Artifact Analysis 会将您的 SBOM 上传到 Cloud Storage,并创建一个 SBOM 参考出现情况

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

    后续步骤