注意:

使用 OCI 稽核從 OCI Identity and Access Management 擷取事件,以實作多重雲端安全性

簡介

Oracle Cloud Infrastructure Identity and Access Management (OCI IAM) 識別網域會產生稽核資料,以回應管理員與一般使用者執行的作業。系統會為建立或更新使用者帳戶或群組成員,以及成功或失敗的登入嘗試等作業產生稽核事件。

若要存取此稽核資料,您可以直接在 Oracle Cloud Infrastructure (OCI) 主控台中產生報表,也可以將這些事件傳送到外部安全監督解決方案 (在外部雲端平台中作業)。組織通常會運用第三方安全性事件和事件管理 (SIEM) 解決方案,而一般需求則是將 OCI IAM 稽核資料擷取至 SIEM 以進行威脅分析和規範。滿足該需求的一種方式是利用 OCI IAM 識別網域 AuditEvents API,但識別網域提供另一種選項,對某些組織來說可能更易於實行,並支援在多重雲端環境中共用稽核事件。

OCI 稽核是一項 OCI 服務,可自動將對所有支援的 OCI API 的呼叫記錄為事件。有一些常見原因可供您選擇從 OCI 稽核服務提取 OCI IAM 稽核事件,而不是使用 OCI IAM 識別網域 API。OCI Audit 提供下列優點:

目標

將 OCI IAM 識別網域中產生的稽核事件同步至外部存放區。

必要條件

作業 1:瞭解如何運用 OCI 稽核從 OCI IAM 擷取稽核事件

為示範使用 OCI Audit 從 OCI IAM 擷取稽核事件的方法,我們將使用下列案例:

您的租用戶使用兩個 OCI IAM 識別網域。租用戶管理使用的租用戶預設網域類型為「免費」。我們將呼叫管理員網域。有一個網域類型為 Oracle Apps Premium 的額外識別網域,所有員工都會佈建來存取 Oracle SaaS 和內部部署應用程式。我們會撥打員工網域。會從 Microsoft Azure AD 將帳戶佈建至員工網域中。這可能會以下列其中一種方式發生 (跨網域身分識別管理系統 [SCIM]、即時佈建或大量使用者匯入)。此外,您還擁有 SIEM 解決方案 (例如 Microsoft Sentinel),可從環境中許多系統擷取稽核資料,並需要近乎即時地將兩個識別網域的所有稽核事件發布到 SIEM。

我們將採取的整體方法包括使用 OCI Audit 服務、 OCI Events 服務、 OCI Functions 服務以及 Azure Log Analytics Workspace 。基本流量如下:

  1. OCI IAM 識別網域會將稽核事件寫入 OCI 稽核
  2. OCI 事件服務中的規則主要監看 OCI IAM 中特定稽核事件類型的 OCI 稽核。觸發規則時,它會呼叫 OCI 函數中的函數。
  3. 此函數會接收其有效負載中的原始稽核日誌,並呼叫 Azure Log Analytics Data Collector API 以將資料傳送至 Azure Log Analytics Workspace
  4. Azure Log Analytics Workspace 可作為 Microsoft Sentinel 的資料存放區。

高階架構的影像

