Skip to content

ranks: every rank connection proves a shared key before its first protocol byte - #3041

Open
ashhart wants to merge 5 commits into
mainfrom
security/rank-link-key
Open

ashhart wants to merge 5 commits into
mainfrom
security/rank-link-key

Conversation

@ashhart

@ashhart ashhart commented Nov 12, 2026

Copy link
Copy Markdown
Owner

What this changes

Before: rank 0 of a multi-GPU group took the first TCP connection as its peer on four paths: the fabric/tp bootstrap, the GLM and Nemotron liveness lines, the HIP link and the Flash Next pair. A host that reached the port first was sent the checkpoint identity, the NCCL or RCCL id and then prompts, or could stop the group. After: both ends send a fresh 32-byte nonce and an HMAC-SHA256 over the nonces, the link, the rank and the group size before any other byte. A connection that fails is closed and cannot stop the group. Ranks with no key meet on one host only.

  • Issue: n/a. SECURITY.md asks for private reports, so there is no public issue.
  • Stacked on: main.
  • atc overlap --json: not run.

Checks on this head

  • Head commit: b83c447d088df47821ba18d1e94a84ca74e41a08
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head: 345 on the base, 345 on this head, 0 new.
  • Tests run, with the command and pass, fail and skip counts:
    • zig fmt --check on 27 files: passes
    • git diff --check: passes
    • zig build test-rank-auth-host test-tp test-stage test-stage-compile test-cli: 88/88 steps succeeded; 254/272 tests passed (18 skipped)
    • zig build -Dhip=true check-native-hip-host test-native-hip-host test-environment-hip-host test-hip-family-offers-host test-qwen3-hip-host test-rank-link-hip-host: 22/22 steps succeeded; 60/60 tests passed
    • zig build check-native-cuda-host compile-flashnext-mtp-parity-host compile-glm-native-open: 11/11 steps succeeded
    • zig build native: 66/66 steps succeeded
    • zig build test-server-cpu: 5/5 steps succeeded; 1326/1333 tests passed (7 skipped)
    • zig build test-cuda-host: 391/391 steps succeeded; 6266/6306 tests passed (40 skipped)
    • zig build test-golden test-server-security test-pull-security: 76/76 steps succeeded; 34/34 tests passed
  • New tests:
    • security: a connection that proves no key is no liveness line and is sent nothing
    • security: a rank with another key and a second line for one rank are not lines
    • stage secret: a proof's bytes are the ones the ring has always sent
    • security: a connection that proves no key cannot end the group or take a rank's place
    • security: a rank with another key or with none joins no keyed group
    • security: rank 0 takes only the peer that proves the key, and a stranger that came first gets no frame
    • security: a rank 1 with another key is refused and rank 0 keeps waiting for its peer
    • security: a stranger that says a rank's hello first hears nothing and takes no place
    • security: a rank with another key or with none is refused by name, and rank 0 still takes its own
    • rank auth: a group across hosts needs a key, and each end is told so
    • rank auth: this host is loopback, a local socket, or the address the connection reached
    • rank auth: ranks with one key prove both ways, keep one session key, and rank 0 learns who came
    • rank auth: ranks with no key meet on one host
    • rank auth: a rank with another key is refused, and so is a key at one end only
    • rank auth: a link, rank or world rank 0 does not take is refused before it answers
    • rank auth: a stranger without the key gets a challenge and nothing more
    • rank auth: a recorded proof replayed, rank 0's proof sent back, and a proof for another rank are refused
    • rank auth: other bytes, a short hello and a silent peer end inside the budget, with nothing sent
    • rank auth: a connector tells an older build and a stranger from a rank, and sends them no proof
    • rank auth: a proof binds the key, the end, the link, the rank, the world and both nonces
    • rank auth: the key comes from the file the setting names, and no setting means no key
    • rank key: a mac changes with the key, with any part, and with the order of the parts
    • rank key: a key file is a regular file only its owner can read, never a link, and holds 16 bytes to 4 KiB
    • security: --rank-secret takes only a key file its owner alone can read, and names it for every rank link
  • CI: runs on this push.
  • Not run, and why: The Flash Next link tests are Linux-only and skip on this Mac. On the earlier base they passed in a Linux VM (3 of 3), and that run was not repeated on this head. Nothing ran on two hosts or on a GPU. zig build test and every step that runs on a GPU were not run: this Mac's GPU was serving a model, and no CUDA, ROCm or Intel hardware was available.

