Skip to content

bootstrap: INSTANCE_ID is empty on Ubuntu (no ec2-metadata), so every tag read and the --command once-marker use an empty ID #1490

Closed

Description

@scttfrdmn

Summary

The Linux bootstrap gets the instance ID only with ec2-metadata (pkg/launcher/bootstrap.go, INSTANCE_ID=$(ec2-metadata --instance-id | cut -d " " -f 2)). That command comes from amazon-ec2-utils, which Ubuntu does not ship. On an Ubuntu --ami the line therefore fails, cut still exits 0, the bootstrap continues, and INSTANCE_ID is empty for the rest of the script.

Evidence

  • Code: INSTANCE_ID is used 22 times in pkg/launcher/bootstrap.go. Most are aws ec2 describe-tags --filters "Name=resource-id,Values=$INSTANCE_ID" ... with || echo <default> fallbacks: the session timeout, the job array ID/name/size/index (/etc/profile.d/job-array.sh), the sweep ID/params, spawn:command/spawn:step and the MOTD's TTL/idle/on-complete. One is the --command once-per-instance marker, /var/lib/spawn/command-ran-$INSTANCE_ID, which becomes /var/lib/spawn/command-ran- on Ubuntu.
  • Package manifests: Canonical's server cloud-image manifests for 22.04 (ubuntu-22.04-server-cloudimg-arm64.manifest) and 24.04 (ubuntu-24.04-server-cloudimg-arm64.manifest) list no amazon-ec2-utils or ec2-utils. They do list curl, cloud-guest-utils and coreutils.
  • Not yet confirmed on an Ubuntu EC2 AMI. The live Ubuntu check for MPI: add an apt install path for Ubuntu AMIs (today --mpi on Ubuntu can never work) #1487 should run command -v ec2-metadata and look for ec2-metadata: command not found in cloud-init-output.log.

Impact

This is not fully assessed. Each tag read falls back to its default instead of the instance's tag. Whether that matters on Ubuntu also depends on whether the aws CLI is present there; it is part of #54's audit.

The MPI user data had the same dependency. Its key owner file was written empty, so pkg/mpicohort (#1338) would never release rank 0's key. #1487's PR reads the ID from IMDSv2 with curl in the MPI fragment only. It leaves the published bootstrap body unchanged.

Suggested fix

In the bootstrap, read the ID with IMDSv2 via curl, which is already used there for the region and token. Either replace ec2-metadata or fall back to curl when it is missing. This changes the published bootstrap body.

Related: #54 (Ubuntu support audit), #1487.

Activity

  1. added
    bug
    on Nov 2, 2026
  2. added this to the v0.155.0 milestone on Nov 2, 2026
  3. scttfrdmn commented on Nov 2, 2026

    @scttfrdmn
    ContributorAuthor

    Confirmed live on Ubuntu 24.04 and 22.04, and the cause is wider than ec2-metadata

    Ran on 2026-11-02 in us-east-1 with c7g.medium arm64, using a CLI built from a local merge of #1489 and #1492 (merge 96a9303a, which reports spawn version 0.154.1-0.20261102045149-96a9303abb35) and --mpi --ttl 1h --on-complete terminate --no-dns.

    • 24.04 ami-09a93d801db0bafae (24.04.5): cluster l1489-u24, instances i-0d5b673b692a3f8f2 and i-0f4ce67ae6be3bf89
    • 22.04 ami-09c99d62ef07e4dd9 (22.04.5): cluster l1489-u22, instances i-0df5efe1a26260ca7 and i-031c66e67d2b54dbd

    Each check below gave the same result on all four members.

    1. ec2-metadata is absent, so INSTANCE_ID is empty.

    $ command -v ec2-metadata          -> (nothing)
    cloud-init-output.log:96: /var/lib/cloud/instance/scripts/part-001: line 264: ec2-metadata: command not found
    part-001:264: INSTANCE_ID=$(ec2-metadata --instance-id | cut -d " " -f 2)
    

    2. There is also no aws CLI on either image.

    $ command -v aws                   -> (nothing)
    $ aws --version                    -> aws: not found
    

    So no describe-tags call in the bootstrap ever runs. It isn't just running with an empty Values=: every call fails on the missing binary, 2>/dev/null hides that, and the || echo <default> fallback takes over. So the fix suggested above (IMDSv2 via curl for INSTANCE_ID) is necessary but not sufficient: on stock Ubuntu, tag reads stay broken until the bootstrap has an aws CLI, or reads tags some other way (IMDS instance tags, or spored). That makes this #54's AWS CLI question too.

    3. What visibly breaks:

    • Hostname from --name is not applied. The Name tag read (part-001 around line 337, the SPAWN_HOSTNAME block) gets nothing back. Ubuntu members keep ip-172-31-42-136 etc. AL2/AL2023 members in the same runs got l1489-al2a-0 etc. It also shows in the MPI output: Ubuntu ranks print ip-… from hostname.
    • /etc/profile.d/job-array.sh is not written, so JOB_ARRAY_* is missing from login shells (ls: cannot access '/etc/profile.d/job-array.sh').
    • The MOTD is wrong. It shows Instance: (empty) and TTL: disabled, Idle Timeout: disabled, On Complete: disabled. The real values were spawn:ttl=1h and spawn:on-complete=terminate.
    • The session timeout was the default 30m, which happens to match the tag here.
    • Not exercised: the --command once-marker (/var/lib/spawn/command-ran-), because these were --mpi-command runs. Also not exercised: sweep params and spawn:command/spawn:step. They go through the same failing path.

    4. What still works:

    • spored reads its config itself. spored status showed TTL: 58m 15s remaining and On complete: terminate, and every member self-terminated on completion.
    • The MPI fragment's IMDSv2 fallback from feat(mpi): install Open MPI with apt-get on Ubuntu AMIs (#1487) #1492 works. /root/.ssh/spawn-mpi-key-owner on rank 0 held i-0d5b673b692a3f8f2 (24.04) and i-0df5efe1a26260ca7 (22.04).
    • Both cohorts recorded {"status": "completed", "exit_code": 0, "source": "mpi"} on every member.

    So the impact is cosmetic and environment-level rather than lifecycle-level, because spored covers TTL and on-complete. But the hostname feature and the job-array env are silently missing on Ubuntu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions