自動掃描 Java 套件
瞭解如何啟用自動掃描功能、將容器映像檔推送到 Artifact Registry,以及查看映像檔中發現的安全漏洞清單。
每當映像檔推送至 Artifact Registry 時,Artifact Analysis 就會掃描安全漏洞。平台管理員和應用程式開發人員可以使用這項自動掃描功能,協助找出軟體交付管道中的風險。
本快速入門導覽課程會使用簡單的公開套件,示範其中一種套件掃描類型。根據預設,啟用掃描 API 後,Artifact Analysis 會掃描多種套件類型的安全漏洞。支援的套件類型包括:OS、Go、Java (Maven)、Python 和 Node.js (npm)。
事前準備
- 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.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
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.
-
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Artifact Registry and Container Scanning APIs:
gcloud services enable containerscanning.googleapis.com
artifactregistry.googleapis.com -
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
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.
-
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Artifact Registry and Container Scanning APIs:
gcloud services enable containerscanning.googleapis.com
artifactregistry.googleapis.com
在 Artifact Registry 中建立 Docker 存放區
您必須建立 Docker 存放區,以便儲存本快速入門導覽課程所用的範例映像檔。
在 Google Cloud 控制台中開啟「Repositories」(存放區) 頁面。
點選 [Create Repository] (建立存放區)。
在「Create Repository」(建立存放區) 頁面中,輸入下列設定:
- Name (名稱):
quickstart-docker-repo
- 格式:Docker
- 模式:標準
- 位置類型:區域
- Region (區域):
us-central1
- Name (名稱):
點選「建立」。
畫面會顯示「Repositories」頁面。您的「quickstart-docker-repo
」存放區會新增至存放區清單。
設定驗證機制
如要使用 Artifact Registry 推送或提取映像檔,請先設定 Docker,透過 Google Cloud CLI 驗證傳送至 Artifact Registry 的要求。
在 Cloud Shell 或本機殼層中,為 us-central1
區域的 Docker 存放區設定驗證機制:
gcloud auth configure-docker us-central1-docker.pkg.dev
取得套件
切換至要儲存容器映像檔的目錄。
將圖片複製到本機目錄。舉例來說,您可以使用 Docker 從 Docker Hub 提取最新版 Jenkins 映像檔。
docker pull jenkins:2.60.3-alpine
使用存放區名稱為套件加上標記
如要將套件推送至 Artifact Registry,您需要設定 docker push
指令,將映像檔推送至特定位置。
執行下列指令,將映像檔標記為 quickstart-image:tag1
:
docker tag jenkins:2.60.3-alpine \ 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 包含冒號 (:
),請參閱網域範圍專案。
查看安全漏洞掃描結果
如要查看映像檔中的安全漏洞:
取得存放區清單。
在存放區清單中,按一下存放區。
在圖片清單中,按一下圖片名稱。
每個映像檔摘要的安全漏洞總數會顯示在「Vulnerabilities」(安全漏洞) 資料欄中。
如要查看映像檔的安全漏洞清單,請按一下「Vulnerabilities」(安全漏洞) 資料欄中的連結。
「掃描結果」部分會顯示掃描的套件類型摘要、安全漏洞總數、有修正的安全漏洞、沒有修正的安全漏洞,以及有效嚴重程度。
安全漏洞表格會列出每個安全漏洞的「常見安全漏洞與資料外洩風險 (CVE)」名稱、實際嚴重程度、「常見安全漏洞評分系統 (CVSS)」分數、修正 (如有)、內含安全漏洞的套件名稱,以及套件類型。
您可以篩選及排序這些檔案,依檔案副檔名檢查特定檔案、目錄或檔案類型。
Google Cloud 控制台最多會在表格中顯示 1200 個安全漏洞。如果映像檔有超過 1200 個安全漏洞,您必須使用 gcloud 或 API 查看完整清單。
如要查看特定 CVE 的詳細資料,請按一下 CVE 名稱。
如要查看安全漏洞發生詳細資料,例如版本號碼和受影響的位置,請在安全漏洞名稱的資料列中,按一下「查看」或「查看已修正」。如果安全漏洞尚未修正,連結文字會顯示「查看」;如果安全漏洞已修正,連結文字則會顯示「查看已修正」。
清除所用資源
如要避免系統向您的 Google Cloud 帳戶收取本頁面所用資源的費用,請刪除含有這些資源的 Google Cloud 專案。
如果您是為了本指南建立新專案,現在可以刪除該專案。- In the Google Cloud console, go to the Manage resources page.
- In the project list, select the project that you want to delete, and then click Delete.
- In the dialog, type the project ID, and then click Shut down to delete the project.