Skip to content

Write side resolves an S3 location, read side guesses it: scheduled params and queue results can read the wrong bucket (or none) #804

Closed

Description

@scttfrdmn

Two subsystems share one defect: the writer determines a bucket at runtime, the
reader reconstructs the name from a template and never learns what was actually
used.
Verified in the tree; both found while auditing persistent stores for
one-ended data chains.

1. Scheduled parameter files

The write side deliberately handles the case where the shared bucket name is
taken by another account — pkg/staging/staging.go:273-283:

preferred := fmt.Sprintf("spawn-schedules-%s", region)
fallback  := fmt.Sprintf("spawn-schedules-%s-%s", c.accountID, region)
if bucket, err := c.ensureBucket(ctx, preferred, region); err == nil {
    return bucket, nil
}
return c.ensureBucket(ctx, fallback, region)   // account-scoped

It returns the bucket it resolved. The caller throws it away —
cmd/schedule.go:226:

_, s3Key, size, sha256, err := stagingClient.UploadScheduleParams(...)

and ScheduleRecord persists only the key (pkg/scheduler/types.go:20,
s3_params_key) — there is no bucket field.

The read side then rebuilds the name from the region alone —
lambda/scheduler-handler/main.go:228:

bucket := fmt.Sprintf(schedulesBucketTmpl, region)   // default "spawn-schedules-%s"

So in any account that took the fallback path, every scheduled execution fails
to find its parameters.
Worse, if the shared spawn-schedules-<region> bucket
is readable by that account, the handler can fetch a different account's object
at the same key — the key is schedules/<scheduleID>/..., which is not
account-qualified.

SPAWN_SCHEDULES_BUCKET_TEMPLATE can override the template, but it takes a
single %s for region (main.go:26), so it cannot express
<account>-<region> without baking an account into the deployment.

Nothing has exercised this yet: all three spawn-schedules-* buckets measured
0 objects. It is latent, not active.

2. Queue results

cmd/queue.go:336 hardcodes the bucket, directly under a comment stating the
invariant it then breaks:

// This should match what was specified in the queue config
bucket := fmt.Sprintf("spawn-results-%s", downloadRegion)
prefix := fmt.Sprintf("queues/%s/", queueID)

It never loads the queue config. The writer — in-instance, at
pkg/agent/queue_runner.go:356,366,371,426 — uploads to
r.config.ResultS3Bucket, i.e. whatever the queue JSON declared.

It happens to work for the wizard default (cmd/queue.go:700 prompts with
spawn-results-us-east-1) and the bundled examples, which is presumably why it
went unnoticed. It does not work for pkg/queue/templates/*.json's
{{S3_BUCKET}}, for any other bucket a user names, or for the integration
fixtures — which declare spawn-queue-results-test, a bucket with no reader
anywhere
and a measured 0 objects.

Also worth noting while here: two subsystems use different shapes for "the
results bucket" — this path assumes spawn-results-<region>, while
pkg/taskproto.DefaultResultsBucket (pkg/taskproto/resultsprefix.go:11) builds
spawn-results-<account>-<region>.

Suggested

Both cases want the same fix: persist the location, don't re-derive it.

  1. Store the resolved bucket on ScheduleRecord and have the handler read it,
    falling back to the template only for records written before the field
    existed.
  2. Have spawn queue results load the queue config and use its
    ResultS3Bucket/ResultS3Prefix, as its own comment already says it should.
  3. Reconcile the two results-bucket naming schemes, or document why they differ.

A gate worth adding alongside: for any store, the code that reads it and the code
that writes it must agree on the name by sharing it rather than by both
constructing it. That is the same principle as #790's Lambda-name constants —
reconstructing an identifier from a convention is how the scheduler handler ended
up asking for a function that never existed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions