Skip to content

Collect the run's stage outputs; paginate, skip markers, refuse traversal; deprecate result_s3_bucket (#989) - #1012

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/989
Oct 17, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/989

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #989
Stacked on #988 (fix/956 → #980 → #972 → #957 → #942 → #931). Review and merge after it.

What was wrong

spawn pipeline collect:

  1. read result_s3_bucket whenever a definition set it. Nothing writes there, and the stage instance profile (StageDataPolicy) grants only s3_bucket/<s3_prefix>/*. So on ml-training.json, fanout-fanin.json and video-streaming.json it printed "No results found".
  2. made one ListObjectsV2 call, collected the first 1000 keys, and reported success.
  3. downloaded the COMPLETE/FAILED markers as results.
  4. (Security) wrote each object to <output-dir>/<full key> without checking it. On the old code, the test below wrote a key .../output/../../../../../../../../../escaped.txt to a file outside the output directory (<parent>/a/b/escaped.txt). Anyone able to write to s3_bucket could plant such a key, a stage command among them.

What changed

  • collect is now pipeline.CollectRunOutputs (in pkg/pipeline, because the cmd/ SDK-import gate wants AWS work there). It lists StagesPrefix(<run prefix>) with s3.NewListObjectsV2Paginator. It keeps only data_output keys, using the new ParseStageOutputKey, which inverts StageOutputPrefix/StageInstanceOutputPrefix in stage_keys.go. Files go to <output-dir>/<stage>/<file>, or <output-dir>/<stage>/<index>/<file> for instance_count > 1.
  • It collects the record's (latest) run by default. The new --run <run-id> flag collects an earlier run of the same pipeline_id, and only accepts the run-id shape (^[0-9a-z][0-9a-z-]*$), because the value goes into an S3 prefix. When a run has no outputs, it lists the run ids that do.
  • Traversal: both the stage segment and the path below output/ must be filepath.IsLocal. The #944 dest_path rule is the same: s/output/../t/x stays inside the directory, but it would write into stage t's files, so it is refused too. Any bad key refuses the whole collection before anything is written. Two keys that clean to one path are also an error. Files are written through an os.Root, so a symlink already in the output directory cannot lead out either.
  • A failed download now exits non-zero. It used to print a warning and then report success.

Decision: deprecate result_s3_bucket, don't publish to it

So the fields are still parsed, which means existing definitions load. They carry // Deprecated:. Pipeline.Deprecations() makes validate, launch and collect warn. The three examples no longer set them, and examples/pipelines/README.md documents collect and the deprecation. Stage commands still get SPAWN_RESULT_S3_*; I didn't remove those from the orchestrator user data, to avoid touching the Lambda.

Tests (Substrate S3)

In pkg/pipeline/collect_test.go, collect_keys_test.go:

  • the run's outputs are collected and nothing else: no markers, no stage config, not run r1 when r2 is latest, not from result_s3_bucket
  • --run, rejection of a bad --run, and --stage
  • 1234 objects (more than one page)
  • traversal: ../×9, sub/../×10, ../train/0/best.h5, a .. stage id. Each asserts a refusal and that nothing at all is written under the test's parent dir
  • symlink in the output dir pointing outside
  • ParseStageOutputKey round-trips the helpers and rejects every marker kind and the config key
  • examples (discovered by glob, failing if none are found) set no deprecated field

Each was run against a revert that compiles (CLAUDE.md rule 1):

revert fails
whole old body (with result bucket) all collect tests
old body, result bucket unset DownloadsTheRunsStageOutputs (markers + full-key paths), Paginates (1000 of 1234), RefusesKeys (wrote <parent>/a/b/escaped.txt), DotDotStageID, StageFlag, RunFlag, RejectsRunID
single ListObjectsV2 call Paginates (1000 vs 1234)
drop the IsLocal check RefusesKeys, DotDotStageID (os.Root still blocks the escape, but the legitimate files are written first and the error is a download failure)
ParseStageOutputKey accepts non-output keys ParseStageOutputKey, DownloadsTheRunsStageOutputs, RunFlag
ignore --run / skip its validation RunFlag, RejectsRunID / RejectsRunID
read result bucket when set 8 collect tests
os.Create instead of os.Root DoesNotFollowASymlink
restore result_s3_bucket in ml-training.json ExamplePipelinesUseNoDeprecatedFields

make check: everything passes except TestGenerateWrapper_ChownFixesCrossUIDStickyUnlink_Docker. That test needs a Docker daemon, which wasn't running locally, and its package is untouched. check-nested passes. Semgrep (p/golang, p/gosec, p/security-audit, p/secrets, run locally without metrics, so not --config=auto): 0 findings, no nosemgrep.

Breaking for scripts

The local layout changed from ./results/<s3_prefix>/runs/<id>/stages/<stage>/output/<file> to ./results/<stage>/<file>. This is noted in the CHANGELOG.

No AWS resources were used. No Lambda redeploy is needed: this is CLI only.

…that leave the output directory; deprecate result_s3_bucket (#989)

spawn pipeline collect read result_s3_bucket whenever a definition set it.
Nothing writes there, and the stage instance profile is granted only
s3_bucket/<s3_prefix>/*, so on every example that set it collect printed
"No results found". It also made one ListObjectsV2 call (first 1000 keys),
downloaded the COMPLETE/FAILED markers as results, and wrote each object to
<output-dir>/<key> unchecked, so a key containing ".." wrote outside the
directory.

collect is now pipeline.CollectRunOutputs: it lists the run's stages/ tree
with the paginator, keeps only data_output keys (ParseStageOutputKey, the
inverse of the stage_keys output helpers), maps them to
<output-dir>/<stage>/<path>, refuses the whole collection if any key's stage
id or path is not local, and writes through an os.Root. --run collects an
earlier run of the pipeline id.

result_s3_bucket/result_s3_prefix are deprecated rather than published to:
validate, launch and collect warn, and the examples no longer set them.
@codecov

codecov Bot commented Oct 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.16779% with 37 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/pipeline/collect.go 78.94% 13 Missing and 11 partials ⚠️
cmd/pipeline.go 15.38% 11 Missing ⚠️
pkg/pipeline/stage_keys.go 85.71% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit b93f1cb into main Oct 17, 2026
8 checks passed
@scttfrdmn
scttfrdmn deleted the fix/989 branch October 17, 2026 05:39
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.

spawn pipeline collect reads result_s3_bucket, which nothing writes, and collects only the first 1000 objects

1 participant