TExcelTAD
Home › Defensive Security: SOC, SIEM, Detection Engineering & Threat Hunting › Collecting, Shipping and Retaining Logs

Collecting, Shipping and Retaining Logs

Logs that stay on the machine that wrote them are the first thing an intruder with admin rights deletes. Logs that are shipped but arrive twice, late or not at all make detections fire wrongly or miss. And logs kept for three years at full search speed can cost more than the rest of the security budget. This lesson covers the pipeline between a log line being written and it being searchable: collection, transport, buffering, deduplication, storage tiers and retention, with a cost model you can change.

The pipeline

  1. Collect on the source: an agent reads files, the Windows event log, journald or an API (Elastic Agent or Beats, the Splunk Universal Forwarder, Fluent Bit, Vector, NXLog, the Wazuh agent), or the device pushes syslog, or a cloud service exports to storage or a stream.
  2. Transport to a central point: syslog over TCP with TLS, the agent's own protocol, HTTPS to an ingestion API, or a message queue (Kafka) in big setups. Windows can forward natively with Windows Event Forwarding (WEF) to a collector (WEC).
  3. Process: parse, normalise (Normalisation and Schemas), enrich, drop noise, route.
  4. Store and index in the SIEM or a data lake, in tiers.

The Observability course builds the same pipeline for application logs with Fluent Bit and Grafana Alloy into Loki; the mechanics are identical, the security requirements below are extra.

Syslog in one paragraph

Syslog is the oldest common transport. The legacy BSD format (RFC 3164) has no year and no time zone in its timestamp; the current format (RFC 5424) has an ISO 8601 timestamp with offset, a hostname, an app name, a process ID, a message ID and structured data. Plain UDP on port 514 loses messages silently under load and can be spoofed; use TCP with TLS (RFC 5425, port 6514) for anything security-relevant.

Delivery: lost, late or twice

Agents buffer to disk when the destination is unreachable and resend later, which gives at-least-once delivery: after a network blip, some events arrive twice. Without a buffer, delivery is at-most-once: events are lost. Exactly-once is rare and expensive. Practical consequences:

  • Deduplicate on a stable event identifier (the Windows EventRecordID plus computer name, a hash of the raw line) at ingestion or in queries, or counting rules (brute force, beaconing) fire on duplicates.
  • Use event time, not arrival time, in detections: a buffered event may arrive an hour late. Rules that only look at "the last 5 minutes of arrivals" miss late data; schedule rules with a look-back that covers the expected delay.
  • Monitor lag (arrival time − event time) per source.
python · try it yourself
import pandas as pd

# One host's events, shipped through an agent that lost its connection from 10:02 to 10:05
# and resent its disk buffer twice after reconnecting (at-least-once delivery).
ev = pd.DataFrame({
    "record_id": [101, 102, 103, 104, 103, 104, 105, 104, 106],
    "event_time": pd.to_datetime(["10:00:10", "10:01:00", "10:02:30", "10:03:40", "10:02:30",
                                  "10:03:40", "10:04:50", "10:03:40", "10:05:20"], format="%H:%M:%S"),
    "arrival":    pd.to_datetime(["10:00:11", "10:01:01", "10:05:05", "10:05:05", "10:05:06",
                                  "10:05:06", "10:05:06", "10:05:07", "10:05:21"], format="%H:%M:%S"),
    "msg": ["logon ok", "logon fail", "logon fail", "logon fail", "logon fail", "logon fail",
            "logon fail", "logon fail", "logon ok"],
})
ev["lag_s"] = (ev.arrival - ev.event_time).dt.total_seconds()
print("received:", len(ev), "events, failures:", (ev.msg == "logon fail").sum())
dedup = ev.drop_duplicates(subset="record_id")
print("after dedup:", len(dedup), "events, failures:", (dedup.msg == "logon fail").sum())
print("max lag:", dedup.lag_s.max(), "s")

# A rule that counts failures in the 5 arrival-minutes before 10:05:30 versus in event time:
by_arrival = dedup[(dedup.arrival > "1900-01-01 10:00:30") & (dedup.msg == "logon fail")]
print("failures that ARRIVED 10:00:30-10:05:30:", len(by_arrival), "| raw, with duplicates:",
      len(ev[(ev.arrival > "1900-01-01 10:00:30") & (ev.msg == "logon fail")]))
received: 9 events, failures: 7
after dedup: 6 events, failures: 4
max lag: 155.0 s
failures that ARRIVED 10:00:30-10:05:30: 4 | raw, with duplicates: 7

The duplicates turned four real failures (records 102 to 105) into seven, enough to push a "5 failures" brute-force rule over its threshold for a user who never had more than four. Deduplicating on the record identifier restores the truth. The lag matters too: the worst event arrived 155 s late, so a rule that ran at 10:04 on what had arrived would have seen one failure, not three.

Storage tiers and retention

SIEMs and data lakes store data in tiers: hot (indexed on fast disks, searchable in seconds, expensive), warm (still searchable, slower), cold / archive (object storage, cheap, must be restored or scanned slowly before searching). Retention is set per source by three forces:

  • Investigation needs. Dwell times of weeks to months are common (SOC Metrics); if identity and DNS logs only go back 7 days, you can't scope an intrusion that started 40 days ago.
  • Regulation and contracts. For example PCI DSS v4.0.1 (requirement 10.5.1) asks for audit-log history of at least 12 months with at least the most recent 3 months immediately available for analysis; other sectors and countries have their own rules. Check the ones that apply to you.
  • Privacy law. Logs contain personal data (user names, IP addresses). Under the GDPR and similar laws, keep them only as long as the purpose requires, restrict access, and document it.

