Skip to content

ami create: an image of an MPI rank-0 instance carries the cohort's root SSH key, which a child cohort reuses #1338

Closed

Description

@scttfrdmn

Found while fixing #1241. That fix discards per-instance state under /etc/spawn, /etc/profile.d, /var/lib/spored and /var/lib/spawn when an instance boots from an image of another instance. It does not cover root's SSH material, which the MPI user data writes and an image also carries.

Evidence (main @ f887212, pkg/userdata/mpi.go lines 197-217)

  • Rank 0 mints the cohort's cluster key only if none exists: if [ ! -f /root/.ssh/id_rsa ]; then ssh-keygen ... fi. So on rank 0 of a cohort launched from an image of an earlier rank 0, the parent cohort's private key is still there and gets REUSED. Every member of the new cohort then authorizes that key, so whoever holds the parent cohort's key (its other members, if they are still running, or anyone with a copy of the image) can ssh as root into the new cohort.
  • cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys and installPubKeyCommand (pkg/mpicohort) both APPEND, so root's authorized_keys on the image keeps the parent cohort's public key, and a child authorizes it whether or not it runs MPI.
  • cat >> /root/.ssh/config appends the Host * / StrictHostKeyChecking no block on every launch, so it accumulates copies.

Not verified

Worked out from the code. I have not launched a cohort from an image of a rank-0 instance.

Options

  • In the MPI user data, mint a fresh key per cohort (always, rather than only when id_rsa is missing) and write root's authorized_keys entry for the cluster key with a marker so it can be replaced, not appended.
  • Or have spawn ami create (launcher.ImageStateCleanupScript) remove the cluster key and its authorized_keys line before the snapshot. The source stays a working MPI node after that only if it is not re-wired, so the first option looks better.
  • instancestate.Paths (ami create: per-instance spored/plugin state (plugins.json, job-array env, peer files) is still baked into images #1241) works by path and mtime and would discard the whole of /root/.ssh/authorized_keys, which also holds keys the image should keep, so it does not fit as it stands.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions