收集 Cloud Run 日志

支持的平台:

本指南介绍了如何使用 Cloud Storage 将 Cloud Run 日志导出到 Google Security Operations。解析器从 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. 点击创建接收器。

设置 Feed

如需配置 Feed,请按以下步骤操作:

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

    • 存储桶 URI:gs://my-bucket/<value>/ 格式的 Google Cloud 存储桶网址。此网址必须以尾随正斜杠 (/) 结尾。
    • 来源删除选项:根据您的偏好选择删除选项。

    • 文件存在时间上限:包含在过去指定天数内修改过的文件。默认值为 180 天。

  10. 点击下一步。

  11. 在最终确定界面中查看新的新闻信息流配置,然后点击提交。

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_ip、has_target_ip 和 httpRequest.protocol 与 HTTP 匹配,则设置为 NETWORK_HTTP。硬编码为 GCP_RUN。硬编码为 GCP_RUN。硬编码为 Google Cloud Platform。硬编码为 GOOGLE_CLOUD_PLATFORM。

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