Skip to content

fix(mpi): pass --allow-run-as-root so --mpi-command starts as root on Open MPI 4.0.1 (AL2) - #1482

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/1481-mpirun-root
Nov 2, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/1481-mpirun-root

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #1481

Decision: keep root, pass --allow-run-as-root (option a)

mpirun runs as root by design, and switching to the default user is not safe:

  • the bootstrap is root's (cloud-init), and the --mpi-command help says "Rank 0 runs mpirun as root";
  • the cluster SSH mesh is root's (/root/.ssh key mint/strip, the owner file, pkg/mpicohort/assembler.go authorizing rank 0's key in root's authorized_keys);
  • the peer-readiness loop and spawn_mpi_done's per-peer completion write go over that root mesh. /tmp/SPAWN_EXITCODE, the completion file, /var/log/spawn-command.log and /etc/spawn/* are all written as root.

Moving to a default user would mean re-plumbing the key mesh, the completion channel and the file ownership the users' commands see, and the default user differs per AMI. No part of the design already works that way. So the fix makes root work on every supported Open MPI.

Matrix (containers, as root, mpirun --mca orte_base_help_aggregate 0 --oversubscribe -np 2)

Open MPI (image) none OMPI_ALLOW_RUN_AS_ROOT* env --allow-run-as-root both PRTE_ALLOW_RUN_AS_ROOT* env
4.0.1 (amazonlinux:2, yum openmpi) refused refused ok ok refused
4.1.2 (amazonlinux:2023) refused ok ok ok refused
4.1.2 (ubuntu:22.04, openmpi-bin) refused ok ok ok refused
4.1.6 (ubuntu:24.04) refused ok ok ok refused
5.0.5 (fedora:41, PRRTE prterun) refused ok ok ok refused

No version printed a warning or deprecation for the flag. The flag is the only mechanism that works everywhere, so no runtime version detection is needed. The env vars stay in /etc/profile.d/mpi.sh for a user's own mpirun. Not checked: the EFA installer's /opt/amazon/openmpi builds (4.1.x / 5.x upstream, the same lines as above).

Change

  • pkg/userdata/mpi.go: the rank-0 mpirun line (the only mpirun invocation, found by discovery) gains --allow-run-as-root. The rationale and matrix live in the Go comment, not the template.
  • MPI user data (rank 0, 2 members, ./sim): raw 7487 → 7507 B, gzip -9 3317 → 3330 B. The bootstrap body is unchanged.

Gates (each watched failing against a compiling revert that drops only the flag)

  • TestEveryMPIRunAllowsRoot (text, all platforms): every mpirun invocation, discovered in the rendered scripts (5 configs) and in cmd/ and pkg/ Go source, passes --allow-run-as-root as an mpirun option before the per-rank program. Revert: 6 errors (5 rendered configs + pkg/userdata/mpi.go:458).
  • TestRenderedMPIRunStartsAsRoot (real mpirun, root only, otherwise skipped): runs mpirun <the rendered options> -np 2 with only the env the rendered mpi.sh exports, and both ranks must run. Revert, in amazonlinux:2: exited 1 with 0 of 2 ranks run: mpirun has detected an attempt to run as root.
  • TestMPIRunEndsAtTheRanksExitWithARealMPIRun (fix(mpi): an --mpi-command rank ends at its command's exit, not its stragglers' (#1479) #1480's test) now takes the rendered mpirun options and the rendered root env instead of hard-coding the flag under root, so it is a second real-mpirun gate. Revert, in amazonlinux:2: all 4 subtests fail, mpirun exited 1.
  • With the fix, all three pass as root in amazonlinux:2 (4.0.1), amazonlinux:2023 (4.1.2), ubuntu:24.04 (4.1.6) and fedora:41 (5.0.5), and as non-root on macOS (Homebrew 5.0.11; the root test skips).
  • Test fix found along the way: the real-mpirun test ran mpirun by absolute path, so Open MPI implied --prefix and put /usr/bin first on the ranks' PATH. On Ubuntu that hid the counting sleep stub, and the stragglers subtest failed with drains polled 0 times. The test now passes argv[0] as the bare mpirun, the way the user data runs it.

Checks

make check OK, make lint 0 issues (10 modules), semgrep scan --config=auto --error . clean, launcher/tasklaunch budget tests OK. No help text changed, so no docs-gen.

For the live AL2 EC2 check (not yet done)

Launch a 2-member --mpi cohort on an AL2 --ami with a CLI built from this branch, e.g. --mpi-command 'echo rank-$OMPI_COMM_WORLD_RANK; hostname', --on-complete terminate, short TTL. Check:

  1. rank 0 /var/log/spawn-command.log has rank-0 and rank-1 and no detected an attempt to run as root;
  2. /tmp/SPAWN_EXITCODE = 0 and SPAWN_COMPLETE {"status": "completed", ... "source": "mpi"} on BOTH members, so both terminate via on-complete. This proves the remote orted (started over ssh as root) accepts root too, which a single-host container can't show;
  3. mpirun --version on the instance says 4.0.1, so the case under test really ran;
  4. optional: AL2023 regression, same command, same result;
  5. nothing leaks afterwards.

@scttfrdmn scttfrdmn added this to the v0.155.0 milestone Nov 2, 2026
@codecov

codecov Bot commented Nov 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@scttfrdmn

Copy link
Copy Markdown
Contributor Author

Live verification on EC2 (2026-11-02), owner-approved

Run in account 942542972736, us-east-1, on 2× c7g.medium with --mpi --mpi-processes-per-node 1, using the AL2 arm64 AMI ami-04c8b521a97d3e2a4. On that AMI yum install openmpi gives Open MPI 4.0.1.

  • Released v0.154.0 on AL2: --mpi-command as root fails on AL2: Open MPI 4.0.1 ignores OMPI_ALLOW_RUN_AS_ROOT #1481 reproduced. Rank 0 logged mpirun has detected an attempt to run as root … add the --allow-run-as-root option, even with OMPI_ALLOW_RUN_AS_ROOT=1 and _CONFIRM=1 exported. SPAWN_COMPLETE on both ranks: {"status":"failed","exit_code":1,"source":"mpi"}.
  • This branch (2463472a) on AL2: PASS.
    • Both ranks ran (rank-0, rank-1) with no root refusal.
    • SPAWN_EXITCODE 0, and SPAWN_COMPLETE completed/mpi on both ranks. That shows the remote orted, started over SSH as root, accepted it.
    • Both terminated via on-complete.
  • This branch on default AL2023 (Open MPI 4.1.2): PASS end to end, so no regression.

Caveat. On stock AL2, the MPI user data dies earlier, at jq: command not found (exit 127), with or without this PR. So the two AL2 runs above used a harness step (yum install jq, then re-running spawn's own script from the hostfile step). That is #1483, now in v0.155.0. This PR is necessary for AL2 but not sufficient.

Cost was under $0.05. All 6 instances terminated, and the 3 test SGs were deleted. The leak check is clean, and I confirmed it independently.

@scttfrdmn
scttfrdmn merged commit edd0ae9 into main Nov 2, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1481-mpirun-root branch November 2, 2026 02:41
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-command as root fails on AL2: Open MPI 4.0.1 ignores OMPI_ALLOW_RUN_AS_ROOT

1 participant