容器分析會針對自動掃描發現的安全漏洞和其他中繼資料,透過 Pub/Sub 傳送通知。建立或更新附註或事件時,系統會為每個 API 版本將訊息發布至對應的主題。請根據您使用的 API 版本,參閱對應的主題。
事前準備
- 登入 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.
Enable the Container Analysis API, if it is 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.
Enable the Container Analysis API, if it is 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 - 瞭解如何設定專案中繼資料的存取控管機制。如果您只使用 Artifact Analysis 容器掃描建立的發生次數中繼資料,請略過這個步驟。
建立 Pub/Sub 主題
啟用 Artifact Analysis API 後,Artifact Analysis 會自動建立 Pub/Sub 主題,主題 ID 如下:
container-analysis-notes-v1container-analysis-occurrences-v1
如果主題遭誤刪或遺失,你可以自行新增。舉例來說,如果 Google Cloud貴組織設有組織政策限制,規定必須使用客戶自行管理的加密金鑰 (CMEK) 加密,就可能不會顯示主題。如果 Pub/Sub API 位於這項限制的拒絕清單中,服務就無法使用Google-owned and Google-managed encryption keys自動建立主題。
如要使用 Google-owned and Google-managed encryption keys建立主題,請按照下列步驟操作:
控制台
前往 Google Cloud 控制台的 Pub/Sub 主題頁面。
按一下 [Create Topic] (建立主題)。
輸入主題 ID:
container-analysis-notes-v1讓名稱與 URI 相符:
projects/PROJECT_ID/topics/container-analysis-notes-v1其中 PROJECT_ID 是您的 Google Cloud 專案 ID。
點選「建立」。
輸入主題 ID:
container-analysis-occurrences-v1讓名稱與 URI 相符:
projects/PROJECT_ID/topics/container-analysis-occurrences-v1
gcloud
在您的殼層或終端機視窗中執行下列指令:
gcloud pubsub topics create projects/PROJECT_ID/topics/container-analysis-notes-v1
gcloud pubsub topics create projects/PROJECT_ID/topics/container-analysis-occurrences-v1
如要進一步瞭解 gcloud pubsub topics 指令,請參閱 topics 說明文件。
如要建立採用 CMEK 加密的主題,請參閱 Pub/Sub 的主題加密說明。
每當建立或更新附註或事件時,系統都會將訊息發布至相應主題,但您也必須建立 Pub/Sub 訂閱項目,才能監聽事件及接收 Pub/Sub 服務傳送的訊息。
建立 Pub/Sub 訂閱項目
如要監聽事件,請建立與主題相關聯的 Pub/Sub 訂閱項目:
控制台
前往Google Cloud 控制台的 Pub/Sub 訂閱項目頁面。
按一下 [Create Subscription] (建立訂閱項目)。
輸入訂閱方案名稱,例如「notes」。
輸入附註主題的 URI:
projects/PROJECT_ID/topics/container-analysis-notes-v1其中 PROJECT_ID 是您的 Google Cloud 專案 ID。
點選「建立」。
使用 URI 為事件建立另一個訂閱項目:
projects/PROJECT_ID/topics/container-analysis-occurrences-v1
gcloud
如要接收 Pub/Sub 事件,請先建立與 container-analysis-occurrences-v1 主題相關聯的訂閱項目:
gcloud pubsub subscriptions create \
--topic container-analysis-occurrences-v1 occurrences
您之後可以使用新訂閱提取有關例項的訊息:
gcloud pubsub subscriptions pull \
--auto-ack occurrences
Java
如要瞭解如何安裝及使用 Artifact Analysis 的用戶端程式庫,請參閱「Artifact Analysis 用戶端程式庫」。詳情請參閱 Artifact Analysis Java API 參考文件。
如要向 Artifact Analysis 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。
Go
如要瞭解如何安裝及使用 Artifact Analysis 的用戶端程式庫,請參閱「Artifact Analysis 用戶端程式庫」。詳情請參閱「Artifact Analysis Go API 參考文件」。
如要向 Artifact Analysis 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。
Node.js
如要瞭解如何安裝及使用 Artifact Analysis 的用戶端程式庫,請參閱「Artifact Analysis 用戶端程式庫」。詳情請參閱「Artifact Analysis Node.js API 參考文件」。
如要向 Artifact Analysis 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。
Ruby
如要瞭解如何安裝及使用 Artifact Analysis 的用戶端程式庫,請參閱「Artifact Analysis 用戶端程式庫」。詳情請參閱「Artifact Analysis Ruby API 參考文件」。
如要向 Artifact Analysis 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。
Python
如要瞭解如何安裝及使用 Artifact Analysis 的用戶端程式庫,請參閱「Artifact Analysis 用戶端程式庫」。詳情請參閱「Artifact Analysis Python API 參考文件」。
如要向 Artifact Analysis 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。
訂閱者應用程式只會收到訂閱項目建立後發布至主題的訊息。
Pub/Sub 酬載採用 JSON 格式,結構定義如下:
注意:
{ "name": "projects/PROJECT_ID/notes/NOTE_ID", "kind": "NOTE_KIND", "notificationTime": "NOTIFICATION_TIME", }
例項:
{ "name": "projects/PROJECT_ID/occurrences/OCCURRENCE_ID", "kind": "NOTE_KIND", "notificationTime": "NOTIFICATION_TIME", }
其中:
- NOTE_KIND 是
NoteKind中的其中一個值 - NOTIFICATION_TIME 是 RFC 3339 UTC「Zulu」格式的時間戳記,精確度可達奈秒。
查看詳細資料
如要進一步瞭解附註或事件,可以存取 Artifact Analysis 中儲存的中繼資料。舉例來說,您可以要求提供特定事件的所有詳細資料。請參閱「調查安全漏洞」一文中的操作說明。
後續步驟
- 如要瞭解如何使用構件分析服務儲存及管理自訂中繼資料,請參閱「建立自訂附註和發生事項」。