收集 Oracle Cloud Infrastructure 稽核記錄

支援的國家/地區:

本文說明如何使用 Google Cloud Storage,將 Oracle Cloud Infrastructure 稽核記錄擷取至 Google Security Operations。

Oracle Cloud Infrastructure Audit 服務會自動將對所有支援的 Oracle Cloud Infrastructure 公開應用程式設計介面 (API) 端點的呼叫記錄為記錄事件。目前所有服務都支援 Oracle Cloud Infrastructure Audit 記錄。Oracle Cloud Infrastructure Audit 記錄的記錄事件包括:Oracle Cloud Infrastructure 主控台、指令列介面 (CLI)、軟體開發套件 (SDK)、您自己的自訂用戶端,或其他 Oracle Cloud Infrastructure 服務發出的 API 呼叫。

事前準備

請確認您已完成下列事前準備事項:

  • Google SecOps 執行個體
  • 已啟用 Cloud Storage API 的 GCP 專案
  • 建立及管理 GCS bucket 的權限
  • 管理 Google Cloud Storage 值區 IAM 政策的權限
  • 建立 Cloud Run 服務、Pub/Sub 主題和 Cloud Scheduler 工作的權限
  • 具備建立及管理下列項目的權限的 Oracle Cloud Infrastructure 帳戶:
    • 服務連接器中樞
    • 函式
    • 物件儲存空間值區
    • IAM 政策
  • Oracle Cloud Infrastructure 控制台的特殊權限存取權

建立 Google Cloud Storage bucket

  1. 前往 Google Cloud 控制台
  2. 選取專案或建立新專案。
  3. 在導覽選單中,依序前往「Cloud Storage」>「Bucket」
  4. 按一下「建立值區」
  5. 請提供下列設定詳細資料:

    設定
    為 bucket 命名 輸入全域不重複的名稱 (例如 oci-audit-logs-gcs)
    位置類型 根據需求選擇 (區域、雙區域、多區域)
    位置 選取位置 (例如 us-central1)
    儲存空間級別 標準 (建議用於經常存取的記錄)
    存取控管 統一 (建議)
    保護工具 選用:啟用物件版本管理或保留政策
  6. 點選「建立」

設定 Oracle Cloud Infrastructure,將稽核記錄匯出至 GCS

Oracle Cloud Infrastructure 不支援原生匯出至 Google Cloud Storage。您將搭配使用 Oracle Cloud Infrastructure 服務連接器中樞和函式,將稽核記錄轉送至 GCS。

