將 Apigee 與 Google SecOps 整合

本頁內容適用於 ApigeeApigee Hybrid

本文說明如何將 Apigee 與 Google Security Operations (Google SecOps) 整合。如果您使用 Google SecOps 做為 SIEM 解決方案,請按照本文中的步驟操作,設定 Apigee 將記錄資料傳送至 SecOps。

為簡化這項整合作業,Google SecOps 支援 Apigee 剖析器,可擷取 Apigee 記錄資料。 另請參閱「將 Google Cloud 資料擷取至 Google Security Operations」。 完成本文件中的設定步驟後,Apigee 記錄資料就會傳送至 Google SecOps。

如要瞭解如何將 SecOps 與其他 SIEM 解決方案整合,請參閱「將 Apigee 與 SIEM 解決方案整合」。

目標對象

這份文件的目標對象包括:

  • API 管理員:負責確保 API 安全、管理平台設定、提升作業效率,以及遵守安全法規遵循規定。
  • 安全分析師:主動偵測及調查 API 相關安全事件,盡量降低風險並保護機密資料。

設定總覽

本文討論的設定會使用 Apigee MessageLogging 政策,將各種 Apigee 記錄資料 (包括特定流程變數) 傳送至 SecOps。

Google SecOps 提供專屬的 Cloud Logging 篩選器,可將特定記錄類型 (包括 Apigee 記錄) 即時傳送至 Google SecOps。Google SecOps 支援 Apigee 剖析器,可將 Apigee 記錄資料擷取至 Google SecOps。另請參閱「將 Google Cloud 資料擷取至 Google Security Operations」。

必要條件

符合上述必備條件後,請按照本文中的操作說明,將 Apigee 與 SecOps 執行個體整合。開始整合前,請確認您具備下列項目:

  • 具有管理員權限的 Apigee 或 Apigee Hybrid 帳戶,可開發及部署 API Proxy
  • Google SecOps 帳戶
  • 啟用 Cloud Logging,並體驗設定及使用 Cloud Logging 的過程
  • 瞭解 Apigee 流程變數
  • 瞭解 Apigee MessageLogging 政策,以及一般政策的使用和設定
  • (選用) 瞭解如何使用 Google SecOps 剖析器解讀擷取的記錄。 根據預設,SecOps 剖析器會內建剖析和解讀 MessageLogging 政策擷取的 Apigee 記錄。
  • 使用 Cloud Logging API 的 Google Cloud IAM 權限,以及將 IAM 角色授予 SecOps 服務帳戶

將 Apigee 與 SecOps 整合

如果您使用 Google SecOps 做為 SIEM 解決方案,請按照下列步驟將 Apigee 記錄資料傳送至 SecOps。基本步驟如下:

  • 設定 MessageLogging 政策,將 Apigee 記錄資料傳送至 Cloud Logging
  • 將 MessageLogging 政策附加至 Apigee Proxy

完成本節所述的 MessageLogging 政策設定後,SecOps 就會剖析傳送至 Cloud Logging 的 Apigee 記錄資料。如要進一步瞭解剖析器,以及 Apigee 流程變數資料如何對應至 SecOps 資料欄位,請參閱「將 Apigee 與 Google SecOps SIEM 整合」。另請參閱「收集 Apigee 記錄」。

