Repository navigation
fix(bootstrap): instance ID from IMDSv2, install the AWS CLI when absent, fail closed on tag reads (#1490) - #1496
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
Author
|
Live-verified on EC2 (2026-11-02) with a CLI built from
None of these appeared anywhere: Pinned zips independently verified: SHA-256 matches fresh downloads for x86_64 and aarch64, and the GPG signature is valid from the AWS CLI key Cost under $0.01; the leak check is clean. |
scttfrdmn
force-pushed
the
fix/1490-ubuntu-bootstrap-tools
branch
from
November 2, 2026 06:02
9586658 to
fb5cba6
Compare
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1490
spawn bootstrap-bodysha256:b447ce0938c5fafd7acc827e0f956bc884ff207e72f0dd0bea7d46c31d56fcbb(main, #1484) →63421a2d49c0564a1289bdcd26c7e0375d8667f000f53ebdfebcf8094f033d23. That is 24421 → 23501 bytes raw and 6617 → 7191 gzipped. Deploy the sweep orchestrator from the release that carries this: it embeds the body.Budget: 7954 is under the 8448 budget, but it would leave only 494 bytes of the 1024 margin #1422 requires. Main had 12 bytes to spare above that margin. I raised the budget by 640, as #1459 did, rather than shrink the margin. The cost lands in the published body. A release launch's stub is unchanged unless it stages files (a task launch), and then it carries
spawn_need_aws(+466) because the staged fetch runs before the body. Raw size went down: the 16describe-tagsblocks are now one function. But those blocks compressed almost to nothing, so the net gzip change is the installer.Inventory (discovered from the rendered script)
TestBootstrapToolsExistOnEveryBaseparses every shape of the bootstrap: inline and stub, the stub with the body spliced in where it is sourced, ± key, command, flush hook, staged files, gates, plugins and launch config. It walks the AST, including the here-docs that are scripts. That gives 45 tools:/tmp/spawn-awscli/aws/install /usr/local/bin/spored awk aws base64 cat chmod chown cp curl cut date dirname dnf grep hostname hostnamectl id logger mkdir mkfifo mktemp mv openssl poweroff ps python3 restorecon rm sed selinuxenabled sha256sum shutdown sleep su systemctl tee timeout touch tr uname useradd usermod yum.The tools were checked against Canonical's 22.04 and 24.04 server-cloudimg manifests. Ubuntu lacked
ec2-metadata,aws,dnf,yum,restorecon,selinuxenabledandunzip. It hascurl,python3,gpg,openssl,bsdutils(logger),passwd,systemd-sysvandutil-linux.servicewas in the old script as a fallback aftersystemctl; it was removed, since every base runs systemd.aws CLI calls, reads vs writes:
ec2 describe-tags(nowspawn_tag)s3 cp s3://…staged → /etc/spawnspawn_fatal_retireec2 terminate-instances(self)command -v awspkg/taskproto)spawn_aws s3 cpstage-in / stage-out / completion.json,ecr get-login-passwords3 cpoutputspkg/userdata)s3 cp,ecr get-login-passwordDecision: (c), with (b) as the mechanism. The CLI is installed when absent; the instance ID comes from IMDSv2.
Why not IMDS instance tags (a) for the reads:
InstanceMetadataTags=enabled, tag keys may contain only letters, digits and+ - = . , _ : @. They may not contain spaces or/, and may not be.,..or_index. "Non-compliance will result in failed launches for new instances" (docs). Colons are allowed, so everyspawn:key, includingspawn:param:<name>, would be readable. The problem is the user's--tag key=value(cmd/launch_flags.go): enabling IMDS tags would make every launch carrying a common key likeCost Centerorteam/projectfail at RunInstances. That is a regression on every distro to fix one.MetadataOptionstoday, exceptHttpTokensunderIMDSv2Enforced. The CLI, the sweep orchestrator Lambda (which runs its own RunInstances) and the pipeline orchestrator would all have to change. Every path that missed it would break tag reads on AL too.Why not
sporedas the tag reader: a dev build installs spored fromspawn/current/, so a new subcommand would be missing at the branch live check. It also would not solve the S3 writes.What this PR does:
curl, using the body's existing$TOKEN(--retry 3). Anything not shapedi-*stops the bootstrap:spawn: no instance ID from IMDS; stopping (#1490).spawn_need_aws: returns at once ifawsexists, so Amazon Linux installs nothing. Otherwise it downloadsawscli-exe-linux-$(uname -m)-2.39.3.zipfromawscli.amazonaws.comand checks it against a pinned sha256 for that architecture. It unpacks withpython3, because Ubuntu has nounzipand cloud-init runs on python3 there; the zip's file modes are kept. Then it runs AWS's ownaws/install, into/usr/local/aws-cliand/usr/local/bin/aws, removes the unpacked files and confirmsawsis on PATH. It is called in two places:spawn_need_aws || { echo …; exit 1; };spawn_need_aws || spawn_fatal_retire …. On a release stub that fetch runs before the body is loaded, so the stub carries its own copy of the function in that case only.spawn_tag <key> [query]: onedescribe-tagscall, retried up to 6 times 5 s apart (for a new role's IAM propagation). If every try fails, the bootstrap stops:spawn: could not read tag K; stopping rather than use a default (#1490). The aws CLI's stderr is no longer hidden. An absent tag still reads asNone, as before, so a healthy AL boot behaves identically. I kept the old success-path value rather than "fixing"Noneto the old|| echodefaults: those defaults were only ever reached on failure, and mappingNoneto them would have changed AL behaviour (for example, an absentspawn:session-timeoutwould become 30m instead of disabled).SPAWN_SPORED_UP=1, so A bootstrap failure after spored starts but before --command launches writes no completion record; the instance bills to TTL #1484's guard writes{"status": "failed", "exit_code": 1, "source": "bootstrap"}, and--on-completefires.command -v dnf/command -v yumfirst. Theservice sshd reloadfallback is gone.Behaviour change (CHANGELOG, Changed): a bootstrap that used to continue with wrong defaults now stops. That happens when IMDS gives no instance ID, when the CLI is absent and cannot be installed, or when a tag read keeps failing (for example, a caller-supplied instance profile without
ec2:DescribeTags, though spored itself needs that permission). On Ubuntu with no route toawscli.amazonaws.com(a private subnet with only endpoints, i.e.--no-public-ip), the launch now fails closed. Filed as #1494 (mirror the pinned zips inspawn-binaries-<region>). No new IAM:ec2:DescribeTagsis already in the spored role, and the download is anonymous.Supply chain
14cb35809ad7547dd3c69fa9899a3975fbd850b6a6791f3fe264856490cd9a63(74,724,393 bytes)f6eb845fbacb11bee87de3f5fbe8043773cbe89d0414607b44b71e216eb9226b(72,175,673 bytes).sigfiles and rangpg --verifyagainst the AWS CLI team key taken from the AWS install guide, fingerprintFB5D B77F D5C1 18B8 0511 ADA8 A631 0ACC 4672 475C. Both reportedGood signature from "AWS CLI Team <[email protected]>".sha256sumagainst the pin is checked. The pin itself sits in the signed, sha-pinned published body, so it is covered by the same trust chain as spored.gpg.Invoke-WebRequest+msiexecwith no pin.Real install, outside the suite: I ran the rendered
spawn_need_awsinubuntu:24.04(arm64) andubuntu:22.04(--platform linux/amd64), with network, afterapt-get install curl python3(the cloud images ship both). Neither image hasunzip. Both returned 0 andaws --versionreportedaws-cli/2.39.3 … exe/aarch64.ubuntu.24and… exe/x86_64.ubuntu.22./tmp/spawn-awscliwas removed. The install took 1 to 2 s on this link; EC2 timing is for the live check.Gates, each watched failing against a compiling revert (
go vetclean)TestBootstrapToolsExistOnEveryBase(inventory, discovered from the AST; guarded tools must sit behindcommand -v;python3and the installer are scoped tospawn_need_aws)INSTANCE_ID=$(ec2-metadata …)backruns "ec2-metadata", which is not a base tool of every supported Linux basein every shaperuns "dnf" outside a 'command -v dnf' check(and yum)TestBootstrapUsesAWSOnlyAfterProvidingIt(every unguardedawscomes after a fail-closedspawn_need_aws, which must be defined by then)spawn_need_awscalls aws at offset N, and nothing provides it firstcalls spawn_need_aws (offset 2638) before defining it: the call fails with 127(andTestStagedFilesAreTheInlineFiles:defines spawn_need_aws 0 times, want once)TestEveryTagReadFailsClosed(discovers the 16 keys from a healthy boot that takes the array and sweep branches, then fails each in turn: exit ≠ 0, abootstraprecord, the tag named, the CLI error shown, exactly 6 tries, user data not run)spawn_tagback to2>/dev/null || echo Nonethe bootstrap exited 0 although reading K failed every time: it carried on with a defaultTestNoInstanceIDFailsClosed(IMDS 404 on instance-id)the bootstrap exited 0 with no instance ID; the healthy boot'sthe tag reads do not name the instance from IMDSTestAWSCLIInstalledWhenAbsent(aws absent; a test zip served at the rewritten URL, its sha substituted for the pin: installed once, then used for the reads, /tmp cleaned up; a tampered zip or none gives no install, a failed record, no MOTD, no command)truethe bootstrap exited 0 with no aws CLI(tampered zip installed)TestBootstrapOnUbuntuReadsTheInstancesTags(the whole inline bootstrap inubuntu:24.04andamazonlinux:2(bash 4.2.46),--network none, stand-in curl serving IMDSv2 and the bucket from files; only AWS-touching tools are stand-ins)a tool the bootstrap runs is missing from ubuntu:24.04(and amazonlinux:2),the MOTD lacks "Instance: i-0ubuntu", everya tag read does not name the instance: …Values= …,the --command once-marker does not carry the instance IDthe failure does not say the AWS CLI could not be installedTestToolScanSeesTheOldInstanceIDAndTagReadsec2-metadataand an unguardedawsin the pre-#1490 linesThe container runs skip unless docker and the image are present locally; they never pull. The Ubuntu run checks the MOTD (
Instance: i-0ubuntu,TTL: 1h,On Complete: terminate,Instance Index: 1 / 2),job-array.sh,hostnamectl set-hostname sim-1,command-ran-i-0ubuntuand acompletedrecord. Its no-aws case and its no-instance-ID case each check for a failedbootstraprecord and no MOTD.Also updated:
TestSpawnTagContract: the scan now recognises$(spawn_tag spawn:x)as a read. Without that it reportedspawn:commandandspawn:session-timeoutas read by nothing.TestStagedFilesAreTheInlineFiles: the stub's extra function copy.awscli.amazonaws.comrewrite, IMDS 404s and "tool absent" stand-ins.AL2: the inline bootstrap runs end to end under bash 4.2.46 in the container, and
bash -nof the published body passes there.Checks
make check(from /private/tmp): pass.make lint: 0 issues.semgrep scan --config=auto --error .: 0 findings.TestBootstrap_Shellcheck: pass.api-snapshot. No help text change.Live check before merge (branch-built CLI, so the body is inline)
--mpi --count 2 --name …, plus one plain--name u-test --command 'hostname; cat /etc/profile.d/job-array.sh 2>/dev/null; true' --on-complete terminate --ttl 1h. Expect:cloud-init-output.log:spawn: no aws CLI; installing AWS CLI 2.39.3 (#1490), noec2-metadata: command not found, nocould not read tag. Note the time from that line toConfiguring session timeouts(the install cost, while spored is already up).aws --version=aws-cli/2.39.3,command -v aws=/usr/local/bin/aws,/tmp/spawn-awscligone.hostname= the--name(…-0/…-1on array members);/etc/profile.d/job-array.shpresent on arrays;/etc/motdshows the instance ID and the real TTL and on-complete;ls /var/lib/spawn/command-ran-i-*names the instance on the--commandrun.cloud-init-output.loghas noinstalling AWS CLIline, and the MOTD and hostname are as before.--no-public-ipin a subnet with no NAT should record{"status":"failed","exit_code":1,"source":"bootstrap"}withcould not install AWS CLI 2.39.3and terminate under--on-complete terminate. That confirms bootstrap: Ubuntu in a private subnet cannot install the AWS CLI (awscli.amazonaws.com unreachable), so it now fails closed #1494's premise.spawn task runon an Ubuntu AMI. The CLI is installed before the staged fetch (before spored), and the wrapper's S3 copies work.Afterwards, verify no instance from these launches is left running.
Not covered here:
pkg/userdata's storage script installsnfs-utils/lustre-clientwithdnfonly, so EFS/FSx on Ubuntu is still part of #54's audit.