收集 GitLab 日志
概览
此解析器从 GitLab JSON 日志中提取字段,将其标准化为统一数据模型 (UDM),并使用其他上下文丰富数据。它可处理各种 GitLab 事件类型,重点关注用户操作、资源访问和安全结果,同时还可处理与网络和应用相关的信息。解析器还会根据 GitLab 中的角色和操作执行逻辑,对事件进行分类并分配适当的严重程度。
准备工作
确保您满足以下前提条件:
- Google SecOps 实例。
- 对 GitLab 的特权访问权限。
设置 Feed
您可以通过两种不同的入口点在 Google SecOps 平台中设置 Feed:
- SIEM 设置 > Feed
- 内容中心 > 内容包
通过“SIEM 设置”>“Feed”设置 Feed
如需配置 Feed,请按以下步骤操作:
- 依次前往 SIEM 设置 > Feed。
- 点击添加新 Feed。
- 在下一页上,点击配置单个 Feed。
- 在 Feed name(Feed 名称)字段中,输入 Feed 的名称(例如 GitLab Logs)。
- 选择 Webhook 作为来源类型。
- 选择 Gitlab 作为日志类型。
- 点击下一步。
- 可选:为以下输入参数指定值:
- 拆分分隔符:用于分隔日志行的分隔符,例如
\n
。 - 资源命名空间:资源命名空间。
- 注入标签:应用于此 Feed 中事件的标签。
- 拆分分隔符:用于分隔日志行的分隔符,例如
- 点击下一步。
- 在最终确定界面中检查 Feed 配置,然后点击提交。
- 点击生成密钥,生成用于对此 Feed 进行身份验证的密钥。
- 复制并存储密钥。您将无法再次查看此密钥。如有需要,您可以重新生成新的 Secret 密钥,但此操作会使之前的 Secret 密钥失效。
- 在详情标签页中,从端点信息字段复制 Feed 端点网址。您需要在客户端应用中指定此端点网址。
- 点击完成。
设置来自内容中心的 Feed
为以下字段指定值:
- 拆分分隔符:用于分隔日志行的分隔符,例如
\n
。
高级选项
- Feed 名称:用于标识 Feed 的预填充值。
- 来源类型:用于将日志收集到 Google SecOps 中的方法。
- 资源命名空间:与 Feed 关联的命名空间。
提取标签:应用于相应 Feed 中所有事件的标签。
点击生成密钥,生成用于对此 Feed 进行身份验证的密钥。
复制并存储密钥。您将无法再次查看此密钥。如有需要,您可以重新生成新的 Secret 密钥,但此操作会使之前的 Secret 密钥失效。
在详情标签页中,从端点信息字段复制 Feed 端点网址。您需要在客户端应用中指定此端点网址。
为 Webhook Feed 创建 API 密钥
前往 Google Cloud 控制台 > 凭据。
点击创建凭据,然后选择 API 密钥。
将 API 密钥访问权限限制为 Chronicle API。
指定端点网址
- 在客户端应用中,指定 webhook Feed 中提供的 HTTPS 端点网址。
通过在自定义标头中指定 API 密钥和密钥来启用身份验证,格式如下:
X-goog-api-key = API_KEY X-Webhook-Access-Key = SECRET
建议:将 API 密钥指定为标头,而不是在网址中指定。如果您的 Webhook 客户端不支持自定义标头,您可以使用以下格式的查询参数指定 API 密钥和密钥:
ENDPOINT_URL?key=API_KEY&secret=SECRET
替换以下内容:
ENDPOINT_URL
:Feed 端点网址。API_KEY
:用于向 Google Security Operations 进行身份验证的 API 密钥。SECRET
:您生成的用于验证 Feed 的密钥。
在 GitLab 中为 Google SecOps 配置 webhook
- 打开您的网络浏览器,然后前往要为其配置 Webhook 的 GitLab 项目。
- 在项目中,依次前往设置 > Webhook。
- 点击添加新的 Webhook。
- 在 网址 字段中,粘贴 Google SecOps 端点网址。
- 点击添加自定义标头。
- 在标头名称字段中输入 X-Webhook-Access-Key。
- 对于 Header Value 字段,请复制在 Google SecOps Feed 配置期间生成的 Secret Key。
- 点击添加自定义标头。
- 在 Header Name 字段中输入 X-goog-api-key。
- 对于 Header Value 字段,请复制在 Google SecOps Feed 配置期间生成的 API 密钥。 注意:为增强安全性,请生成一个密钥令牌,并将其添加到 GitLab Webhook 配置和相应的 Google SecOps Feed 配置中。这有助于验证传入 Webhook 的真实性。
- 选择应触发 Webhook 的 GitLab 事件。例如,您可以选择推送事件,以便在每次将代码推送到代码库时将数据发送到 Google SecOps。请仔细考虑哪些事件与您的安全监控需求相关。过多的事件可能会导致不必要的负载。
- 为了更好地了解 webhook 的用途,请为其指定一个有意义的名称,例如 Google SecOps Webhook。
- 确保选中启用 SSL 验证 复选框。这对于安全通信至关重要。
- 点击添加 Webhook 以保存您的配置。
UDM 映射表
日志字段 | UDM 映射 | 逻辑 |
---|---|---|
author_id |
principal.user.userid |
已转换为字符串。 |
author_name |
principal.user.email_addresses |
如果值与电子邮件地址正则表达式匹配。 |
author_name |
principal.user.user_display_name |
如果值与电子邮件地址正则表达式不匹配。 |
details.as |
principal.resource.attribute.labels |
添加为键为“as”的标签。 |
details.add |
principal.resource.attribute.labels |
添加为键为“add”的标签。 |
details.as |
principal.user.role_name |
原始日志字段值。 |
details.as |
principal.user.attribute.roles.type |
如果 details.as 为“所有者”,则设置为“ADMINISTRATOR”;如果 details.as 为“开发者”“维护者”或“报告者”,则设置为“SERVICE_ACCOUNT”;如果 details.as 为“访客”,则设置为“TYPE_UNSPECIFIED”。 |
details.custom_message |
security_result.description |
原始日志字段值。 |
details.custom_message.action |
security_result.summary |
原始日志字段值。 |
details.entity_path |
target.file.full_path |
原始日志字段值。 |
details.target_id |
target.resource.id |
已转换为字符串。 |
entity_path |
target.file.full_path |
原始日志字段值。 |
entity_type |
target.resource.attribute.labels |
添加为键为“实体类型”的标签。 |
event_type |
metadata.product_event_type |
原始日志字段值。 |
insertId |
metadata.product_log_id |
原始日志字段值。 |
ip_address |
principal.ip ,principal.asset.ip |
原始日志字段值。 |
jsonPayload.action |
additional.fields |
添加为具有键“action”和字符串值的字段。 |
jsonPayload.controller |
additional.fields |
添加为键为“controller”的字段,并具有字符串值。 |
jsonPayload.correlation_id |
principal.asset_id |
以“id: ”为前缀。 |
jsonPayload.cpu_s |
additional.fields |
添加为键为“cpu_s”的字段,并具有字符串值。 |
jsonPayload.details.custom_message.protocol |
network.application_protocol |
如果值为“web”,则设置为“UNKNOWN_APPLICATION_PROTOCOL”,否则转换为大写。如果值为“web”,则还会添加一个键为“Application Protocol”的附加字段。 |
jsonPayload.mem_total_bytes |
additional.fields |
以键为“mem_total_bytes”的字段形式添加,值为字符串。 |
jsonPayload.meta_caller_id |
additional.fields |
添加为键为“Caller Id”的字段,并具有字符串值。 |
jsonPayload.meta_client_id |
target.user.userid |
原始日志字段值。 |
jsonPayload.meta_feature_category |
additional.fields |
添加为键为“功能类别”的字段,并具有字符串值。 |
jsonPayload.meta_remote_ip |
principal.ip ,principal.asset.ip |
原始日志字段值,解析为 JSON 数组并合并到 IP 字段中。 |
jsonPayload.meta_user |
principal.user.userid |
如果 jsonPayload.username 为空,则用作后备。 |
jsonPayload.method |
network.http.method |
原始日志字段值。 |
jsonPayload.path |
target.process.file.full_path |
原始日志字段值。 |
jsonPayload.pid |
target.process.pid |
已转换为字符串。 |
jsonPayload.remote_ip |
principal.ip ,principal.asset.ip |
原始日志字段值。 |
jsonPayload.request_urgency |
additional.fields |
添加为具有键“Request Urgency”和字符串值的字段。 |
jsonPayload.severity |
security_result.severity |
如果值为“INFO”,则设置为“INFORMATIONAL”;如果值为“ERROR”,则设置为“ERROR”;如果值为“NOTICE”,则设置为“MEDIUM”。 |
jsonPayload.status |
network.http.response_code |
如果不是“ACTIVE”,则转换为整数。 |
jsonPayload.ua |
network.http.user_agent |
原始日志字段值。 |
jsonPayload.username |
principal.user.userid |
原始日志字段值。 |
jsonPayload.worker_id |
principal.application |
原始日志字段值。 |
labels.instance_name |
principal.hostname ,principal.asset.hostname |
原始日志字段值,如果消息包含“正在移除用户”,则使用此值。 |
logName |
security_result.category_details |
原始日志字段值。 |
message |
security_result.summary |
原始日志字段值,当 jsonPayload.severity 为“ERROR”时使用。 |
protoPayload.@type |
additional.fields |
添加为具有键“protoPayload type”和字符串值的字段。 |
protoPayload.authenticationInfo.principalEmail |
principal.user.email_addresses ,principal.user.userid |
原始日志字段值。 |
protoPayload.authenticationInfo.principalSubject |
additional.fields |
添加为具有键“authenticationInfo principalSubject”和字符串值的字段。 |
protoPayload.authenticationInfo.serviceAccountKeyName |
additional.fields |
添加为具有键“authenticationInfo serviceAccountKeyName”和字符串值的字段。 |
protoPayload.authorizationInfo |
target.resource.attribute.labels ,security_result.action |
此字段中的值会添加为标签,且键以“authenticationInfo”为前缀。如果 granted 中的某个值为 true,则将 security_result.action 设置为“ALLOW”;如果为 false,则设置为“BLOCK”。嵌套字段(如 resourceAttributes )也会作为标签添加,其键带有“authenticationInfo_resourceAttributes”前缀。 |
protoPayload.methodName |
additional.fields |
添加为具有键“protoPayload methodName”和字符串值的字段。 |
protoPayload.request.@type |
additional.fields |
添加为具有键“Request Type”和字符串值的字段。 |
protoPayload.request.resource |
target.resource.attribute.labels |
添加为键为“请求资源”的标签。 |
protoPayload.requestMetadata.callerIp |
additional.fields |
添加为具有键“requestMetadata callerIp”和字符串值的字段。 |
protoPayload.requestMetadata.callerSuppliedUserAgent |
additional.fields |
添加为具有键“requestMetadata callerSuppliedUserAgent”和字符串值的字段。 |
protoPayload.serviceName |
additional.fields |
以键为“serviceName”的字段形式添加,值为字符串。 |
protoPayload.status.code |
additional.fields |
添加为键为“protoPayload status code”的字段,并具有字符串值。 |
protoPayload.status.message |
additional.fields 、target.user.email_addresses 、target.user.userid |
添加为具有键“protoPayload status message”和字符串值的字段。如果可以从邮件中提取电子邮件地址,则该地址会添加到 target.user.email_addresses 和 target.user.userid 中。 |
receiveTimestamp |
metadata.event_timestamp ,timestamp |
解析为事件时间戳。 |
resource.labels.project_id |
target.resource.attribute.labels |
添加为键为“项目 ID”的标签。 |
resource.labels.zone |
target.cloud.availability_zone |
原始日志字段值。 |
resource.type |
target.cloud.environment |
如果值与“gce”匹配,则设置为“GOOGLE_CLOUD_PLATFORM”。 |
security_result.action |
security_result.action |
派生自 protoPayload.authorizationInfo.granted 。 |
security_result.category_details |
security_result.category_details |
已与 logName 合并。 |
security_result.description |
security_result.description |
派生自 jsonPayload.details.custom_message 。 |
security_result.severity |
security_result.severity |
派生自 severity 或 jsonPayload.severity 。 |
security_result.summary |
security_result.summary |
派生自 jsonPayload.details.custom_message.action 或 jsonPayload.message 。 |
severity |
security_result.severity |
如果值为“INFO”,则设置为“INFORMATIONAL”;如果值为“ERROR”,则设置为“ERROR”;如果值为“NOTICE”,则设置为“MEDIUM”。 |
sourceLocation |
principal.resource.attribute.labels |
此字段中的值会添加为标签。 |
target_details |
target.resource.attribute.labels |
添加为键为“Target Details”的标签。 |
target_type |
target.resource.attribute.labels |
以键为“target type”的标签形式添加。 |
timestamp |
timestamp |
原始日志字段值。根据是否存在正文字段和目标字段进行设置。如果未满足任何特定条件,则默认为“GENERIC_EVENT”。可能的值包括“USER_RESOURCE_UPDATE_CONTENT”“USER_RESOURCE_ACCESS”“USER_UNCATEGORIZED”。设置为“GITLAB”。设置为“GITLAB”。 |
需要更多帮助?从社区成员和 Google SecOps 专业人士那里获得解答。