請按照下列步驟,使用 MessageLogging 政策將 Apigee 與 SecOps 整合:

  1. 設定新的 MessageLogging 政策。請參閱「透過使用者介面附加和設定政策」。

    以下是將資料傳送至 Cloud Logging 的 MessageLogging 政策範例。這項政策指定要傳送至 Cloud Logging 的大量流程變數。您可以視需要新增或移除流程變數,具體取決於您認為哪些欄位對 SecOps 分析至關重要。如要瞭解 Apigee 流程變數資料如何對應至 SecOps 資料欄位,請參閱「整合 Apigee 與 Google SecOps SIEM」。

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
      <MessageLogging continueOnError="false" enabled="true" name="ML-CloudLoggingSecOps">
       <DisplayName>ML-CloudLoggingSecOps</DisplayName>
       <CloudLogging>
         <LogName>projects/{organization.name}/logs/apigee-secops-integration-{environment.name}</LogName>
         <Message contentType="application/json">{
       "apiproduct.name": "{apiproduct.name}",
       "app.name": "{developer.app.name}",
       "cachehit":"{cachehit}",
       "client.country": "{client.country}",
       "client.cn": "{client.cn}",
       "client.ip": "{proxy.client.ip}",
       "client.locality": "{client.locality}",
       "client.port": "{client.port}",
       "client.scheme": "{client.scheme}",
       "client.state": "{client.state}",
       "developer.email": "{developer.email}",
       "environment.name": "{environment.name}",
       "error":"{is.error}",
       "error.state":"{error.state}",
       "error.message":"{escapeJSON(error.message)}",
       "fault.name":"{fault.name}",
       "messageid":"{messageid}",
       "organization.name": "{organization.name}",
       "proxy.name": "{apiproxy.name}",
       "proxy.basepath": "{proxy.basepath}",
       "proxy.pathsuffix": "{proxy.pathsuffix}",
       "proxy.proxyendpoint.name": "{proxy.name}",
       "proxy.revision":"{apiproxy.revision}",
       "request.content-length":"{request_msg.header.content-length}",
       "request.content-type":"{request_msg.header.content-type}",
       "request.host":"{request_msg.header.host}",
       "request.httpversion": "{request.version}",
       "request.url": "{client.scheme}://{request_msg.header.host}{request_msg.uri}",
       "request.user-agent":"{request.header.user-agent}",
       "request.verb": "{request.verb}",
       "request.x-b3-traceid": "{request.header.x-b3-traceid}",
       "request.x-cloud-trace-context": "{request.header.x-cloud-trace-context}",
       "response.content-length":"{response.header.content-length}",
       "response.content-type":"{response.header.content-type}",
       "response.status.code": "{message.status.code}",
       "system.region.name": "{system.region.name}",
       "system.timestamp": "{system.timestamp}",
       "system.uuid": "{system.uuid}",
       "target.cn": "{target.cn}",
       "target.country": "{target.country}",
       "target.host": "{target.host}",
       "target.ip": "{target.ip}",
       "target.locality": "{target.locality}",
       "target.organization": "{target.organization}",
       "target.port": "{target.port}",
       "target.scheme": "{target.scheme}",
       "target.state": "{target.state}",
       "target.url": "{request.url}"
      }
         </Message>
         <ResourceType>api</ResourceType>
       </CloudLogging>
      </MessageLogging>
  2. 將政策附加為 API Proxy 中的條件步驟。其中一個做法是在 PostFlow 的 FaultRule 中附加政策,通常會在此處引發安全性相關錯誤。例如:

    <PostFlow name="PostFlow">
      <Request>
        <Step>
          <Condition>flow.isError == true)</Condition>
          <Name>ML-CloudLoggingSecOps</Name>
        </Step>
      </Request>
    </PostFlow>

    現在,當使用這項政策的 API Proxy 執行時,Apigee 記錄資料就會傳送至 Google SecOps。

    另一種常見做法是將 MessageLogging 政策放在 ProxyEndpoint 回應的 PostClientFlow 中。

    將 MessageLogging 政策附加至 API Proxy 時,請參考下列建議:

    • 將政策放在 FaultRule 中。 建議您在 FaultRule 中記錄安全性例外狀況和政策違規事項。
    • 將政策放在 PostFlow 中。PostFlow 也是記錄安全性問題的合適位置。
    • 避免記錄成功的要求。如要監控威脅,通常會在發生錯誤 (引發故障) 時記錄詳細資料。記錄每項成功的要求,並包含完整訊息內容,可能會產生過多記錄檔,導致費用增加。
    • 針對特定用途考慮使用自訂變數。舉例來說,如果您需要在錯誤流程中擷取原始要求 URI,可以在要求 PreFlow 中使用 AssignMessage 政策,將 URI 複製到自訂變數 (例如 original.request.uri),然後在 MessageLogging 政策中記錄該變數。

最佳做法

使用 Google SecOps 設定 Apigee 時,請參考下列最佳做法:

  • 著重於安全性背景資訊:只記錄可提供安全性監控和威脅偵測重要背景資訊的流程變數。避免記錄過多與安全性無關的資料。
  • 使用一致的記錄格式:在採用 SecOps 的 API Proxy 中,維持一致的記錄格式。
  • 使用安全的服務帳戶:遵循安全最佳做法,管理及保護用於 SecOps 擷取的 Google Cloud 服務帳戶。如有可能,請限制記錄檢視器的權限。
  • 監控 SecOps 動態消息:定期監控 SecOps 動態消息的健康狀態和狀態,確保系統能順利擷取記錄,且不會發生錯誤。
  • 使用 SecOps 規則和資訊主頁:將安全性相關記錄匯入 SecOps 後,即可根據記錄的詳細資訊,制定特定規則和資訊主頁,偵測並呈現安全性威脅。

疑難排解

本節說明使用 SecOps 設定 Apigee 時可能遇到的問題,以及應檢查的項目。

問題:Cloud Logging 中未顯示安全性事件記錄

檢查事項:

  • 請仔細檢查 MessageLogging 政策是否已正確設定,以便在發生安全性事件時觸發 Condition
  • 請確認 MessageLogging 政策已附加至適當的流程環境,例如 FaultRule 或 PostFlow。
  • 確認 Google Cloud 專案已啟用 Cloud Logging。
  • 查看 Apigee Proxy 記錄中與 MessageLogging 政策相關的錯誤訊息。

