Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 0 additions & 86 deletions .github/workflows/fuzz.yml

This file was deleted.

2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
- **Strings from tenants and the network are cleaned.** Container names and images, a tenant's interface names, LLDP and NIC strings, the ASN feed's network owner, netns names and congestion names are cut to 256 bytes (16 for interface and congestion names) at a UTF-8 boundary. Invalid UTF-8 and control characters (C0, DEL, C1) become U+FFFD. Each is cleaned once, where it enters, not per row.
- **Per-namespace caps.** `-maxDumpBytes` (default 256 MiB) and `-maxRecordsPerNetns` (default 262144) bound one namespace's dump per poll: packets past the byte cap are drained undecoded, and records past the record cap are dropped before decode. `-maxNetns` (default 4096) bounds the namespaces tracked. At the cap, tracked namespaces keep their slots, and new ones wait for a freed slot, first come, first served. Alert on `xtcp_netns_dropped_total`. Drops are counted in `xtcp_dump_dropped_total{reason}` and `xtcp_netns_dropped_total`, with one log line per truncated dump or short reconcile. `0` turns a cap off; the matching env vars are `MAX_DUMP_BYTES`, `MAX_RECORDS_PER_NETNS` and `MAX_NETNS`. The caps are startup-only: `ConfigService.Set` keeps the running values. No healthy host should reach the defaults; a host that does now loses that namespace's excess rows, where it used to collect them all ([polling and batching](docs/polling-and-batching.md#per-namespace-caps)).
- **Socket-count gate, reconcile limits, per-owner quota.** Before each poll xtcp2 reads each namespace's sockstat (an fd opened in the namespace; `pread`, or io_uring batches with `-ioUring`) and, when the total is over `-maxRecordsPerPoll` (default 1,048,576), degrades only the namespaces over their fair share: first TIME_WAIT/SYN_RECV are not asked for, then one of K port shards is dumped per poll. `-maxNetnsPerOwner` (default 64) caps namespaces tracked per owner (the container runtime's cgroup), `-maxNetnsAddsPerReconcile` (256) the adds per reconcile, and `-reconcileTimeout` (1s) the namespace scan; a timed-out scan deletes nothing. New metrics `xtcp_poll_sockets`, `xtcp_poll_degraded_total{level}` and `xtcp_reconcile_incomplete_total{reason}`; `xtcp_netns_dropped_total` gains `reason`. `0` turns each off; all are startup-only. Each tracked namespace now holds four fds (was two: sockstat and `ip_local_port_range` are new), and xtcp2 warns at startup when `RLIMIT_NOFILE` can't cover them ([polling and batching](docs/polling-and-batching.md#socket-count-gate), [network namespaces](docs/network-namespaces.md#configuration)). The analysis behind an upstream all-namespace dump is in [docs/kernel](docs/kernel/inet-diag-all-netns.md).
- **Fuzzing in CI.** `fuzz-all` (dev shell) finds every Go fuzz target with `go test -list` and fuzzes each in turn: 10 s per target on each PR, 2 min nightly (`.github/workflows/fuzz.yml`), with crashers uploaded as an artifact. Two new fuzzers cover tenant-reachable paths: `FuzzDockerProjection` (a Docker inspect body to a container's name and image) and `FuzzRowFromProto` (an S3 envelope through Parquet and back). `FuzzClean` now also checks idempotence and the fast path. The first run found `/ip/vrf/show/NAME` returning 500 for a name that is no VRF; it is now a 404. Docker container list and inspect bodies are now streamed, keeping only the fields used: memory stays bounded however large a container's labels are, a container whose entry passes 4 MiB is skipped and logged (never the whole list), each request has a 10 s timeout, and an oversized `/events` line no longer stalls container-metadata refresh. Limits: [Docker API limits](docs/design-metadata-enrichment.md#docker-api-limits).
- **Fuzzing every target.** `fuzz-all` (dev shell, `nix run .#fuzz-all`) finds every Go fuzz target with `go test -list` and fuzzes each in turn; `checks.test-fuzz-all` runs it sandboxed at 10 s per target, so `nix flake check` fuzzes again whenever the source changes. Two new fuzzers cover tenant-reachable paths: `FuzzDockerProjection` (a Docker inspect body to a container's name and image) and `FuzzRowFromProto` (an S3 envelope through Parquet and back). `FuzzClean` now also checks idempotence and the fast path. The first run found `/ip/vrf/show/NAME` returning 500 for a name that is no VRF; it is now a 404. Docker container list and inspect bodies are now streamed, keeping only the fields used: memory stays bounded however large a container's labels are, a container whose entry passes 4 MiB is skipped and logged (never the whole list), each request has a 10 s timeout, and an oversized `/events` line no longer stalls container-metadata refresh. Limits: [Docker API limits](docs/design-metadata-enrichment.md#docker-api-limits).
- **Vulnerability check.** `checks.govulncheck` runs govulncheck against a pinned snapshot of the Go vulnerability database, with no tags and with every flavor tag, and fails on a reachable finding not in its accepted list. One is accepted: GO-2026-6859 in `net/http`, fixed in go1.27.4, until the toolchain moves. `nix run .#govulncheck-fresh` checks against the live database and runs `go mod verify`; `nix build .#sbom-<binary>` writes a CycloneDX SBOM for any binary package.

## 0.2.1 (2026-11)
Expand Down
2 changes: 1 addition & 1 deletion docs/security-hardening/focused-implementation-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ Non-blocking shortfalls found while implementing F1; none blocks R1.
### FP-7 — fuzzers (D4)

- [x] `FuzzDockerProjection` (`pkg/dockermeta`), `FuzzStrPolicy`, `FuzzRowFromProto`; corpora seeded from F0.5. *Done as:* `FuzzDockerProjection` drives a raw inspect body through `json.Unmarshal` and the new pure `project` (split out of `(*Index).inspect`); a projected name and image are always valid UTF-8, ≤ 256 bytes and control-free. `FuzzRowFromProto` (`dest_s3parquet`) takes arbitrary envelope bytes through the worker's row path (unmarshal, `rowFromProto`, event date, Parquet write) and reads the object back: every decoded row must round-trip unchanged. `FuzzStrPolicy` is `FuzzClean`, which now also checks idempotence and the fast path. Each fuzzer shares a table with a unit test (`TestDockerProjectionJSON` 12 rows, `TestRowFromProtoRoundTrip` 12, `TestCleanProperties` 7, plus `TestProject` 9), so every seed has a description and an expected result. F0.5 isn't captured yet, so the seeds are the fixtures and the real netlink dump; the F0.5 rows are a TODO below. Pinned on the way: invalid UTF-8 in a proto3 string fails the unmarshal, so the worker drops the whole envelope (the sources clean strings first, so it can't come from them).
- [x] CI runs every fuzzer (existing netlink ones included) for a fixed time budget per PR and longer nightly. *Done as:* `nix/scripts/fuzz-all.bash` (`fuzz-all` in the dev shell) finds every target with `go test -list` under the flavor tags (50 today), fails below `FUZZ_MIN_TARGETS`, runs them all even after a failure, and lists the crasher files. `.github/workflows/fuzz.yml`: `fuzz-pr` at 10 s per target, `fuzz-nightly` daily at 2 min (and `workflow_dispatch`); crashers and logs uploaded on failure. Not a nix check: a cached derivation would never fuzz again. `-fuzzminimizetime` is 5 s: with Go's 60 s default, `FuzzRowFromProto` spent a 10 s budget minimizing (0 execs/s after the first 3 s). First full run (50 targets at 10 s, loaded host): 588 s, one crasher in the existing `FuzzIPHandler`: `/i/v/s/0` (vrf show for a name that is no VRF) returned 500; `goip.ErrVrfInvalid` now maps to 404, the input is committed as a seed and a `TestFuzzIPHandlerRows` row.
- [x] CI runs every fuzzer (existing netlink ones included) for a fixed time budget per PR and longer nightly. *Done as:* `nix/scripts/fuzz-all.bash` (`fuzz-all` in the dev shell) finds every target with `go test -list` under the flavor tags (50 today), fails below `FUZZ_MIN_TARGETS`, runs them all even after a failure, and lists the crasher files. Run through nix, not GitHub Actions (`nix/fuzz-all.nix`): `checks.test-fuzz-all` at 10 s per target in the sandbox, re-run by `nix flake check` whenever the source changes, and `nix run .#fuzz-all` with a longer `FUZZTIME` for campaigns. (A `.github/workflows/fuzz.yml` briefly did this and was removed.) `-fuzzminimizetime` is 5 s: with Go's 60 s default, `FuzzRowFromProto` spent a 10 s budget minimizing (0 execs/s after the first 3 s). First full run (50 targets at 10 s, loaded host): 588 s, one crasher in the existing `FuzzIPHandler`: `/i/v/s/0` (vrf show for a name that is no VRF) returned 500; `goip.ErrVrfInvalid` now maps to 404, the input is committed as a seed and a `TestFuzzIPHandlerRows` row.

### Phase F2 TODOs

Expand Down
6 changes: 4 additions & 2 deletions nix/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,13 @@ Use the full path: `nix build path:.#checks.x86_64-linux.NAME -L`.

## Fuzzing

`fuzz-all` (in the dev shell; source `nix/scripts/fuzz-all.bash`) finds every `Fuzz*` target with `go test -list` and fuzzes each in turn, so a new fuzzer needs no list entry. It runs every target even after a failure, then names the failures and the crasher files Go wrote under `<pkg>/testdata/fuzz/<Target>/`.
`fuzz-all` (in the dev shell and as `nix run .#fuzz-all`; source `nix/scripts/fuzz-all.bash`, wired in `nix/fuzz-all.nix`) finds every `Fuzz*` target with `go test -list` and fuzzes each in turn, so a new fuzzer needs no list entry. It runs every target even after a failure, then names the failures and the crasher files Go wrote under `<pkg>/testdata/fuzz/<Target>/`.

```bash
nix develop -c fuzz-all # every target, 10 s each
FUZZ_FILTER=dockermeta FUZZTIME=5m nix develop -c fuzz-all # one package, longer
FUZZTIME=2m nix run .#fuzz-all # long run, from the checkout root
nix build .#checks.x86_64-linux.test-fuzz-all -L # sandboxed, 10 s each
```

| Variable | Default | Meaning |
Expand All @@ -241,7 +243,7 @@ FUZZ_FILTER=dockermeta FUZZTIME=5m nix develop -c fuzz-all # one package, longe
| `FUZZ_MIN_TARGETS` | `50` | Fail if discovery finds fewer, so a broken discovery can't pass |
| `FUZZ_LOG_DIR` | a temporary directory | One log per target |

CI (`.github/workflows/fuzz.yml`) runs it on every PR to main at 10 s per target (`fuzz-pr`), and daily at 2 min per target (`fuzz-nightly`, also `workflow_dispatch` with a chosen budget). It is not a nix check, because a cached derivation would never fuzz again. A failed run uploads the crashers and logs as an artifact. Fix the bug, then commit the crasher file and add the input as a row of the fuzzer's table, which its unit test and seed corpus share.
`checks.test-fuzz-all` runs it in the sandbox at 10 s per target (about 10-16 min), so `nix flake check` fuzzes every target again whenever the source changes; its logs are kept in `result/logs/`. Being a cached derivation, it does not fuzz again for unchanged source: use the app with a longer `FUZZTIME` for a campaign. Crashers from the app land in the checkout; from the check, in the failing log. Fix the bug, then commit the crasher file and add the input as a row of the fuzzer's table, which its unit test and seed corpus share.

`test-linkmonitor-fuzz` still fuzzes its own 10 targets for 30 s each under `nix build`.

Expand Down
17 changes: 17 additions & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,13 @@ let
# Dev shell
devshell = import ./devshell.nix { inherit pkgs; };

# Every Go fuzz target: the `fuzz-all` app for long runs from a checkout,
# and a short sandboxed check (nix/fuzz-all.nix).
fuzzAll = import ./fuzz-all.nix {
inherit pkgs;
inherit (goSource) vendoredSource;
};

# Proto plumbing
protos = import ./protos { inherit pkgs src; };

Expand Down Expand Up @@ -1234,6 +1241,10 @@ in
# case, so per-package would be duplicate work.
test-go-race = tests.go-race;

# Every Fuzz* target, 10 s each in the sandbox (about 10-16 min). Runs
# again whenever the source changes; `nix run .#fuzz-all` for longer.
test-fuzz-all = fuzzAll.check;

# The ASN bootstrap wiring (one-prefix fixture) and the real checked-in
# snapshot, loaded and looked up, and found byte-identical in the image
# the fleet runs. A refresh by update-ipmeta-bootstrap-lock that drops a
Expand All @@ -1260,6 +1271,12 @@ in
};

apps = {
# Fuzz every Fuzz* target from the current checkout, so crashers land in
# its testdata/fuzz/. FUZZTIME, FUZZ_FILTER etc.: nix/scripts/fuzz-all.bash.
fuzz-all = {
type = "app";
program = "${fuzzAll.script}/bin/fuzz-all";
};
test-tcp-controller-vm = {
type = "app";
program = "${vmTests.tcp-controller}/bin/test-tcp-controller-vm";
Expand Down
20 changes: 7 additions & 13 deletions nix/devshell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,9 @@ let
# The five golangci-lint tiers, shared verbatim with nix/default.nix's
# `packages` so the shell and the flake cannot drift.
lintTiers = import ./lint-tiers.nix { inherit pkgs; };
# Every Go fuzz target, found by `go test -list` (FP-7). The script stays a
# plain file so CI and contributors run the same thing; the shebang is
# dropped because writeShellApplication adds its own.
fuzzAll = pkgs.writeShellApplication {
name = "fuzz-all";
runtimeInputs = [
pkgs.coreutils
pkgs.findutils
pkgs.gawk
];
text = pkgs.lib.removePrefix "#!/usr/bin/env bash\n" (builtins.readFile ./scripts/fuzz-all.bash);
};
# Every Go fuzz target, found by `go test -list` (FP-7). Shared with
# `nix run .#fuzz-all` and checks.test-fuzz-all (nix/fuzz-all.nix).
fuzzAll = (import ./fuzz-all.nix { inherit pkgs; }).script;

# Shell-entry banner. A writeShellApplication rather than a shellHook
# function so its (admittedly trivial) bash is shellcheck'd like everything
Expand Down Expand Up @@ -113,7 +104,10 @@ let
Fuzzing:
fuzz-all Fuzz every Fuzz* target in turn
(FUZZTIME=10s per target; set
FUZZ_FILTER=<regex> to pick some)
FUZZ_FILTER=<regex> to pick some;
also nix run .#fuzz-all)
nix build .#checks.x86_64-linux.test-fuzz-all
The same, sandboxed, 10 s each

Nix:
nix flake check Tier 0+1 lint + all custom audits
Expand Down
65 changes: 65 additions & 0 deletions nix/fuzz-all.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# nix/fuzz-all.nix
#
# Every Go fuzz target, found by `go test -list` (FP-7), in two forms:
#
# script `fuzz-all` on PATH: the dev shell and `nix run .#fuzz-all` both run
# it from a checkout, with FUZZTIME etc. set by the caller. Crashers
# land in the checkout's testdata/fuzz/, ready to commit.
# check the same script in the sandbox at a short budget per target, so
# `nix flake check` fuzzes again whenever the source changes. A
# cached derivation does not fuzz again for unchanged source; use
# the app for long runs.
#
# Source: nix/scripts/fuzz-all.bash (the shebang is dropped because
# writeShellApplication adds its own).
{
pkgs,
vendoredSource ? null,
# Per-target budget for the check. 10 s over about 50 targets is 10-16 min,
# most of it the instrumented build of each package.
checkFuzztime ? "10s",
}:

let
versions = import ./versions.nix { inherit pkgs; };
script = pkgs.writeShellApplication {
name = "fuzz-all";
runtimeInputs = [
versions.go
pkgs.coreutils
pkgs.findutils
pkgs.gawk
];
text = pkgs.lib.removePrefix "#!/usr/bin/env bash\n" (builtins.readFile ./scripts/fuzz-all.bash);
};
in
{
inherit script;
check =
pkgs.runCommand "xtcp2-test-fuzz-all"
{
# go too: the builder runs `go version` itself, and only the script's
# own wrapper puts its runtimeInputs on PATH.
nativeBuildInputs = [
script
versions.go
];
inherit vendoredSource;
}
''
set -euo pipefail
cp -r "$vendoredSource" ./xtcp2
chmod -R u+w ./xtcp2
cd ./xtcp2
export HOME="$TMPDIR/home" GOTOOLCHAIN=local GOFLAGS=-mod=vendor CGO_ENABLED=0
export GOCACHE="$TMPDIR/go-cache" GOMODCACHE="$TMPDIR/go-modcache"
mkdir -p "$HOME" "$out/logs"
go version > "$out/go-version.txt"
FUZZTIME=${checkFuzztime} FUZZ_LOG_DIR="$out/logs" fuzz-all > "$out/fuzz-all.log" 2>&1 || {
rc=$?
cat "$out/fuzz-all.log" >&2
exit "$rc"
}
tail -n 1 "$out/fuzz-all.log"
'';
}
3 changes: 2 additions & 1 deletion nix/scripts/fuzz-all.bash
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
# FUZZ_MIN_TARGETS fail if discovery finds fewer (default 50)
# FUZZ_LOG_DIR per-target logs (default: a new temporary directory)
#
# Run from the repository root: nix develop -c fuzz-all
# Run from the repository root: nix develop -c fuzz-all, or nix run .#fuzz-all.
# checks.test-fuzz-all runs it in the sandbox (nix/fuzz-all.nix).
set -euo pipefail

fuzztime=${FUZZTIME:-10s}
Expand Down