收集 NGINX 記錄

支援的服務:

本文說明如何使用 Bindplane 代理程式,將 NGINX 記錄擷取至 Google Security Operations。

NGINX 是網路伺服器和反向 Proxy,會針對 HTTP 存取事件、錯誤事件、驗證活動和程序資訊產生 syslog 訊息。剖析器會使用 grok 模式,從多種記錄格式 (syslog、JSON、存取記錄) 擷取欄位,並對應至統合式資料模型 (UDM)。

事前準備

請確認您符合下列必要條件:

  • Google SecOps 執行個體
  • Windows Server 2016 以上版本,或搭載 systemd 的 Linux 主機
  • Bindplane 代理程式與 NGINX 伺服器之間的網路連線
  • 如果透過 Proxy 執行,請確保防火牆通訊埠已根據 Bindplane 代理程式需求開啟
  • NGINX 主機的管理員權限

取得 Bindplane 代理程式的 Google SecOps 憑證

如要向 Google SecOps 驗證 Bindplane 代理程式,請選擇下列其中一種方法:

  • 新部署作業:使用 Chronicle API (選項 1)。
  • 舊版部署作業:繼續使用擷取驗證檔案 (選項 2),直到 Ingestion API 於 2027 年 7 月 20 日停用。
  1. 登入 Google Cloud 控制台,選取連結至 Google SecOps 執行個體的 Google Cloud 專案。
  2. 依序前往 「IAM & Admin」(IAM 與管理) >「Service Accounts」(服務帳戶)。
  3. 按一下「建立服務帳戶」。
  4. 提供下列設定詳細資料:
    • 「Service account name」(服務帳戶名稱):輸入帳戶名稱 (例如 bindplane-ingest)。
    • 「服務帳戶說明」:輸入說明 (例如 Bindplane agent log ingestion)。
  5. 點按「Create and continue」(建立並繼續)。
  6. 在「將專案存取權授予這個服務帳戶」部分,按一下「選取角色」,然後選取「Chronicle 編輯者」。
  7. 依序點選「繼續」和「完成」。
  8. 按一下您建立的服務帳戶,然後前往「金鑰」分頁。
  9. 依序點選「新增金鑰」>「建立新的金鑰」。
  10. 選取「JSON」,然後點選「建立」。金鑰檔案會下載到電腦。
  11. 將金鑰檔案儲存為 Bindplane 收集器目錄中的 ingestion-auth.json (Linux 上的 /opt/observiq-otel-collector/ingestion-auth.json 或 Windows 上的 C:\Program Files\observIQ OpenTelemetry Collector\ingestion-auth.json),或更新 config.yaml 中的 creds_file_path,使其與儲存路徑相符。
  12. 依序前往「IAM & Admin」(IAM 與管理) >「Settings」(設定),然後複製「Project number」(專案編號)。設定匯出工具時會用到。

方法 2:下載擷取驗證檔案 (舊版)

  1. 登入 Google SecOps 控制台。
  2. 依序前往「SIEM Settings」 > 「Collection Agents」。
  3. 下載擷取驗證檔案。
  4. 將檔案安全地儲存在要安裝 Bindplane 代理程式的系統中。

取得 Google SecOps 客戶 ID

  1. 登入 Google SecOps 控制台。
  2. 依序前往「SIEM 設定」>「設定檔」。
  3. 複製並儲存「機構詳細資料」部分的客戶 ID。

安裝 Bindplane 代理程式

請按照下列操作說明,在 Windows 或 Linux 作業系統上安裝 Bindplane 代理程式。

Windows 安裝

  1. 以管理員身分開啟「命令提示字元」或「PowerShell」。
  2. 執行下列指令:

    msiexec /i "https://github.com/observIQ/bindplane-agent/releases/latest/download/observiq-otel-collector.msi" /quiet
    
  3. 等待安裝完成。

  4. 執行下列指令,確認安裝成功:

    sc query observiq-otel-collector
    

    服務應顯示為「RUNNING」。