建立 Oracle Cloud Infrastructure 函式,將記錄轉送至 GCS

  1. 登入 Oracle Cloud Console
  2. 依序前往「開發人員服務」>「函式」>「應用程式」
  3. 選取要建立函式應用程式的區間。
  4. 點選「Create Application」(建立應用程式)
  5. 請提供下列設定詳細資料:
    • 「Name」(名稱):輸入 audit-logs-to-gcs-app
    • VCN:選取虛擬雲端網路。
    • 子網路:選取可存取網際網路的子網路。
  6. 點選「建立」
  7. 建立應用程式後,按一下「開始使用」,然後按照操作說明,使用 Fn CLI 設定本機開發環境。
  8. 在本機電腦上建立新的函式目錄:

    mkdir oci-audit-to-gcs
    cd oci-audit-to-gcs
    
  9. 初始化 Python 函式:

    fn init --runtime python oci-audit-to-gcs
    cd oci-audit-to-gcs
    
  10. func.py 的內容替換為下列程式碼:

    import io
    import json
    import logging
    import os
    from fdk import response
    from google.cloud import storage
    from google.oauth2 import service_account
    from datetime import datetime
    
    # Configure logging
    logging.basicConfig(level=logging.INFO)
    logger = logging.getLogger()
    
    # Environment variables
    GCS_BUCKET = os.environ.get('GCS_BUCKET')
    GCS_PREFIX = os.environ.get('GCS_PREFIX', 'oci-audit-logs')
    GCS_CREDENTIALS_JSON = os.environ.get('GCS_CREDENTIALS_JSON')
    
    def handler(ctx, data: io.BytesIO = None):
        """
        Oracle Cloud Infrastructure Function to forward Audit logs to GCS.
    
        Args:
            ctx: Function context
            data: Input data containing Audit log events
        """
    
        if not all([GCS_BUCKET, GCS_CREDENTIALS_JSON]):
            logger.error('Missing required environment variables: GCS_BUCKET or GCS_CREDENTIALS_JSON')
            return response.Response(
                ctx, response_data=json.dumps({"error": "Missing configuration"}),
                headers={"Content-Type": "application/json"}
            )
    
        try:
            # Parse input data
            body = json.loads(data.getvalue())
            logger.info(f"Received event: {json.dumps(body)}")
    
            # Extract log entries
            log_entries = []
            if isinstance(body, list):
                log_entries = body
            elif isinstance(body, dict):
                # Service Connector Hub sends data in specific format
                if 'data' in body:
                    log_entries = [body['data']] if isinstance(body['data'], dict) else body['data']
                else:
                    log_entries = [body]
    
            if not log_entries:
                logger.info("No log entries to process")
                return response.Response(
                    ctx, response_data=json.dumps({"status": "no_logs"}),
                    headers={"Content-Type": "application/json"}
                )
    
            # Initialize GCS client with service account credentials
            credentials_dict = json.loads(GCS_CREDENTIALS_JSON)
            credentials = service_account.Credentials.from_service_account_info(credentials_dict)
            storage_client = storage.Client(credentials=credentials, project=credentials_dict.get('project_id'))
            bucket = storage_client.bucket(GCS_BUCKET)
    
            # Write logs to GCS as NDJSON
            timestamp = datetime.utcnow().strftime('%Y%m%d_%H%M%S_%f')
            object_key = f"{GCS_PREFIX}/logs_{timestamp}.ndjson"
            blob = bucket.blob(object_key)
    
            ndjson = '\n'.join([json.dumps(entry, ensure_ascii=False) for entry in log_entries]) + '\n'
            blob.upload_from_string(ndjson, content_type='application/x-ndjson')
    
            logger.info(f"Wrote {len(log_entries)} records to gs://{GCS_BUCKET}/{object_key}")
    
            return response.Response(
                ctx, response_data=json.dumps({"status": "success", "records": len(log_entries)}),
                headers={"Content-Type": "application/json"}
            )
    
        except Exception as e:
            logger.error(f'Error processing logs: {str(e)}')
            return response.Response(
                ctx, response_data=json.dumps({"error": str(e)}),
                headers={"Content-Type": "application/json"},
                status_code=500
            )
    
  11. 使用下列依附元件更新 requirements.txt

    fdk>=0.1.0
    google-cloud-storage>=2.0.0
    google-auth>=2.0.0
    
  12. 將函式部署至 Oracle Cloud Infrastructure:

    fn -v deploy --app audit-logs-to-gcs-app
    
  13. 部署完成後,請記下函式 OCID。後續步驟會用到。

設定函式環境變數

  1. 在 Oracle Cloud 控制台中,依序前往「Developer Services」>「Functions」>「Applications」
  2. 按一下應用程式 (audit-logs-to-gcs-app)。
  3. 按一下函式名稱 (oci-audit-to-gcs)。
  4. 按一下「設定」
  5. 新增下列設定變數:

    GCS_BUCKET 您的 GCS bucket 名稱 (例如 oci-audit-logs-gcs)
    GCS_PREFIX 記錄檔的前置字串 (例如 oci-audit-logs)
    GCS_CREDENTIALS_JSON GCP 服務帳戶金鑰的 JSON 字串 (請見下文)
  6. 按一下 [儲存變更]。

為 Oracle Cloud Infrastructure Function 建立 GCP 服務帳戶

