tuxvador@blog:~/blog/tamper-evident-logs-hash-chain$

~/blog/tamper-evident-logs-hash-chain

Tamper-Evident Logs With a Daily Hash in My Inbox

4 min readLire en français →

#security#logging#monitoring#homelab#linux

Every machine in my lab sends its syslog to one container. It writes them to /var/log/remote/<host>/<program>.log, ships them to Loki, and an hourly job copies them to a USB disk. That’s two copies, which sounds safe.

Both copies are writable by root on that one container. An intruder with root there can delete their SSH session from the live file and from the backup, and the two will still agree with each other. Neither copy can vouch for the other.

What was missing is a record outside that machine, which it can write once and can’t rewrite later. The cheapest such place I have is a mailbox.

The idea: seal what was added

Once a day at 23:55, log-seal does three things.

1. Seal. For every log file, it hashes the bytes the file gained since the previous seal, not the whole file. Each range is recorded by inode, start offset, end offset, SHA-256 and line count. Tracking by inode means a rotated file is followed under its new name. The manifest also records prev, the SHA-256 of the previous manifest, so the seals form a chain:

{
  "version": 1, "host": "mon-srv",
  "created": "2026-12-01T23:55:02+01:00",
  "from": "2026-11-30T23:55:01+01:00",
  "prev": "9f2c4e...",
  "segments": [
    { "path": "web-proxy/nginx.log", "inode": 2884911,
      "start": 104857600, "end": 112640331,
      "sha256": "51ab07...", "lines": 41022 }
  ],
  "anomalies": [],
  "files": { "web-proxy/nginx.log": { "inode": 2884911, "size": 112640331 } }
}

2. Verify. It walks the chain (each prev must match the manifest before it), compares each manifest with its copy on the USB disk, and re-hashes every range sealed in the last 14 days, both on the server and in the backup copy. A sealed file that shrank, changed or disappeared without rotating is a problem.

3. Mail. It sends one email to an outside mailbox: the subject says OK or ⚠ N problem(s), and the body holds the new manifest’s hash, the previous one and the counts. Only a problem also sends a push notification.

Why byte ranges and not timestamps

Syslog lines don’t arrive in timestamp order. A host that was offline for an hour sends an hour of old lines when it reconnects. Sealing “everything timestamped before midnight” would then either miss those lines or flag them as tampering.

Sealing byte ranges sidesteps that: whatever the file contained at 23:55 is sealed, whatever arrives later belongs to the next seal. It also needs no log parsing at all. It reads bytes and hashes them, so it works the same for nginx, sshd or a program I haven’t heard of.

It depends on one property: a file only grows until it rotates. Here logrotate rotates the remote logs at 200 MB, and the seal also covers the uncompressed .log.1, so a range stays readable, and therefore verifiable, for the whole 14 days.

What the mail is for

If an intruder edits a log after it was sealed, the next run reports it: the range’s hash no longer matches. A capable intruder would notice that and rewrite the manifests too, recomputing every hash and every prev link so the chain is consistent again. Everything on the server can be made consistent.

The mailed hashes can’t. They are in a mailbox the log server can only send to. To check the server’s chain against them:

log-seal check 9f2c4e...     # a hash from a past email

It must name a manifest that still exists, and the chain from that manifest to today must verify. A rewritten history fails at the first manifest whose hash was mailed before the rewrite.

What it doesn’t do

I’d rather say this plainly than oversell it:

  • It only protects what was already sealed. A line deleted between when it was written and 23:55 is sealed as already missing. Real-time detection is Wazuh’s job, and this is the after-the-fact check.
  • The first seal only marks where each file ended. Anything written before the install isn’t sealed.
  • The mail is the trust anchor. If the mails are lost, the chain proves only that it agrees with itself. They have to be kept, even if nobody reads them every day.

Cost

One Python script, one timer, one service. A run hashes one day of new log data, then re-hashes 14 days of ranges on two disks. That’s mostly sequential reads.

Pitfalls

  • A backup on the same root isn’t evidence. It helps you recover, but it can’t prove the logs weren’t changed.
  • Seal bytes, not timestamps. Late syslog lines make time-based sealing either leaky or noisy.
  • Track files by inode. Rotation renames a file under you, and a path-based seal reports every rotation as tampering.
  • Your backup tool may not follow rotation either. My hourly rsync --append silently skipped any file whose copy was already as big as the live one. After every rotation, the fresh log wasn’t backed up at all. One file’s backup was 1.8 GB of the old log while the live 246 MB went uncopied. I found it while writing the verifier and rewrote the backup to detect rotation.
  • Put the anchor somewhere the server can only append to. A mailbox works. So would a write-only bucket or a printout.

cd ~/blog