Linux 安裝

  1. 開啟具有 root 或 sudo 權限的終端機。
  2. 執行下列指令:

    sudo sh -c "$(curl -fsSlL https://github.com/observiq/bindplane-agent/releases/latest/download/install_unix.sh)" install_unix.sh
    
  3. 等待安裝完成。

  4. 執行下列指令,確認安裝成功:

    sudo systemctl status observiq-otel-collector
    

    服務應顯示為「active (running)」。

其他安裝資源

如需其他安裝選項和疑難排解資訊,請參閱 Bindplane 代理程式安裝指南。

設定 Bindplane 代理,擷取系統記錄檔並傳送至 Google SecOps

找出設定檔

  • Linux:

    sudo nano /opt/observiq-otel-collector/config.yaml
    
  • Windows:

    notepad "C:\Program Files\observIQ OpenTelemetry Collector\config.yaml"
    

編輯設定檔

  • 將 config.yaml 的全部內容替換為下列設定:

    receivers:
      udplog:
        listen_address: "0.0.0.0:514"
    
    exporters:
      chronicle/nginx:
        protocol: https
        # Region of your instance, for example us, europe, asia-southeast1
        location: <LOCATION>
        # Project number of the Google Cloud project linked to the instance
        project: '<PROJECT_NUMBER>'
        compression: gzip
        creds_file_path: '/opt/observiq-otel-collector/ingestion-auth.json'
        customer_id: '<customer_id>'
        endpoint: chronicle.googleapis.com
        log_type: NGINX
        raw_log_field: body
    
    service:
      pipelines:
        logs/nginx_to_chronicle:
          receivers:
            - udplog
          exporters:
            - chronicle/nginx
    

設定參數

替換下列預留位置:

  • 接收器設定:

    • listen_address:要接聽的 IP 位址和通訊埠:
      • 0.0.0.0 在所有介面接聽電話 (建議)
      • 通訊埠 514 是標準的系統記錄通訊埠 (在 Linux 上需要根層級權限;如果沒有根層級權限,請使用 1514)
  • Exporter 設定:

    • creds_file_path:服務帳戶 JSON 金鑰檔案的完整路徑 (選項 1):
      • Linux:/opt/observiq-otel-collector/ingestion-auth.json
      • Windows:C:\Program Files\observIQ OpenTelemetry Collector\ingestion-auth.json
    • customer_id:從 Google SecOps 控制台複製的客戶 ID
    • location:將 <LOCATION> 替換為 Google SecOps 執行個體的區域 (例如 us、europe 或 asia-southeast1)。匯出工具會以這個值做為 chronicle.googleapis.com 的前置字元。如需完整清單,請參閱「區域性端點」。
    • project:將 <PROJECT_NUMBER> 替換為「IAM 與管理」>「設定」中的專案編號。
    • endpoint:請將此值設為 chronicle.googleapis.com。

舊版擷取 API 匯出工具

  • 如果您使用方式 2 的擷取驗證檔案,請將 exporters 區塊替換成下列內容。將 creds_file_path 設為擷取驗證檔案的路徑,如果您的執行個體位於美國境外,請將 malachiteingestion-pa.googleapis.com 替換為區域端點 (例如 europe-malachiteingestion-pa.googleapis.com)。

    exporters:
      chronicle/nginx:
        compression: gzip
        creds_file_path: '/opt/observiq-otel-collector/ingestion-auth.json'
        customer_id: '<customer_id>'
        endpoint: malachiteingestion-pa.googleapis.com
        log_type: NGINX
        raw_log_field: body
    

儲存設定檔

  • 編輯完成後,請儲存檔案:
    • Linux:依序按下 Ctrl+O、Enter 和 Ctrl+X
    • Windows:依序點選「檔案」 > 「儲存」