Receipt

  • Main against branch: could not be run. It needs two hosts with CUDA or ROCm GPUs.
  • Boxes it reaches: multi-rank startup on CUDA (--tp with --master, TF_TP_*, the GLM and Nemotron liveness lines, the Flash Next pair) and on ROCm.
  • New switch? Default, accepted values, profile row: TF_RANK_SECRET_FILE, or serve --rank-secret FILE. Default unset, and then ranks meet on one host only. Accepted: a path without control characters to a regular file only its owner can read, holding 16 bytes to 4 KiB. It has a row in platform/environment.zig and in docs/environment.md. No profile row.
  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: this head on Zig 0.17.0, on an Apple silicon Mac, CPU-only steps. No GPU and no checkpoint was used.
  • Paths and platforms the change reaches, which I ran and which I could not: the handshake, the bootstrap, the liveness lines and the HIP link ran over loopback on macOS. The Flash Next pair's link is Linux-only: its tests compile here and skip.
  • Exactness: not measured. The change is to connection setup. No kernel, no arithmetic and no frame after the proof changes.
  • Main against this branch, same machine and checkpoint: not run, for the reason above.
  • Decode speed before and after: not measured.
  • Prompt speed before and after: not measured.
  • Licence of any new weights or drafter: n/a.

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency. Each new test was shown to fail without its fix on the earlier base b38a4dd02. On this base only the passing side was rerun.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.

For a change that reaches inference:

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. Not measured: no served run.
  • No precision traded for speed.
  • Decode and prompt processing are no slower than main. Not measured: no served run.

Notes for the reviewer

  • Operators: a group that spans hosts now refuses to start until every rank has the same key file. An error names the setting.
  • A build with this change and a build without it do not join: the proof comes before the first protocol byte.
  • Phase 1 only. Frames after the proof are not signed and the links are not encrypted. SECURITY.md says so.
  • Four pinned serving sources change, so zig/tests/fixtures/gradient-serving.tsv needs their lines re-pinned after merge (hashes below). The fixture is not edited here because its zig/src/cuda/experts.zig line is already stale on main.
  • zig/build/hip.zig is at 600 lines with this change.
  • New hashes for the pinned sources: zig/src/cuda/root.zig ab1760e269f72b970ecf5f0a2b808777ff31001918b7d1134c3f083c20d12852; zig/src/cuda/tp_watch.zig 4de1a9f14d514f1cbb5576b1db33cc11bd504b5a434ad3e7787af6d3a40c91a7; zig/src/families/flashnext/cuda_rank_engine.zig e229100dc45d140a1ce138e22f7014527a38d900bbd8b0a62281a65ae7e956c7; zig/src/families/flashnext/cuda_rank_wire.zig 5beb7662040418d09fd18400edcf0c1761b7ef9d157c43b847fef8178ddc13bd.

Suggested changelog line

Multi-GPU ranks: every rank connection proves a shared key (TF_RANK_SECRET_FILE, or serve --rank-secret FILE) before any other byte. Ranks with no key meet on one host only, so a group across hosts needs the key file on each.

@ashhart

ashhart commented Nov 12, 2026

Copy link
Copy Markdown
Owner Author

Review: the handshake is sound, but it needs four fixes and a two-machine run before landing.

The crypto checks out:

  • fresh nonces from the OS;
  • an HMAC over the role, the link, the rank, the group size and both nonces;
  • a constant-time compare;
  • the role byte stops a proof being sent back;
  • a downgrade to no key is refused at both ends.

All four TCP rank paths are covered, and one machine with several GPUs still meets without a key.

To land:

  1. Allow a key file that is a symlink. rank_key.zig opens the key with NOFOLLOW, which breaks Kubernetes and secret-manager mounts (those are symlinks). It adds nothing, since the mode is checked on the opened file. It also quietly tightens TF_STAGE_SECRET_FILE.
  2. Say how to fix a missing key. explain() should name serve --rank-secret FILE and a one-line command to make a key, not only the environment variable. Rank 0 should also say a peer was refused for no key, rather than "check that port is reachable" after 5 minutes.
  3. Bound a silent connection. A connection that never sends its hello holds the acceptor for 10 s, and accepts are serial, so about 30 of them use up rank 0's 300 s startup. Give the first message a short budget, because an honest rank sends it at once.
  4. Require a 32-byte key. The acceptor sends its proof to anyone, so a short typed passphrase can be guessed offline. Raise the minimum to 32 bytes, or have the connector prove first.

Two-machine run, as we'll do it: two GB10s at TP=2 over the network, on the Flash Next pair, GLM or Nemotron, and the TF_TP_* bootstrap.

  • No key: both ends refuse with the key message.
  • The same key: it starts, tokens are byte-identical to main, and decode and prompt speed are unchanged.
  • Different keys: refused.

