Skip to content

fix(task): refuse user data over EC2's 16 KiB limit before any AWS call - #1247

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/1063-userdata-limit
Oct 20, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/1063-userdata-limit

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #1063

What changed

  • One shared check, in pkg/aws. It adds MaxUserDataBytes (16384, applied to the bytes after base64 decoding, i.e. the gzip stream) and MaxEncodedUserDataBytes (25600, the base64 string), plus CheckUserDataSize, UserDataSize, *UserDataTooLargeError and LaunchConfig.ValidateUserDataSize. These are the two 400s quoted in task run: a spec over EC2's 16 KiB user-data limit passes --dry-run, then RunInstances fails with 400 #1063.
  • Client.Launch calls the check first, next to ValidateDurations and before its identity, pricing and AMI calls. That covers every path that goes through it: spawn launch, sweeps, job arrays, burst, pools, app, image, and Provision.
  • launcher.BuildUserData (new, exported) returns the exact encoded user data that Provision sends. Provision now builds and checks the user data before the AMI lookup and SetupSporedIAMRole, since the bootstrap depends on neither. An oversized config therefore creates nothing.
  • spawn task run:
    • The wrapper, flush-hook and config assembly is now buildTaskLaunch. Both paths use it, so they measure the same bytes.
    • taskUserDataPreflight runs right after sizing and before any AWS call (GetAccountID included) in the real run, and in --dry-run. It uses placeholders of the same length for the account ID, the run ID and any FSx names.
    • The real run re-checks the exact bytes before provisionTask.
    • The dry run prints User data: N of 16384 bytes after gzip (EC2 limit).
    • The refusal names the size and the limit, and says to move long inline scripts into inputs: and to stage many per-file inputs as one directory prefix.
  • pipeline-orchestrator Lambda: checks after generatePipelineUserData. It is hand-deployed, so this only takes effect once the Lambda is redeployed.
  • make api-snapshot: additions only.

Gates

Every gate counts HTTP requests through the AWS client's transport, so any AWS call is seen. None of them use wall-clock time.

  • TestTaskRunRefusesUserDataOverTheEC2Limit binary-searches for the boundary. It measures independently, via buildTaskLaunch, then launcher.BuildUserData, then base64 decode. The boundary falls at 2,676 incompressible command characters: 16384 B fits, 16385 B does not. It asserts:
    • the dry run refuses 16385 B and the error mentions the size, 16384 and inputs:;
    • the dry run passes 16384 B and prints the size line;
    • runTaskReal refuses 16385 B with 0 AWS requests;
    • runTaskReal lets 16384 B through: it reaches AWS and is not a size error.
  • TestTaskUserDataPreflightMatchesTheLaunch checks that the preflight measures the same bytes the launch builds.
  • TestLaunchRefusesOversizedUserDataBeforeAnyAWSCall and TestProvisionRefusesOversizedUserDataBeforeAnyAWSCall assert 0 requests.
  • TestCheckUserDataSizeLimits checks the boundaries: 16384 passes, 16385 fails, and non-base64 input over 25600 fails.

I watched each gate fail against a revert that compiles:

  • check disabled (if false && ...): all of them fail;
  • real-path preflight removed: the 0-requests subtest fails;
  • dry-run preflight removed: both dry-run subtests fail;
  • Provision check disabled: the Provision gate fails;
  • Launch check disabled: the Launch gate fails.

Finding, filed as #1246

A trivial task's user data is already 14,146 of 16,384 bytes, and the bare spored bootstrap alone is 12,488 B gzipped. So about 2 KB of compressed command plus inputs fit. This PR makes the failure early and clear, but it does not give back any headroom. The S3-carried bootstrap asked for in #1063's comments is tracked in #1246.

Not changed

spawn launch --dry-run still reports only the custom user-data size. Its existing comment explains why: the full bootstrap needs a key pair that a real launch may create first. The real spawn launch is protected by the Client.Launch check, but only after its key, IAM and security-group setup, which are idempotent.

Checks

  • make check: all tests pass. check-build-tags fails on /private/tmp paths, and it fails the same way on unmodified main.
  • make lint: 0 issues.
  • semgrep --config=auto --error: 0 findings.
  • make check-docs: clean.

No AWS calls were made.

@scttfrdmn scttfrdmn added this to the v0.138.0 milestone Oct 20, 2026
@codecov

codecov Bot commented Oct 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 65.78947% with 39 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/task.go 56.25% 21 Missing and 7 partials ⚠️
pkg/launcher/provision.go 78.57% 3 Missing and 3 partials ⚠️
pkg/aws/userdata_limit.go 83.33% 3 Missing ⚠️
lambda/pipeline-orchestrator/main.go 0.00% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

…ll (#1063)

task run and its --dry-run now build the exact gzip+base64 user data
(launcher.BuildUserData, the bytes Provision sends) and refuse a spec over
16,384 decoded bytes before any AWS call; the dry run prints the size.
One shared check (aws.CheckUserDataSize) also runs at the top of
Client.Launch, in Provision before its AMI/IAM steps, and in the pipeline
orchestrator Lambda.

Fixes #1063
@scttfrdmn
scttfrdmn force-pushed the fix/1063-userdata-limit branch from 8eb6386 to e7a3da7 Compare October 20, 2026 19:01
@scttfrdmn
scttfrdmn merged commit 00a7118 into main Oct 20, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1063-userdata-limit branch October 20, 2026 19:25
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.

task run: a spec over EC2's 16 KiB user-data limit passes --dry-run, then RunInstances fails with 400

1 participant