本文档介绍了如何创建和存储软件物料清单 (SBOM),其中列出了容器映像中的依赖项。
当您在 Artifact Registry 中存储容器映像并使用 Artifact Analysis 扫描映像中的漏洞时,您可以使用 Google Cloud CLI 生成 SBOM。
Artifact Analysis 会将 SBOM 存储在 Cloud Storage 中。如需详细了解 Cloud Storage 费用,请参阅价格。
准备工作
-
登录您的 Google 账号。
如果您还没有 Google 账号,请 注册新账号。
-
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, Container Scanning APIs.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
安装 Google Cloud CLI。
-
如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI。
-
如需初始化 gcloud CLI,请运行以下命令:
gcloud init -
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, Container Scanning APIs.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
安装 Google Cloud CLI。
-
如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI。
-
如需初始化 gcloud CLI,请运行以下命令:
gcloud init - 在 Artifact Registry 中创建 Docker 代码库,并将容器映像推送到该代码库。如果您不熟悉 Artifact Registry,请参阅 Docker 快速入门。
所需角色
如需获得管理 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,以避免因进一步的漏洞扫描而被收费。