This is a breaking change for multi-machine setups, and the changelog line should say so.

  • Synthena (Ash's Agent)

@ashhart

ashhart commented Nov 12, 2026

Copy link
Copy Markdown
Owner Author

Review fixes pushed (41354b8):

  1. Key files may be links. The key opens without NOFOLLOW, and the file type and mode are still checked on the opened file, so a link to a 0644 file is refused.
  2. Clear errors. Every key error names serve --rank-secret FILE and a one-line command to make a key. Rank 0 logs each refused connection with the peer's address and the reason.
  3. Silent connections. A connection that sends nothing gets 2 s for its first message, so it can't use up rank 0's startup.
  4. Key length. Rank keys need 32 bytes. The stage ring keeps its 16-byte minimum (TF_STAGE_SECRET_FILE), so no stage ring that starts today stops starting.

Also fixed: zig/tests/cuda/flashnext_rank_tests.zig still called Link.open without the new secret argument, which broke the Linux CUDA test build.

Results:

  • test-rank-auth-host, test-tp, test-stage and test-server-security: 26/26 steps, 246/249 tests (3 skipped). That includes a key-length test at 15, 16, 31 and 32 bytes for both loaders.
  • check-native-cuda-host and compile-cuda-tests for Linux: 16/16 steps.

Lean: 345 before and after.

Still owed before landing: the two-machine run on two GB10s at TP=2.

  • No key: both ends refuse with the key message.

  • The same key: it starts, tokens equal main's, and speed is level.

  • Different keys: refused.

  • Synthena (Ash's Agent)

@ashhart

ashhart commented Nov 13, 2026

Copy link
Copy Markdown
Owner Author

Two-GB10 run at TP=2 on 41354b8 against main, GLM-5.3-Flash NVFP4:

  • Same key on both ranks: the pair came up in 3 of 3 runs, and rank 0 refused no connection. Token hashes equal main's in all 52 cells, chat matches with thinking off and on, and prompt and decode speed are level.
  • No key: refused. Rank 1 prints "ranks on more than one host need a shared key: pass serve --rank-secret FILE (or set TF_RANK_SECRET_FILE) on every rank…" with the one-line key command. Rank 0 logs the peer's address and the same reason.
  • Different keys: refused. Rank 1 prints "the other rank holds a different key…". Rank 0 logs "the peer closed during the key proof", because rank 1 checks first and hangs up.

Ready, and queued to land. Setups that run ranks on more than one machine need a key from this release; the changelog line says so.

  • Synthena (Ash's Agent)

…tocol byte

The TCP links between the ranks of a multi-GPU group took whichever host connected first. Both ends now
send a fresh nonce and an HMAC-SHA256 over the nonces, the link, the rank and the group size, on the
bootstrap, the liveness lines, the HIP link and the Flash Next pair. A connection that fails is closed
and cannot stop the group. Ranks with no key meet on one host only. TF_RANK_SECRET_FILE or --rank-secret
names the key file. Later frames are not signed and the links are not encrypted.
… gets 2 s

- The key file opens through symbolic links, as secret mounts give it; the type and
  mode checks still run on the opened file, so a link to a file others can read is
  refused.
- Rank keys need 32 bytes after trailing whitespace. The shared loader takes the
  minimum from its caller: rank links pass 32 and the stage ring keeps its 16, so
  every stage ring that starts today keeps starting.
- A missing, different or short key's error names serve --rank-secret FILE and a
  one-line command that makes a key.
- Rank 0 logs each refused connection with the peer's address and the reason.
- An acceptor waits 2 s for the hello, so a silent connection no longer holds the
  serial accept for the whole 10 s budget.
- The Flash Next CUDA rank device test passes the new secret argument to Link.open.
test-gradient-serving pins the bytes of the maintained serving sources; the
train CI for this branch (#3168) stopped at zig/src/cuda/root.zig, but four
differ:

- zig/src/cuda/root.zig: tp_line.zig's tests are imported.
- zig/src/cuda/tp_watch.zig, zig/src/families/flashnext/cuda_rank_engine.zig
  and cuda_rank_wire.zig: rank connections prove a shared key before their
  first protocol byte (b83c447).

Each row takes its file's new hash, with the change named beside it.
Share one cumulative deadline across accepting and proving rank connections, closing accepted followers if formation expires. Cover it with a short-budget loopback host regression.
@ashhart
ashhart force-pushed the security/rank-link-key branch from 85da6c9 to bf1d50b Compare November 23, 2026 19:43

This branch has not been deployed

No deployments
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