Skip to content

fix(mpi): distribute the cluster SSH key over SSM, and make the enrollment probe see mpirun - #687

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/684-mpi-key-over-ssm
Oct 4, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/684-mpi-key-over-ssm

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #684. --mpi had never worked end-to-end. Verified on real hardware at 2, 4, 8 and 16 nodes, plus a 2-node EFA run.

Two independent defects, each sufficient alone

1. The cluster SSH key could not be distributed. mpirun reaches the other ranks over ssh as root, so every node needs rank 0's public key. That went through S3 — but MPIConfig.BinariesBucket was never set by any caller, so the upload rendered s3:///, failed parameter validation, and aborted cloud-init's scripts-user module, taking the rest of MPI setup with it. mpirun was therefore never installed and cloud-init status read error.

Naming the bucket would not have helped: the spored role grants only s3:GetObject on spawn-binaries-*, so the upload would have been AccessDenied. The field's comment claimed a default ("defaults to spawn-binaries-{region}") that no code applied; the field is removed rather than left as a trap.

Distribution now rides SSM, the path the peers file already used — no bucket, no IAM grant, no cross-node polling race. The private key stays on rank 0: user-data would expose it to any local user via IMDS, and SSM would record it in CloudTrail. The key is installed before the peers file, because the peers file is the release signal and mpirun follows it immediately.

2. The enrollment probe could never pass. On AL2023 openmpi installs to /usr/lib64/openmpi/bin, which is not on the default PATH — the user-data adds it via /etc/profile.d/mpi.sh. But SSM runs a non-login shell, so profile.d is never sourced. Confirmed on a live c6i.large:

/usr/lib64/openmpi/bin/mpirun -> orterun          (installed)
$PATH = /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
command -v mpirun                                  → nothing
. /etc/profile.d/mpi.sh && command -v mpirun       → /usr/lib64/openmpi/bin/mpirun

So the probe tested a PATH the workload never uses, and no amount of correct installation could satisfy it. It now sources the MPI/EFA profiles first — the same thing the user-data does before invoking mpirun — and tolerates their absence for a custom AMI.

Together these are why 4 of 4 earlier MPI launches died at phase=enrolled, and why #671 and #683 had to land first: each failure was hiding the next.

Hardware verification

Nodes Ranks Unique hosts Result
2 4 2 ✅
4 8 4 ✅
8 16 8 ✅
16 32 16 ✅

c6i.large, us-east-1. Rank output from the 2-node run, which is the whole fix in four lines:

Warning: Permanently added '172.31.12.146' (ED25519) to the list of known hosts.
ip-172-31-4-147
ip-172-31-12-146
ip-172-31-12-146
ip-172-31-4-147

The known-hosts line is rank 0 actually SSHing to node 1 — i.e. the key distribution working. At 16 nodes, authorized_keys had exactly 2 lines, so the dedupe guard is holding rather than appending per push.

EFA, 2 × c5n.9xlarge (spot). This closes the one claim I kept flagging as unverified in #659 — fi_pingpong -p efa uses the libfabric EFA provider exclusively, with no TCP fallback:

bytes   #sent   #ack     total    MB/sec   usec/xfer
64      10      =10      1.2k       3.76     17.00
256     10      =10      5k        17.47     14.65
1k      10      =10      20k       67.81     15.10
4k      10      =10      80k      248.24     16.50
RC=0

Every transfer acknowledged at ~17 µs/xfer — SRD latency, not TCP. EFA SRD passes traffic between nodes through the security group spawn creates, which is exactly what #659's TCP-only rule blocked.

