收集 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 存储分区
- 登录 Google Cloud 控制台。
前往 Cloud Storage 存储分区页面。
点击创建。
在创建存储桶页面上,输入您的存储桶信息。完成以下每一步后,点击继续以继续执行后续步骤:
在开始使用部分中,执行以下操作:
- 输入符合存储桶名称要求的唯一名称,例如 cloudrun-logs。
如需启用分层命名空间,请点击展开箭头以展开优化文件导向型和数据密集型工作负载部分,然后选择在此存储桶上启用分层命名空间。
如需添加存储桶标签,请点击展开箭头以展开标签部分。
点击添加标签,然后为标签指定键和值。
在选择数据存储位置部分中,执行以下操作:
- 选择位置类型。
使用位置类型菜单选择一个位置,用于永久存储存储桶中的对象数据。
如需设置跨存储桶复制,请展开设置跨存储桶复制部分。
在为数据选择一个存储类别部分中,为存储桶选择默认存储类别,或者选择 Autoclass 对存储桶数据进行自动存储类别管理。
在选择如何控制对对象的访问权限部分中,选择不强制执行禁止公开访问,然后为存储桶对象选择访问权限控制模型。
在选择如何保护对象数据部分中,执行以下操作:
- 在数据保护下,选择您要为存储桶设置的任何选项。
- 如需选择对象数据的加密方式,请点击标有数据加密的展开箭头,然后选择数据加密方法。
点击创建。
在 Cloud Run 中配置日志导出
- 在 Google Cloud 欢迎页面上,点击 Cloud Run 图标。
- 在顶部的搜索栏中搜索记录,然后点击 Enter 键。
- 在日志浏览器中,通过在日志名称中选择 Cloud Run 来过滤日志,然后点击应用。
- 在菜单中依次点击更多操作 > 创建接收器。
- 提供以下配置:
- 接收器详情:输入名称和说明。
- 点击下一步。
- 接收器目标位置:选择 Cloud Storage 存储分区。
- Cloud Storage 存储桶:选择之前创建的存储桶或创建新存储桶。
- 点击下一步。
- 选择要包含在接收器中的日志:当您在 Cloud Storage 存储分区中选择一个选项时,系统会填充默认日志。
- 点击下一步。
- 可选:选择要从接收器中过滤掉的日志:选择您不想接收的日志。
- 点击创建接收器。
设置 Feed
您可以通过两种不同的入口点在 Google SecOps 平台中设置 Feed:
- SIEM 设置 > Feed
- 内容中心 > 内容包
通过“SIEM 设置”>“Feed”设置 Feed
如需配置 Feed,请按以下步骤操作:
- 依次前往 SIEM 设置 > Feed。
- 点击添加新 Feed。
- 在下一页上,点击配置单个 Feed。
- 在 Feed name 字段中,输入 Feed 的名称,例如 Cloud Run Logs。
- 选择 Google Cloud Storage 作为来源类型。
- 选择 GCP Cloud Run 作为日志类型。
- 点击获取服务账号作为 Chronicle 服务账号。
- 点击下一步。
为以下输入参数指定值:
- 存储桶 URI:
gs://my-bucket/<value>
格式的 Google Cloud 存储桶网址。 - URI Is A:选择目录(包括子目录)。
来源删除选项:根据您的偏好设置选择删除选项。
- 存储桶 URI:
点击下一步。
在最终确定界面中查看新的 Feed 配置,然后点击提交。
设置来自内容中心的 Feed
为以下字段指定值:
- 存储桶 URI:
gs://my-bucket/<value>
格式的 Google Cloud 存储桶网址。 - URI Is A:选择目录(包括子目录)。
- 来源删除选项:根据您的偏好设置选择删除选项。
高级选项
- Feed 名称:用于标识 Feed 的预填充值。
- 来源类型:用于将日志收集到 Google SecOps 中的方法。
- 资源命名空间:与 Feed 关联的命名空间。
- 提取标签:应用于相应 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_ip 、has_target_ip 和 httpRequest.protocol 与 HTTP 相匹配,则设置为 NETWORK_HTTP 。硬编码为 GCP_RUN 。硬编码为 GCP_RUN 。硬编码为 Google Cloud Platform 。硬编码为 GOOGLE_CLOUD_PLATFORM 。 |
需要更多帮助?从社区成员和 Google SecOps 专业人士那里获得解答。