Skip to content

FP-6: bounded S3 queue, disk spill, string policy - #308

Merged
randomizedcoder merged 9 commits into
mainfrom
sec/fp6-s3-queue-strpolicy
Nov 23, 2026
Merged

randomizedcoder merged 9 commits into
mainfrom
sec/fp6-s3-queue-strpolicy

Conversation

@randomizedcoder

@randomizedcoder randomizedcoder commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

FP-6 of the security-hardening plan (C3, C4): a tenant or an S3 outage can cost data, not the collector.

S3 queue

  • Send never blocks: it used to stall the poller mid-poll once 16 envelopes waited on S3.
  • envelopeQueue (pkg/xtcp/s3queue.go) drops the oldest past -s3QueueDepth (default 16, max 4096) or -s3MaxBufferedBytes (default 64 MiB, 0 = no byte bound), always keeping the newest.
  • New metrics xtcp_s3_dropped_total{reason}, xtcp_s3_dropped_bytes_total{reason}, xtcp_s3_buffered_bytes{stage}; queueFull now counts drops.
  • XtcpConfig fields 116/117, env S3_QUEUE_DEPTH / S3_MAX_BUFFERED_BYTES; startup-only (preserveCaps keeps them across Set).
  • Memory budget documented next to the GOMEMLIMIT guidance (≈ 190 MiB with defaults).

String policy

  • New pkg/strpolicy.Clean: cut at a UTF-8 boundary (256 bytes, 16 for ifnames and congestion names), invalid UTF-8 and C0/DEL/C1 become U+FFFD; printable ASCII returns without allocating.
  • Applied once where each value enters: docker name/image, NIC and LLDP strings, tenant ifnames (localnet), ASN network owner, netns names, congestion name.

Tests / evidence

  • Table-driven TestClean, FuzzClean, TestEnvelopeQueue (+ concurrent, -race), TestS3ParquetDest_queueBounds, reworked corner_queueFull, one test per call site, flag/env/validation/preserveCaps rows.
  • BenchmarkDeserializeCongInfoXTCP vs main (10 interleaved): 21.0 → 23.3 ns, allocs unchanged; BenchmarkS3Send 52 ns vs 118 ns for the old channel send.
  • New microVM Check 14c (S3PARQUET_OUTAGE): Garage stopped mid-run → polls continue, 22 drops, RSS +5 MB, upload resumes after restart. microvm-x86_64-lifecycle-s3parquet: all checks pass.
  • Fixes TestS3ParquetDest_timeFlush, which failed under -race on main (fixed 30 ms sleep).
  • nix checks green: lint-baseline, nix-fmt, gofmt, go-vet, golangci (3 tiers), no-write-encoders, flavor-tags, tcp-controller-unit.

Spill directory (follow-up)

  • -s3SpillDir / S3_SPILL_DIR (field 118, off by default): objects that fail to upload go to disk and are re-uploaded oldest first under their original keys, including after a restart.
  • With a spill dir the worker tries each upload once and spills, so it keeps draining the queue during an outage instead of waiting in retries.
  • -s3SpillMaxBytes / S3_SPILL_MAX_BYTES (field 119, default 1 GiB) bounds it; oldest deleted past it.
  • Files 0600 in a 0700 dir via os.Root, .tmp → sync → rename; bad headers deleted; dir and bound kept across Set.
  • Metrics xtcp_s3_spill_total{result}, xtcp_s3_spill_objects, xtcp_s3_spill_bytes.
  • Tests: TestS3Spill (12 rows), TestS3Spill_contentAndModes, TestS3ParquetDest_spill, TestS3ParquetDest_spillKeptOnClose, flag/env/validation/preserveCaps rows.
  • New VM Check 14d (S3PARQUET_SPILL): Garage stopped 160 s → 12 objects spilled, all 12 uploaded after restart, 0 left; Check 14c still passes (336 polls, 4 drops).

Operator strings (follow-up)

  • hostname, location, label, tag already had max_len (253/253/40/40); now a pattern also rejects C0/DEL/C1 controls (exit 64 / Set refused).

Also

  • Fixes the goip and gordma import-closure tests, which failed with FP-6's xtcpnl → strpolicy import.

🤖 Generated with Claude Code

randomizedcoder and others added 9 commits November 14, 2026 07:33
pkg/strpolicy.Clean cuts a string at a UTF-8 boundary (256 bytes, 16 for
interface and congestion names) and replaces invalid UTF-8, C0, DEL and
C1 with U+FFFD; printable ASCII that fits returns without allocating.

Applied once per entity: dockermeta inspect (name, image), the uplink
stamp (NIC strings, LLDP fields), localnet ifnames, the ipasn owner,
netns names, and the congestion decode, which folds the check into its
NUL scan (+3 ns per socket, allocs unchanged).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Send used to block the poller once 16 envelopes waited on a slow or
unreachable S3. envelopeQueue drops the oldest past -s3QueueDepth
(default 16, max 4096) or -s3MaxBufferedBytes (default 64 MiB, 0 = no
byte bound), always keeping the newest. New xtcp_s3_dropped_total,
xtcp_s3_dropped_bytes_total and xtcp_s3_buffered_bytes{stage};
queueFull now counts drops. XtcpConfig fields 116/117, env
S3_QUEUE_DEPTH / S3_MAX_BUFFERED_BYTES, kept across Set by preserveCaps.

Docs: metrics, memory budget, plan FP-6 done-as, CHANGELOG. Also polls
in TestS3ParquetDest_timeFlush, which failed under -race on a fixed
30 ms sleep.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Check 14c: with -s3QueueDepth 2, a Garage outage must keep polls at
cadence, raise xtcp_s3_dropped_total, keep RSS growth under 128 MiB,
and land a new object after Garage restarts (S3PARQUET_OUTAGE).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…3 queue env/print in helpers (funlen)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
xtcpnl's congestion-name decoder imports it since FP-6; stdlib only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t control characters

- -s3SpillDir / S3_SPILL_DIR (field 118) and -s3SpillMaxBytes /
  S3_SPILL_MAX_BYTES (field 119, default 1 GiB): Parquet objects that
  fail to upload are kept on disk and re-uploaded oldest first under
  their original keys, including after a restart. With a spill dir the
  worker tries each upload once, so it keeps draining the queue during
  an outage. Oldest deleted past the bound; 0600 files in a 0700 dir via
  os.Root, .tmp -> sync -> rename. Kept across ConfigService.Set.
- Metrics xtcp_s3_spill_total{result}, xtcp_s3_spill_objects,
  xtcp_s3_spill_bytes.
- hostname, location, label, tag: their max_len was already set; add a
  pattern rejecting C0, DEL and C1 controls.
- VM: the s3parquet flavor spills (-s3FlushInterval 10s); Check 14d
  S3PARQUET_SPILL. Docs, CHANGELOG, plan follow-ups.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@randomizedcoder randomizedcoder changed the title FP-6: bounded S3 queue that never blocks polling; string policy for tenant/network strings FP-6: bounded S3 queue, disk spill, string policy Nov 23, 2026
@randomizedcoder
randomizedcoder merged commit 74ec22b into main Nov 23, 2026
1 check passed
@randomizedcoder
randomizedcoder deleted the sec/fp6-s3-queue-strpolicy branch November 23, 2026 04:49
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