作業 2:使用 OCI 稽核從 OCI IAM 擷取稽核事件

  1. 此範例假設您在 Azure 入口網站中設定 Azure Log Analytics Workspace。設定好之後,請複製工作區 ID 和工作區名稱、設定值、代理程式、Log Analytics 代理程式指示底下的主要 (或次要) 金鑰。使用 OCI 函數撰寫自訂函數時,您將需要這些值。

    Azure Log Analytics Workspace 代理程式的影像

  2. 以租用戶管理員身分登入 OCI 主控台。

  3. 撰寫將使用 OCI 函數部署的自訂函數。下列程式碼範例使用 Python,但是您可以輕鬆地以您選擇的語言實行此函數。讓我們在三個簡單步驟中新增函數代碼。

    • 建立一個名為 func.py 的 Python 檔案,並新增下列必要的匯入敘述句和參數宣告。參數值必須與您的 Log Analytics 工作區環境相符。您可以在 Log Analytics 工作區、您的工作區名稱以及「代理程式」管理頁面下的 Azure Portal 中,找到客戶 ID (入口網站中的工作區 ID) 和共用金鑰值。日誌類型參數是一個易記名稱,用於在 Azure Log Analytics 工作區中定義新的 (或選取現有) 自訂日誌,以及資料上傳的目標位置。

      您可以使用 OCI 加密密碼服務,以安全的方式存取 OCI 函數中的值,而不使用硬式編碼 Log Analytics 工作區客戶 ID 和共用金鑰值。如需在程式碼中使用 OCI 加密密碼的詳細逐步解說,請參閱下列文章:

      基於本教學課程的目的,我們假設您的加密密碼儲存在保存庫中,並設定 IAM 原則以授予 OCI 函數執行處理主要項目的存取權。

      {.python .numberLines .lineAnchors}
      import oci
      import io
      import json
      import requests
      import datetime
      import hashlib
      import hmac
      import base64
      import logging
      from fdk import response
      
      # Get instance principal context, and initialize secrets client
      signer = oci.auth.signers.InstancePrincipalsSecurityTokenSigner()
      secret_client = oci.secrets.SecretsClient(config={}, signer=signer)
      
      # Replace values below with the ocids of your secrets
      customer_id_ocid = "ocid1.vaultsecret.oc1.<customer_id_ocid>"
      shared_key_ocid = "ocid1.vaultsecret.oc1.<shared_key_ocid>"
      
      # Retrieve secret
      def read_secret_value(secret_client, secret_id):
          response = secret_client.get_secret_bundle(secret_id)
          base64_Secret_content = response.data.secret_bundle_content.content
          base64_secret_bytes = base64_Secret_content.encode('ascii')
          base64_message_bytes = base64.b64decode(base64_secret_bytes)
          secret_content = base64_message_bytes.decode('ascii')
          return secret_content
      
      # Retrieve the customer ID using the secret client.
      customer_id =  read_secret_value(secret_client, customer_id_ocid)
      
      # For the shared key, use either the primary or the secondary Connected Sources client authentication key    
      _shared_key =  read_secret_value(secret_client, shared_key_ocid)
      
      # The log type is the name of the event that is being submitted
      log_type = 'OCILogging'
      
    • 新增下列程式碼行以定義對 Azure 資料上傳端點進行安全 REST 呼叫的作業。您可能需要驗證此程式碼,以根據 Microsoft 的最新端點或版本語法驗證語法。

      注意:此程式碼的部分會從下列 Microsoft 文件複製。

      {.python .numberLines .lineAnchors}
      # Build the API signature
      def  build_signature(customer_id, shared_key, date, content_length, method, content_type, resource):
      x_headers =  'x-ms-date:'  + date
      string_to_hash = method +  "\n"  + str(content_length) +  "\n"  + content_type +  "\n"  + x_headers +  "\n"  + resource
      bytes_to_hash = bytes(string_to_hash, encoding= "utf-8" )  
      decoded_key = base64.b64decode(shared_key)
      encoded_hash = base64.b64encode(hmac.new(decoded_key, bytes_to_hash, digestmod=hashlib.sha256).digest()).decode()
      authorization =  "SharedKey {}:{}" .format(customer_id,encoded_hash)
      return  authorization
      
      # Build and send a request to the POST API
      def  post_data(customer_id, shared_key, body, log_type, logger):
      method =  'POST'
      content_type =  'application/json'
      resource =  '/api/logs'
      rfc1123date = datetime.datetime.utcnow().strftime( '%a, %d %b %Y %H:%M:%S GMT' )
      content_length = len(body)
      signature = build_signature(customer_id, shared_key, rfc1123date, content_length, method, content_type, resource)
      uri =  'https://'  + customer_id +  '.ods.opinsights.azure.com'  + resource +  '?api-version=2016-04-01'
      
      headers = {
      'content-type' : content_type,
      'Authorization' : signature,
      'Log-Type' : log_type,
      'x-ms-date' : rfc1123date
      }
      
      response = requests.post(uri,data=body, headers=headers)
      if (response.status_code >= 200 and  response.status_code <=  299 ):
      logger.info( 'Upload accepted' )
      else :
      logger.info( "Error during upload.  Response code: {}" .format(response.status_code))
      print(response.text)
      
    • 將下列程式碼區塊新增至您的 func.py 程式碼檔案,以定義執行進入點與架構明細。除非您想要新增選擇性功能 (例如進階資料剖析、格式或自訂異常狀況處理),否則不需要進行任何變更。

      {.python .numberLines .lineAnchors}
      """
      Entrypoint and initialization
      """
      def  handler(ctx, data: io.BytesIO= None ):
      logger = logging.getLogger()
      try :
      _log_body = data.getvalue()
      post_data(_customer_id, _shared_key, _log_body, _log_type, logger)
      except  Exception  as  err:
      logger.error( "Error in main process: {}" .format(str(err)))
      return  response.Response(
      ctx,  
      response_data=json.dumps({ "status" :  "Success" }),
      headers={ "Content-Type" :  "application/json" }
      )
      
  4. 依照本指南使用 CloudShell 來部署您的函數:CloudShell 上的函數快速啟動

  5. 在「OCI 事件」服務中建立一個規則,此服務會尋找符合您條件的稽核日誌,並呼叫您在步驟 3 和 4 中建立和部署的函數。

    • 透過在主控台搜尋列或左側服務選單中的搜尋列中搜尋「事件」,前往「事件服務」。按一下搜尋結果中的規則

      在 OCI 主控台 1 中尋找規則

      尋找 OCI 主控台 2 中的規則

    • 建立規則,其中包含尋找使用者在管理員和員工網域中建立、更新或刪除事件的條件。

      1. 識別服務底下將提供使用者建立、更新及刪除事件類型。

      2. 新增另一個包含兩個識別網域 GUID 的「屬性」條件。

        注意:這是選擇性項目。依照預設,會比對雲端帳戶中所有識別網域的稽核事件。但是如果您只對識別網域的子集感興趣,可以明確指定範圍內的網域。)您可以在識別網域總覽頁面找到識別網域 GUID。

      3. 動作面板中,選取函數動作類型,然後選取您在上述步驟 3 與 4 中建立與部署的函數。

        在 OCI 主控台中建立規則

  6. 現在,當您在其中一個識別網域中建立、更新或刪除使用者時,會以原始稽核日誌作為有效負載來呼叫 OCI 函數。OCI 函數接著會將資料張貼至 Azure Log Analytics Workspace。您將會在名為 OCILogging_CL 的自訂表格中看到資料。

    在 Azure Log Analytics 工作區中尋找 OCI 日誌記錄資料

確認

其他學習資源

探索 docs.oracle.com/learn 的其他實驗室,或者存取更多 Oracle Learning YouTube 頻道上的免費學習內容。此外,請瀏覽 education.oracle.com/learning-explorer 以成為 Oracle Learning 檔案總管。

如需產品文件,請造訪 Oracle Help Center