自動掃描 OS 套件

瞭解如何啟用自動掃描功能、在 Artifact Registry 上推送容器映像檔,以及查看映像檔中找到的安全漏洞清單。

每次將映像檔推送至 Artifact Registry 時,Artifact Analysis 都會掃描安全漏洞。平台管理員和應用程式開發人員可以使用這項自動掃描功能,找出軟體提交管道中的風險。

本快速入門導覽課程會使用簡單的公開套件,示範一種套件掃描作業。根據預設,啟用掃描 API 後,Artifact Analysis 會掃描多種套件類型的安全漏洞。支援的套件類型包括:OS、Go、Java (Maven)、Python 和 Node.js (npm)。

事前準備

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. Install the Google Cloud CLI.

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

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

    gcloud init
  5. Create or select a Google Cloud project.

    • Create a Google Cloud project:

      gcloud projects create PROJECT_ID

      Replace PROJECT_ID with a name for the Google Cloud project you are creating.

    • Select the Google Cloud project that you created:

      gcloud config set project PROJECT_ID

      Replace PROJECT_ID with your Google Cloud project name.

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

  7. Install the Google Cloud CLI.

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

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

    gcloud init
  10. Create or select a Google Cloud project.

    • Create a Google Cloud project:

      gcloud projects create PROJECT_ID

      Replace PROJECT_ID with a name for the Google Cloud project you are creating.

    • Select the Google Cloud project that you created:

      gcloud config set project PROJECT_ID

      Replace PROJECT_ID with your Google Cloud project name.

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

在 Artifact Registry 中建立 Docker 存放區

您必須建立 Docker 存放區,以便儲存本快速入門教學所用的範例映像檔。

  1. 在 Google Cloud 控制台中開啟「Repositories」頁面。

    開啟「存放區」頁面

  2. 點選 [Create Repository] (建立存放區)

  3. 在「Create Repository」頁面中輸入下列設定:

    • Name (名稱):quickstart-docker-repo
    • 格式:Docker
    • 模式:標準
    • 位置類型:區域
    • Region (區域):us-central1
  4. 按一下 [建立]。

畫面會顯示「Repositories」頁面。您的 quickstart-docker-repo 存放區會新增至存放區清單。

設定驗證機制

在使用 Artifact Registry 推送或提取映像檔之前,您必須先設定 Docker,透過 Google Cloud CLI 驗證傳送至 Artifact Registry 的要求。

在 Cloud Shell 或本機 Shell 中,為 us-central1 區域中的 Docker 存放區設定驗證機制:

gcloud auth configure-docker us-central1-docker.pkg.dev

取得套件

  1. 切換至要儲存容器映像檔的目錄。

  2. 將圖片複製到本機目錄。舉例來說,您可以使用 Docker 從 Docker Hub 提取最新的 Ubuntu 映像檔。

    docker pull ubuntu:latest
    

為套件加上存放區名稱標記

如要將套件推送至 Artifact Registry,您需要設定 docker push 指令,將映像檔推送至特定位置。

執行下列指令,將映像檔標記為 quickstart-image:tag1

docker tag ubuntu:latest \
us-central1-docker.pkg.dev/PROJECT/quickstart-docker-repo/quickstart-image:tag1

地點

  • PROJECT 是您的 Google Cloud 專案 ID。如果您的專案 ID 包含冒號 (:),請參閱網域範圍專案
  • us-central1 是 Artifact Registry 存放區的區域。
  • docker.pkg.dev 是 Docker 存放區的主機名稱。
  • quickstart-image 是您要用於存放區的映像檔名稱。映像檔名稱可以與本機映像檔名稱不同。
  • tag1 是您要新增至 Docker 映像檔的標記。如果您沒有指定標記,Docker 會套用預設標記 latest

將映像檔推送至 Artifact Registry

將新的映像檔上傳至 Artifact Registry 時,容器分析會自動掃描這些映像檔。

如要將映像檔推送至 Artifact Registry 中的 Docker 存放區,請執行下列指令:

docker push us-central1-docker.pkg.dev/PROJECT/quickstart-docker-repo/quickstart-image:tag1

PROJECT 替換為您的 Google Cloud 專案 ID。如果您的專案 ID 包含冒號 (:),請參閱網域範圍專案

查看安全漏洞掃描結果

如何查看映像檔中的安全漏洞:

  1. 在 Artifact Analysis 主控台中開啟 Artifact Registry 存放區清單。

    開啟「存放區」頁面

  2. 在存放區清單中,按一下所需存放區。

  3. 按一下圖片名稱。

    畫面上會顯示圖片的摘要清單。

    每個圖片摘要的安全漏洞總數會顯示在「Vulnerabilities」(安全漏洞) 資料欄中。

    發生安全漏洞的映像檔螢幕擷取畫面

  4. 按一下「Vulnerabilities」欄中連結的安全漏洞總數。

    畫面上會顯示安全漏洞清單。

    圖像清單和安全漏洞詳細資料的螢幕截圖

    安全漏洞清單會顯示此映像檔的掃描次數、安全漏洞嚴重程度等級、修正可用性、內含安全漏洞的套件名稱和套件類型。

  5. 如要進一步瞭解安全漏洞來源的特定安全漏洞,請按一下「Name」資料欄中的連結 CVE ID。

查看結果的其他方式

Google Cloud 控制台最多可顯示 1,200 個漏洞。如果映像檔含有超過 1, 200 個安全漏洞,請使用 gcloudAPI查看完整清單。

清除所用資源

如要避免系統向您的 Google Cloud 帳戶收取您在本頁面使用資源的費用,請刪除含有這些資源的 Google Cloud 專案。

如果您是為了本指南建立新的專案,現在可以刪除該專案。

  1. In the Google Cloud console, go to the Manage resources page.

    Go to Manage resources

  2. In the project list, select the project that you want to delete, and then click Delete.
  3. In the dialog, type the project ID, and then click Shut down to delete the project.

後續步驟