Skip to content

Bound the volume of collected logs - #138

Merged
tricknotes merged 3 commits into
mainfrom
bound-log-volume
Nov 23, 2026
Merged

tricknotes merged 3 commits into
mainfrom
bound-log-volume

Conversation

@tricknotes

Copy link
Copy Markdown
Owner

Summary

The log collector copied every line of every container and of the per-app access log, with a limit per line (16 KiB) but none on the total. An unauthenticated client sending requests with large headers to any app hostname, or a noisy container, could fill the data disk, which stops SQLite, every app's database and deploys.

Three layers:

  • Small access log entries. Request and response headers and the TLS details are not logged; User-Agent and Location are kept as short fields, and everything a client chooses is cut to a fixed length. An entry is 400–500 bytes for an ordinary request and about 2.5 KiB at most (measured against a real Caddy). Cookies and credentials are no longer in the stored logs.
  • A limit per service and day. [logs] daily_limit_mb (default 100). When a day's file reaches it, one marker line is written and further lines of that service are dropped until the day changes. koroku's own log reports how many lines were dropped, without their content.
  • A last resort on disk usage. While the data disk is at or above the deploy limit plus 5 points (90% by default), no lines are written; writing resumes when usage falls.

The minimum Caddy version goes from 2.7 to 2.8 (log_append). deploy/provision.sh, OPERATIONS and ARCHITECTURE say so. A host on Caddy 2.7 must upgrade Caddy before koroku.

Idle detection reads the new location field; for a protected app, a line that is not JSON no longer counts as a visit.

Test plan

  • go vet ./..., go vet -tags integration ./..., go test ./...
  • internal/logs/limit_test.go: the limit, the marker, the dropped count, resuming the next day and below the disk threshold, archive offsets after drops, restarts
  • Integration against a real Caddy 2.11.9: TestAccessLogThroughCaddy (no header values in the entries, entry size, idle detection reads them)
  • caddy validate of the generated configuration with Caddy 2.8.4
  • The whole integration suite on the combined stack
  • A real host with a disk that is actually full (the disk layer is covered by unit tests with a fake probe)

🤖 Generated with Claude Code

tricknotes and others added 3 commits November 24, 2026 03:43
Every request to an app hostname is logged, including the 503 of a stopped
app and the gate's 302 of a protected one, so anyone can make Caddy write
access log entries. With the request and response headers in them, one
request could add about 20 KB (what Caddy accepts as request line and
headers), and koroku's collector copied every entry into the data
directory. The headers also put cookies and credentials into the stored
logs and the archive.

The generated logger configuration now uses Caddy's filter encoder around
the JSON one: request>headers, request>tls and resp_headers are deleted,
and the values a client chooses (method, host, URI) are cut to a fixed
number of bytes, ending at the first byte that JSON would escape. The
filter encoder cannot keep only some headers, so the User-Agent and the
Location of the response are added as fields of their own by a log_append
handler in a first, non-terminal route for the app hostnames, and cut the
same way. An entry is now 400 to 500 bytes for an ordinary request and
about 2.5 KB at most, measured against Caddy 2.11.9 in the new integration
test.

The idle tracker read resp_headers.Location to tell the gate's redirect
from an app's own; it reads the location field instead. An entry can no
longer be cut by the collector's 16 KiB line limit, so an entry that is not
valid JSON is not something Caddy wrote for a request that passed the
gate: it does not keep a protected app awake any more. Which status codes
count is unchanged.

log_append exists since Caddy 2.8 (2.7.6 rejects the whole configuration
with "unknown module"), so the provisioning script requires 2.8.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
The collector copied every line it received into the data directory:
a line was cut at 16 KiB, but nothing bounded the number of lines. A noisy
container, or requests sent in bulk to an app hostname (the access log
records them whoever sends them), could fill the disk all apps share, which
stops SQLite, the apps' databases and deployments.

A day file of a service (container output and _access alike) now stops at
[logs] daily_limit_mb, 100 MiB by default. The line that would exceed it
and everything after it for that service and day are dropped. One marker
entry, written by the collector with the time of the first dropped line,
stands in their place, so the live view, the search and the archive all
show the gap. koroku's own log says when dropping starts, how many lines
it was so far every ten minutes, and the total once the service is written
again or its collection ends; it never shows line content.

The state survives a restart without a new file: a day whose last entry is
the marker of the current limit stays closed. The marker names the limit,
so raising the setting reopens the day. The bytes of a compressed day count
when lines arrive late for it.

Nothing changes for the archive (it follows the bytes of the day files) or
for the duplicate detection after a restart (it counts what the files
hold: a dropped line that Docker delivers again is dropped again). The
idle tracker still hears of every access log entry, kept or not.

The default leaves a host with 20 day files that all fill up every day at
about 5 GB (2 GB for the current day, the 14 compressed days at a tenth),
and one runaway service at 240 MiB. The setting is capped at 2048 MiB,
which also keeps a day below the 4 GiB where the size in a gzip trailer
wraps.

The prepare-app requirements and the deploy-status skill mention the limit
and the marker; the plugin version goes to 0.25.2. USAGE also describes
the access log entries.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
The daily limit bounds what the logs can add, but not what the disk holds
already: images, volumes or a raised limit can still bring it close to
full, and the log collector would then use up what is left, which SQLite
and the apps' databases need.

While the usage of the data disk is at or above a threshold, the collector
now drops every line instead of writing it, and writes again once the usage
is below. It behaves like the daily limit: one marker entry where the
dropping starts (again after each resumption, and at the start of a new
day file), a count in koroku's own log, and the idle tracker still hears
of every access log entry. A day that reached its daily limit stays closed
and gets no disk marker, so its own marker remains the last entry.

The usage comes from the probe that already rejects deployments
(system.Prober.DiskUsage). It is read at most every ten seconds, not per
line, and a probe that fails does not stop the logs.

The threshold is not a setting of its own: it is the deploy limit plus five
points (90% by default, at most 100%). Deployments, the largest consumers,
are refused first, while the logs that explain a filling disk are kept a
little longer; stopping at 90% of a 40 GB disk leaves 4 GB for the
databases.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
Base automatically changed from gate-path-normalization to main November 23, 2026 19:23
@tricknotes
tricknotes merged commit 53a5375 into main Nov 23, 2026
5 checks passed
@tricknotes
tricknotes deleted the bound-log-volume branch November 23, 2026 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant