Repository navigation
launch: report --command's outcome, signal completion, and let it reach your own S3 - #630
Merged
Merged
Conversation
…t reach your own S3 Three defects, all in the path a user takes for a one-shot headless run. 1. --on-complete never fired for a --command launch. Nothing on that path wrote /tmp/SPAWN_COMPLETE — only pkg/taskproto/wrapper.go did — so the instance ran to its full TTL whether the command passed or failed, even though --on-complete terminate is the documented way to bound batch cost. The reporter's box idled 38 minutes after its command died in the first second. 2. A failed command reported success. It ran as a plain background job with its exit code discarded, so the success line printed unconditionally. The code now comes from PIPESTATUS[0]: after 'cmd | tee log', $? is TEE's status and is 0 even when the command failed, so using $? would have reported every failure as a success (verified under bash: $?=0 vs PIPESTATUS[0]=7). The capture happens in a BACKGROUNDED SUBSHELL, not by waiting. spored is installed and started later in the bootstrap, so blocking cloud-init here would leave TTL, idle and cost enforcement unarmed for the command's entire duration — the spored#65 failure, and worse than the bug being fixed. A test asserts the block stays both before spored's start and backgrounded. 3. The instance could not read the caller's own S3 bucket. spawn task run derives a least-privilege policy from its spec's DECLARED inputs/outputs; a --command is an opaque string with nothing to derive from, so 'give launch the same access' was not implementable as asked. New --s3-read/--s3-write give launch the same DECLARATIVE capability using the same policy builder (taskStagingPolicy), instead of the s3:ReadOnly (Resource '*') or AmazonS3FullAccess workarounds. Wildcards, ARNs and s3:// URIs are refused, since the name goes straight into a Resource ARN. Also documents what --command's instance actually is: the login user, not root, with no Docker or fuse — all three of which cost the reporter a run to discover. Refs #614
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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 #614. All four reported items verified in code. The first is worse than the issue states, and the second's suggested fix turned out not to be implementable as written.
1.
--on-completehas never fired for a--commandlaunchThe bootstrap never writes
/tmp/SPAWN_COMPLETE— onlypkg/taskproto/wrapper.godoes. So nothing on the--commandpath ever signals completion, and--on-complete(whose help promises "Action when workload signals completion") was dead there. The instance ran to its full TTL whether the command succeeded or failed.That's the expensive part:
--on-complete terminateis the documented way to bound batch cost (cmd/launch_flags.go), and on this path it never worked. The reporter's 38 idle minutes weren't bad luck.Now the command's completion is signalled on both paths, so
--on-completefires when the command exits. This is a behaviour change users will notice and it's called out in the changelog: boxes that used to sit until TTL now take their action. Anyone wanting to keep a failed instance uses--on-complete stopor omits the flag. No spored change was needed —Agent.checkCompletiontriggers on file existence and reads the content only to log it.2. A failed command reported success
Backgrounded, exit code discarded, success printed unconditionally.
$?would not have fixed it. Aftercmd | tee log,$?is tee's status —0even when the command failed. Verified under bash:So
${PIPESTATUS[0]}it is, written to/tmp/SPAWN_EXITCODE, with a pass/fail line printed once the answer is actually known.The
&is load-bearing — this is the important design constraintspored is installed and started later in the bootstrap. De-backgrounding the command would block cloud-init, so spored would not start and TTL / idle / cost enforcement would all be unarmed for as long as the command runs — the spored#65 failure (never block the ticker startup path), and strictly worse than the bug being fixed.
So the exit code is captured in a backgrounded subshell.
TestCommandStaysBackgroundedBeforeSporedasserts the block is both still beforesystemctl start sporedand still backgrounded, so a future "simplification" of the&fails loudly. I verified it by de-backgrounding and watching it fail.3. The instance couldn't read the caller's own bucket
cmd/task.goderives its policy from the spec's declared inputs/outputs (taskStagingPolicy). A--commandis an opaque shell string — there is nothing to derive from, so the issue's "give the launch role the same bucket access the task path has" isn't directly implementable. Meanwhile a bare launch lands onSetupSporedIAMRole's static policy, whose S3 grants cover only spawn's own infrastructure buckets. Hence the 403.New
--s3-read/--s3-write(repeatable) give launch the same declarative capability, reusingtaskStagingPolicyunchanged:{"Effect":"Allow","Action":["s3:GetObject","s3:GetObjectVersion"],"Resource":["arn:aws:s3:::my-inputs/*"]}, {"Effect":"Allow","Action":["s3:ListBucket","s3:GetBucketLocation"],"Resource":["arn:aws:s3:::my-inputs"]}, {"Effect":"Allow","Action":["s3:PutObject"],"Resource":["arn:aws:s3:::my-results/*"]}versus the previous options: a 403,
--iam-policy s3:ReadOnly(Resource "*"— every bucket in the account), or theAmazonS3FullAccessthe reporter resorted to. It attaches as its ownspawn-scoped-policydocument, so it is additive with--iam-policy/--iam-policy-filerather than replacing them. Wildcards, ARNs ands3://URIs are refused — the name goes straight into a Resource ARN, so--s3-read '*'would quietly grant the account.4 & 3 (docs)
--command's help now says it runs on the bare instance as the login user, not root (usesudo), that Docker and fuse are not installed unlikespawn task run, and that the instance reaches only spawn's own buckets without--s3-read/--s3-write/--iam-policy. All three cost the reporter a run.Tests
TestCommandOutcomeIsCaptured— PIPESTATUS,SPAWN_EXITCODE,SPAWN_COMPLETE, and both outcome branches. Verified to fail when reverted to$?.TestCommandSuccessClaimIsGone— gates the exact sentence that lied, like fix(fsx): stop promising synchronous ephemeral reaping; surface FSx in terminate and estimates (#613) #617's FSx promise gate. It caught my own explanatory comment quoting the old line, so I reworded the comment rather than loosening the gate.TestCommandStaysBackgroundedBeforeSpored— the spored#65 guard above. Verified to fail when de-backgrounded.TestBootstrapWithCommandIsValidBash— runsbash -nover the generated script for three command shapes including quotes and$. A syntax error here breaks every launch, and the new heredoc-inside-subshell is exactly that risk. (Worth noting: my first attempt put backticks in a comment inside the Go raw string and broke the Go build — the shell-level equivalent would have shipped silently.)Behaviour was also validated by running the subshell pattern directly:
echo ok→0/completed,exit 7→7/failed,false; echo unreachable→1/failedwithset -estopping before the echo.Gates
gofmt·go vet ./...·go build ./...·go test ./...all green ·make check-docsclean withdocs-gen/launch.mdregenerated and committed ·go mod tidyclean ·staticcheckzero added, diffed by message (the line-number diff gave a false positive on the previous PR).Not done
Real-AWS validation of the terminate-on-exit behaviour — a launch with
--command 'exit 7',--on-complete terminateand a short TTL should terminate within the grace period instead of idling. Worth doing before release; it needs a billable instance so I'd rather you greenlight it, and it must come with an explicit terminate and a leak-check.Suggested bump: MINOR — new flags, and
--on-completenow firing on a path where it never did is a user-visible behaviour change.