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

Offen Anfängerfreundlich
#229 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
76/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
python

Rechercherichtung

Beginne damit, ingest_log() und die dortige Behandlung von Zeitstempeln zu lesen, einschließlich der im Issue beschriebenen Standardwerte, der Reihenfolgeprüfung und der Formatierung. Vergleiche das Verhalten mit get_alerts, das laut Issue naive und zeitzonenbewusste Datums- und Zeitangaben behandelt. Aktualisiere die UTC-Behandlung für Standardwerte und zeitzonenbewusste Eingaben und überprüfe anschließend Standardwerte und Reihenfolge mit einem gemockten Transport in UTC und Nicht-UTC-Zeitzonen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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.

Vorherrschende Sprache
Python
Sterne
94
Forks
49
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus google/secops-wrapper

Alle Issues in google/secops-wrapper

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.