本文說明如何建立及儲存軟體物料清單 (SBOM),列出容器映像檔中的依附元件。
將容器映像檔儲存在 Artifact Registry 中,並使用 Artifact Analysis 掃描安全漏洞後,即可使用 Google Cloud CLI 產生 SBOM。
如要瞭解如何使用安全漏洞掃描功能,請參閱「自動掃描」和「定價」。
Artifact Analysis 會將 SBOM 儲存在 Cloud Storage 中,如要進一步瞭解 Cloud Storage 費用,請參閱「定價」一文。
事前準備
-
登入 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 bucket 和上傳 SBOM 檔案所需的權限,請要求管理員授予您專案的「Storage 管理員 」(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 bucket,Cloud Storage 會為您建立一個名為 artifactanalysis-<var>REGION</var>-<var>PROJECT_NUMBER</var> 的 bucket,並將 SBOM 傳送至該 bucket。該區域的其他 SBOM 會傳送至同一個值區。
您可以使用 Google Cloud 控制台或 gcloud CLI 查看 SBOM。 如要找出含有 SBOM 的 Cloud Storage bucket,請使用 gcloud CLI 搜尋 SBOM。
產生 SBOM,但不掃描安全漏洞
如要產生 SBOM,但不想持續掃描專案中的安全性漏洞,只要在將映像檔推送至 Artifact Registry 前啟用 Container Scanning API,仍可匯出 SBOM。將映像檔推送至 Artifact Registry 並匯出 SBOM 後,請務必停用 Container Scanning API,以免系統對後續的安全漏洞掃描作業收費。