Skip to content

fix(mpi): strip inherited MPI cluster keys at boot (#1343) - #1363

Merged
scttfrdmn merged 2 commits into
mainfrom
fix/1343-legacy-peer-key
Oct 27, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
fix/1343-legacy-peer-key

Conversation

@scttfrdmn

@scttfrdmn scttfrdmn commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

An instance launched from an image of an MPI cohort member no longer authorizes that cohort's cluster key for root.

Fixes #1343

Reworked per owner decision: strip at boot instead of editing the live source. The first version of this PR held the keys out of the source across CreateImage. That version is gone: no hold/restore scripts, no rank-0 key read, no Client.ImageSnapshotsTaken, no SSM wait, and no new IAM. api/public-surface.txt and docs/reference/cli-iam-actions.md match main.

What changes

  • instancestate.StripClusterKeys (new, pkg/instancestate/clusterkeys.go) removes every line of /root/.ssh/authorized_keys whose last field is exactly spawn-mpi-cohort.
    • Every other byte is kept: options, comments, blank lines, CRLF, a missing final newline.
    • The file is rewritten in place, so owner, mode and SELinux label are kept, and only when a line goes.
    • It logs the count removed, never the keys.
  • Once per instance. /var/lib/spawn/root-ak-owner (userdata.MPIClusterKeyStripOwnerFile) records the instance the strip ran for, and nothing is touched when it names this instance. So a source whose bootstrap runs again (cloud-init clean and the CreateImage reboot), or whose spored restarts, keeps its live cohort's key. An instance launched from its image strips it.
  • Where it runs:
  • No fight with the MPI key install. For --mpi, the discard runs before the MPI script touches root's authorized_keys, and before enrollment, so the strip comes first. On an image with MPI preinstalled, enrollment can pass, and the SSM install run, before the bootstrap reaches the strip. So installPubKeyCommand now also writes the record for its instance, and a later strip leaves this cohort's key alone.
  • spawn ami create does not touch the source's keys.

Where the strip lives, and the size impact

I wrote a shell version in the body first. It added 184 gzipped bytes to the bare inline bootstrap, from 8023 to 8207, over the 8192-byte budget (TestBareBootstrapFitsItsBudget). So the strip lives in spored instead, behind the discard-inherited-state call the body already makes. Its user-data and stub cost is 0 bytes: pkg/launcher is unchanged, the bare inline bootstrap stays 8023 gzipped and the release stub 1827. The SSM key-install command grows by about 60 bytes, and that is not user data. Windows is not affected: the Windows bootstrap never calls discard-inherited-state, the subcommand's strip is a no-op off Linux, and the daemon path is gated on Linux and root.

Images made before this release

Releases before #1338 installed rank 0's key untagged (root@ip-...), and nothing on an instance tells that line from a user's key. Nor can spawn find such images. An image records only spawn:managed, spawn:created, spawn:created-from, spawn:source-region, spawn:arch, spawn:gpu, spawn:base-ami and the user's --tags, not the source's MPI tags or spawn:version. #1364 tracks recording those, so a later fix can warn. The rebuild is documented in the CHANGELOG, the create-ami help and spore-host/spore-host#614.

Gates (each watched failing against a compiling revert)

  • TestStripClusterKeysRemovesTaggedLinesAndKeepsEveryOtherByte (Go, temp root). The fixture holds:

    Reverts:

    • never drop: fails;
    • prefix match: fails, the -notes key is dropped;
    • match anywhere in the line: fails.
  • TestStripClusterKeysOncePerInstance: reverting the owner check fails it.

  • TestEveryLinuxLaunchStripsInheritedClusterKeys (cmd) covers a plain launch, the published body, and --mpi ranks 0 and 1, where the discard must come before the MPI script's first /root/.ssh/authorized_keys. Replacing the discard line in the body fails it.

  • TestDiscardInheritedStateStripsInheritedClusterKeys (cmd/spored) and TestDiscardInheritedStateReconcilesThisInstance (pkg/provider) check that both call sites strip for this instance. Dropping either call fails its test.

  • TestBootStripAndKeyInstallAgreeInEitherOrder (pkg/mpicohort; the install runs under bash, the strip in Go) runs strip then install, install then strip, and strip, install, strip. Each must end with the user's key plus this cohort's key, not the parent's. Reverts:

    • the install does not record the instance: install, strip fails;
    • no owner check: two orders fail.
  • TestAMICreate_NeverTouchesAuthorizedKeys (negative) covers plain, MPI rank 0 and MPI non-zero sources. Only the run-state clean and CreateImage run, and no script mentions /root/.ssh. Making the clean also touch authorized_keys for MPI sources fails it.

The strip itself is Go, so dash and busybox don't apply to it. The changed shell (the key install) was run under Debian dash and Alpine busybox (docker, local images) with the expected result.

Checks

make check OK, make lint 0 issues in all 10 modules, semgrep scan --config=auto --error . 0 findings, make check-docs clean, make api-snapshot and make cli-iam-actions give no diff against main. Not tested on AWS.

@codecov

codecov Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.83051% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/instancestate/clusterkeys.go 88.57% 4 Missing ⚠️
cmd/spored/inherited_state.go 91.66% 1 Missing ⚠️
pkg/provider/ec2.go 80.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn scttfrdmn changed the title fix(ami): hold an MPI source's cluster-key lines out of the image (#1343) fix(mpi): strip inherited MPI cluster keys at boot (#1343) Oct 27, 2026
@scttfrdmn
scttfrdmn force-pushed the fix/1343-legacy-peer-key branch from 11856fe to cfdeec4 Compare October 27, 2026 04:40
An instance launched from an image of an MPI cohort member authorized that
cohort's cluster key for root. instancestate.StripClusterKeys now removes every
line of /root/.ssh/authorized_keys whose last field is exactly
spawn-mpi-cohort, once per instance (recorded in /var/lib/spawn/root-ak-owner,
so a source whose bootstrap re-runs keeps its live cohort's key). It runs from
the bootstrap body's existing spored discard-inherited-state call and at
spored startup, so the user data gains no bytes. The MPI SSM key install
records the instance too, so strip and install agree in either order.
spawn ami create does not touch the source's keys.

Pre-#1338 untagged rank-0 lines cannot be identified, and images record
nothing that would let spawn find them (#1364); the CHANGELOG and create-ami
help give the rebuild.
@scttfrdmn
scttfrdmn force-pushed the fix/1343-legacy-peer-key branch from cfdeec4 to ff09557 Compare October 27, 2026 05:31
@scttfrdmn
scttfrdmn merged commit 400ba25 into main Oct 27, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1343-legacy-peer-key branch October 27, 2026 05:53
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: a peer image made before #1338 keeps the parent cohort's untagged cluster-key line in root's authorized_keys

1 participant