Oracle Cloud Infrastructure Function 需要 GCP 服務帳戶,才能寫入 GCS bucket。

  1. GCP 控制台中,依序前往「IAM & Admin」(IAM 與管理) >「Service Accounts」(服務帳戶)
  2. 按一下「Create Service Account」(建立服務帳戶)
  3. 請提供下列設定詳細資料:
    • 服務帳戶名稱:輸入 oci-function-gcs-writer
    • 服務帳戶說明:輸入 Service account for OCI Function to write Audit logs to GCS
  4. 按一下「建立並繼續」
  5. 在「將專案存取權授予這個服務帳戶」部分,新增下列角色:
    1. 按一下「選擇角色」
    2. 搜尋並選取「Storage 物件管理員」
  6. 按一下「繼續」
  7. 按一下 [完成]
  8. 按一下新建立的服務帳戶電子郵件地址。
  9. 前往「金鑰」分頁標籤。
  10. 依序點選「新增金鑰」>「建立新的金鑰」
  11. 選取「JSON」做為金鑰類型。
  12. 點選「建立」
  13. JSON 金鑰檔案會下載至您的電腦。
  14. 開啟 JSON 金鑰檔案,然後複製所有內容。
  15. 返回 Oracle Cloud 控制台函式設定。
  16. 將 JSON 內容貼到 GCS_CREDENTIALS_JSON 設定變數中。

授予 GCS 值區的 IAM 權限

將 GCS bucket 的寫入權限授予服務帳戶:

  1. 依序前往「Cloud Storage」>「Buckets」
  2. 按一下 bucket 名稱 (oci-audit-logs-gcs)。
  3. 前往「權限」分頁標籤。
  4. 按一下「授予存取權」
  5. 請提供下列設定詳細資料:
    • 新增主體:輸入服務帳戶電子郵件地址 (oci-function-gcs-writer@PROJECT_ID.iam.gserviceaccount.com)。
    • 指派角色:選取「Storage 物件管理員」
  6. 按一下 [儲存]

建立 Oracle Cloud Infrastructure 服務連接器中樞

  1. 登入 Oracle Cloud 控制台。
  2. 依序前往「可觀測性與管理」>「記錄」>「服務連接器中樞」。
  3. 選取要建立服務連接器的區間。
  4. 按一下「建立服務連接器」
  5. 請提供下列設定詳細資料:

    • 服務連結器資訊:
    設定
    連接器名稱 輸入audit-logs-to-gcs-connector人數
    說明 輸入Forward OCI Audit logs to Google Cloud Storage人數
    資源區間 選取區間
    • 設定來源:
    設定
    來源 選取「記錄」
    Compartment 選取包含稽核記錄的區間
    記錄群組 選取「_Audit」 (稽核記錄的預設記錄群組)
  6. 按一下「+ 另一個記錄」

  7. 選取區間的稽核記錄 (例如 _Audit_Include_Subcompartment)。

    • 設定目標:
    設定
    目標 選取「函式」
    函式區間 選取含有函式的區間
    函式應用程式 選取「audit-logs-to-gcs-app
    功能 選取「oci-audit-to-gcs
  8. 捲動至「設定工作 (選用)」,保留預設設定。

  9. 點選「建立」

為 Service Connector Hub 建立 IAM 政策

服務連接器中樞需要叫用函式的權限。

  1. 在 Oracle Cloud 控制台中,依序前往「Identity & Security」(身分與安全性)>「Policies」(政策)
  2. 選取您建立 Service Connector Hub 的區間。
  3. 點選「建立政策」
  4. 請提供下列設定詳細資料:
    • 「Name」(名稱):輸入 service-connector-functions-policy
    • 說明:輸入 Allow Service Connector Hub to invoke Functions
    • 區間:選取區間。
  5. 在「政策建立工具」部分,切換「顯示手動編輯器」
  6. 輸入下列政策聲明:

    Allow any-user to use fn-function in compartment <compartment-name> where all {request.principal.type='serviceconnector'}
    Allow any-user to use fn-invocation in compartment <compartment-name> where all {request.principal.type='serviceconnector'}
    
    • <compartment-name> 替換為您的區間名稱。
  7. 點選「建立」

