本文說明如何使用 Gemini Cloud Assist 瞭解構件狀態、取得存放區和構件中繼資料的相關資訊,以及使用構件分析資訊來回答有關構件漏洞和軟體物料清單 (SBOM) 的問題。
事前準備
- 確認您已在 Google Cloud 專案中設定 Gemini Cloud Assist。
- 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.
-
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 and Container Scanning APIs.
-
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
-
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 and Container Scanning APIs.
-
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
必要的角色
如要取得提示 Gemini Cloud Assist 提供構件資訊所需的權限,請要求管理員授予您下列 IAM 角色:
-
專案或存放區的發生頻率檢視器 (
roles/containeranalysis.occurrences.viewer
) -
專案的 Gemini Cloud Assist 使用者 (
roles/cloudaicompanion.user
)
如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。
開啟 Gemini Cloud Assist
您可以在Google Cloud 主控台的任何位置開啟 Gemini Cloud Assist 對話。
- 在 Google Cloud 控制台中,選取已將容器映像檔儲存在 Artifact Registry 中的專案。
- 如要開啟「Cloud Assist」面板,請點選 火花 「開啟或關閉 Gemini AI 對話」。
- 如要輸入提示,請輸入提示內容,然後按一下「傳送」。
提示注意事項
以下是產生 Gemini Cloud Assist 提示時,應注意的「構件分析」專屬注意事項清單。如要進一步瞭解一般提示撰寫建議,請參閱「為 Gemini 撰寫更有效的提示 Google Cloud」。
- 所有提示預設為所選專案,但您可以將提示設為依位置、存放區或圖片篩選。
- 任何以容器映像檔名稱為基礎的查詢都會將容器映像檔名稱視為前置字串。這樣一來,您就能在專案、存放區或特定映像檔 (跨不同 SHA) 中篩選,但無法依標記篩選。
- 如要取得更具體的結果,請加入範圍。舉例來說,如要取得特定圖片的結果,請在範圍中加入圖片名稱。您可以將專案、存放區、映像檔或映像檔@摘要詳細資料新增至容器映像檔名稱,藉此進行篩選。
- 由於「構件分析」會提供所有區域的合併結果,因此不需在「構件分析」提示中使用區域限定條件。您可以指定區域限定條件來篩選結果。
列出我的前幾個已知安全漏洞
您可以提示 Gemini Cloud Assist 列出目前專案中已知的重大安全漏洞。安全漏洞會依據通用安全漏洞評分系統 (CVSS) 分數遞減排序,並依安全漏洞 ID 分組。只會顯示前 10 個安全漏洞。結果包含過去 30 天內掃描的所有映像檔所發現的安全漏洞。
您可以依容器映像檔名稱篩選回應。
如要列出已知的重大漏洞,請在 Gemini Cloud Assist 對話中輸入下列提示:
List artifact vulnerabilities for `CONTAINER_IMAGE_NAME`.
將 CONTAINER_IMAGE_NAME
替換為包含存放區的容器映像檔名稱,例如 us-central1-docker.pkg.dev/my-project/my-repository
。
在容器映像檔名稱中加入更多詳細資料,即可傳回更精確的回應。舉例來說,LOCATION-docker.pkg.dev/PROJECT-ID/REPOSITORY/IMAGE
會提供特定映像檔的安全漏洞詳細資料。
以下提示要求 Gemini Cloud Assist 列出存放區 us-central1-docker.pkg.dev/my-project/my-repository
的重大已知安全漏洞:
List artifact vulnerabilities for
`us-central1-docker.pkg.dev/my-project/my-repository`.
回應會包含最多 10 個漏洞清單,並依指定存放區的 CVSS 分數由高至低排序。
如要查看所有安全漏洞,請使用 artifacts vulnerabilities list gcloud CLI 指令。您可以提供未經限定的圖片名稱,或提供安全雜湊演算法 (SHA) 來查看安全漏洞。
依安全漏洞列出圖片
您可以要求 Gemini Cloud Assist 顯示所有含有特定漏洞的圖片。回應會依最新建立日期遞減排序,並包含過去 30 天內掃描的圖片。這則提示最多會顯示 10 張圖片,且只包含已由「遺跡分析」掃描的圖片。
您可以根據下列條件篩選回應:
- 安全漏洞 ID
- 容器映像檔名稱
如要列出含有特定安全漏洞的圖片,請在 Cloud Assist 即時通訊中輸入下列提示:
List docker container images that contain vulnerability
`VULNERABILITY_ID`.
將 VULNERABILITY_ID
替換為您要找出漏洞的 ID,例如 CVE-2024-01234
。
下列提示會要求 Gemini Cloud Assist 列出含有 CVE-2024-01234
安全漏洞的圖片:
List artifact vulnerabilities for `CVE-2024-01234`.
回應會列出最多 10 個含有指定安全漏洞的映像檔,並依據指定存放區的 CVSS 分數以降冪排序。
依套件列出圖片
您可以提示 Gemini Cloud Assist 傳回包含指定套件的圖片清單。系統會依建立日期由新到舊排序圖片,並納入過去 30 天內掃描的圖片。這個提示會顯示最多 10 張圖片,且只包含已由「遺跡分析」掃描的圖片。
您可以依容器映像檔名稱篩選回應。
如要列出包含特定套件的圖片,請在 Cloud Assist 即時通訊中輸入下列提示:
List docker container images that contain package
`PACKAGE_ID`.
將 PACKAGE_ID
替換為您要尋找的套件 ID。
舉例來說,下列提示會要求 Gemini Cloud Assist 列出包含套件 my-package-name
的映像檔:
List images that contain package `my-package-name`.
回應會列出最多 10 張包含指定套件的圖片。
列出建構來源資訊
您可以要求 Gemini Cloud Assist 針對指定專案和範圍,傳回 10 個最新的建構來源詳細資料。結果會依建立日期以遞減方式排序,最近建立的項目會顯示在清單頂端。最多會顯示 10 個版本。您必須在過去 30 天內建立版本,才能列入清單。這個提示僅支援具有 SLSA 1.0 來源的版本。
您可以依容器映像檔名稱篩選回應。
如要列出建構來源,請在 Cloud Assist 即時通訊中輸入以下提示:
List build provenance for CONTAINER_IMAGE_NAME.
將 CONTAINER_IMAGE_NAME 替換為您要瞭解來源的圖片 ID。
舉例來說,下列提示會要求 Gemini Cloud Assist 列出 us-central1-docker.pkg.dev/my-project/my-image
的建構來源:
List build provenance for `us-central1-docker.pkg.dev/my-project/my-image`.
您可以從容器映像檔名稱中移除位置、專案或圖片詳細資料,以便傳回更廣泛的結果。回應會包含 10 個最新版本的建構來源詳細資料。
如要在 Google Cloud 控制台中查看版本,請前往「Build History」頁面。
列出 SBOM
您可以要求 Gemini Cloud Assist 傳回存放區中的最新 SBOM。結果會依建立日期遞減排序,最近建立的項目會顯示在清單頂端。最多可顯示過去 30 天內建立的 10 個版本。
您可以依容器映像檔名稱篩選回應,包括 image@digest 詳細資料。
如要列出 SBOM,請在 Cloud Assist 對話中輸入下列提示:
List SBOMs for `CONTAINER_IMAGE_NAME`.
將 CONTAINER_IMAGE_NAME
替換為要搜尋的容器映像檔名稱,例如 us-central1-docker.pkg.dev/my-project/my-repo
。
以下提示要求 Gemini Cloud Assist 列出存放區 us-central1-docker.pkg.dev/my-project/my-repo
的 SBOM:
List SBOMs for `us-central1-docker.pkg.dev/my-project/my-repo`.
回應會包含 10 個最新存放區的 SBOM 詳細資料。您可以從容器映像檔名稱中移除位置、專案或圖片詳細資料,以便傳回更廣泛的結果。
您可以使用 artifacts SBOM list gcloud CLI 指令查看所有 SBOM。
其他提示
以下提示說明如何使用變數搭配 Gemini Cloud Assist 進行篩選。
如要依特定變數列出漏洞,請在 Cloud Assist 即時通訊中輸入以下內容:
List vulnerabilities for `SCOPE`.
在這個提示中,SCOPE
可以設為專案、存放區、映像檔或映像檔和摘要。
如要列出含有特定套件的映像檔,請在 Cloud Assist 即時通訊中輸入以下內容:
List images that contain the log4j package.
如要列出含有特定安全漏洞的圖片,請在 Cloud Assist 即時通訊中輸入以下內容:
List images that contain `VULNERABILITY_ID`.
請在這個提示中將 VULNERABILITY_ID
替換為 CVE 編號。