重新啟動 Bindplane 代理程式,套用變更

  • 如要在 Linux 重新啟動 Bindplane 代理程式,請執行下列指令:

    sudo systemctl restart observiq-otel-collector
    
    1. 確認服務正在執行:

      sudo systemctl status observiq-otel-collector
      
    2. 查看記錄檔是否有錯誤:

      sudo journalctl -u observiq-otel-collector -f
      
  • 如要在 Windows 中重新啟動 Bindplane 代理程式,請選擇下列其中一個選項:

    • 以管理員身分開啟命令提示字元或 PowerShell:

      net stop observiq-otel-collector && net start observiq-otel-collector
      
    • 服務控制台:

      1. 按下 Win+R 鍵,輸入 services.msc,然後按下 Enter 鍵。
      2. 找出「observIQ OpenTelemetry Collector」。
      3. 按一下滑鼠右鍵,然後選取「重新啟動」。
      4. 確認服務正在執行:

        sc query observiq-otel-collector
        
      5. 檢查記錄是否有錯誤:

        type "C:\Program Files\observIQ OpenTelemetry Collector\log\collector.log"
        

設定 NGINX 將記錄轉送至 Bindplane

  1. 開啟 NGINX 設定檔 (例如 /etc/nginx/nginx.conf):

    sudo vi /etc/nginx/nginx.conf
    
  2. 編輯設定,將 <BINDPLANE_SERVER> 和 <BINDPLANE_PORT> 替換為您的值:

    http {
        access_log syslog:server=<BINDPLANE_SERVER>:<BINDPLANE_PORT>,facility=local7,tag=nginx_access;
        error_log syslog:server=<BINDPLANE_SERVER>:<BINDPLANE_PORT>,facility=local7,tag=nginx_error;
    }
    
  3. 重新啟動 NGINX,以套用變更:

    sudo systemctl reload nginx
    

UDM 對應表

