收集 NGINX 日志
本文档介绍了如何使用 Bindplane 代理将 NGINX 日志注入 Google Security Operations。
NGINX 是一个 Web 服务器和反向代理,可为 HTTP 访问事件、错误事件、身份验证活动和进程信息生成 syslog 消息。解析器使用 grok 模式从多种日志格式(系统日志、JSON、访问日志)中提取字段,并将这些字段映射到统一数据模型 (UDM)。
准备工作
请确保满足以下前提条件:
- Google SecOps 实例
- Windows Server 2016 或更高版本,或者具有
systemd的 Linux 主机 - Bindplane 代理与 NGINX 服务器之间的网络连接
- 如果在代理后面运行,请确保按照 Bindplane 代理要求打开防火墙端口
- 对 NGINX 主机的管理员权限
获取 Bindplane 代理的 Google SecOps 凭证
如需向 Google SecOps 验证 Bindplane 代理的身份,请选择以下方法之一:
- 新部署:使用 Chronicle API(选项 1)。
- 旧版部署:继续使用数据注入身份验证文件(方法 2),直到 Ingestion API 于 2027 年 7 月 20 日停用。
方法 1:为 Chronicle API 创建服务账号(推荐)
- 登录 Google Cloud 控制台,然后选择与您的 Google SecOps 实例关联的 Google Cloud 项目。
- 前往 IAM 和管理 > 服务账号。
- 点击创建服务账号。
- 提供以下配置详细信息:
- 服务账号名称:输入账号的名称(例如
bindplane-ingest)。 - 服务账号说明:输入说明(例如
Bindplane agent log ingestion)。
- 服务账号名称:输入账号的名称(例如
- 点击创建并继续。
- 在向此服务账号授予对项目的访问权限部分,点击选择角色,然后选择 Chronicle Editor。
- 点击继续,然后点击完成。
- 点击您创建的服务账号,然后前往密钥标签页。
- 依次点击添加密钥 > 创建新密钥。
- 选择 JSON,然后点击创建。密钥文件会下载到您的计算机上。
- 将密钥文件另存为 Bindplane 收集器目录(在 Linux 上为
/opt/observiq-otel-collector/ingestion-auth.json,在 Windows 上为C:\Program Files\observIQ OpenTelemetry Collector\ingestion-auth.json)中的ingestion-auth.json,或更新config.yaml中的creds_file_path以与您保存密钥文件的路径相匹配。 - 前往 IAM 和管理 > 设置,然后复制项目编号。您在配置导出器时需要用到该名称。
方法 2:下载数据注入身份验证文件(旧版)
- 登录 Google SecOps 控制台。
- 依次前往 SIEM 设置 > 收集代理。
- 下载数据注入身份验证文件。
- 将文件安全地保存在将要安装 Bindplane 代理的系统上。
获取 Google SecOps 客户 ID
- 登录 Google SecOps 控制台。
- 前往 SIEM 设置 > 个人资料。
从组织详细信息部分复制并保存客户 ID。
安装 Bindplane 代理
根据以下说明,在 Windows 或 Linux 操作系统上安装 Bindplane 代理。
Windows 安装
- 以管理员身份打开命令提示符或 PowerShell。
运行以下命令:
msiexec /i "https://github.com/observIQ/bindplane-agent/releases/latest/download/observiq-otel-collector.msi" /quiet等待安装完成。
运行以下命令,验证安装是否成功:
sc query observiq-otel-collector该服务应显示为正在运行。
Linux 安装
- 打开具有 root 或 sudo 权限的终端。
运行以下命令:
sudo sh -c "$(curl -fsSlL https://github.com/observiq/bindplane-agent/releases/latest/download/install_unix.sh)" install_unix.sh等待安装完成。
运行以下命令,验证安装是否成功:
sudo systemctl status observiq-otel-collector该服务应显示为有效(正在运行)。
其他安装资源
如需了解其他安装选项和问题排查,请参阅 Bindplane 代理安装指南。
配置 Bindplane 代理以注入 syslog 并将其发送到 Google SecOps
找到配置文件
Linux:
sudo nano /opt/observiq-otel-collector/config.yamlWindows:
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是标准 syslog 端口(在 Linux 上需要 root 权限;对于非 root 用户,请使用1514)
导出器配置:
creds_file_path:服务账号 JSON 密钥文件的完整路径(选项 1):- Linux:
/opt/observiq-otel-collector/ingestion-auth.json - Windows:
C:\Program Files\observIQ OpenTelemetry Collector\ingestion-auth.json
- Linux:
customer_id:从 Google SecOps 控制台复制的客户 IDlocation:将<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:依次点击文件 > 保存
- Linux:依次按
重启 Bindplane 代理以应用更改
如需在 Linux 中重启 Bindplane 代理,请运行以下命令:
sudo systemctl restart observiq-otel-collector验证服务是否正在运行:
sudo systemctl status observiq-otel-collector检查日志中是否存在错误:
sudo journalctl -u observiq-otel-collector -f
如需在 Windows 中重启 Bindplane 代理,请选择以下选项之一:
以管理员身份运行命令提示符或 PowerShell:
net stop observiq-otel-collector && net start observiq-otel-collector“服务”控制台:
- 按
Win+R,输入services.msc,然后按 Enter 键。 - 找到 observIQ OpenTelemetry 收集器。
- 右键点击并选择重启。
验证服务是否正在运行:
sc query observiq-otel-collector检查日志中是否存在错误:
type "C:\Program Files\observIQ OpenTelemetry Collector\log\collector.log"
- 按
配置 NGINX 以将日志转发到 Bindplane
打开 NGINX 配置文件(例如
/etc/nginx/nginx.conf):sudo vi /etc/nginx/nginx.conf修改配置,将
<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; }重启 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 专业人士的解答。