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
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,17 @@ clear_docker_volumes:
protos:
nix run .#regen-protos

# Red-team harness (vagrant/, docs/redteam-plan.md). VM scenarios run on the
# harness host (l): KVM + libvirtd + network. The lint is hermetic CI.
redteam-lint:
nix build .#checks.x86_64-linux.redteam-lint -L

redteam-smoke:
nix run .#redteam-rt-1-1

redteam-destroy:
nix run .#redteam-destroy

nuke_clickhouse:
rm -rf ./build/containers/clickhouse/db/*
docker volume rm xtcp_clickhouse_db
Expand Down
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ See **[CONTRIBUTING.md](../CONTRIBUTING.md)** for the development environment, t
- [Listener security hardening](design-listener-security-hardening.md) — historical design, including unimplemented proposals; use the [security guide](security.md) for current behavior and deployment recommendations.
- [Red-team plan](redteam-plan.md) — adversary simulation for xtcp2 in a container on Ubuntu 24.04: attack-surface inventory, scenario catalog (recon, auth, admin abuse, DoS, host/netlink assurance, UDS, artifacts, parsers), and the Vagrant/libvirt harness that runs the scenarios from this repo.
- [Red-team implementation](redteam-implementation.md) — execution companion to the red-team plan: harness architecture, per-phase tasks with definition of done, cross-cutting workstreams, effort estimates, risks, and the program-level exit criteria.
- [Red-team harness build plan](redteam-harness.md) — concrete Phase 0 wiring into flake.nix and nix/: what the existing infra already provides (verified), design decisions, the nix/redteam.nix and vagrant/ file specs, the rt-1-1 walkthrough, and the commit-by-commit build sequence.
- [Fleet jitter & upload backoff](design-jitter-and-backoff.md) — thundering-herd avoidance: poll jitter, jittered S3 flush (size + time), and jittered proportional upload retry, for fleet-scale (5–10k machine) deployments.
- [The link monitor in xtcp2](design-linkmonitor-in-xtcp2.md) — go-link-monitor's features inside xtcp2, on by default: the persisted expected up-link count in `/var/lib/xtcp2`, the detail paths on the Prometheus listener, the lifecycle under xtcp2's context, SIGUSR1/reload, and the degrade-not-exit failure mode; progress in its [status doc](status-linkmonitor-in-xtcp2.md).
- [Summary metrics](design-summary-metrics.md) — proposed 15-series `/metrics` (a self-computed `xtcp2_healthy` gauge plus throughput, delivery, error and resource counters, destination-generic) with full detail moved to `/metrics-all`, plus follow-ups found reviewing the fleet dashboard.
Expand Down
338 changes: 338 additions & 0 deletions docs/redteam-harness.md

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions docs/redteam-implementation.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ Flake side: `nix/redteam.nix` (imported from `nix/default.nix`) exposing:

- `apps.x86_64-linux.redteam-<scenario>` — wraps `scenarios/<script>` with the
dev-shell `vagrant` (added to `nix/packages.nix` devshell tool list; the
`vagrant-libvirt` plugin is vendored via the plugin gem set).
pinned nixpkgs `vagrant` bundles the `vagrant-libvirt` plugin on Linux —
its `withLibvirt` default — so no plugin wiring is needed).
- `apps.x86_64-linux.redteam-matrix` — sweeps one row group.
- `packages.x86_64-linux.redteam-oci` — the `oci-xtcp2` tarball materialized as
a file the Vagrantfile can share (Phase 0 proves the path:
Expand Down Expand Up @@ -121,22 +122,22 @@ ability to `nix build .#oci-xtcp2`.

| # | Task | Files |
|---|---|---|
| 0.1 | Pick and pin the box: `ubuntu/noble64` (libvirt provider) with fallback `generic/ubuntu2404`; record digest + why in `vagrant/README.md` | `vagrant/Vagrantfile`, `vagrant/README.md` |
| 0.1 | Pick and pin the box: `cloud-image/ubuntu-24.04` (the official Ubuntu cloud-image libvirt box — there is no `ubuntu/noble64`); record the pin log in `vagrant/README.md` | `vagrant/Vagrantfile`, `vagrant/README.md` |
| 0.2 | `provision/common.sh`: docker-ce from Docker's apt repo (Ubuntu 24.04), chrony; `provision/victim.sh`: `docker load` the shared tarball, `docker compose`-free run script honoring `lib/matrix.sh` | `vagrant/provision/*.sh` |
| 0.3 | `nix/redteam.nix`: OCI tarball package + per-scenario apps; add `vagrant` (+`vagrant-libvirt`) to the dev shell | `nix/redteam.nix`, `nix/packages.nix`/`devshell.nix`, `nix/default.nix` (import + merge apps), `flake.nix` if needed |
| 0.4 | `lib/`: assert.sh (ok/not-ok, wait_for, retry), matrix.sh (env → flags/mounts/caps), evidence.sh | `vagrant/lib/*.sh` |
| 0.5 | Victim deployment matrix rows: `host+off+priv` (prod shape) and `bridge+raw+min`; `/var/lib/xtcp2` bind; `/run/netns`+`/run/docker/netns` `ro,rslave`; read/admin token files 0400 | `vagrant/lib/matrix.sh` |
| 0.6 | Work population: 2 containers running `tcp_server`/`tcp_client` (from `binaries.xtcp2-all`); destination: `tcp:catcher:9999` sink that writes envelopes to disk | `vagrant/provision/victim.sh` |
| 0.7 | Scenario rt-1-1 (unauthenticated co-tenant scrape): EXPECT=CONFIRMED (documented default); asserts 200 + record-bearing metric labels from the co-tenant vantage | `vagrant/scenarios/rt-1-1-unauth-scrape.sh` |
| 0.7 | Scenario rt-1-1 (unauthenticated co-tenant scrape): EXPECT=BLOCKED — the listener-security-hardening program (PRs #291, #300) removed the unauthenticated-TCP default before the harness ran; the exposure is the credential-theft tier (`XTCP2_AUTH=raw XTCP2_ATTACKER=read-cred XTCP2_EXPECT=CONFIRMED`), verified 200 + xtcp_ series | `vagrant/scenarios/rt-1-1-unauth-scrape.sh` |
| 0.8 | `findings.md` seed + `checks.redteam-lint` + `make redteam-smoke`/`redteam-lint` targets | `vagrant/redteam/findings.md`, `Makefile`, `nix/redteam.nix` |
| 0.9 | Cross-link: plan doc, TODO-SOON §29 (shared box/provision base for the future `ubuntu-fleet/` suite) | `docs/redteam-plan.md`, `TODO-SOON.md` |

**Definition of done**

- [ ] `nix build .#redteam-oci` produces a loadable tarball; `docker load` in the victim VM succeeds.
- [ ] `nix run .#redteam-rt-1-1` on `l`: boots both VMs from cold, prints TAP + `RESULT rt-1-1 CONFIRMED ...`, exits 0.
- [x] `nix run .#redteam-rt-1-1` on `l`: boots the victim VM from cold, prints TAP + `RESULT rt-1-1 BLOCKED ...` (the amended default), exits 0.
- [ ] Re-running it (`vagrant provision`) is idempotent; `vagrant destroy` leaves no libvirt networks/volumes beyond the two defined.
- [ ] `XTCP2_MODE=bridge XTCP2_AUTH=raw nix run .#redteam-rt-1-1` flips the scenario to BLOCKED (401) — proving the matrix drives real behavior.
- [x] The matrix drives real behavior, verified end to end: `XTCP2_MODE=bridge XTCP2_AUTH=raw` → 401 (BLOCKED); `XTCP2_AUTH=raw XTCP2_ATTACKER=read-cred XTCP2_EXPECT=CONFIRMED` → 200 with xtcp_ series (the credential-theft exposure).
- [ ] `checks.x86_64-linux.redteam-lint` green; `nix flake check` still green.
- [ ] `vagrant/README.md` documents prerequisites, box pin, ~15 min cold-boot time, and teardown.
- [ ] `findings.md` has the rt-1-1 row with evidence path + linked issue ("default exposure documented; recommended loopback/UDS + auth").
Expand Down
7 changes: 5 additions & 2 deletions docs/redteam-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ https://github.com/randomizedcoder/xtcp2.

The execution companion — harness architecture, per-phase tasks, and
definition of done — is [redteam-implementation.md](redteam-implementation.md).
The concrete Phase 0 wiring into `flake.nix` and `nix/` — including what the
existing infrastructure already provides and the commit-by-commit build
sequence — is [redteam-harness.md](redteam-harness.md).

Related: [listener security guide](security.md), [hardening design](design-listener-security-hardening.md),
[integration testing](integration-testing.md), [TODO-SOON §29](../TODO-SOON.md)
Expand Down Expand Up @@ -133,7 +136,7 @@ Scenario IDs are stable (`rt-N-M`) and become script filenames in the harness.

| ID | Scenario | Steps | Expected today | Pass criteria | Severity if failed |
|---|---|---|---|---|---|
| rt-1-1 | Unauthenticated co-tenant scrape | from attacker container on the same bridge: `curl :9088/metrics` (default config) | 200 with full socket/link metrics: internal IPs, ports, RTTs, host topology | reveals the default exposure; with auth on, 401 | S2 (documented default; test proves it) |
| rt-1-1 | Unauthenticated co-tenant scrape | from attacker container on the same bridge: `curl :9088/metrics` | connection refused (the default refuses unauthenticated non-loopback TCP — see the premise note); with the §29 prod shape (auth on): 401 | **AMENDED at harness build (2026-11-14)**: the listener-security-hardening program (PRs #291, #300) landed after this plan was written, so the old default (auth off, TCP) no longer exists — the daemon exits 64 on it. The exposure is gated on credential theft: CONFIRMED with a stolen read token (verified: HTTP 200, full xtcp_ series). Default row EXPECT=BLOCKED, pinned by the harness | S2 (the credential-theft tier is the remaining exposure) |
| rt-1-2 | Unauthenticated record streaming | `xtcp2client`/grpcurl FlatRecords with no token | full `XtcpFlatRecord` stream incl. peer addresses, container IDs, uplink NIC/LLDP | with auth on: Unauthenticated; default: stream succeeds | S2 |
| rt-1-3 | gRPC reflection enumeration | grpcurl reflect/list, no creds | service list incl. admin methods when auth disabled | with auth on: refused | S3 |
| rt-1-4 | goip HTTP inspection recon | enable `-linkMonitorIPPaths`; `/ip/addr`, `/ip/route`, `/ip/link` | host routes/addresses disclosed to any read credential (or unauthenticated by default) | with auth on: read-classified; loopback listener: loopback peers only | S3 |
Expand Down Expand Up @@ -340,7 +343,7 @@ suites):
```text
vagrant/
README.md # how to run, prerequisites (libvirt, vagrant, nix build of the image)
base/ # Vagrantfile base: ubuntu/noble64 (24.04) + jammy (22.04) boxes, libvirt provider
base/ # Vagrantfile base: cloud-image/ubuntu-24.04 + jammy boxes, libvirt provider
provision/
victim.sh # docker-ce install, load oci-xtcp2 tarball, compose daemon (env matrix below)
attacker.sh # attack tools: slowhttptest, h2load, ghz, grpcurl(repo), socat, jq, tcpdump, strace
Expand Down
1 change: 1 addition & 0 deletions nix/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ The flake currently exports `x86_64-linux` only. See
| Capture netlink dump fixtures in a guest | `nix run path:.#microvm-x86_64-netlink-dump-capture -- --out /tmp/xtcp2-dumps` |
| Run all registered flake checks | `nix flake check path:. -L -j1` |
| Measure monitor performance freshly | `nix run path:.#bench-linkmonitor -- --output /tmp/xtcp2-bench` |
| Run a red-team scenario on the harness host | `nix run path:.#redteam-rt-1-1` (KVM + libvirtd; see [docs/redteam-harness.md](../docs/redteam-harness.md)) |

### Contents

Expand Down
34 changes: 31 additions & 3 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,24 @@ let
artifact = tests.test-linkmonitor-performance;
};

# Red-team harness wiring (docs/redteam-plan.md, docs/redteam-implementation.md,
# docs/redteam-harness.md). Apps run on the harness host (l); only the lint is
# a `nix flake check` member.
# vagrant is licensed bsl11, which nixpkgs marks unfree: it is evaluated in
# its own allowUnfree instance so neither the dev shell nor any other flake
# output needs NIXPKGS_ALLOW_UNFREE. Only the redteam-* apps pull it in.
redteamVagrant =
(import nixpkgs {
inherit (pkgs.stdenv.hostPlatform) system;
config.allowUnfree = true;
}).vagrant;
redteam = import ./redteam.nix {
inherit pkgs lib src;
vagrant = redteamVagrant;
inherit (binaries) xtcp2client xtcp2ctl;
inherit (containers) oci-xtcp2 oci-xtcp2-tcp-stress;
};

# Guest tests that report through the serial console, each built around
# microvms/mkVmCheck.nix's runner: checks.vm-<name>, run in the build
# sandbox with KVM and cached by its inputs, and the app test-<name>-vm,
Expand Down Expand Up @@ -1181,7 +1199,9 @@ in
# Per-flavor + per-package test targets. The two imports above each
# return an attrset whose keys already start with `test-` so they
# merge straight into the flake's packages namespace.
// (lib.filterAttrs (n: _v: lib.hasPrefix "test-" n) tests);
// (lib.filterAttrs (n: _v: lib.hasPrefix "test-" n) tests)
# Red-team harness images/tools (docs/redteam-harness.md).
// redteam.packages;

devShells = {
default = devshell;
Expand Down Expand Up @@ -1232,7 +1252,12 @@ in
// {
inherit (tests) test-linkmonitor;
}
// (lib.filterAttrs (n: _v: lib.hasPrefix "test-go-flavor-" n) tests);
// (lib.filterAttrs (n: _v: lib.hasPrefix "test-go-flavor-" n) tests)
# Red-team harness lint — the only hermetic member of the red-team program
# (VM scenarios are apps; see nix/redteam.nix).
// {
redteam-lint = redteam.checks.redteam-lint;
};

apps = {
test-tcp-controller-vm = {
Expand Down Expand Up @@ -1672,7 +1697,10 @@ in
type = "app";
program = "${drv}/bin/${name}";
}) tiers
);
)
# Red-team harness: one app per scenario (vagrant/scenarios/rt-*.sh) plus
# lifecycle helpers. See nix/redteam.nix.
// redteam.apps;

inherit tests;
}
7 changes: 7 additions & 0 deletions nix/devshell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ let
nix flake check Tier 0+1 lint + all custom audits
nixfmt --check **/*.nix Verify nix formatting

Red-team harness (vagrant/, docs/redteam-plan.md):
nix run .#redteam-rt-1-1 Boot the Ubuntu+Docker victim VM and
attack it (harness host only: KVM,
libvirtd, network)
nix run .#redteam-destroy Tear the VMs down
make redteam-lint shellcheck the harness tree

EOF
'';
};
Expand Down
Loading