收集 Cloud Run 日志

支持的平台:

本指南介绍了如何使用 Cloud Storage 将 Cloud Run 日志导出到 Google 安全运营中心。解析器会从 JSON 日志中提取字段,并将其转换为统一数据模型 (UDM)。它可处理各种日志格式,包括 HTTP 请求数据和系统审核日志,将相关字段映射到 UDM,同时还会使用 Cloud Run 专有的标签和元数据丰富数据。

准备工作

  • 确保您拥有 Google SecOps 实例。
  • 确保 Cloud Run 已在您的 Google Cloud 环境中设置并处于活跃状态。
  • 确保您拥有对 Google Cloud的特权访问权限。

创建 Google Cloud Storage 存储分区

  1. 登录 Google Cloud 控制台
  2. 前往 Cloud Storage 存储分区页面。

    进入“存储桶”

  3. 点击创建

  4. 创建存储桶页面上,输入您的存储桶信息。完成以下各步骤后,点击继续以进入下一步:

    1. 开始使用部分中,执行以下操作:

      1. 输入符合存储分区名称要求的唯一名称;例如 cloudrun-logs
      2. 如需启用分层命名空间,请点击展开箭头以展开优化文件导向型和数据密集型工作负载部分,然后选择在此存储分区上启用分层命名空间

      3. 如需添加存储分区标签,请点击展开箭头以展开标签部分。

      4. 点击添加标签,然后为标签指定键和值。

    2. 选择数据存储位置部分中,执行以下操作:

      1. 选择位置类型
      2. 使用位置类型菜单选择一个位置,用于永久存储存储分区中的对象数据。

      3. 如需设置跨存储分区复制,请展开设置跨存储分区复制部分。

    3. 为数据选择一个存储类别部分中,为存储分区选择默认存储类别,或者选择 Autoclass 对存储分区数据进行自动存储类别管理。

    4. 选择如何控制对对象的访问权限部分中,选择以强制执行禁止公开访问,然后为存储分区对象选择访问权限控制模型

    5. 选择如何保护对象数据部分中,执行以下操作:

      1. 数据保护下,选择您要为存储分区设置的任何选项。
      2. 如需选择对象数据的加密方式,请点击标有数据加密的展开箭头,然后选择数据加密方法
  5. 点击创建

在 Cloud Run 中配置日志导出

  1. 在 Google Cloud 欢迎页面上,点击 Cloud Run 图标。
  2. 在顶部的搜索栏中搜索日志记录,然后点击 Enter
  3. Logs Explorer 中,在日志名称中选择 Cloud Run,然后点击应用以过滤日志。
  4. 从菜单中依次点击更多操作 > 创建接收器
  5. 提供以下配置:
    1. 接收器详情:输入名称和说明。
    2. 点击下一步
    3. 接收器目标位置:选择 Cloud Storage 存储分区
    4. Cloud Storage 存储分区:选择之前创建的存储分区或创建新存储分区。
    5. 点击下一步
    6. 选择要包含在接收器中的日志:当您在 Cloud Storage 存储分区中选择一个选项时,系统会填充一个默认日志。
    7. 点击下一步
    8. 可选:选择要从接收器中过滤掉的日志:选择您不想写入接收器的日志。
  6. 点击创建接收器

在 Google SecOps 中配置 Feed 以提取 Cloud Run 日志

  1. 依次前往 SIEM 设置 > Feed
  2. 点击新增
  3. Feed 名称字段中,输入 Feed 的名称;例如 Cloud Run 日志
  4. 选择 Google Cloud Storage 作为来源类型
  5. 选择 GCP Cloud Run 作为日志类型
  6. 点击获取服务账号作为 Chronicle 服务账号
  7. 点击下一步
  8. 为以下输入参数指定值:

    • 存储分区 URI: Google Cloud 采用 gs://my-bucket/<value> 格式的存储分区网址。
    • URI 类型:选择包含子目录的目录
    • 来源删除选项:根据您的偏好选择删除选项。

    • 资源命名空间资源命名空间

    • 提取标签:应用于此 Feed 中事件的标签。

  9. 点击下一步

  10. 最终确定界面中查看新的 Feed 配置,然后点击提交

UDM 映射表