記錄欄位 UDM 對應 邏輯
_Internal_WorkspaceResourceId target.resource.product_object_id 直接對應
Computer principal.asset.hostname 直接對應
Facility additional.fields[設施] 直接對應
HostName principal.asset.hostname 如果沒有 src_ip,則直接對應
ProcessName principal.application 直接對應
SeverityLevel security_result.severity 如果值為 info,則對應至 INFORMATIONAL
SourceSystem principal.asset.platform 如果值與 Linux 相符,則對應至 LINUX
SyslogMessage 多個欄位 使用 grok 剖析,擷取 time、method、target_path、protocol、response_code、referral_url、user_agent、target_ip、target_host和 cache
TenantId additional.fields[TenantId] 直接對應
acct principal.user.user_id 如果不是空白或 ?,則直接對應
addr principal.asset.ip 直接對應
audit_epoch metadata.event_timestamp 使用 UNIX 格式轉換為時間戳記。從原始記錄訊息中擷取奈秒。
cache additional.fields[快取] 直接對應
collection_time.nanos metadata.event_timestamp.nanos 用於事件時間戳記的奈秒 (如有)
collection_time.seconds metadata.event_timestamp.seconds 用於事件時間戳記的秒數 (如有)
data 多個欄位 主要資料來源,系統會根據記錄格式 (Syslog、JSON 或其他) 以不同方式剖析資料
exe target.process.command_line 移除反斜線和引號後直接對應
hostname principal.asset.hostname 或 principal.asset.ip 如果是 IP 位址,則對應至 principal.asset.ip。否則會對應至 principal.asset.hostname
msg metadata.description 直接對應為說明
node target.asset.hostname 直接對應
pid target.process.pid 直接對應
protocol network.application_protocol 如果值與 HTTP 相符,則對應至 HTTP
referral_url network.http.referral_url 如果不是空白或 -,則直接對應
res security_result.action_details 直接對應
response_code network.http.response_code 直接對應並轉換為整數
ses network.session_id 直接對應
src_ip principal.asset.ip 直接對應
target_host target.asset.hostname 直接對應
target_ip target.asset.ip 直接對應,先將字串表示法轉換為 JSON 陣列,然後擷取個別 IP
target_path target.url 直接對應
time metadata.event_timestamp 剖析時間戳記,格式為 dd/MMM/yyyy:HH:mm:ss Z
user_agent network.http.user_agent 如果不是空白或 -,則直接對應
metadata.event_type 一開始會設為 GENERIC_EVENT,之後可能會根據 terminal 和 protocol 等其他欄位覆寫。如果主要 grok 模式不相符,預設值為 USER_UNCATEGORIZED。如果 protocol 是 HTTP 且 target_ip 存在,則設為 NETWORK_HTTP;如果 protocol 是 HTTP 但 target_ip 不存在,則設為 STATUS_UPDATE
metadata.log_type 設為 NGINX
metadata.product_name 設為 NGINX
metadata.vendor_name 設為 NGINX
network.ip_protocol 如果 terminal 為 sshd 或 ssh,或主要 grok 模式不相符,請設為 TCP
principal.asset_id 如果 terminal 為 sshd 或 ssh,請設為 GCP.GCE:0001。如果主要 grok 模式不符,請設為 GCP.GCE:0002
extensions.auth.type 如果 terminal 為 sshd 或 ssh,則設為 MACHINE
log_hostname event.idm.read_only_udm.principal.asset.hostname 從變更記錄對應
ip_part event.idm.read_only_udm.intermediary.ip 從變更記錄對應
domain_part event.idm.read_only_udm.intermediary.administrative_domain 從變更記錄對應
location_part event.idm.read_only_udm.intermediary.location.name 從變更記錄對應
labels.compute_googleapis_com/resource_name event.idm.read_only_udm.target.hostname 從變更記錄對應
resource.labels.instance_id event.idm.read_only_udm.target.resource.product_object_id 從變更記錄對應
resource.labels.project_id event.idm.read_only_udm.target.resource_ancestors.name 從變更記錄對應
resource.labels.zone event.idm.read_only_udm.target.resource.attribute.cloud.availability_zone 從變更記錄對應
resource.type event.idm.read_only_udm.target.resource.resource_type 從變更記錄對應
insertId event.idm.read_only_udm.metadata.product_log_id 從變更記錄對應
jsonPayload.latency event.idm.read_only_udm.additional.fields 從變更記錄對應
remoteIp event.idm.read_only_udm.target.ip 從變更記錄對應
jsonPayload.requestMethod event.idm.read_only_udm.network.http.method 從變更記錄對應
jsonPayload.requestSize event.idm.read_only_udm.network.sent_bytes 從變更記錄對應
jsonPayload.requestUrl event.idm.read_only_udm.network.http.referral_url 從變更記錄對應
jsonPayload.responseSize event.idm.read_only_udm.network.received_bytes 從變更記錄對應
jsonPayload.serverIp event.idm.read_only_udm.target.ip 從變更記錄對應
jsonPayload.status event.idm.read_only_udm.network.http.response_code 從變更記錄對應
jsonPayload.userAgent event.idm.read_only_udm.network.http.user_agent 從變更記錄對應
jsonPayload.userAgent event.idm.read_only_udm.network.http.parsed_user_agent 從變更記錄對應
labels event.idm.read_only_udm.additional.fields 從變更記錄對應
terminal event.idm.read_only_udm.additional.fields 從變更記錄對應
logName event.idm.read_only_udm.additional.fields 從變更記錄對應
resource.labels event.idm.read_only_udm.target.resource.attribute.labels 從變更記錄對應
resource.type event.idm.read_only_udm.target.resource.attribute.labels 從變更記錄對應
resource.name event.idm.read_only_udm.target.resource.name 從變更記錄對應
timestamp event.idm.read_only_udm.metadata.event_timestamp 從變更記錄對應
user_agent event.idm.read_only_udm.network.http.parsed_user_agent 從變更記錄對應

變更記錄

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

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