產生及儲存 SBOM

本文說明如何建立及儲存軟體物料清單 (SBOM),列出容器映像檔中的依附元件。

將容器映像檔儲存在 Artifact Registry 中,並使用 Artifact Analysis 掃描是否有安全漏洞,然後使用 Google Cloud CLI 產生 SBOM。

如要瞭解如何使用安全漏洞掃描功能,請參閱「自動掃描」和「定價」。

Artifact Analysis 會將 SBOM 儲存在 Cloud Storage 中。如要進一步瞭解 Cloud Storage 費用,請參閱「定價」一文。

不支援 Container Registry (已淘汰) 存放區。瞭解如何從 Container Registry 轉換

事前準備

  1. Sign in to your Google Account.

    If you don't already have one, sign up for a new account.

  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

  4. Enable the Artifact Registry, Container Analysis, Container Scanning APIs.

    Enable the APIs

  5. Install the Google Cloud CLI.

  6. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  7. To initialize the gcloud CLI, run the following command:

    gcloud init
  8. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  9. Make sure that billing is enabled for your Google Cloud project.

  10. Enable the Artifact Registry, Container Analysis, Container Scanning APIs.

    Enable the APIs

  11. Install the Google Cloud CLI.

  12. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  13. To initialize the gcloud CLI, run the following command:

    gcloud init
  14. 在 Artifact Registry 中建立 Docker 存放區,並將容器映像檔推送至存放區。如果您不熟悉 Artifact Registry,請參閱 Docker 快速入門
  15. 必要的角色

    如要取得管理 Cloud Storage 值區和上傳 SBOM 檔案所需的權限,請要求管理員為您授予專案的 Storage 管理員 (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,以免日後再產生安全漏洞掃描費用。

    後續步驟