日志字段 UDM 映射 逻辑
httpRequest.latency target.resource.attribute.labels.[] 原始日志中的 httpRequest.latency 值用作 target.resource.attribute.labels 中键值为 http_request_latency 的标签的值。
httpRequest.protocol network.application_protocol 如果 httpRequest.protocol 包含 HTTP,则 UDM 字段会设置为 HTTP
httpRequest.remoteIp principal.asset.ip 系统会使用原始日志中的 httpRequest.remoteIp 值。
httpRequest.remoteIp principal.ip 系统会使用原始日志中的 httpRequest.remoteIp 值。
httpRequest.requestMethod network.http.method 系统会使用原始日志中的 httpRequest.requestMethod 值。
httpRequest.requestSize network.sent_bytes 系统会将原始日志中的 httpRequest.requestSize 值转换为无符号整数并加以使用。
httpRequest.requestUrl target.url 系统会使用原始日志中的 httpRequest.requestUrl 值。
httpRequest.responseSize network.received_bytes 系统会将原始日志中的 httpRequest.responseSize 值转换为无符号整数并加以使用。
httpRequest.serverIp target.asset.ip 系统会使用原始日志中的 httpRequest.serverIp 值。
httpRequest.serverIp target.ip 系统会使用原始日志中的 httpRequest.serverIp 值。
httpRequest.status network.http.response_code 系统会将原始日志中的 httpRequest.status 值转换为整数并加以使用。
httpRequest.userAgent network.http.parsed_user_agent 系统会将原始日志中的 httpRequest.userAgent 值解析为用户代理字符串。
httpRequest.userAgent network.http.user_agent 系统会使用原始日志中的 httpRequest.userAgent 值。
insertId metadata.product_log_id 系统会使用原始日志中的 insertId 值。
labels.instanceId additional.fields.[] labels.instanceId 的值用作 additional.fields 中键值为 instanceId 的标签的值。
labels.run.googleapis.com_execution_name additional.fields.[] labels.run.googleapis.com_execution_name 的值用作 additional.fields 中键值为 execution_name 的标签的值。
labels.run.googleapis.com_task_attempt additional.fields.[] labels.run.googleapis.com_task_attempt 的值用作 additional.fields 中键值为 task_attempt 的标签的值。
labels.run.googleapis.com_task_index additional.fields.[] labels.run.googleapis.com_task_index 的值用作 additional.fields 中键值为 task_index 的标签的值。
logName metadata.product_event_type 系统会使用原始日志中的 logName 值。
resource.labels.configuration_name target.resource.attribute.labels.[] resource.labels.configuration_name 的值用作 target.resource.attribute.labels 中键值为 configuration_name 的标签的值。
resource.labels.job_name additional.fields.[] resource.labels.job_name 的值用作 additional.fields 中键值为 job_name 的标签的值。
resource.labels.location target.location.name 系统会使用原始日志中的 resource.labels.location 值。
resource.labels.project_id target.resource.attribute.labels.[] resource.labels.project_id 的值用作 target.resource.attribute.labels 中键值为 project_id 的标签的值。
resource.labels.revision_name target.resource.attribute.labels.[] resource.labels.revision_name 的值用作 target.resource.attribute.labels 中键值为 revision_name 的标签的值。
resource.labels.service_name target.resource.attribute.labels.[] resource.labels.service_name 的值用作 target.resource.attribute.labels 中键值为 service_name 的标签的值。
resource.type target.resource.resource_subtype 系统会使用原始日志中的 resource.type 值。
severity security_result.severity 如果 severity 的值与 Info 匹配(不区分大小写),则 UDM 字段会设置为 INFORMATIONAL
textPayload additional.fields.[] textPayload 的值用作 additional.fields 中键值为 Textpayload 的标签的值。
timestamp metadata.event_timestamp 系统会将原始日志中的 timestamp 值解析为时间戳。
timestamp timestamp 系统会将原始日志中的 timestamp 值解析为时间戳。由解析器逻辑根据是否存在特定字段来确定。默认值为 GENERIC_EVENT。如果 has_principal_iphas_target_iphttpRequest.protocolHTTP 匹配,则设置为 NETWORK_HTTP。已硬编码为 GCP_RUN。已硬编码为 GCP_RUN。已硬编码为 Google Cloud Platform。已硬编码为 GOOGLE_CLOUD_PLATFORM

变化

2024-01-22

增强功能

  • 为 logName 为 projects/1234/logs/run.googleapis.com%2Fstderrprojects/1234/logs/run.googleapis.com%2Fstdoutprojects/1234/logs/run.googleapis.com%2Frequestsprojects/1234/logs/run.googleapis.com%2Fvarlog%2Fsystem 的日志添加了映射。
  • httpRequest.latency 映射到 target.resource.attribute.labels
  • resource.labels.configuration_name 映射到 target.resource.attribute.labels
  • resource.labels.revision_name 映射到 target.resource.attribute.labels
  • resource.labels.service_name 映射到 target.resource.attribute.labels
  • httpRequest.protocol 映射到 network.application_protocol
  • httpRequest.requestMethod 映射到 network.http.method
  • httpRequest.requestSize 映射到 network.sent_bytes
  • httpRequest.requestUrl 映射到 target.url
  • httpRequest.responseSize 映射到 network.received_bytes
  • httpRequest.remoteIp 映射到 principal.ipprincipal.asset.ip
  • httpRequest.serverIp 映射到 target.ipandtarget.asset.ip`。
  • httpRequest.status 映射到 network.http.response_code
  • httpRequest.userAgent 映射到 network.http.user_agent
  • logName 映射到 metadata.product_event_type
  • textPayload 映射到 additional.fields
  • labels.run.googleapis.com_execution_name 映射到 additional.fields
  • labels.run.googleapis.com_task_attempt 映射到 additional.fields
  • labels.run.googleapis.com_task_index 映射到 additional.fields
  • labels.instanceId 映射到 additional.fields
  • resource.labels.job_name 映射到 additional.fields

2023-04-13

增强功能

  • target.resource.attribute.cloud.environment 设置为 GOOGLE_CLOUD_PLATFORM
  • target.resource.name 设置为完整资源名称值。

2022-07-13

  • 新创建的解析器。

需要更多帮助?向社区成员和 Google SecOps 专业人士寻求解答。