Skip to content

Install spored on spawn burst instances and pick an AMI that fits (#924) - #940

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/924
Oct 17, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/924

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Stacked on #934 (fix/918), which is stacked on #926 (fix/905). Only the #924 change is in this diff.

Problem

  • Burst never installed spored. generateBurstUserData waited up to 300s for /usr/local/bin/spored, then exited 1. spored only ran on an AMI that already had it. Without spored a member has no idle termination, no on-complete, no hybrid-registry registration and no DNS. After Give spawn burst instances credentials, tags and a TTL (#905) #926 the TTL reaper still bounds the instance through its deadline, but in-instance enforcement (launch should fail if spored fails to install on the instance #50) is missing.
  • AMI auto-detect checked nothing. findLatestSpawnAMI took the newest self-owned spawn-* image of any architecture or OS. An arm64 or Windows image could land on an x86 Linux type.

Fix

  • Shared bootstrap. Burst user-data is now launcher.BuildLinuxBootstrap, the bootstrap spawn launch and launcher.Provision use. It:

    • downloads spored from spawn-binaries-<region> for the instance's architecture;
    • verifies it through pkg/sporedinstall (sha256 plus signature, fail closed, aborting the boot rather than running an unverified agent);
    • starts it under systemd.

    Nothing burst-specific is appended. spored registers the member with the hybrid registry from its spawn:burst and spawn:job-array-* tags. Members set LaunchConfig.Username = ec2-user (spawn:local-username), the user the bootstrap configures, as Provision does.

  • AMI selection. There is a new exported pkg/aws Client.GetSelfOwnedSpawnAMI(ctx, region, instanceType). It returns the newest available self-owned spawn-* AMI that:

    • has the instance type's architecture (Image.Architecture against resolveArchitecture, the resolver GetRecommendedAMI uses);
    • is Linux (Platform is not windows, and spawn:os, if present, is linux);
    • matches GPU-ness. A GPU type needs spawn:gpu=true, because nothing else says the image has a driver. A CPU type skips spawn:gpu=true images.

    It returns "" if none fits. resolveBurstAMI falls back to GetRecommendedAMI, the AL2023 resolution spawn launch uses, when no image fits or when the self-owned lookup fails. "" and auto both mean auto-detect, as for spawn launch. Whether spored is baked into the image no longer matters, because the bootstrap installs it.

  • Windows --ami is refused. The bootstrap is Linux-only. The AMI is now resolved before registry.EnsureTable and the IAM setup, so a refusal creates nothing.

  • cmd/burst.go no longer imports the EC2 SDK. TestNoNewAWSSDKImportsInCmd's allowlist is tightened accordingly.

Found while doing this: the bootstrap erased the EC2 key pair's key

BuildLinuxBootstrap with no PublicKey wrote an empty authorized_keys for its user. cloud-init installs the KeyName key pair's key into the default user's authorized_keys before user-data runs. So with ec2-user and no public key, the bootstrap erased the key the user had asked for. Moving burst to the bootstrap would have broken spawn burst --key-name. The old script never touched authorized_keys. The same applies to any launcher.Provision caller that sets KeyName. The bootstrap now writes the file only when it has a key, and otherwise just touches it. spawn launch, which always passes a key, still replaces the file.

Public surface

This adds func (*Client) GetSelfOwnedSpawnAMI(ctx context.Context, region, instanceType string) (string, error) to pkg/aws. It is an addition, not a removal. api/public-surface.txt was regenerated with make api-snapshot, and docs-gen/burst.md with make gen-docs.

Tests

  • cmd/burst_spored_test.go
    • TestBurstMembersInstallAndVerifySpored checks the decoded member user-data. It must:
      • define sporedinstall.VerifiedInstallFunc();
      • run spore_install_verified_spored "$BINARY", matched at line start (rule 3);
      • have a fail-closed exit 1;
      • run systemctl start spored after the install;
      • not contain the old wait-only loop.
    • TestBurstUserDataIsValidBash runs bash -n on the script.
    • TestBurstMembersRecordTheBootstrapUser
    • TestResolveBurstAMI uses a fake resolver to cover: an explicit Linux AMI, a Windows refusal, a fitting self-owned AMI preferred, auto, the fallback when nothing fits, the fallback on a lookup error, and no AMI at all. A compile-time assertion pins *aws.Client as the resolver.
  • pkg/aws/ami_spawn_test.go
    • TestPickSpawnAMI tests the selector directly (rule 2): architecture, Windows by Platform and by spawn:os, and GPU in both directions.
    • TestGetSelfOwnedSpawnAMIMatchesTheInstanceType runs the real DescribeImages path on Substrate. t3.micro gets the x86 image and t4g.micro gets the arm64 one.
  • pkg/launcher/bootstrap_authorized_keys_test.go extracts the generated authorized_keys step and runs it under bash against a temp home. With no key, an existing key pair's key is kept, or an empty file is created if none exists. With a key, the file is replaced.

Each test was watched failing against a revert that compiles, with go vet clean on each reverted tree:

Revert Fails
buildBurstUserData returns the old bounded-wait script (_ = script) TestBurstMembersInstallAndVerifySpored
Windows check → false && … TestResolveBurstAMI/explicit_Windows_AMI_is_refused
self-owned preference → case false && own != "" TestResolveBurstAMI/auto_prefers…, /"auto"_is_auto…
lookup error → return "", err TestResolveBurstAMI/a_failed_self-owned_lookup_falls_back…
architecture check → false && … three TestPickSpawnAMI cases, TestGetSelfOwnedSpawnAMIMatchesTheInstanceType
Platform windows check → false && … TestPickSpawnAMI/a_Windows_image_is_never_chosen
spawn:os check → false && … TestPickSpawnAMI/an_image_tagged_spawn:os=windows…
GPU-type requirement → return true two GPU TestPickSpawnAMI cases
member Username: "" TestBurstMembersRecordTheBootstrapUser
if true || [ -n "$LOCAL_SSH_KEY_BASE64" ] (always overwrite) TestEmptyPublicKeyKeepsTheKeyPairsKey

make check passes except TestGenerateWrapper_ChownFixesCrossUIDStickyUnlink_Docker, which needs a Docker daemon. make check-nested reports all 9 nested modules clean. No AWS resources were created and no instances were launched.

Caveats

  • The bootstrap needs outbound access to spawn-binaries-<region> (S3), the AWS CLI and ec2-metadata, as with spawn launch. That means an Amazon Linux 2023 image. A self-owned spawn-* image built on another distro passes the architecture and OS checks but may not run the bootstrap.
  • An explicit --ami is not checked for architecture. RunInstances rejects a mismatch itself. IsWindowsAMI treats a failed DescribeImages as "not Windows", as it does for spawn launch.
  • Not tested on real EC2: whether a burst member with --key-name can log in as ec2-user. The fix follows from cloud-init's documented module order (the ssh module runs in the init stage, before scripts-user in final). It has not been observed on an instance.

Filed separately

Fixes #924

Burst's boot script never installed spored: it waited up to 300s for
/usr/local/bin/spored and exited, so spored only ran on an AMI that already
had it. Burst members now boot with launcher.BuildLinuxBootstrap, the same
bootstrap spawn launch uses, which downloads spored for the instance's
architecture, verifies it (pkg/sporedinstall, fail closed) and starts it.
Members record ec2-user as spawn:local-username, the user it configures.

Without --ami, burst took the newest self-owned spawn-* image of any
architecture or OS. pkg/aws Client.GetSelfOwnedSpawnAMI now only returns one
matching the instance type's architecture, Linux, and GPU-ness where tagged;
otherwise burst falls back to GetRecommendedAMI, as spawn launch does. A
Windows --ami is refused before the registry table or IAM role is touched.
cmd/burst.go no longer imports the EC2 SDK.

The shared bootstrap truncated authorized_keys when given no public key,
which erased the key cloud-init installs from an EC2 key pair. It now leaves
the file alone in that case, so burst --key-name (and Provision callers with
KeyName) can still log in.

Fixes #924.
@codecov

codecov Bot commented Oct 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.44444% with 14 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/burst.go 74.41% 10 Missing and 1 partial ⚠️
pkg/aws/ami_spawn.go 93.61% 2 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

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.

spawn burst never installs spored; it only works on an AMI that already has it

1 participant