本文档介绍了如何创建和存储软件物料清单 (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
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.-
安装 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
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.-
安装 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=LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE_NAME
位置
- LOCATION 是 Artifact Registry 制品库的位置。
- PROJECT_ID 是包含 Artifact Registry 代码库的项目的 ID。
- REPOSITORY 是包含相应映像的 Artifact Registry 制品库的名称。
- IMAGE_NAME 是映像的名称。映像可以采用标记格式或摘要格式。以标记格式提供的映像将解析为摘要格式。
Artifact Analysis 会将您的 SBOM 存储在 Cloud Storage 中。如果您还没有与映像位于同一区域的 Cloud Storage 存储桶,Cloud Storage 会为您创建一个名为 artifactanalysis-<var>REGION</var>-<var>PROJECT_NUMBER</var> 的存储桶,并将您的 SBOM 发送到该存储桶。相应区域中的其他 SBOM 会发送到同一存储桶。
您可以使用 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,以免因进一步的漏洞扫描而产生费用。