本页面介绍了如何将软件物料清单 (SBOM) 文件上传到 Cloud Storage,以帮助跟踪和证明您存储在 Artifact Registry 中的容器映像的组件。
如需了解 Cloud Storage 价格,请参阅价格。
准备工作
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Artifact Registry, Container Analysis APIs, if any are not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
Install the Google Cloud CLI.
-
Configure the gcloud CLI to use your federated identity.
For more information, see Sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init - 在 Artifact Registry 中拥有一个 Docker 代码库,其中包含您的 SBOM 所描述的容器映像。如果您不熟悉 Artifact Registry,请参阅 Docker 快速入门。
- 准备好要上传的 SBOM 文件(采用支持的格式)。
所需的角色
如需获得创建和管理 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 文件,且采用以下格式之一:
- 软件包数据交换 (SPDX) 版本 2.2 或 2.3
- CycloneDX 1.4 或 1.5 版
上传 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。