本文說明如何使用 Gemini Cloud Assist 瞭解構件狀態、取得存放區和構件中繼資料的資訊,以及使用 Artifact Analysis 資訊回答構件安全漏洞和軟體物料清單 (SBOM) 的相關問題。
事前準備
- 確認已在 Google Cloud 專案中設定 Gemini Cloud Assist。
- 登入 Google Cloud 帳戶。如果您未曾使用過 Google Cloud,歡迎 建立帳戶,親自體驗實際使用我們產品的成效。新客戶還能獲得價值 $300 美元的免費抵免額,用於執行、測試及部署工作負載。
-
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 and Container Scanning APIs, if any are not already enabled.
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.-
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.
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 and Container Scanning APIs, if any are not already enabled.
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.-
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 角色:
- 專案或存放區的「Occurrences Viewer」(發生次數檢視器) (
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 for Google Cloud提示詞」。
- 所有提示詞預設會套用至所選專案,但您可以依位置、存放區或映像檔篩選提示詞。
- 任何以容器映像檔名稱為基礎的查詢,都會將容器映像檔名稱視為前置字串。您可以在專案、存放區或特定映像檔 (跨不同 SHA) 中進行篩選,但無法依標記篩選。
- 如要取得更具體的結果,請加入範圍。舉例來說,如要取得特定映像檔的結果,請在範圍中加入映像檔名稱。您可以將專案、存放區、映像檔或映像檔@摘要詳細資料新增至容器映像檔名稱,藉此進行篩選。
- Artifact Analysis 會提供所有區域的合併結果,因此 Artifact Analysis 提示不需要區域限定詞。您可以指定區域限定符來篩選結果。
列出我最嚴重的已知安全漏洞
您可以提示 Gemini Cloud Assist 列出目前專案中已知的重大安全漏洞。安全漏洞會依通用漏洞評分系統 (CVSS) 分數降序排序,並依安全漏洞 ID 分組。只會顯示前 10 個安全漏洞。結果包含過去 30 天內掃描的所有映像檔安全漏洞。
您可以依容器映像檔名稱篩選回應。
如要列出最常見的已知安全漏洞,請在 Gemini Cloud Assist Chat 中輸入下列提示:
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 張圖片,且只會顯示 Artifact Analysis 掃描過的圖片。
您可以依下列條件篩選回覆:
- 安全漏洞 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 張圖片,且只會顯示 Artifact Analysis 掃描過的圖片。
您可以依容器映像檔名稱篩選回應。
如要列出含有特定套件的映像檔,請在 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。搜尋結果會依建立日期遞減排序,最新建立的項目會列在清單頂端。最多可顯示 10 個在過去 30 天內建立的版本。
您可以依容器映像檔名稱篩選回應,包括 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 編號。