Files
fips/testing/nat
Johnathan Corgan 0c3c0c79c0 Retry test, package and NAT lab image builds across transient registry failures
Image builds in CI pull base images from Docker Hub and ghcr.io and fetch
packages from distribution mirrors, and each has failed a leg for a few
seconds at a time: a registry dial timeout, a 502, an apt file truncated
mid-fetch. A single failed build failed the leg, and a rerun of the whole
workflow was the only recovery.

Add retry_build to testing/lib/image-build.sh: up to three attempts with
10 s and then 20 s between them, whole-build so the base is resolved
again and every package-fetching RUN step runs again. It is quiet on a
first-attempt success, prints each failed attempt and a recovery to
stderr, and on GitHub Actions also raises a warning on the run summary
when a build recovered, so recovered failures remain countable. It never
wraps a test or a container start.

Use it for the shared test images in the integration job, the
deb-install and dns-resolver runtime images, and the package builder
image. Each deb-install and dns-resolver attempt prints its captured
output on failure, so a recovered failure still shows its cause.

The NAT, nostr publish-consume and STUN fault suites built their lab
images inside `docker compose up --build`: the relay image from ghcr.io
and Alpine, the STUN server from the Python image, and the routers from
Debian with apt. Build the profile's images first through retry_build,
then bring the lab up with --no-build. The start is not retried, since a
container that fails to start is a test result; only the build is.
2026-09-19 15:43:27 +00:00
..

NAT Lab Harness

Real Docker-based NAT traversal integration tests for the mainline FIPS Nostr/STUN bootstrap path.

This harness spins up:

  • two FIPS nodes
  • a local Nostr relay
  • a local STUN server
  • one or two Linux router containers performing NAT with iptables

For the NAT scenarios, the node LAN interfaces are not attached to Docker bridge networks. The harness creates explicit veth pairs and moves them into the node and router namespaces after docker compose up so every packet must traverse the router namespace.

It covers three scenarios:

  • cone: both peers behind explicit namespace/veth full-cone emulation, UDP traversal succeeds
  • symmetric: both peers behind symmetric-style NAT, UDP traversal fails, TCP fallback succeeds
  • lan: both peers share a LAN subnet, LAN targets are preferred over reflexive addresses

NAT model notes

The harness does not rely on plain Docker MASQUERADE for the cone case.

  • cone
    • uses explicit full-cone emulation in the router namespace
    • outbound UDP is SNATed to the router WAN address while preserving the source port
    • inbound UDP to the router WAN address is DNATed back to the single LAN host regardless of remote source
  • symmetric
    • uses UDP MASQUERADE --random-fully
    • outbound mappings may be port-randomized and are only reopened by matching conntrack state

This distinction matters because plain MASQUERADE is convenient source NAT, but it does not by itself model the "accept from any remote once mapped" behavior expected from a full-cone NAT.

Prerequisites

  • Docker with Compose support
  • locally built fips-test:latest

Build the test image with:

./testing/scripts/build.sh

Run

Run all scenarios:

./testing/nat/scripts/nat-test.sh

Run one scenario:

./testing/nat/scripts/nat-test.sh cone
./testing/nat/scripts/nat-test.sh symmetric
./testing/nat/scripts/nat-test.sh lan

Layout

  • docker-compose.yml
    • relay/STUN/WAN topology plus container definitions
  • node/
    • node bootstrap wrapper that waits for the injected veth interface
  • router/
    • NAT router image and iptables setup
  • stun/
    • minimal STUN binding responder
  • relay/
    • local strfry config. The relay image's strfry build is pinned by digest in docker-compose.yml (STRFRY_IMAGE); bump it there deliberately.
  • scripts/generate-configs.sh
    • derives ephemeral identities and writes per-scenario FIPS configs
  • scripts/setup-topology.sh
    • injects and configures the NAT LAN veth pairs in the container namespaces
  • scripts/nat-test.sh
    • boots the lab, waits for convergence, and asserts the resulting path
  • scripts/nostr-relay-test.sh
    • exercises the Nostr overlay advert publish/consume round-trip, including rejection of a malformed advert event
  • scripts/stun-faults-test.sh
    • cycles the daemon through STUN drop, delay and outage faults and asserts graceful behavior at each step

Assertions

  • cone

    • both nodes connect
    • connected transport is UDP
    • active link remote addresses are on the WAN NAT subnet
  • symmetric

    • NAT bootstrap does not establish a UDP link
    • fallback converges
    • connected transport is TCP via router-published WAN addresses
  • lan

    • both nodes connect
    • connected transport is UDP
    • active link remote addresses stay on the shared LAN subnet