`ingest_log` sends local wall-clock time labelled as UTC by default, and raises TypeError for timezone-aware `log_entry_time`

未关闭 适合新手
#229 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
76/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python

调研方向

首先阅读 ingest_log() 及其时间戳处理方式,包括 issue 中描述的默认值、顺序检查和格式化。将其行为与 get_alerts 进行比较;issue 指出该函数会处理 naive 和带时区的 datetime。更新默认值和带时区输入的 UTC 处理方式,然后使用模拟的 transport,在 UTC 和非 UTC 时区中验证默认值和顺序。

由索引模型根据 Issue 内容生成。

描述

Summary

ingest_log() (and therefore secops log ingest in the CLI, which never passes timestamps) builds its default log_entry_time / collection_time from datetime.now(), which is a naive local time, and then formats it with a literal Z suffix:

now = datetime.now()
...
log_entry_time_str = log_entry_time.strftime("%Y-%m-%dT%H:%M:%S.%fZ")

On any machine whose local timezone is not UTC, every ingested log gets timestamps shifted by the local UTC offset. In addition, passing a timezone-aware log_entry_time while leaving collection_time at its default raises TypeError: can't compare offset-naive and offset-aware datetimes, independent of the local timezone.

The Chronicle logs.import reference defines both fields as RFC 3339 timestamps ("Z-normalized"), and states that collectionTime "Must be after the logEntryTime".

Reproduction (mocked transport, no credentials)

The probe calls ingest_log(client, "OKTA", ["{}"], force_log_type=True) with chronicle_request patched, then compares the log_entry_time that was sent with datetime.now(timezone.utc):

local TZ sent log_entry_time vs real UTC now
UTC +0.0 h
Europe/Berlin +1.0 h (in the future)
America/Los_Angeles -8.0 h

Same probe, ingest_log(..., log_entry_time=datetime.now(timezone.utc) - timedelta(minutes=5)) with no collection_time:

TypeError: can't compare offset-naive and offset-aware datetimes

(raised in all three timezones).

Expected

Defaults should be the current UTC time, and timezone-aware inputs should be converted to UTC before the ordering check and formatting. This is how get_alerts already handles its time range since #35 (naive -> UTC, aware -> astimezone(timezone.utc)).

Environment

secops at ca553eb (main), Python 3.12, macOS arm64. The behaviour comes from datetime.now() semantics, so it is not platform-specific.

Related: the same "format with a literal Z without converting" pattern exists in other modules (for example search_udm / get_stats send 09:00:00Z for a 09:00+01:00 input), but this issue is limited to ingest_log, where it triggers on the default path.

This issue was drafted with Claude Code (claude-opus-5-5); the results above are from the runs described.

主要语言
Python
星标
94
派生
49
PR 合并指标
30 天内没有已合并 PR

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

google/secops-wrapper 的其他 Issue

查看 google/secops-wrapper 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。