問題:安全性事件記錄檔未顯示在 SecOps 中

  • 確認 SecOps 動態饋給已正確設定,包括正確的專案 ID、記錄篩選器 (確保擷取安全記錄政策中的記錄),以及服務帳戶憑證。
  • 在 SecOps 使用者介面中檢查 SecOps 動態饋給的狀態,查看是否有任何錯誤訊息或擷取問題。
  • 確認 SecOps 使用的服務帳戶在 Google Cloud 專案中具有「記錄檢視者」角色。
  • 在 Cloud Logging 中檢查記錄的 JSON 結構,確保格式正確且包含預期的欄位名稱。
  • 確認已啟用適當的 Google Cloud 剖析器。
  • 如果懷疑有剖析問題,請檢查 SecOps 原始資料中的記錄項目樣本,瞭解剖析前擷取資料的方式。如果特定欄位未如預期擷取,您可能需要參閱 SecOps 剖析器說明文件,或考慮是否需要自訂剖析器。

將 Apigee 與 Google SecOps SIEM 整合

下表列出 Apigee 流程變數名稱與對應的 Google Security Operations SIEM 欄位名稱。舉例來說,在 Cloud Logging 中查看 Apigee 記錄資料時,client.id flow 變數會對應至名為 principle_ip 的 SecOps SIEM 欄位。另請參閱「收集 Apigee 記錄」。

Apigee 流程變數 SecOps SIEM 欄位名稱 說明
client.country principal.hostname ProxyEndpoint 收到的要求相關聯的 HTTP 主機 IP。
client.host principal.location.country_or_region 用戶端應用程式提供的 TLS/SSL 憑證中的國家/地區。 Proxy 要求 principal.location.country_or_region
client.ip principle.ip 將訊息傳送至負載平衡器的用戶端或系統 IP 位址。例如原始用戶端 IP 或負載平衡器 IP。
client.locality principal.location.city 用戶端提供的 TLS/SSL 憑證中的所在地 (城市)。
client.port principal.port 與傳送至 ProxyEndpoint 的原始用戶端要求相關聯的 HTTP 通訊埠。
client.state principal.location.state 用戶端提供的 TLS/SSL 憑證中的州/省。
organization.name intermediary.cloud.project.name Apigee 機構名稱。
proxy.client.ip src.ip 傳入呼叫的 X-Forwarded-For 位址,也就是 Apigee 從最後一次外部 TCP 交握收到的 IP 位址。這可能是呼叫端用戶端或負載平衡器。
proxy.name intermediary.resource.name 為 ProxyEndpoint 設定的名稱屬性。
proxy.pathsuffix intermediary.resource.attribute.labels[pathsuffix] "The value of the path suffix in the URL that is sent from the client and received at the ProxyEndpoint. Basepath 是最左側的路徑元件,用於在環境群組中唯一識別 API Proxy。假設您已設定 API Proxy 端點,且基本路徑為 /v2/weatherapi。在這種情況下,傳送至 https://myhost.example.net/v2/weatherapi/forecastrss?w=12797282 的要求,proxy.pathsuffix 變數會保留字串「/forecastrss」。
proxy.url intermediary.url 「Gets the complete URL associated with the proxy request received by the ProxyEndpoint, including any query parameters present. 如需使用原始要求主機 (而非 proxy.url 中使用的路由器主機) 建構要求網址的範例,請參閱「存取要求訊息」。
request.uri target.resource.name 目標服務的網域名稱,會將回應傳回 API Proxy。
request.verb network.http.method 要求使用的 HTTP 動詞。例如 GET、PUT 和 DELETE。
response.content security_result.description 目標傳回的回應訊息酬載內容。
response.status.code network.http.response_code 要求傳回的回應代碼。您可以使用這個變數覆寫回應狀態碼,該狀態碼儲存在 message.status.code 中。詳情請參閱訊息。
system.region.name intermediary.location.name 執行 Proxy 的資料中心區域名稱。
system.timestamp additional.fields[jsonPayload_system_timestamp] 代表讀取這個變數時間的 64 位元 (長) 整數。這個值是自世界標準時間 1970 年 1 月 1 日午夜起經過的毫秒數。例如 1534783015000。
system.uuid intermediary.process.pid 或 intermediary.process.product_specific_process_id 處理 Proxy 的訊息處理器 UUID。
target.country target.location.country_or_region 目標伺服器提供的 TLS/SSL 憑證國家/地區
target.host target.hostname 目標服務的網域名稱,會將回應傳回 API Proxy。
target.ip target.ip 目標服務的 IP 位址,會將回應傳回 API Proxy。
target.locality target.location.city 目標伺服器提供的 TLS/SSL 憑證所在地 (城市)
target.organization target.resource_ancestors.name 目標伺服器提供的 TLS/SSL 憑證機構。
target.port target.port 目標服務的通訊埠號碼,會將回應傳回 API Proxy。
target.scheme target.network.application_protocol 視要求訊息而定,傳回 HTTP 或 HTTPS。
target.state target.location.state 目標伺服器提供的 TLS/SSL 憑證狀態。
target.url target.url 在 TargetEndpoint XML 檔案中設定的網址,或動態目標網址 (如果是在訊息流程期間設定 target.url)。變數不包含任何其他路徑元素或查詢參數。如果超出範圍呼叫或未設定,則傳回空值。

注意:請使用附加至 TargetEndpoint 的 JavaScript 政策設定這個變數。