測試整合項目

  1. 登入 Oracle Cloud 控制台。
  2. 執行一些會產生稽核記錄的動作 (例如建立或修改資源)。
  3. 等待 2 到 5 分鐘,讓系統處理記錄。
  4. 前往 GCP Console 的「Cloud Storage」>「Buckets」頁面。
  5. 按一下 bucket 名稱 (oci-audit-logs-gcs)。
  6. 前往前置字元資料夾 (oci-audit-logs/)。
  7. 確認 bucket 中顯示新的 .ndjson 檔案。

擷取 Google SecOps 服務帳戶

Google SecOps 會使用專屬服務帳戶,從 GCS bucket 讀取資料。您必須授予這個服務帳戶值區存取權。

取得服務帳戶電子郵件地址

  1. 依序前往「SIEM 設定」>「動態饋給」
  2. 按一下「新增動態消息」
  3. 按一下「設定單一動態饋給」
  4. 在「動態饋給名稱」欄位中輸入動態饋給名稱 (例如 Oracle Cloud Audit Logs)。
  5. 選取「Google Cloud Storage V2」做為「來源類型」
  6. 選取「Oracle Cloud Infrastructure Audit Logs」(Oracle Cloud Infrastructure 稽核記錄) 做為「記錄類型」
  7. 按一下「取得服務帳戶」。系統會顯示專屬服務帳戶電子郵件地址,例如:

    chronicle-12345678@chronicle-gcp-prod.iam.gserviceaccount.com
    
  8. 複製這個電子郵件地址,以便在下一步中使用。

將 IAM 權限授予 Google SecOps 服務帳戶

Google SecOps 服務帳戶需要 GCS bucket 的「Storage 物件檢視者」角色。

  1. 依序前往「Cloud Storage」>「Buckets」
  2. 按一下 bucket 名稱 (oci-audit-logs-gcs)。
  3. 前往「權限」分頁標籤。
  4. 按一下「授予存取權」
  5. 請提供下列設定詳細資料:
    • 新增主體:貼上 Google SecOps 服務帳戶電子郵件地址。
    • 指派角色:選取「Storage 物件檢視者」
  6. 按一下 [儲存]

在 Google SecOps 中設定資訊提供,擷取 Oracle Cloud Infrastructure 稽核記錄

  1. 依序前往「SIEM 設定」>「動態饋給」
  2. 按一下「新增動態消息」
  3. 按一下「設定單一動態饋給」
  4. 在「動態饋給名稱」欄位中輸入動態饋給名稱 (例如 Oracle Cloud Audit Logs)。
  5. 選取「Google Cloud Storage V2」做為「來源類型」
  6. 選取「Oracle Cloud Infrastructure Audit Logs」(Oracle Cloud Infrastructure 稽核記錄) 做為「記錄類型」
  7. 點選「下一步」
  8. 指定下列輸入參數的值:

    • 儲存空間 bucket URL:輸入 GCS bucket URI,並加上前置路徑:

      gs://oci-audit-logs-gcs/oci-audit-logs/
      
      • 更改項目:

        • oci-audit-logs-gcs:您的 GCS bucket 名稱。
        • oci-audit-logs:儲存記錄的選用前置字元/資料夾路徑 (如為根目錄,請留空)。
      • 範例:

        • 根層級 bucket:gs://company-logs/
        • 加上前置字元:gs://company-logs/oci-audit-logs/
        • 含子資料夾:gs://company-logs/oracle/audit/
    • 來源刪除選項:根據偏好設定選取刪除選項:

      • 永不:移轉後一律不刪除任何檔案 (建議用於測試)。
      • 刪除已轉移的檔案:成功轉移檔案後刪除檔案。
      • 刪除已轉移的檔案和空白目錄:成功轉移後刪除檔案和空白目錄。
    • 檔案存在時間上限:納入在過去天數內修改的檔案。預設值為 180 天。
    • 資產命名空間資產命名空間
    • 擷取標籤:要套用至這個動態饋給事件的標籤。
  9. 點選「下一步」

  10. 在「Finalize」(完成) 畫面中檢查新的動態饋給設定,然後按一下「Submit」(提交)