Honest caveats

  • 16 nodes failed once, then succeeded. The first 16-node attempt died with AssemblyFailed in ~100s (not a budget timeout); the identical re-run passed with 32/16. So there is flakiness at that width — most likely SSM — rather than a hard ceiling. I am not claiming 16 is reliable on the strength of one green run, and it is worth its own issue if it recurs.
  • EFA is quota-capped at 4 nodes, not a code limit: c5n.9xlarge is 36 vCPU, so 2 nodes is 72 and 8 would need 288 against a 256 spot limit. I checked six regions and the quotas are uniform (64 on-demand / 256 spot), so no region gives more headroom. The EFA run above is 2 nodes.

Two things found while verifying

  • Assembly errors were swallowed. cohort collapses any assembly failure to terminal/AssemblyFailed at phase=cohort-assembly with no cause, and on a failed cohort the instances are already drained — so the reason is unrecoverable. The assembler now prints its own error to stderr before returning it. This is what let me distinguish the transient 16-node failure from a systematic one.
  • The template's comments ship in every instance's user-data, which EC2 caps at 16 KB. My first draft put the full rationale inline; it now lives in Go comments beside the template, with one-line notes in the script. The MPI block is 3497 bytes for a 16-node EFA config.

Three tests asserted the bug

pkg/userdata had tests requiring aws s3 cp /root/.ssh/id_rsa.pub and spawn-binaries-us-east-1 in the script — they encoded the broken design as the expected one. The worst was TestGenerateMPIUserData_RegionSubstitution, which asserted region-specific buckets across four regions and passed for years, because the test itself set BinariesBucket. No caller ever did. It proved the template could interpolate a bucket; it never proved anything supplied one.

They now assert the absence of the S3 path, and specifically that s3:/// — the string that actually aborted cloud-init — cannot be rendered.

Also in here

The unbounded peers-file wait now times out after 10 minutes and writes a failed completion record, so a node the control plane never reaches stops instead of idling on a billing instance until TTL (and #682 means the TTL may not fire either).

Gates

gofmt -l empty, go vet ./..., go test -short ./... (0 failures), make check-docs, changelog gate, semgrep scan --config=auto --error . → 0 findings. A slow new test that sat through the real 3-minute key-wait budget was made injectable instead (180s → 0.42s), because a slow test becomes a skipped test.

Leak-checked after every run: instances 0 across four regions, plus the spawn-mpi-* security groups and placement groups cleaned up by hand — nothing reaps those yet, which is #685.

…lment probe see mpirun

--mpi had never worked end-to-end. Two independent defects, each
sufficient on its own, both invisible to unit tests.

1. MPIConfig.BinariesBucket was never set by any caller, so rank 0's
   pubkey upload rendered "s3:///", failed parameter validation and
   aborted cloud-init's scripts-user module — taking the rest of MPI
   setup with it, so mpirun was never installed. Naming the bucket would
   not have helped: the spored role grants only s3:GetObject there. The
   field's comment claimed a default no code applied; it is removed.

   The public key now rides SSM, the path the peers file already used.
   The private key stays on rank 0 (user-data would expose it via IMDS;
   SSM would log it in CloudTrail), and the key is installed before the
   peers file, which is the release signal.

2. On AL2023 openmpi installs to /usr/lib64/openmpi/bin, which is absent
   from the non-login PATH SSM gives the enrollment probe. So
   `command -v mpirun` could never succeed. The probe now sources the
   MPI/EFA profiles first, testing the environment the job actually runs
   in.

Also: the unbounded peers-file wait now times out after 10 minutes and
writes a failed completion record, and assembly failures are reported to
stderr instead of being collapsed to "AssemblyFailed" with no cause.

Three existing tests asserted the broken S3 exchange as expected
behaviour, including a region-substitution test that passed only because
the test itself set the field no caller ever set. They now assert its
absence.

Verified on real hardware at 2, 4, 8 and 16 nodes.

Fixes #684
@codecov

codecov Bot commented Oct 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.84848% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/mpicohort/assembler.go 84.12% 8 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

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.

--mpi has never worked: BinariesBucket is never set, so cloud-init dies on 's3:///' and mpirun is never installed

1 participant