收集 Menlo Security Isolation Platform (MSIP) 記錄
本指南說明如何使用 Google Cloud Storage,將 Menlo Security Isolation Platform (MSIP) 記錄擷取至 Google SecOps。
Menlo Security 的隔離式方法會將網頁瀏覽和文件擷取作業,分別在使用者裝置和隔離式拋棄式虛擬容器 (DVC) 上執行,與端點分開。所有有風險的程式碼都會在獨立的 DVC 中執行,絕不會傳送到端點。系統只會將安全顯示資料傳送至使用者的瀏覽器。這個平台提供網頁存取、稽核事件、電子郵件安全、DLP 違規事項和 SMTP 活動的完整記錄。
事前準備
請確認您已完成下列事前準備事項:
- Google SecOps 執行個體
- Menlo Security 管理入口網站的特殊存取權
- 在 Menlo Security 中建立 API 權杖的權限
- 已啟用 Cloud Storage、Cloud Run、Pub/Sub 和 Cloud Scheduler API 的 GCP 專案
設定 Menlo Security API 存取權
如要讓 Cloud Run 函式擷取記錄,請建立具有 Log Export API 權限的 API 權杖。
建立 API 權杖
- 前往
https://admin.menlosecurity.com,登入 Menlo Security 管理入口網站。 - 依序前往「設定」>「驗證」>「API 權杖」。
- 按一下「建立權杖」。
- 在「權杖名稱」欄位中,輸入描述性名稱 (例如
Chronicle GCS Integration)。 - 在「權限」部分,選取「記錄匯出 API」。
- 按一下「建立」或「儲存」。
- 複製並安全儲存產生的 API 權杖。
重要事項:API 權杖只會顯示一次。建立後請立即將其存放在安全的位置。
必要的 API 權限
API 權杖必須具備下列權限:
權限/範圍 存取層級 目的 記錄匯出 API 讀取 從 Menlo Security API 擷取記錄
建立 Google Cloud Storage bucket
- 前往 Google Cloud 控制台。
- 選取專案或建立新專案。
- 在導覽選單中,依序前往「Cloud Storage」>「Bucket」。
- 按一下「建立值區」。
請提供下列設定詳細資料:
設定 值 為 bucket 命名 輸入全域不重複的名稱 (例如 menlo-security-logs)位置類型 根據需求選擇 (區域、雙區域、多區域) 位置 選取位置 (例如 us-central1)儲存空間級別 標準 (建議用於經常存取的記錄) 存取控管 統一 (建議) 保護工具 選用:啟用物件版本管理或資料保留政策 點選「建立」。
為 Cloud Run 函式建立服務帳戶
建立服務帳戶
- 在 GCP 控制台中,依序前往「IAM & Admin」(IAM 與管理) >「Service Accounts」(服務帳戶)。
- 按一下「Create Service Account」(建立服務帳戶)。
- 請提供下列設定詳細資料:
- 服務帳戶名稱:輸入
menlo-logs-collector-sa - 服務帳戶說明:輸入
Service account for Cloud Run function to collect Menlo Security logs
- 服務帳戶名稱:輸入
- 按一下「建立並繼續」。
- 在「將專案存取權授予這個服務帳戶」部分,新增下列角色:
- 按一下「選擇角色」。
- 搜尋並選取「Storage 物件管理員」。
- 點選「+ 新增其他角色」。
- 搜尋並選取「Cloud Run Invoker」。
- 點選「+ 新增其他角色」。
- 搜尋並選取「Cloud Functions Invoker」(Cloud Functions 叫用者)。
- 按一下「繼續」。
- 按一下 [完成]。
授予 GCS 值區的 IAM 權限
- 依序前往「Cloud Storage」>「Buckets」。
- 按一下 bucket 名稱 (
menlo-security-logs)。 - 前往「權限」分頁標籤。
- 按一下「授予存取權」。
- 請提供下列設定詳細資料:
- 新增主體:輸入服務帳戶電子郵件地址 (
menlo-logs-collector-sa@PROJECT_ID.iam.gserviceaccount.com) - 指派角色:選取「Storage 物件管理員」
- 新增主體:輸入服務帳戶電子郵件地址 (
- 按一下 [儲存]。
建立 Pub/Sub 主題
- 在 GCP Console 中,前往「Pub/Sub」>「Topics」(主題)。
- 按一下「建立主題」。
- 請提供下列設定詳細資料:
- 主題 ID:輸入
menlo-logs-trigger - 其他設定保留預設值
- 主題 ID:輸入
- 點選「建立」。
建立 Cloud Run 函式來收集記錄
- 前往 GCP Console 的「Cloud Run」。
- 按一下「Create service」(建立服務)。
- 選取「函式」 (使用內嵌編輯器建立函式)。
在「設定」部分,提供下列設定詳細資料:
設定 值 服務名稱 menlo-logs-collector區域 選取與 GCS bucket 相符的區域 (例如 us-central1)執行階段 選取 Python 3.12 以上版本 在「Trigger (optional)」(觸發條件 (選用)) 專區:
- 按一下「+ 新增觸發條件」。
- 選取「Cloud Pub/Sub」。
- 在「Select a Cloud Pub/Sub topic」(選取 Cloud Pub/Sub 主題) 中,選擇
menlo-logs-trigger。 - 按一下 [儲存]。
在「Authentication」(驗證) 部分:
- 選取「需要驗證」。
- 檢查 Identity and Access Management (IAM)。
向下捲動並展開「容器」、「網路」和「安全性」。
前往「安全性」分頁:
- 服務帳戶:選取
menlo-logs-collector-sa
- 服務帳戶:選取
前往「容器」分頁:
- 按一下「變數與密鑰」。
- 針對每個環境變數,按一下「+ 新增變數」:
變數名稱 範例值 說明 GCS_BUCKETmenlo-security-logsGCS bucket 名稱 GCS_PREFIXmenlo-logs記錄檔的前置字串 STATE_KEYmenlo-logs/state.json狀態檔案路徑 MENLO_API_TOKENyour-menlo-api-tokenMenlo Security API 權杖 MENLO_API_HOSTlogs.menlosecurity.comMenlo Security API 主機 MENLO_LOG_TYPESweb,audit,email,dlp以半形逗號分隔的記錄類型 LOOKBACK_HOURS1初始回溯期 在「變數與密鑰」部分,向下捲動至「要求」:
- 要求逾時:輸入
600秒 (10 分鐘)
- 要求逾時:輸入
前往「設定」分頁:
- 在「資源」部分:
- 記憶體:選取 512 MiB 以上
- CPU:選取 1
- 在「資源」部分:
在「修訂版本資源調度」部分:
- 執行個體數量下限:輸入
0 - 執行個體數量上限:輸入
100
- 執行個體數量下限:輸入
點選「建立」。
等待服務建立完成 (1 到 2 分鐘)。
服務建立完成後,系統會自動開啟內嵌程式碼編輯器。
新增函式程式碼
- 在「進入點」欄位中輸入「main」。
在內嵌程式碼編輯器中,建立兩個檔案:
- main.py:
import functions_framework from google.cloud import storage import os import json import urllib3 import time import uuid from datetime import datetime, timezone, timedelta http = urllib3.PoolManager( timeout=urllib3.Timeout(connect=5.0, read=60.0), retries=False, ) storage_client = storage.Client() GCS_BUCKET = os.environ.get('GCS_BUCKET') GCS_PREFIX = os.environ.get('GCS_PREFIX', 'menlo-logs') STATE_KEY = os.environ.get('STATE_KEY', 'menlo-logs/state.json') API_TOKEN = os.environ.get('MENLO_API_TOKEN') API_HOST = os.environ.get('MENLO_API_HOST', 'logs.menlosecurity.com') LOG_TYPES = os.environ.get('MENLO_LOG_TYPES', 'web').split(',') LOOKBACK_HOURS = int(os.environ.get('LOOKBACK_HOURS', '1')) @functions_framework.cloud_event def main(cloud_event): if not all([GCS_BUCKET, API_TOKEN, API_HOST]): print('Error: Missing required environment variables') return try: bucket = storage_client.bucket(GCS_BUCKET) state = load_state(bucket) now = datetime.now(timezone.utc).replace(microsecond=0) if isinstance(state, dict) and state.get('last_event_time'): try: last_val = state['last_event_time'] if last_val.endswith('Z'): last_val = last_val[:-1] + '+00:00' last_time = datetime.fromisoformat(last_val) last_time = last_time - timedelta(minutes=2) except Exception as e: print(f"Warning: Could not parse last_event_time: {e}") last_time = now - timedelta(hours=LOOKBACK_HOURS) else: last_time = now - timedelta(hours=LOOKBACK_HOURS) print(f"Fetching logs from {last_time.isoformat()} to {now.isoformat()}") total = 0 newest_time = None for log_type in LOG_TYPES: log_type = log_type.strip() print(f"Fetching {log_type} logs...") events = fetch_logs(log_type, API_TOKEN, API_HOST, last_time, now) if events: object_key = f"{GCS_PREFIX}/{now:%Y/%m/%d}/menlo-{log_type}-{uuid.uuid4()}.ndjson" blob = bucket.blob(object_key) ndjson = '\n'.join( [json.dumps(ev, ensure_ascii=False) for ev in events] ) + '\n' blob.upload_from_string(ndjson, content_type='application/x-ndjson') print(f"Uploaded {len(events)} {log_type} events to gs://{GCS_BUCKET}/{object_key}") total += len(events) for ev in events: ev_time = ev.get('timestamp') or ev.get('time') or ev.get('created_at') if ev_time and (newest_time is None or str(ev_time) > str(newest_time)): newest_time = str(ev_time) else: print(f"No {log_type} events found") save_state(bucket, newest_time if newest_time else now.isoformat()) print(f"Successfully processed {total} total events") except Exception as e: print(f'Error processing logs: {str(e)}') raise def fetch_logs(log_type, token, api_host, start, end): url = f"https://{api_host}/api/v1/logs/{log_type}" headers = { 'Authorization': f'Token {token}', 'Accept': 'application/json', } params = { 'start': start.strftime('%Y-%m-%dT%H:%M:%SZ'), 'end': end.strftime('%Y-%m-%dT%H:%M:%SZ'), } query = '&'.join(f'{k}={v}' for k, v in params.items()) full_url = f'{url}?{query}' all_events = [] backoff = 1.0 while full_url: response = http.request('GET', full_url, headers=headers) if response.status == 429: retry_after = int(response.headers.get('Retry-After', str(int(backoff)))) print(f"Rate limited. Waiting {retry_after}s...") time.sleep(retry_after) backoff = min(backoff * 2, 60.0) continue if response.status != 200: print(f"API error {response.status}: {response.data.decode('utf-8')}") break backoff = 1.0 data = json.loads(response.data.decode('utf-8')) events = data if isinstance(data, list) else data.get('events', data.get('data', [])) all_events.extend(events) full_url = data.get('next') if isinstance(data, dict) else None print(f"Total {log_type} events fetched: {len(all_events)}") return all_events def load_state(bucket): try: blob = bucket.blob(STATE_KEY) if blob.exists(): return json.loads(blob.download_as_text()) except Exception as e: print(f"Warning: Could not load state: {e}") return {} def save_state(bucket, last_event_time_iso): try: state = { 'last_event_time': last_event_time_iso, 'last_run': datetime.now(timezone.utc).isoformat() } blob = bucket.blob(STATE_KEY) blob.upload_from_string( json.dumps(state, indent=2), content_type='application/json' ) print(f"Saved state: last_event_time={last_event_time_iso}") except Exception as e: print(f"Warning: Could not save state: {e}")- requirements.txt:
functions-framework==3.* google-cloud-storage==2.* urllib3>=2.0.0點選「部署」即可儲存並部署函式。
等待部署作業完成 (2 到 3 分鐘)。
建立 Cloud Scheduler 工作
- 前往 GCP 主控台的「Cloud Scheduler」。
- 點選「建立工作」。
請提供下列設定詳細資料:
設定 值 名稱 menlo-logs-collector-hourly區域 選取與 Cloud Run 函式相同的區域 頻率 0 * * * *(每小時整點)時區 選取時區 (建議使用世界標準時間) 目標類型 Pub/Sub 主題 選取「 menlo-logs-trigger」郵件內文 {}(空白 JSON 物件)點選「建立」。
測試整合項目
- 在 Cloud Scheduler 控制台中,找出您的工作 (
menlo-logs-collector-hourly)。 - 按一下「強制執行」即可手動觸發工作。
- 稍等幾秒鐘。
- 前往「Cloud Run」>「Services」。
- 按一下
menlo-logs-collector。 - 按一下 [Logs] (記錄) 分頁標籤。
確認函式是否已順利執行。尋找:
Fetching logs from YYYY-MM-DDTHH:MM:SS+00:00 to YYYY-MM-DDTHH:MM:SS+00:00 Fetching web logs... Total web events fetched: X Uploaded X web events to gs://menlo-security-logs/menlo-logs/YYYY/MM/DD/menlo-web-UUID.ndjson Successfully processed X total events依序前往「Cloud Storage」>「Buckets」。
按一下
menlo-security-logs。前往
menlo-logs/資料夾。確認是否已建立新的
.ndjson檔案,且檔案名稱包含目前日期。
如果記錄中顯示錯誤:
- HTTP 401:確認
MENLO_API_TOKEN環境變數是否正確 - HTTP 403:確認 API 權杖是否具備 Log Export API 權限
- HTTP 429:頻率限制,函式會自動重試並延遲
- 缺少環境變數:確認 Cloud Run 函式設定中已設定所有必要變數
擷取 Google SecOps 服務帳戶
- 依序前往「SIEM 設定」>「動態饋給」。
- 按一下「新增動態消息」。
- 按一下「設定單一動態饋給」。
- 在「動態饋給名稱」欄位中輸入動態饋給名稱 (例如
Menlo Security MSIP Logs)。 - 選取「Google Cloud Storage V2」做為「來源類型」。
- 選取「Menlo Security」做為「記錄類型」。
按一下「取得服務帳戶」。系統會顯示專屬服務帳戶電子郵件地址,例如:
chronicle-12345678@chronicle-gcp-prod.iam.gserviceaccount.com複製這個電子郵件地址,以便在下一步中使用。
點選「下一步」。
指定下列輸入參數的值:
儲存空間 bucket URL:輸入 GCS bucket URI,並加上前置路徑:
gs://menlo-security-logs/menlo-logs/
來源刪除選項:根據偏好設定選取刪除選項:
- 永不:移轉後一律不刪除任何檔案 (建議用於測試)。
- 刪除已轉移的檔案:成功轉移檔案後刪除檔案。
刪除已轉移的檔案和空白目錄:成功轉移後刪除檔案和空白目錄。
檔案存在時間上限:包含在過去天數內修改的檔案 (預設為 180 天)
資產命名空間:資產命名空間
擷取標籤:要套用至這個動態饋給事件的標籤
點選「下一步」。
在「Finalize」(完成) 畫面中檢查新的動態饋給設定,然後按一下「Submit」(提交)。
將 IAM 權限授予 Google SecOps 服務帳戶
- 依序前往「Cloud Storage」>「Buckets」。
- 按一下
menlo-security-logs。 - 前往「權限」分頁標籤。
- 按一下「授予存取權」。
- 請提供下列設定詳細資料:
- 新增主體:貼上 Google SecOps 服務帳戶電子郵件地址
- 指派角色:選取「Storage 物件檢視者」
- 按一下 [儲存]。
UDM 對應表
| 記錄欄位 | UDM 對應 | 邏輯 |
|---|---|---|
| customer_name | intermediary.hostname | 設定 customer_name (如果不是 IP) |
| customer_name | intermediary.ip | 如果為 IP,則從 customer_name 擷取;如果為 xff_ip IP,則從 xff_ip 擷取 |
| xff_ip | intermediary.ip | |
| event_data.event_time | metadata.event_timestamp | 使用 grok 和日期篩選器剖析 |
| request_type | metadata.event_type | 根據這些欄位設定條件式邏輯 |
| has_principal | metadata.event_type | |
| has_top_url | metadata.event_type | |
| has_dest | metadata.event_type | |
| log_type | metadata.log_type | 直接複製值 |
| event_data.name | metadata.product_event_type | 直接複製值 |
| reqId | metadata.product_log_id | 直接複製值 |
| event_data.version | metadata.product_version | 直接複製值 |
| event_data.protocol | network.application_protocol | 使用預先定義的通訊協定清單對應 |
| request_type | network.http.method | 直接複製值 |
| 參照網址 | network.http.referral_url | 直接複製值 |
| response_code | network.http.response_code | 已轉換為整數 |
| event_data.user-agent | network.http.user_agent | 直接複製值 |
| full_session_id | network.session_id | 直接複製值 |
| browser_and_version | principal.application | 直接複製值 |
| event_data.x-client-ip | principal.asset.ip | 如果 event_data.x-client-ip 不為空值,則為該值,否則為 src_ip |
| src_ip | principal.asset.ip | |
| 群組 | principal.group.product_object_id | 直接複製值 |
| event_data.x-client-ip | principal.ip | 如果 event_data.x-client-ip 不為空值,則為該值,否則為 src_ip |
| src_ip | principal.ip | |
| 區域 | principal.location.country_or_region | 如果區域不為空白,則為區域值,否則為 egress_country |
| egress_country | principal.location.country_or_region | |
| region_name | principal.location.name | 直接複製值 |
| egress_ip | principal.nat_ip | 直接複製值 |
| event_data.userid | principal.user.email_addresses | 如果符合電子郵件規則運算式,則會合併 |
| event_data.userid | principal.user.userid | 直接複製值 |
| event_data.domain | security_result.about.administrative_domain | 直接複製值 |
| event_data.url | security_result.about.url | 直接複製值 |
| event_data.pe_action | security_result.action | 對應至 ALLOW、BLOCK 或 ALLOW_WITH_MODIFICATION |
| event_data.categories | security_result.category_details | 從 event_data.categories (已擷取或直接) 和 casb_cat_name 合併 |
| casb_cat_name | security_result.category_details | |
| event_data.risk_score | security_result.confidence_details | 直接複製值 |
| content-type | security_result.detection_fields | 從各種標籤欄位合併 |
| 產品 | security_result.detection_fields | |
| 威脅 | security_result.detection_fields | |
| virusDetails | security_result.detection_fields | |
| sandboxResult | security_result.detection_fields | |
| fullScanResult | security_result.detection_fields | |
| tab_id | security_result.detection_fields | |
| pe_reason | security_result.detection_fields | |
| ua_type | security_result.detection_fields | |
| email_isolation_state | security_result.detection_fields | |
| document_url | security_result.detection_fields | |
| archive_path | security_result.detection_fields | |
| casb_app_name | security_result.detection_fields | |
| casb_fun_name | security_result.detection_fields | |
| casb_org_name | security_result.detection_fields | |
| casb_profile_id | security_result.detection_fields | |
| casb_profile_name | security_result.detection_fields | |
| casb_profile_type | security_result.detection_fields | |
| casb_risk_score | security_result.detection_fields | |
| connId | security_result.detection_fields | |
| origin_country | security_result.detection_fields | |
| egress_country | security_result.detection_fields | |
| is_casb_ddl | security_result.detection_fields | |
| is_iframe | security_result.detection_fields | |
| parent_file_id | security_result.detection_fields | |
| parent_filename | security_result.detection_fields | |
| parent_sha256 | security_result.detection_fields | |
| parent_tid | security_result.detection_fields | |
| root_file_id | security_result.detection_fields | |
| root_filename | security_result.detection_fields | |
| root_sha256 | security_result.detection_fields | |
| casb_risk_score | security_result.risk_score | 已轉換為浮點數 |
| casb_profile_id | security_result.rule_id | 直接複製值 |
| pe_rulename | security_result.rule_name | 直接複製值 |
| casb_profile_name | security_result.rule_set | 直接複製值 |
| casb_profile_type | security_result.rule_type | 直接複製值 |
| event_data.severity | security_result.severity_details | 直接複製值 |
| magicName | security_result.summary | 串連為「%{magicName} is %{threats}。」 |
| 威脅 | security_result.summary | |
| threat_types | security_result.threat_name | 直接複製值 |
| origin_ip | src.ip | 直接複製值 |
| origin_country | src.location.country_or_region | 直接複製值 |
| event_data.dst | target.asset.ip | 使用 grok IP 模式從 event_data.dst 或 dst 擷取 |
| dst | target.asset.ip | |
| filename | target.file.full_path | 直接複製值 |
| mimeType | target.file.mime_type | 直接複製值 |
| sha256 | target.file.sha256 | 直接複製值 |
| file_size | target.file.size | 已轉換為浮點數,然後轉換為不帶正負號的整數 |
| event_data.dst | target.ip | 使用 grok IP 模式從 event_data.dst 或 dst 擷取 |
| dst | target.ip | |
| top_url | target.url | 使用 URI grok 模式擷取 |
| metadata.product_name | metadata.product_name | 設為「MENLO SECURITY」 |
| metadata.vendor_name | metadata.vendor_name | 設為「MENLO SECURITY」 |
region |
event.idm.read_only_udm.principal.location.country_or_region |
從變更記錄對應 |
region_name |
event.idm.read_only_udm.principal.location.name |
從變更記錄對應 |
src_ip |
event.idm.read_only_udm.principal.ip 和 event.idm.read_only_udm.principal.asset.ip |
從變更記錄對應 |
groups |
event.idm.read_only_udm.principal.group.product_object_id |
從變更記錄對應 |
content-type |
event.idm.read_only_udm.security_result.detection_fields |
從變更記錄對應 |
product |
event.idm.read_only_udm.security_result.detection_fields |
從變更記錄對應 |
mimeType |
event.idm.read_only_udm.target.file.mime_type |
從變更記錄對應 |
變更記錄
還有其他問題嗎?向社群成員和 Google SecOps 專業人員尋求答案。