UDM 對應表

記錄欄位 UDM 對應 邏輯
accept_encoding_field additional.fields 已合併
accept_field additional.fields 已合併
additional_app additional.fields 已合併
additional_content_type additional.fields 已合併
additional_sort_by additional.fields 已合併
additionaldetails_data additional.fields 已合併
allow_methods_field additional.fields 已合併
auth_type_label additional.fields 已合併
authorization_field additional.fields 已合併
backend_connect_time_field additional.fields 已合併
backend_processing_time_field additional.fields 已合併
caller_id_label additional.fields 已合併
caller_name_label additional.fields 已合併
cloud_event_versiom_field additional.fields 已合併
compartment_id_field additional.fields 已合併
compartment_name_field additional.fields 已合併
connection_field additional.fields 已合併
content_length_field additional.fields 已合併
content_type_field additional.fields 已合併
event_grouping_id_field additional.fields 已合併
event_name_label additional.fields 已合併
event_resource_label additional.fields 已合併
event_source_label additional.fields 已合併
event_type_label additional.fields 已合併
event_type_versiom_field additional.fields 已合併
has_compariment_id additional.fields 已對應:trueadditional_app
has_sort_by additional.fields 已對應:trueadditional_sort_by
listener_name_field additional.fields 已合併
log_group_id_field additional.fields 已合併
log_id_field additional.fields 已合併
message additional.fields 對應值 (共 41 個,例如 \/tenant_id_label\/auth_type_label\/ → `ca... )
opc_request_id_field additional.fields 已合併
origin_field additional.fields 已合併
param0_field additional.fields 已合併
param1_field additional.fields 已合併
referer_field additional.fields 已合併
request_processing_time_field additional.fields 已合併
resource_id_field additional.fields 已合併
routing_rules_engine_errors_field additional.fields 已合併
routing_rules_matched_rule_field additional.fields 已合併
routing_rules_rule_hits_field additional.fields 已合併
routing_rules_rule_misses_field additional.fields 已合併
source_field additional.fields 已合併
tenant_id_label additional.fields 已合併
column3 extensions.auth.type 已對應:login successfulAUTHTYPE_UNSPECIFIED
message extensions.auth.type 已對應:\/AUTHTYPE_UNSPECIFIED
column3 metadata.description 直接對應
data.message metadata.description 直接對應
column1 metadata.event_timestamp 已剖析為 yyyy-MM-dd HH:mm:ss
data_event_time metadata.event_timestamp 已剖析為 yyyy-MM-ddTHH:mm:ss.SSSSSSZ
time metadata.event_timestamp 已剖析為 ISO8601
metadata_event_type metadata.event_type 直接對應
type metadata.product_event_type 直接對應
data_event_id metadata.product_log_id 直接對應
id metadata.product_log_id 直接對應
message metadata.product_name 已對應:\/OCI_AUDIT
specversion metadata.product_version 直接對應
message metadata.vendor_name 已對應:\/Oracle
message network.application_protocol 已對應:\/HTTPS\/HTTP
protocol network.application_protocol 已對應:(?i)HTTPSHTTPS(?i)HTTPHTTP
version network.application_protocol_version 直接對應
data_request_action network.http.method 直接對應
method network.http.method 直接對應
data_identity_userAgent network.http.parsed_user_agent 已重新命名/對應
data_request_agent network.http.parsed_user_agent 已重新命名/對應
url network.http.referral_url 直接對應
data.backendStatusCode network.http.response_code 直接對應
data_response_status network.http.response_code 已重新命名/對應
data.userAgent network.http.user_agent 直接對應
data_identity_userAgent network.http.user_agent 直接對應
data_request_agent network.http.user_agent 直接對應
data.receivedBytes network.received_bytes 直接對應
message network.received_bytes 已對應:\/uinteger
data.sentBytes network.sent_bytes 直接對應
message network.sent_bytes 已對應:\/uinteger
data_identity_consoleSessionId network.session_id 已重新命名/對應
data.sslCipher network.tls.cipher 直接對應
data.sslProtocol network.tls.version 直接對應
data.host principal.asset.hostname 直接對應
hostname principal.asset.hostname 直接對應
column6 principal.asset.ip 已合併
data.forwardedForAddr principal.asset.ip 已合併
data_identity_ipAddress principal.asset.ip 已對應:^(?:[0-9]{1,3}[.]){3}[0-9]{1,3}$data_identity_ipAddress
data_request_origin principal.asset.ip 已合併
ip1 principal.asset.ip 已合併
ip2 principal.asset.ip 已合併
message principal.asset.ip 對應值 (共 7 個,例如 \/column6\/data_request_origin\/ip2)
src_ip principal.asset.ip 已合併
data.host principal.hostname 直接對應
hostname principal.hostname 直接對應
column6 principal.ip 已合併
data.forwardedForAddr principal.ip 已合併
data_identity_ipAddress principal.ip 已對應:^(?:[0-9]{1,3}[.]){3}[0-9]{1,3}$data_identity_ipAddress
data_request_origin principal.ip 已合併
ip1 principal.ip 已合併
ip2 principal.ip 已合併
message principal.ip 對應值 (共 7 個,例如 \/column6\/data_request_origin\/ip2)
src_ip principal.ip 已合併
data_request_headers_sec-ch-ua-platform_0 principal.platform 對應:(?i)LinuxLINUX(?i)windowsWINDOWS(?i)mac/iosMAC
message principal.platform 對應:\/LINUX\/WINDOWS\/MAC
originalConnection.sourcePort principal.port 直接對應
src_port principal.port 直接對應
data_request_headers_oci-original-url_0 principal.url 直接對應
credentials_label principal.user.attribute.labels 已合併
message principal.user.attribute.labels 已對應:\/credentials_label
data.identity.principalName principal.user.user_display_name 直接對應
data.username principal.user.user_display_name 直接對應
data.identity.principalId principal.user.userid 直接對應
data.principalId principal.user.userid 直接對應
column3 security_result 已對應:login successfulsecurity_result
message security_result 已對應:\/security_result
allow_action security_result.action 已合併
column3 security_result.action 已對應:login successfulallow_action
message security_result.action 已對應:\/allow_action
credential_type_field security_result.detection_fields 已合併
message security_result.detection_fields 已對應:\/credential_type_field
data.response.message security_result.summary 直接對應
message target.asset.ip 已對應:\/originalConnection.destinationIp\/tar_ip
originalConnection.destinationIp target.asset.ip 已合併
tar_ip target.asset.ip 已合併
message target.ip 已對應:\/originalConnection.destinationIp\/tar_ip
originalConnection.destinationIp target.ip 已合併
tar_ip target.ip 已合併
originalConnection.destinationPort target.port 直接對應
tar_port target.port 直接對應
message target.resource.attribute.labels 已對應:\/namespace_label
namespace_label target.resource.attribute.labels 已合併
type target.resource.attribute.labels 已對應:listretentionrulesnamespace_label
data.resourceId target.resource.name 直接對應
data.resourceName target.resource.name 直接對應
bucketId target.resource.product_object_id 直接對應
data.resourceId target.resource.product_object_id 直接對應
data_request_id target.resource.product_object_id 直接對應
message target.resource.resource_type 已對應:\/STORAGE_BUCKET
type target.resource.resource_type 已對應:listretentionrulesSTORAGE_BUCKET
data_request_path target.url 直接對應
column2 target.user.email_addresses 已合併
message target.user.email_addresses 已對應:\/column2
不適用 extensions.auth.type 常數:AUTHTYPE_UNSPECIFIED
不適用 metadata.product_name 常數:OCI_AUDIT
不適用 metadata.vendor_name 常數:Oracle
不適用 network.application_protocol 常數:HTTPS
不適用 principal.platform 常數:LINUX
不適用 target.resource.resource_type 常數:STORAGE_BUCKET

變更記錄

查看這個剖析器的變更記錄

還有其他問題嗎?向社群成員和 Google SecOps 專業人員尋求答案。