收集 Atlassian Bitbucket 記錄
剖析器版本:2.0
本文說明如何設定 Atlassian Bitbucket,透過 Webhook 將記錄檔推送至 Google Security Operations。
Atlassian Bitbucket 是以 Git 為基礎的程式碼存放區代管服務。為開發團隊提供程式碼協作、提取要求工作流程和 CI/CD 管道。Bitbucket 支援雲端和自行代管 (資料中心) 部署作業。
事前準備
請確認您已完成下列事前準備事項:
- Google SecOps 執行個體
- 具備管理員存取權的 Atlassian Bitbucket Cloud 或 Data Center 執行個體
- 存取 Google Cloud 控制台 (用於建立 API 金鑰)
在 Google SecOps 中建立 Webhook 動態饋給
建立動態饋給
- 依序前往「SIEM 設定」>「動態饋給」。
- 按一下「新增動態消息」。
- 在下一個頁面中,按一下「設定單一動態饋給」。
- 在「動態饋給名稱」欄位中輸入動態饋給名稱 (例如
Bitbucket Webhook Logs)。 - 選取「Webhook」做為「來源類型」。
- 選取「Atlassian Bitbucket」做為「記錄類型」。
- 點選「下一步」。
- 指定下列輸入參數的值:
- 分割分隔符號 (選用):輸入分隔符號,分割多行事件。常見值:
\n- 換行分隔符號 (NDJSON 最常見)- 如果每個要求都包含單一活動,請留空
- 資產命名空間:資產命名空間
- 擷取標籤:要套用至這個動態饋給事件的標籤
- 分割分隔符號 (選用):輸入分隔符號,分割多行事件。常見值:
- 點選「下一步」。
- 在「Finalize」(完成) 畫面中檢查新的動態饋給設定,然後按一下「Submit」(提交)。
產生並儲存密鑰
建立動態饋給後,您必須產生驗證用的密鑰:
- 在動態饋給詳細資料頁面中,按一下「產生密鑰」。
- 對話方塊會顯示密鑰。
- 複製並妥善儲存密鑰。
取得動態消息端點網址
- 前往動態消息的「詳細資料」分頁。
- 在「端點資訊」部分,複製「動態消息端點網址」。
網址格式為:
https://malachiteingestion-pa.googleapis.com/v2/unstructuredlogentries:batchCreate或
https://<REGION>-malachiteingestion-pa.googleapis.com/v2/unstructuredlogentries:batchCreate請儲存這個網址,以供後續步驟使用。
按一下 [完成]。
建立 Google Cloud API 金鑰
Google SecOps 需要 API 金鑰才能進行驗證。在 Google Cloud 控制台中建立受限制的 API 金鑰。
建立 API 金鑰
- 前往 Google Cloud 控制台的「憑證」頁面。
- 選取專案 (與 Google SecOps 執行個體相關聯的專案)。
- 依序按一下「建立憑證」>「API 金鑰」。
- 系統會建立 API 金鑰,並顯示在對話方塊中。
- 按一下「編輯 API 金鑰」即可限制金鑰。
限制 API 金鑰
- 在「API 金鑰」設定頁面中:
- 名稱:輸入描述性名稱 (例如
Webhook API Key)
- 名稱:輸入描述性名稱 (例如
- 在「API 限制」下方:
- 選取「Restrict key」(限制金鑰)。
- 在「選取 API」下拉式選單中,搜尋並選取「Google SecOps API」。
- 按一下 [儲存]。
- 從頁面頂端的「API key」(API 金鑰) 欄位複製 API 金鑰值。
安全地儲存 API 金鑰。
設定 Atlassian Bitbucket Webhook
建構 Webhook 網址
合併 Google SecOps 端點網址和 API 金鑰:
<ENDPOINT_URL>?key=<API_KEY>&secret=<SECRET_KEY>範例:
https://malachiteingestion-pa.googleapis.com/v2/unstructuredlogentries:batchCreate?key=AIzaSyD...&secret=abcd1234...
在 Bitbucket Cloud 中建立 Webhook
- 以工作區或存放區管理員身分登入 Bitbucket Cloud。
- 前往要設定 Webhook 的存放區。
- 依序前往「存放區設定」>「Webhook」。
- 按一下 [Add Webhook]。
- 請提供下列設定詳細資料:
- 標題:輸入描述性名稱 (例如
SIEM Webhook)。 - 網址:貼上完整的端點網址,並附上上述 API 金鑰和密鑰。
- 狀態:選取「有效」。
- 觸發條件:選取「從完整觸發條件清單中選擇」,然後選取要傳送的事件:
- 存放區:推送、分叉、建立提交留言
- 提取要求:已建立、已更新、已核准、未核准、已合併、已拒絕、已建立留言
- 問題:已建立、已更新、已建立留言
- 標題:輸入描述性名稱 (例如
- 按一下 [儲存]。
在 Bitbucket Data Center 中建立 Webhook
- 以專案或存放區管理員身分登入 Bitbucket Data Center。
- 前往要設定 Webhook 的專案或存放區。
- 依序前往「專案設定」>「Webhook」 (專案層級) 或「存放區設定」>「Webhook」 (存放區層級)。
- 按一下「建立 Webhook」。
- 請提供下列設定詳細資料:
- 名稱:輸入描述性名稱 (例如
SIEM Webhook)。 - 網址:貼上完整的端點網址,並附上上述 API 金鑰和密鑰。
- 狀態:選取「有效」。
- 活動:選取要轉寄的活動:
- 存放區:參考資料已變更、已建立分支、已新增註解
- 提取要求:已開啟、來源分支已更新、已修改、審查員已更新、已核准、未核准、需要處理、已合併、已拒絕、已刪除、已新增註解
- 名稱:輸入描述性名稱 (例如
- 按一下 [儲存]。
確認 Webhook 傳送狀態
- 建立 Webhook 後,請在存放區中執行動作 (例如推送提交)。
- 依序前往「存放區設定」>「Webhook」。
- 按一下 Webhook 旁的「查看要求」。
- 確認要求顯示 200 狀態碼,表示傳送成功。
詳情請參閱 Bitbucket Cloud 網頁掛鉤說明文件或 Bitbucket Data Center 網頁掛鉤說明文件。
驗證方法參考資料
Google SecOps 網頁掛鉤動態消息支援多種驗證方法。選擇供應商支援的方法。
方法 1:自訂標頭 (建議)
如果供應商支援自訂 HTTP 標頭,請使用這個方法,以提升安全性。
要求格式:
POST <ENDPOINT_URL> HTTP/1.1 Content-Type: application/json x-goog-chronicle-auth: <API_KEY> x-chronicle-auth: <SECRET_KEY> { "event": "data", "timestamp": "2025-01-15T10:30:00Z" }優點:
- 網址中不會顯示 API 金鑰和密鑰
- 更安全 (標頭不會記錄在網路伺服器存取記錄中)
- 供應商支援時的首選方法
方法 2:查詢參數
如果供應商不支援自訂標頭,請將憑證附加至網址。
網址格式:
<ENDPOINT_URL>?key=<API_KEY>&secret=<SECRET_KEY>範例:
https://malachiteingestion-pa.googleapis.com/v2/unstructuredlogentries:batchCreate?key=AIzaSyD...&secret=abcd1234...要求格式:
POST <ENDPOINT_URL>?key=<API_KEY>&secret=<SECRET_KEY> HTTP/1.1 Content-Type: application/json { "event": "data", "timestamp": "2025-01-15T10:30:00Z" }
缺點:
- 網址中顯示憑證
- 可能會記錄在網路伺服器存取記錄中
- 安全性不如標頭
方法 3:混合式 (網址 + 標頭)
部分設定會在網址中使用 API 金鑰,並在標頭中使用密鑰。
要求格式:
POST <ENDPOINT_URL>?key=<API_KEY> HTTP/1.1 Content-Type: application/json x-chronicle-auth: <SECRET_KEY> { "event": "data", "timestamp": "2025-01-15T10:30:00Z" }
驗證標頭名稱
Google SecOps 接受下列驗證標頭名稱:
API 金鑰:
x-goog-chronicle-auth(建議)X-Goog-Chronicle-Auth(不區分大小寫)
密鑰:
x-chronicle-auth(建議)X-Chronicle-Auth(不區分大小寫)
Webhook 限制和最佳做法
要求限制
| 限制 | 值 |
|---|---|
| 要求大小上限 | 4 MB |
| 每秒查詢次數 (QPS) 上限 | 15,000 |
| 要求逾時 | 30 秒 |
| 重試行為 | 自動執行指數輪詢 |
UDM 對應表
| 記錄欄位 | UDM 對應 | 邏輯 |
|---|---|---|
actor.display_name |
principal.user.user_display_name |
取自 actor.display_name 欄位的值。 |
actor.nickname |
principal.user.userid |
取自 actor.nickname 欄位的值。 |
actor.account_id |
principal.user.product_object_id |
取自 actor.account_id 欄位的值。 |
actor.uuid |
principal.user.product_object_id |
如果沒有 actor.account_id,則取自 actor.uuid 欄位的值。 |
actor.links.html.href |
principal.url |
取自 actor.links.html.href 欄位的值。 |
repository.full_name |
target.resource.name |
取自 repository.full_name 欄位的值。 |
repository.uuid |
target.resource.product_object_id |
取自 repository.uuid 欄位的值。 |
repository.links.html.href |
target.url |
取自 repository.links.html.href 欄位的值。 |
repository.project.key |
target.resource.attribute.labels |
以鍵/值組合形式新增,鍵為「project_key」。 |
repository.project.name |
target.resource.attribute.labels |
以鍵/值組合形式新增,鍵為「project_name」。 |
repository.workspace.slug |
target.resource.attribute.labels |
以鍵/值組合形式新增,鍵為「workspace」。 |
push.changes[].new.name |
target.resource.attribute.labels |
以鍵/值組合形式新增,鍵為「branch_name」。 |
push.changes[].new.target.hash |
target.resource.attribute.labels |
以鍵/值組合形式新增,鍵為「commit_hash」。 |
push.changes[].new.target.message |
target.resource.attribute.labels |
以鍵/值組合形式新增,鍵為「commit_message」。 |
push.changes[].new.target.date |
target.resource.attribute.labels |
以鍵/值組合形式新增,鍵為「commit_date」。 |
push.changes[].new.target.author.raw |
target.user.email_addresses |
從作者原始欄位擷取的電子郵件地址。 |
pullrequest.id |
target.resource.attribute.labels |
以鍵/值組合形式新增,鍵為「pullrequest_id」。 |
pullrequest.title |
target.resource.attribute.labels |
以鍵/值組合形式新增,鍵為「pullrequest_title」。 |
pullrequest.state |
target.resource.attribute.labels |
以鍵/值組合形式新增,鍵為「pullrequest_state」。 |
pullrequest.author.display_name |
target.user.user_display_name |
取自 pullrequest.author.display_name 欄位的值。 |
pullrequest.source.branch.name |
target.resource.attribute.labels |
以鍵/值組合形式新增,鍵為「source_branch」。 |
pullrequest.destination.branch.name |
target.resource.attribute.labels |
以鍵/值組合形式新增,鍵為「destination_branch」。 |
date |
metadata.event_timestamp |
剖析為 ISO8601 時間戳記。如果 Webhook 酬載中存在這個值,系統會將其做為事件時間戳記。 |
metadata.event_type |
一開始請設為「GENERIC_EVENT」。根據事件鍵和主體/目標欄位是否存在,變更為「USER_RESOURCE_ACCESS」、「USER_RESOURCE_UPDATE_CONTENT」或「USER_UNCATEGORIZED」。 | |
metadata.product_event_type |
根據 X-Event-Key 網路鉤子標頭值設定 (例如 repo:push、pullrequest:created、pullrequest:updated)。 |
|
metadata.product_name |
設為「Atlassian Bitbucket」。 | |
metadata.vendor_name |
設為「Atlassian」。 |
變更記錄
還有其他問題嗎?向社群成員和 Google SecOps 專業人員尋求答案。