Repository navigation
feat(launcher): fetch the static bootstrap body per release behind a verifying stub (#1274, PR A) - #1290
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…verifying stub A release build's user data now carries a small stub instead of the static spored/lifecycle bootstrap body. The release workflow publishes the body, printed by the release's own spawn binary (hidden `spawn bootstrap-body`) and KMS-signed with the spored signing key, as spawn/versions/<v>/bootstrap.sh (+ .sig, .sha256) in all 11 spawn-binaries buckets. The stub fetches it from the regional bucket (us-east-1 fallback, retries), requires both the sha256 the build expects and a valid signature against the compiled-in key, and aborts loudly (stderr, console, journal) before running anything otherwise. Per-launch content stays inline in the same order around the body. Dev/pseudo-version builds, builds without a signing key, and callers setting BootstrapConfig.InlineBody keep the inline bootstrap. The completion file is now a shell variable so the body has no per-launch text. Fold-ins: strip the verified installer at the app, pipeline-orchestrator and upgrade-spored splice sites; spawn resume now gzips its user data (it was 25 KB raw base64, over EC2's limit). Bare launch 7253 -> 1222 bytes gz; trivial task 9324 -> 3454. Refs #1274
…ance
An aborted stub left a running instance with no spored, so nothing enforced
its TTL. spawn_fatal_retire (defined in the bootstrap prefix) logs to stderr,
console and journal, then self-terminates via the role's TerminateOnlySelf
grant (aws:ARN == ${ec2:SourceInstanceARN}) with IMDSv2 instance ID and
region, 3 bounded tries; failing that it shuts down, which STOPS the instance
since spawn sets no InstanceInitiatedShutdownBehavior.
Refs #1274
… instance too 'spored install failed' and 'Unsupported architecture' exited 1 and left the instance running with no spored and so no TTL enforcement: the same leak. Both now go through spawn_fatal_retire. Refs #1274
…he CLI The body is generated from the tagged source (go run with the release's version ldflag) into RUNNER_TEMP, KMS-signed and uploaded to every SPAWN_BINARY_BUCKETS bucket (now a job env shared with the spored upload) before GoReleaser runs, so no installable spawn exists without its body. After GoReleaser, the shipped linux binary's 'spawn bootstrap-body' must match the published sha256 or the job fails. Also drops an unused exported const from the previous commit and records the self-terminate in the CHANGELOG. Refs #1274
scttfrdmn
force-pushed
the
feat/1274-release-bootstrap-body
branch
from
October 24, 2026 05:08
f37676e to
6df4dab
Compare
…spored exit Live test of #1290 on a t4g.nano: dnf was OOM-killed installing acpid, the following `systemctl enable --now acpid` failed under set -e, and the body ended before `systemctl start spored`, while the backgrounded --command ran on with no spored, TTL or on-complete. The inline bootstrap had the same lines. - spored's unit and start now follow its verified install directly, ahead of the user, session-timeout, array/sweep, hostname, --command, banner and acpid steps (plugins.json is still written before it, #1023; the Spot replacement stop still ends the body). - acpid is optional: install failure and enable failure are reported, not fatal. - An EXIT trap installed with spawn_fatal_retire in the prefix retires the instance on any exit before SPAWN_SPORED_UP=1 (set after systemctl start spored), naming the last failed command (ERR trap). Only the main shell (BASHPID), and spawn_fatal_retire clears it to avoid re-entry. Refs #1274
Contributor
Author
|
Live-tested on the head commit
Leak check: no instances, no available volumes. |
This was referenced Oct 24, 2026
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.
Refs #1274
PR A of the owner-approved hybrid design: the static bootstrap body is published per release beside spored and fetched by a verifying stub. PR B (staged task wrapper and flush hook) follows. Nothing here is deployed, released or run against AWS.
What changed
pkg/launcher:BuildLinuxBootstrapis now prefix + per-launch-pre + (body | stub) + per-launch-post.BootstrapBody()) is the stripped verified-install funcs, the spot-check func,linuxBootstrapBodyand the spot-replacement stop, in today's order.SPAWN_CMD_COMPLETION_FILE, assigned in the prefix. The name avoidsSPAWN_COMPLETION_FILE, which the queue runner already uses.KeySetupScript, then the per-launch files (command, flush hook, gates, plugins.json, so Linux bootstrap writes /etc/spawn/plugins.json after starting spored, which reads it only at startup #1023 order holds), then fetchspawn/versions/<v>/bootstrap.sh+.sigfromspawn-binaries-<IMDS region>(us-east-1 fallback, 4 tries per source, only curl 7.61-safe flags). It requires the sha256 this build expects (pinned, which also refuses another release's validly-signed body) andopenssl dgst -sha256 -verifyagainst the embedded key. Then. /etc/spawn/bootstrap-body.sh, then the post-body inline parts./dev/consoleandlogger -p user.crit -t spawn-bootstrap, and then terminates the instance (spawn_fatal_retire, defined in the prefix), so a boot without spored does not keep billing with no TTL.TerminateOnlySelfgrant (ec2:TerminateInstanceswithaws:ARN==${ec2:SourceInstanceARN}, in every spored role viasporedSelfManagementStatements). Instance ID and region come from IMDSv2. It makes 3 tries, bounded by--cli-connect-timeout 10 --cli-read-timeout 30, sleeping 5 s between them.shutdown -h now(thenpoweroff). spawn sets noInstanceInitiatedShutdownBehavior, so that stops the instance rather than terminating it; both the log line and the code comment say so.exit 1and left the instance running with no spored. Both now go throughspawn_fatal_retire(a separate commit).launcher.CallerVersionis set by the CLI'sExecute, next toaws.CallerVersion. Library callers (lagotto, MCP) use the spawn module version fromdebug.ReadBuildInfo().Deps, and a replaced module counts as no version. Only a strictX.Y.Zgets the stub. Dev, pseudo-version and+dirtybuilds, builds with no signing key, andBootstrapConfig.InlineBody: trueget today's inline bootstrap.spawn bootstrap-bodycommand, not a go:generate tool. The release runsdist/spawn_linux_amd64_v1/spawn bootstrap-body, so the published bytes come from the exact binary users install. Its stub pinssha256(launcher.BootstrapBody()), so the two cannot disagree.release.yaml: the body is published before GoReleaser publishes the CLI and taps, so no installable spawn exists without its body.go run -ldflags "-X github.com/spore-host/spawn/cmd.Version=${VERSION}" . bootstrap-body, written to$RUNNER_TEMP(GoReleaser refuses a dirty tree). It is sha256'd, KMS-signed (DIGEST, same key and format as spored) and uploaded to every bucket.SPAWN_BINARY_BUCKETS, shared with the spored upload so the two cannot drift.if: !cancelled()) requires the sha256 ofdist/spawn_linux_amd64_v1/spawn bootstrap-bodyto equal the published one, or the job fails with::error::.cmd/app.go,lambda/pipeline-orchestrator/main.goandcmd/upgrade_spored.gonow spliceshellmin.Strip(KeySetupScript())+shellmin.Strip(VerifiedInstallFunc()).cmd/resume.gonow usesencodeUserDataForOS. It was base64 of the raw script, 25,389 B decoded / 33,852 B base64, so RunInstances refused every resumed Linux member. That is a real, previously unnoticed bug.Objects the release publishes per bucket (new)
For each of the 11 buckets
spawn-binaries-{us-east-1,us-east-2,us-west-1,us-west-2,ca-central-1,eu-west-1,eu-west-2,eu-central-1,ap-southeast-1,ap-southeast-2,ap-northeast-1}:spawn/versions/<VERSION>/bootstrap.sh: exactlyspawn bootstrap-bodyoutput (no trailing newline added)spawn/versions/<VERSION>/bootstrap.sh.sig: base64 DER ECDSA_SHA_256 over the body's SHA-256 digest (KMS--message-type DIGEST), the same format as spored's.sigspawn/versions/<VERSION>/bootstrap.sh.sha256: bare hex digestThat is 3 objects × 11 buckets = 33 new objects. The existing spored objects are unchanged. To verify:
sha256sumshould equal.sha256; it should also equalsha256(spawn bootstrap-body)from the released binary; andbase64 -d < .sig > sig.der && openssl dgst -sha256 -verify <SigningKeyPEM> -signature sig.der bootstrap.sh.Live-test finding fixed here: spored never started on a t4g.nano
In the parent's live test (9.9.9 body in us-west-2, dev account), the stub fetch, sha256 and KMS signature check all worked on real instances, and the 9.9.8 negative (no body) self-terminated in 29 s. The test also exposed a pre-existing bootstrap bug, present in every current release:
dnf install -y acpid 2>/dev/null || yum install -y acpid 2>/dev/null || true, which was tolerated.systemctl enable --now acpid, then FAILED because acpid was absent, andset -eaborted the body.systemctl start spored(line 534) never ran.--command, started earlier in the background, still ran and uploaded its records. But the instance stayed RUNNING with no spored, so no TTL and no on-complete terminate; it had to be terminated by hand.Fixed in aba223b:
--command, MOTD and acpid steps. plugins.json is still written before spored (Linux bootstrap writes /etc/spawn/plugins.json after starting spored, which reads it only at startup #1023), and the Spot-replacement stop still ends the body.spawn_fatal_retire, retires the instance on any exit beforeSPAWN_SPORED_UP=1, which is set aftersystemctl start sporedsucceeds. The message names the last failed command, recorded by an ERR trap.spawn_fatal_retireclears it so it cannot run twice.TestSporedStartsBeforeTheCommandWhichStaysBackgroundedreplaces the spored#65 "command before spored" guard; the command must still be backgrounded.systemctl start spored.Sizes (gzip, as EC2 counts)
spawn task run(bash -c 'echo hi')The inline path grows by the variable assignment, the self-terminate function and the exit guard (about 600 B gz). The stub budget is still 3 KiB.
Gates (each watched failing against a revert that compiles)
TestStubWithThePublishedBodyIsTheInlineBootstrap: the stub with its fetch block replaced byBootstrapBody()must match the inline bootstrap command for command (mvdan tree with function decls hoisted; the test also checks that nothing before the body calls a body function). It covers 7 configs: plain, key+command, task+flush hook, plugins, storage+gates, container, custom user data. Revert: per-launch-pre moved after the stub, which fails 4 configs.TestStubRunsOnlyAVerifiedBody: runs the real stub under bash against an httptest bucket/IMDS, with the real curl+openssl and a test P-256 key. The PATH holds only the needed tools plus stand-ins forsleep,logger,aws,shutdownandpoweroff, so nothing real can be called.ec2 terminate-instances --region eu-west-1 --instance-ids i-0test.shutdown -h now, with "STOPS" in the log) and no aws CLI (shutdown).exit 1.TestSporedStartsAndNoFailureLeavesAnInstanceWithoutItruns the whole inline bootstrap, with a test-key-signed fake spored served from the stand-in bucket, OOM-killed dnf/yum, and stand-ins for systemctl, useradd, su and the rest. Cases:daemon-reloadorstart sporedfailing: retired, with the failing line named.--commandthat exits 3 in the background: no retire, and the failure is recorded in SPAWN_COMPLETE.SPAWN_SPORED_UP(fails a, c, d); noSPAWN_SPORED_UP=1(fails a, c, d).TestInlineBootstrapRetiresAnInstanceWithoutSpored: the real inline bootstrap against an empty bucket (install fails, terminating or with a failing terminate) and with a stand-inunamereturning sparc64. Reverts: each abort back toexit 1. It covers 11 cases plus a retry case: good, regional tampered → fallback, tampered, bad sig, another release's body validly signed, no sig, nothing, non-DER sig, empty regional object, foreign key, and us-east-1 tampered with regional good. Reverts, each failing the relevant cases:if truecontinueremoved|| trueTestStubBootstrapFitsItsBudget(3 KiB). Revert: the body inlined into the stub path gives 7,895 > 3,072.TestStubIsTheDefault,TestPublishedBodyVersion(12 cases). Revert:_ = PublishedBodyVersion().TestEveryBootstrapCallerGetsTheStub: AST walk of all non-test Go. It finds everyBuildLinuxBootstrapcall (fails on fewer than 4) and everyInlineBodykey or assignment. Reverts:InlineBody: truein burst.go, andbc.InlineBody = truein provision.go.TestExecuteTellsTheLauncherItsVersionandTestBootstrapBodyCommandPrintsThePublishedBody. Reverts: assignment removed, andFprintln.TestEverySplicedInstallerIsStripped: AST walk; everysporedinstall.VerifiedInstallFunc()/KeySetupScript()outside pkg/sporedinstall must be the direct argument ofshellmin.Strip. Reverts: app.go, and orchestrator.TestReleasePublishesTheBodyBeforeTheCLI: in step order, credentials precede the body step, which precedes GoReleaser, which precedes the check step (!cancelled()). Revert: the body block moved after GoReleaser.TestReleasePublishesTheSignedBootstrapBodyBesideSpored,...FailsWithoutASignedBootstrapBody,...FailsWhenTheShippedBodyDiffers: these execute the body, spored and check steps'run:with the job env, a stand-ingo,aws(fake KMS, and s3 cp into a mirror with a region check) and a dist spawn..sigupload dropped, key check off, mismatch check off, version ldflag dropped.TestResumedSweepUserDataFitsEC2. Revert to raw base64: 25,389 > 16,384.bodyStubTemplatewas added to the strip-safety template set.Checks
make checkpasses exceptcheck-build-tags, which fails identically on unmodified origin/main (the /private/tmp path issue; verified in a throwaway worktree).make lint: 0 issues in all 10 modules.make check-docs: no drift (the command is hidden).semgrep --config=auto --error: exit 0.make api-snapshot: committed. Additions only:BootstrapConfig.InlineBody,BootstrapBody,BootstrapBodyName,BootstrapBodyKey,PublishedBodyVersion,CallerVersion.Not verified (needs AWS or a release)
spawn/versions/*is anonymously readable in all 11 buckets.upgrade-sporedalready fetches versioned objects anonymously over HTTPS, which suggests it is, but I made no AWS call.SPORED_SIGNING_KEY_IDmatchessporedinstall.SigningKeyPEM. This is already true for spored, and the body uses the same path.TerminateOnlySelfwhen the caller supplied their own instance profile. Without it, the fallback is a shutdown, which stops the instance.InlineBodyor updating.