收集 MySQL 日志

支持的语言:

本文档介绍了如何使用 Bindplane 代理将 MySQL 日志注入到 Google Security Operations。

MySQL 是一种关系型数据库管理系统,可针对身份验证事件、查询执行、数据库操作和审核跟踪记录生成 syslog 消息。解析器会从 syslog 格式的审核日志中提取字段,并将其映射到统一数据模型 (UDM)。

准备工作

请确保满足以下前提条件:

  • Google SecOps 实例
  • Windows Server 2016 或更高版本,或者具有 systemd 的 Linux 主机
  • Bindplane 代理与 MySQL 服务器之间的网络连接
  • 如果通过代理运行,请确保防火墙端口根据 Bindplane 代理要求处于开放状态
  • 对 MySQL 主机的 SSH 访问权限(具有 root 或 sudo 权限)

获取 Bindplane 代理的 Google SecOps 凭证

如需向 Google SecOps 验证 Bindplane 代理,请选择以下方法之一:

  • 新部署:使用 Chronicle API(选项 1)。
  • 旧版部署:继续使用数据注入身份验证文件(方法 2),直到 Ingestion API 于 2027 年 7 月 20 日停用。
  1. 登录 Google Cloud 控制台,然后选择与您的 Google SecOps 实例关联的 Google Cloud 项目。
  2. 前往 IAM 和管理 > 服务账号。
  3. 点击创建服务账号。
  4. 提供以下配置详细信息:
    • 服务账号名称:输入账号的名称(例如 bindplane-ingest)。
    • 服务账号说明:输入说明(例如 Bindplane agent log ingestion)。
  5. 点击创建并继续。
  6. 在向此服务账号授予对项目的访问权限部分,点击选择角色,然后选择 Chronicle Editor。
  7. 点击继续,然后点击完成。
  8. 点击您创建的服务账号,然后前往密钥标签页。
  9. 依次点击添加密钥> 创建新密钥。
  10. 选择 JSON,然后点击创建。密钥文件会下载到您的计算机上。
  11. 将密钥文件另存为 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 以匹配您保存该文件的路径。
  12. 前往 IAM 和管理 > 设置,然后复制项目编号。您在配置导出器时需要用到该名称。

方法 2:下载数据注入身份验证文件(旧版)

  1. 登录 Google SecOps 控制台。
  2. 前往 SIEM 设置> 收集代理。
  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
    

    该服务应显示为有效(正在运行)。

其他安装资源

如需了解其他安装选项和问题排查,请参阅 Bindplane 代理安装指南。

配置 Bindplane 代理以注入 Syslog 并发送到 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/mysql:
        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: MYSQL
        raw_log_field: body
    
    service:
      pipelines:
        logs/mysql_to_chronicle:
          receivers:
            - udplog
          exporters:
            - chronicle/mysql
    

配置参数

替换以下占位符:

  • 接收器配置:

    • 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
    • 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/mysql:
        compression: gzip
        creds_file_path: '/opt/observiq-otel-collector/ingestion-auth.json'
        customer_id: '<customer_id>'
        endpoint: malachiteingestion-pa.googleapis.com
        log_type: MYSQL
        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 收集器。
      3. 右键点击,然后选择重新启动。
      4. 验证服务是否正在运行:

        sc query observiq-otel-collector
        
      5. 检查日志中的错误:

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

在 MySQL 中配置 syslog

  1. 使用 SSH 登录 MySQL 主机。
  2. 连接到 MySQL 数据库:

    mysql -u root -p
    
  3. 验证 server_audit.so 审核插件:

    show variables like 'plugin_dir';
    
  4. 如果未找到该插件,请安装它:

    install plugin server_audit soname 'server_audit.so';
    
  5. 确认插件已安装并已启用:

    show plugins;
    
  6. 修改文件 /etc/my.cnf 并启用以下审核设置:

    server_audit_events='CONNECT,QUERY,TABLE'
    server_audit_file_path=server_audit.log
    server_audit_logging=ON
    server_audit_output_type=SYSLOG
    server_audit_syslog_facility=LOG_LOCAL6
    
  7. 验证审核变量:

    show global variables like "server_audit%";
    
  8. 验证审核是否已启用:

    Show global status like 'server_audit%';
    
  9. 修改文件 /etc/rsyslog.conf 以启用通过 UDP 进行转发:

    *.* @@<bindplane-agent-ip>:<bindplane-agent-port>
    
    • 将 <bindplane-agent-ip> 和 <bindplane-agent-port> 替换为您的 Bindplane 代理配置。
  10. 重启 MySQL 服务:

    /etc/init.d/mysqld restart
    

