Repository navigation
feat(task): stage the task wrapper and flush hook in S3 behind a sha256-verified fetch (#1274, PR B) - #1293
Merged
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
…56-verified fetch (#1274, PR B) A release build's spawn task run uploads the wrapper and terminal-flush hook as one content-addressed object, <results_prefix>/bootstrap-<sha256>.sh, before RunInstances. The user data carries only its URI and sha256; the bootstrap fetches it with the instance role, verifies it and writes the two files exactly where the inline user data did, or retires the instance. The task instance policy gains s3:GetObject on the staged objects' name shape in the results bucket (TaskRunPolicyFor). Not the task's own prefix: roles are named by their policy hash, so that would mint a role per task_id. Trivial task: 3,965 -> 2,075 bytes gzipped. 20 KB command: 16,533 (refused) -> 2,071. Dev builds and AWS implementations without PutS3Object stay inline; a failed upload falls back inline when the task fits.
… per-run unguessable keys (#1274, PR B) The shared s3:GetObject grant on bootstrap-<sha256>.sh is safe because task roles cannot list the results bucket and each key hashes the attempt's random run id. A task whose role can list the bucket (it is among its inputs, which get s3:ListBucket, or in resources.s3_read_write) is now never staged: it launches inline with a note, or is refused with the reason when it does not fit. The trust model is documented on the grant.
…staging bucket (#1274, PR B) The task wrapper and flush hook now go to spawn-staging-<account>-<region> as <task_id>/bootstrap-<sha256>.sh, not the results prefix. The bucket is created on first use with Block Public Access, SSE-S3, BucketOwnerEnforced, a 1-day expiry (and incomplete-upload abort) rule and spawn:managed=true; an existing one missing the rule gets the configuration re-applied; one owned by another account is never written to (ExpectedBucketOwner on every call). The task role's grant is s3:GetObject on <task_id>/bootstrap-<64 ?>.sh in that bucket only. No generated policy reaches the bucket (source-walk gate), and a TaskSpec or --s3-read/--s3-write naming spawn-staging-* is refused. The listing-task guard is removed: with the dedicated bucket it protected nothing.
…pened before v0.143.0)
scttfrdmn
force-pushed
the
feat/1274-staged-task-wrapper
branch
from
October 25, 2026 01:56
8062921 to
46d3578
Compare
Contributor
Author
|
Live-checked after merge (dev account, us-west-2, 2026-10-24). I built a throwaway 9.9.9 from main and published its body to us-west-2 only; it was deleted afterwards.
Cleanup: staged object and test bucket deleted, instance terminated, leak check clean. |
This was referenced Oct 25, 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.
Fixes #1274
Second half of #1274, after PR A (#1290), which moved the static bootstrap body behind a verifying stub. This PR moves the per-launch content that was still inline for tasks, the task wrapper (the
--command) and the terminal-flush hook. A task's user data no longer grows with its command and manifests.What it does
pkg/tasklaunch). From a release build,Launchuploads the wrapper and flush hook before RunInstances.<task_id>/bootstrap-<sha256>.sh, in a dedicated staging bucket,spawn-staging-<account>-<launch region>(taskproto.StagingBucket). It is one object rather than two because the bootstrap needs both or neither, so there is one fetch, one hash and one way to fail.launcher.StagedFilesObject, the same heredoc shell the inline user data carries. Staging changes where the bytes come from, not what they do.aws.Client.EnsureStagingBucket) is made sure of on every staged launch.ObjectOwnership: BucketOwnerEnforced;spawn-staging-expire-1d: every object expires after 1 day, and incomplete multipart uploads are aborted after 1 day;spawn:managed=trueandspawn:purpose=bootstrap-staging.ExpectedBucketOwnerto the launching account: Head, the config calls, the lifecycle read, List, and the upload's Put. A bucket of that name in another account fails the HeadBucket check, so nothing is written to it.pkg/launcher). WhenBootstrapConfig.StagedFiles/Options.StagedFilesis set, the fetch block takes the place of the two inline heredocs. The fetch runs at the same point, before gates,plugins.jsonand the body, so spored still starts after both files exist.aws s3 cp --only-show-errors --region <task region>, using the instance role, with 6 tries 5 s apart and umask 077.spawn_fatal_retire, so neither spored nor any workload starts.BuildLinuxBootstraprefuses a reference whose sha256 is not that of the config's own command and flush hook.UserDataBytesis the staged size. A note under theUser data:line gives the object's size and says it is staged.launcher.PublishedBodyVersion(), the same switch as the body.tasklaunch.AWSlacks the staging methods (found with an optional-interface type assertion) also stays inline, sotasklaunch.AWSgets no new methods.tasklaunch.NewDeps(*aws.Client), so it stages with no change.<task_id>/bootstrap-in the staging bucket and deletes what it finds before uploading its own object. This is best effort; the 1-day expiry is the backstop.Trust model
s3:GetObjecton exactlyarn:aws:s3:::spawn-staging-<acct>-<region>/*/bootstrap-<64 ?>.sh(TaskRunPolicyFor,StagedFilesResources). It gets no ListBucket and nothing else on that bucket.spawn-staging-*bucket is refused, byTaskSpec.Validateand again bytasklaunch.Plan. That coversinputs,outputs,resources.s3_read_writeandresults_prefix. So are--s3-read/--s3-writeonlaunch, sweeps andpool create.--iam-policy s3:ReadOnly/s3:FullAccesstemplates (Resource*), a user's own--iam-policy-file, and humans with S3 rights in the account. These are explicit grants, so I did not block them. If wanted, a bucket policy denyings3:ListBucket/s3:GetObjecttoarn:aws:iam::<acct>:role/spawn-instance-*except on the bootstrap key shape would close the template case; I have not built or verified it.spawn-instance-*role.cmd/pool.go) are unchanged. Their user data has no Command or TaskFlushScript, because their tasks arrive through the queue. Their policy is gated never to name the staging bucket.IAM the launching principal now needs (for the umbrella
docs/reference/iam-permissions.md)The documented baseline (spore-host
docs/reference/iam-permissions.md) has no S3 statements at all today. It also lacks thespawn-instance-*roles thatspawn task runalready creates; that gap is older than this PR. spawn'sdoctorenumerates no S3 actions, so no doctor change is needed.On
arn:aws:s3:::spawn-staging-*:s3:ListBucket(HeadBucket and ListObjectsV2)s3:CreateBuckets3:PutBucketOwnershipControls(required for CreateBucket with ObjectOwnership, and for the re-apply)s3:PutBucketPublicAccessBlocks3:PutEncryptionConfigurations3:PutLifecycleConfigurations3:GetLifecycleConfigurations3:PutBucketTaggingOn
arn:aws:s3:::spawn-staging-*/*:s3:PutObjects3:DeleteObjectWithout these, staging falls back inline when the task fits, with a warning.
Footprint
spawn footprint(pkg/aws/footprint.go) discovers buckets by name prefix, andspawncoversspawn-staging-*. A gate checks the staging bucket's name against the inventory's matcher. I found no other teardown or cleanup inventory that listsspawn-results-*buckets; the reaper teardown covers only its own stack.Sizes (decoded user data, gzipped, as EC2 counts it)
Gates (each watched failing against a revert that compiles)
TestLargeTaskLaunchesWithinBudgetWhenStaged: a 20 KB command is refused from a dev build and launches from a release build within budget, carrying only the URI and sha256. Exactly one object is uploaded, to the staging bucket, under<task_id>/, byte-identical toStagedFilesObjectand hashing to the user data's sha256. The bucket is ensured before the put, the put happens before Provision, and every call carries the account as expected owner.TestEnsureStagingBucketCreatesItConfigured/...ReappliesAMissingOrChangedRule/...RefusesABucketItDoesNotOwn: checks the create path (BucketOwnerEnforced, location), BPA×4, SSE-S3, the 1-day expiry and abort rule over the whole bucket, the managed tag, and ExpectedBucketOwner on every call. An existing bucket that is correct is left alone. Re-apply happens when the lifecycle is missing, longer, disabled or prefix-scoped. A 403 or other Head error means no further calls, and so does a missing owner.TestTaskRoleCanReadExactlyItsStagedObjects(default, custom and bucket-rootresults_prefix, with inputs ands3_read_write): checked with IAM*/?matching, the role can Get its own staged key. It has no List, ListBucketVersions or GetBucketLocation on the staging bucket. It has no Get, Put or Delete on other keys there, on wrong-shaped bootstrap names, or on another account's staging bucket, and no Get of a staged-looking key in its results bucket.TestNoGeneratedPolicyReachesTheStagingBucket(pkg/taskiam, walks every non-test .go file, fails if it finds fewer than 10 ARNs): no S3 ARN pattern in the source matches the staging bucket or an object in it, with Printf verbs treated as caller values.spawn-binaries-*widened tospawn-*in the pool worker policyTestPoolWorkerPolicyNeverNamesTheStagingBucketTestValidateRefusesTheStagingBucket(input, output,s3_read_write,results_prefix; any account or region) /TestPlanRefusesASpecNamingTheStagingBucket, which refuses before any AWS call /TestNoFlagGrantsTheStagingBucket(launch and sweep--s3-read/--s3-write, andpool create's, including an s3:// URI)TestStagingBucketIsInTheFootprintTestStagedKeyIsUnguessablePerRun: the identical spec gives different keys, and each object contains its run id.TestStagingClearsAPreviousAttemptsObject: the old object is deleted before the new put, and the new one is never deleted.TestStagingFallsBackInlineWhenTheBucketCannotBeReady/...WhenTheUploadFails: a small task goes inline with a warning; a large one is refused with the cause.TestDevBuildAndPlainAWSStayInlineTestStagedFilesAreTheInlineFiles(mvdan tree equality, stub and inline body) /TestStagedFilesRefusesAnotherLaunchsObject/TestStagedFilesFetchRunsOnlyTheStagedObject(bash harness: modes, root chown, region pin, retire on tampered, other, missing, empty or partial object, failing aws or no aws CLI; 6 bounded tries)--regiondroppedThe existing budget and user-data tests (
TestBareBootstrapFitsItsBudget,TestStubBootstrapFitsItsBudget,TestTaskRunRefusesUserDataOverTheEC2Limit,TestTaskUserDataPreflightMatchesTheLaunch) are unchanged and pass.Checks
make check: everything passes up tocheck-build-tags. That step fails identically on unmodified main in this /private/tmp worktree.semgrep scan --config=auto --error .is clean.make api-snapshotis committed; against origin/main it is additions only.Not verified
ObjectOwnershipplus the follow-up configuration calls succeed in one pass, or the exact action names above, against a live account.aws s3 cp--only-show-errorsand the--cli-*-timeoutoptions are assumed to be in the AMIs' CLI.