本文档介绍了如何创建和存储软件清单 (SBOM),以列出容器映像中的依赖项。
将容器映像存储在 Artifact Registry 中并使用 Artifact Analysis 扫描它们以查找漏洞后,您可以使用 Google Cloud CLI 生成 SBOM。
工件分析会将 SBOM 存储在 Cloud Storage 中。如需详细了解 Cloud Storage 费用,请参阅价格。
不支持 Container Registry(已弃用)代码库。了解如何从 Container Registry 过渡。
准备工作
-
Sign in to your Google Account.
If you don't already have one, sign up for a new account.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Artifact Registry, Container Analysis, Container Scanning APIs.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Artifact Registry, Container Analysis, Container Scanning APIs.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
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
。图片可以采用标记格式或摘要格式。以标记格式提供的图片将解析为摘要格式。
工件分析会将您的 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,以免为进一步的漏洞扫描付费。