UDM 映射表

日志字段 UDM 映射 逻辑
操作 read_only_udm.metadata.event_type 如果值为 Created,则为 FILE_CREATION;如果值为 Deleted,则为 FILE_DELETION;否则不发生变化。
数据库 read_only_udm.target.resource.parent
db_hostname read_only_udm.target.hostname
db_user read_only_udm.target.user.userid
说明 read_only_udm.security_result.description
error_details 这是一个临时变量,请忽略它
error_level read_only_udm.security_result.severity 如果值为 error,则为 ERROR;如果值为 warning,则为 MEDIUM;如果值为 note,则为 INFORMATIONAL;否则不更改。
error_message read_only_udm.security_result.summary
file_path read_only_udm.target.file.full_path
file_size read_only_udm.target.file.size
主机名 read_only_udm.principal.hostname
inner_message read_only_udm.security_result.description
摘要 read_only_udm.metadata.product_event_type
表 read_only_udm.target.resource.name
table_not_found 这是一个临时变量,请忽略
时间戳 read_only_udm.metadata.event_timestamp
read_only_udm.extensions.auth.type 静态价值 - MACHINE
read_only_udm.metadata.event_type 静态价值 - USER_LOGIN、GENERIC_EVENT、STATUS_UPDATE、FILE_CREATION、FILE_DELETION
read_only_udm.metadata.log_type 静态价值 - MYSQL
read_only_udm.metadata.product_name 静态价值 - MySQL
read_only_udm.metadata.vendor_name 静态价值 - Oracle Corporation
read_only_udm.security_result.action 静态价值 - BLOCK
read_only_udm.target.resource.resource_type 静态价值 - DATABASE、TABLE
properties.event_time event.idm.read_only_udm.metadata.event_timestamp 从更新日志映射
properties.ip event.idm.read_only_udm.principal.ip和event.idm.read_only_udm.principal.asset.ip之间 从更新日志映射
properties.user event.idm.read_only_udm.principal.user.userid 从更新日志映射
properties.error_code event.idm.read_only_udm.security_result.description 从更新日志映射
properties.event_subclass event.idm.read_only_udm.additional.fields 从更新日志映射
properties.is_aad_auth event.idm.read_only_udm.additional.fields 从更新日志映射
category event.idm.read_only_udm.metadata.product_event_type 从更新日志映射
ServerType event.idm.read_only_udm.target.application 从更新日志映射
target_app event.idm.read_only_udm.target.application 从更新日志映射
properties.start_time event.idm.read_only_udm.metadata.event_timestamp 从更新日志映射
ts event.idm.read_only_udm.metadata.event_timestamp 从更新日志映射
time event.idm.read_only_udm.metadata.collected_timestamp 从更新日志映射
properties.server_id event.idm.read_only_udm.target.asset.asset_id 从更新日志映射
properties.thread_id event.idm.read_only_udm.principal.process.pid 从更新日志映射
user_id event.idm.read_only_udm.principal.user.userid 从更新日志映射
p_host event.idm.read_only_udm.principal.hostname 从更新日志映射
p_host event.idm.read_only_udm.principal.asset.hostname 从更新日志映射
properties.db event.idm.read_only_udm.target.resource.name 从更新日志映射
resourceId event.idm.read_only_udm.target.resource.product_object_id 从更新日志映射
operationName event.idm.read_only_udm.metadata.description 从更新日志映射
location event.idm.read_only_udm.target.location.name 从更新日志映射
properties.host event.idm.read_only_udm.additional.fields 从更新日志映射
properties.last_insert_id event.idm.read_only_udm.additional.fields 从更新日志映射
properties.insert_id event.idm.read_only_udm.additional.fields 从更新日志映射
properties.sql_text event.idm.read_only_udm.additional.fields 从更新日志映射
properties.rows_examined event.idm.read_only_udm.additional.fields 从更新日志映射
properties.rows_sent event.idm.read_only_udm.additional.fields 从更新日志映射
properties.lock_time event.idm.read_only_udm.additional.fields 从更新日志映射
properties.query_time event.idm.read_only_udm.additional.fields 从更新日志映射
properties.replication_set_role event.idm.read_only_udm.additional.fields 从更新日志映射
properties.event_class event.idm.read_only_udm.additional.fields 从更新日志映射
csv_principal_hostname event.idm.read_only_udm.principal.ip和event.idm.read_only_udm.principal.asset.ip之间 从更新日志映射
csv_hostname event.idm.read_only_udm.target.hostname和event.idm.read_only_udm.target.asset.hostname之间 从更新日志映射
csv_principal_hostname event.idm.read_only_udm.principal.hostname和event.idm.read_only_udm.principal.asset.hostname之间 从更新日志映射
ts event.idm.read_only_udm.additional.fields 从更新日志映射
csv_query_id event.idm.read_only_udm.additional.fields 从更新日志映射
csv_mysql event.idm.read_only_udm.additional.fields 从更新日志映射
account_host event.idm.read_only_udm.principal.resource.attribute.labels 从更新日志映射
login_proxy event.idm.read_only_udm.principal.resource.attribute.labels 从更新日志映射
login_os event.idm.read_only_udm.principal.resource.attribute.labels 从更新日志映射
arg event.idm.read_only_udm.principal.resource.attribute.labels 从更新日志映射
startup_data_server_id event.idm.read_only_udm.principal.resource.product_object_id 从更新日志映射
startup_data_os_version event.idm.read_only_udm.principal.platform_version 从更新日志映射
startup_data_mysql_version event.idm.read_only_udm.metadata.product_version 从更新日志映射
arg event.idm.read_only_udm.principal.process.command_line 从更新日志映射
csv_mysql_sql_query event.idm.read_only_udm.target.resource.attribute.labels 从更新日志映射
hostname event.idm.read_only_udm.intermediary.hostname和event.idm.read_only_udm.intermediary.asset.hostname之间 从更新日志映射
id event.idm.read_only_udm.additional.fields 从更新日志映射
login.proxy event.idm.read_only_udm.additional.fields 从更新日志映射
connection_data.connection_type event.idm.read_only_udm.additional.fields 从更新日志映射
connection_data.status event.idm.read_only_udm.additional.fields 从更新日志映射
login.os event.idm.read_only_udm.principal.platform_version 从更新日志映射
account.host event.idm.read_only_udm.target.hostname和event.idm.read_only_udm.target.asset.hostname之间 从更新日志映射
connection_data.db event.idm.read_only_udm.target.application 从更新日志映射
mysql_description event.idm.read_only_udm.metadata.description 从更新日志映射
mysql_errno event.idm.read_only_udm.metadata.product_log_id 从更新日志映射
mysql_version event.idm.read_only_udm.metadata.product_version 从更新日志映射
process_path event.idm.read_only_udm.principal.process.file.full_path 从更新日志映射
mysql_port event.idm.read_only_udm.principal.port 从更新日志映射
status event.idm.read_only_udm.security_result.summary 从更新日志映射
error_level event.idm.read_only_udm.security_result.severity_details 从更新日志映射
mysql_thread_id event.idm.read_only_udm.network.session_id 从更新日志映射
mysql_socket event.idm.read_only_udm.additional.fields 从更新日志映射
log_level event.idm.read_only_udm.additional.fields 从更新日志映射
mysql_timestamp event.idm.read_only_udm.metadata.event_timestamp 从更新日志映射
event_date event.idm.read_only_udm.metadata.event_timestamp 从更新日志映射
event_time event.idm.read_only_udm.metadata.event_timestamp 从更新日志映射
csv_timestamp event.idm.read_only_udm.metadata.event_timestamp 从更新日志映射
mysql_action event.idm.read_only_udm.metadata.product_event_type 从更新日志映射
log_category event.idm.read_only_udm.metadata.product_event_type 从更新日志映射
csv_mysql_action event.idm.read_only_udm.metadata.product_event_type 从更新日志映射
csv_mysql_connection_type event.idm.read_only_udm.metadata.product_event_type 从更新日志映射
event_message event.idm.read_only_udm.metadata.description 从更新日志映射
resolution_error event.idm.read_only_udm.metadata.description 从更新日志映射
component event.idm.read_only_udm.principal.application 从更新日志映射
mysql_hostname event.idm.read_only_udm.principal.ip和event.idm.read_only_udm.principal.asset.ip之间 从更新日志映射
csv_hostname_ip event.idm.read_only_udm.principal.ip和event.idm.read_only_udm.principal.asset.ip之间 从更新日志映射
mysql_username event.idm.read_only_udm.principal.user.userid 从更新日志映射
csv_username event.idm.read_only_udm.principal.user.userid 从更新日志映射
csv_target_hostname event.idm.read_only_udm.target.hostname和event.idm.read_only_udm.target.asset.hostname之间 从更新日志映射
csv_database_name event.idm.read_only_udm.target.resource.name 从更新日志映射
mysql_sql_query event.idm.read_only_udm.target.resource.attribute.labels 从更新日志映射
csv_connection_id event.idm.read_only_udm.network.session_id 从更新日志映射
mysql_message_id event.idm.read_only_udm.security_result.rule_id 从更新日志映射
target_mysql_hostname event.idm.read_only_udm.target.hostname和event.idm.read_only_udm.target.asset.hostname之间 从更新日志映射
csv_mysql_connection_type event.idm.read_only_udm.security_result.detection_fields 从更新日志映射
login.ip event.idm.read_only_udm.principal.ip 从更新日志映射
login.ip event.idm.read_only_udm.principal.asset.ip 从更新日志映射
login.user event.idm.read_only_udm.principal.user.userid 从更新日志映射
account.user event.idm.read_only_udm.target.user.userid 从更新日志映射
inter_host event.idm.read_only_udm.intermediary.hostname 从更新日志映射
target_host event.idm.read_only_udm.target.hostname 从更新日志映射
target_host event.idm.read_only_udm.target.asset.hostname 从更新日志映射
target_ip event.idm.read_only_udm.target.ip 从更新日志映射
target_ip event.idm.read_only_udm.target.asset.ip 从更新日志映射
connection_id event.idm.read_only_udm.network.session_id 从更新日志映射
general_data.command event.idm.read_only_udm.target.process.command_line 从更新日志映射
general_data.query event.idm.read_only_udm.security_result.summary 从更新日志映射
connection_data.connection_type event.idm.read_only_udm.network.ip_protocol 从更新日志映射
general_data.sql_command event.idm.read_only_udm.security_result.detection_fields 从更新日志映射
event_data event.idm.read_only_udm.security_result.detection_fields 从更新日志映射
general_data.status event.idm.read_only_udm.security_result.detection_fields 从更新日志映射
class event.idm.read_only_udm.security_result.detection_fields 从更新日志映射
Status event.idm.read_only_udm.security_result.detection_fields 从更新日志映射
sql_query event.idm.read_only_udm.target.resource.attribute.labels 从更新日志映射
value event.idm.read_only_udm.target.resource.attribute.labels 从更新日志映射
num event.idm.read_only_udm.target.resource.attribute.labels 从更新日志映射
ns event.idm.read_only_udm.target.resource.attribute.labels 从更新日志映射
itemid event.idm.read_only_udm.target.resource.attribute.labels 从更新日志映射
value_min event.idm.read_only_udm.target.resource.attribute.labels 从更新日志映射
value_avg event.idm.read_only_udm.target.resource.attribute.labels 从更新日志映射
value_max event.idm.read_only_udm.target.resource.attribute.labels 从更新日志映射
query_id event.idm.read_only_udm.target.resource.attribute.labels 从更新日志映射
clock event.idm.read_only_udm.metadata.event_timestamp 从更新日志映射
path principal.file.full_path 从更新日志映射
logtype metadata.product_event_type 从更新日志映射

更新日志

查看相应解析器的更新日志

需要更多帮助?获得社区成员和 Google SecOps 专业人士的解答。