A cost model

python · try it yourself
sources = {  # events per second (average), bytes per event after parsing, hot days, total days
    "domain controllers": (300, 900, 90, 365),
    "endpoints (EDR)":    (4000, 700, 30, 180),
    "firewall + proxy":   (2500, 450, 30, 365),
    "DNS resolver":       (1200, 250, 30, 180),
    "cloud audit":        (80, 1500, 90, 365),
}
HOT, COLD = 0.10, 0.004          # illustrative storage+index cost, USD per GB per month (not a quote)
total = 0
print(f"{'source':20} {'GB/day':>7} {'hot GB':>8} {'cold GB':>8} {'USD/month':>10}")
for name, (eps, size, hot_d, all_d) in sources.items():
    gb_day = eps * size * 86400 / 1e9
    hot, cold = gb_day * hot_d, gb_day * (all_d - hot_d)
    cost = hot * HOT + cold * COLD
    total += cost
    print(f"{name:20} {gb_day:7.1f} {hot:8.0f} {cold:8.0f} {cost:10.0f}")
print(f"{'total':20} {'':7} {'':8} {'':8} {total:10.0f}")

# What does filtering noisy endpoint events at the agent save?
eps, size, hot_d, all_d = sources["endpoints (EDR)"]
gb = eps * 0.6 * size * 86400 / 1e9          # keep 60 %
print(f"\nEDR filtered to 60 %: {gb:.1f} GB/day, saves {(1 - 0.6) * eps * size * 86400 / 1e9 * (hot_d * HOT + (all_d - hot_d) * COLD):.0f} USD/month")
source                GB/day   hot GB  cold GB  USD/month
domain controllers      23.3     2100     6415        236
endpoints (EDR)        241.9     7258    36288        871
firewall + proxy        97.2     2916    32562        422
DNS resolver            25.9      778     3888         93
cloud audit             10.4      933     2851        105
total                                                1726

EDR filtered to 60 %: 145.2 GB/day, saves 348 USD/month

Endpoint telemetry dominates volume, which is why the first cost lever is filtering at the source (drop events no detection uses, such as some image-load or file-read events) and the second is moving older data to cold storage. The numbers are illustrative; real prices vary by product and contract, and many SIEMs charge by ingested volume rather than storage.

How collection problems are detected

  • A heartbeat per agent and per source, with an alert when it stops.
  • Lag and volume per source against a baseline.
  • Parser failure rate: events that end up in an "unparsed" bucket.
  • Duplicate rate: share of record IDs seen more than once.

How the logs are protected

  • Forward quickly and keep only a short local buffer; an attacker who gains admin later cannot rewrite what has already left.
  • Separate access: the people and accounts that administer servers should not be able to delete their logs in the SIEM.
  • Integrity: write-once (WORM) storage or object lock for archives, and hash chains or signed batches where evidence value matters (Evidence Handoff to DFIR).
  • Encrypt in transit (TLS) and at rest; logs contain secrets that developers accidentally printed.

Pitfalls

  • UDP syslog for security logs. Silent loss under exactly the conditions (a flood) when you need the logs.
  • Filtering before you know what detections need. Dropping "noisy" process events can remove the one field a future rule needs; filter with the detection engineers.
  • Retention set by the default. Many products default to short retention; decide it per source.

Practice

1. In the first program, why did the agent's resend produce duplicates, and what identifier would you use on Linux journald events?

After the reconnection the agent resent its disk buffer and part of it again, because it had not received the acknowledgement for the first resend: at-least-once delivery. For journald, the __CURSOR field uniquely identifies an entry; failing that, a hash of host, timestamp and message.

2. Change the DNS resolver's retention to 365 days. What happens to the total?

Its cold days go from 150 to 335: 25.9 GB/day × 185 extra days × 0.004 ≈ 19 USD more per month. Cheap, because DNS logs are small per event and cold storage is cheap, which is why long DNS retention is usually worth it.

3. Name two signals that an attacker is tampering with logging on a Windows server.

Event 1102 (Security log cleared) or 104 (another event log, such as System, cleared; it is written to the System log); the logging agent's service stopping (7036/7040 service events, or the agent's heartbeat missing); event 4719 (audit policy changed); a sudden volume drop while the host's EDR telemetry continues.

Test yourself

What delivery behaviour do buffering agents usually give after a network outage?

  1. At-most-once: events are lost
  2. At-least-once: some events may arrive twice
  3. Exactly-once, always
  4. Events arrive in reverse order only

In the program, how many real failed logons were there, and how many did the raw stream show?

  1. 4 and 7
  2. 7 and 4
  3. 5 and 5
  4. 3 and 9

Why should detections use event time with a look-back rather than only the last minutes of arrivals?

  1. Event time is shorter
  2. Buffered events can arrive late and would be missed or counted in the wrong window
  3. Arrival time is not stored
  4. It is faster

Which syslog transport is appropriate for security logs?

  1. UDP 514
  2. TCP with TLS (RFC 5425, port 6514)
  3. Email
  4. FTP