11 KiB
Pipeline-Scoped Upload API Implementation Plan
This roadmap is for an LLM coding agent implementing the planned API work in
docs/roadmap/api.md. It describes future work only. Do not update
current-behavior docs outside docs/roadmap/ until the corresponding stage is
implemented.
Before implementation, read:
docs/policy/architecture.mddocs/policy/development.mddocs/policy/documentation.mddocs/roadmap/api.md
Target Behavior
The final implementation is a breaking v1 HTTP upload API change:
- Upload authentication is configured with top-level
upload_tokens. - Pipeline routing is selected by
POST /v1/pipelines/{pipeline_id}/upload. - Producers must set
PipelineIDinpkg/uploadupload options. - Legacy per-source
source.token_envis removed. - Legacy
POST /uploadno longer accepts uploads. - Idempotency is scoped by token id, pipeline id, and idempotency key.
/healthzand/runs/<run-id>continue to work.
The producer contract is:
- token authenticates the producer/client;
PipelineIDselects the configured distributor workflow;- source manifest
ididentifies the logical artifact within that workflow; - idempotency key identifies one producer run and retry group.
Stage 1: Config Model And Validation
Goal: make the YAML schema express upload authentication separately from pipeline source configuration.
Implementation:
- Add
UploadTokens []UploadTokentointernal/config.Configwith YAML keyupload_tokens. - Add
UploadTokenwith fields:ID stringasid;TokenEnv stringastoken_env;AllowPipelines []stringasallow_pipelines.
- Remove
TokenEnvfromHTTPUpload; keepStagingPathandMaxUploadSize. - Keep
http_uploadsource defaults forstaging_pathandmax_upload_size. - Update validation:
upload_tokensis required when any pipeline usessource.backend: http_upload.upload_tokensis invalid when it references no configured upload pipelines.- token
idis required, slug-like, and unique. - token
token_envis required. - token
allow_pipelinesis required. - each token's
allow_pipelinesentries are unique. - each allowed pipeline id exists and names a pipeline whose source backend
is
http_upload. - every configured
http_uploadpipeline is allowed by at least one token. http_uploadsources no longer requiretoken_env.
- Remove tests and fixtures that expect
source.token_env. - Add config load/validation tests for valid multi-pipeline tokens, multiple tokens for one pipeline, missing token list, duplicate token ids, duplicate allowlist entries, unknown allowed pipeline id, non-upload allowed pipeline id, and upload pipeline not allowed by any token.
Acceptance:
go test ./internal/configpasses.- YAML containing
source.token_envfails as an unknown field. - YAML using top-level
upload_tokensandhttp_uploadsources withoutsource.token_envloads and validates.
Stage 2: Upload Token Resolution And HTTP Routing
Goal: authenticate by bearer token, authorize by token allowlist, and route by URL pipeline id.
Implementation:
- Replace the current token-to-single-pipeline map with resolved upload token
records containing:
- token id;
- resolved token value;
- allowed pipeline id set.
- Resolve token values through the existing config environment resolver so
process environment and
secrets.directorybehavior remains consistent. - Startup must fail when a token env is missing, empty, or resolves to the same token value as another upload token. Error messages may name token ids and env var names, but must not print token values.
- Change
uploadHTTPHandlerroutes:- keep
GET /healthz; - keep
GET /runs/<run-id>; - add
POST /v1/pipelines/{pipeline_id}/upload; - remove legacy
POST /upload.
- keep
- Path parsing rules:
- match exactly
/v1/pipelines/<pipeline-id>/upload; - reject missing pipeline id, extra path segments, and query-based
pipelineorpipeline_idrouting; - validate requested pipeline id using the same slug-like id policy used for configured pipeline ids.
- match exactly
- Request handling rules:
- missing, malformed, or unknown bearer token returns
401; - valid token not allowed for requested pipeline returns
403; - requested pipeline must be configured with
source.backend: http_upload; - content type and idempotency key validation remain unchanged;
- successful requests submit the requested pipeline id and token id to the upload coordinator.
- missing, malformed, or unknown bearer token returns
- Update HTTP handler tests for accepted v1 upload, unauthorized upload,
forbidden pipeline, invalid pipeline path, removed
/upload, invalid content type, invalid idempotency key, and no token leakage.
Acceptance:
go test ./internal/apppasses for handler tests touched in this stage.POST /uploadreturns not found or another non-accepting error and does not callSubmit.POST /v1/pipelines/{pipeline_id}/uploadroutes only when token authorization allows that pipeline.
Stage 3: Coordinator Idempotency Scope
Goal: prevent idempotency collisions between distinct authorized clients and between pipelines.
Implementation:
- Add
TokenID stringtoUploadRequest. - Update idempotency scope to include token id, pipeline id, and key.
- Preserve existing behavior inside one idempotency scope:
- same key and same normalized manifest returns the original accepted run;
- same key and different normalized manifest returns conflict;
- same key while staging returns retryable conflict.
- Keep requests without idempotency keys unscoped and always admitted according to queue capacity.
- Update coordinator tests:
- same token, same pipeline, same key returns original run;
- same token, same pipeline, same key with changed manifest conflicts;
- different token ids can use the same key for the same pipeline without collision;
- same token id can use the same key for different pipelines without collision;
- pending-key retryable conflict still applies only within the same token and pipeline scope.
Acceptance:
go test ./internal/apppasses.- Existing queueing, retention, status, and same-pipeline serialization behavior remains unchanged.
Stage 4: Public pkg/upload API
Goal: make producer clients route uploads through the v1 pipeline-scoped API.
Implementation:
- Add
PipelineID stringtoUploadFilesOptions. - Add
PipelineID stringtoUploadBundleOptions. - Require non-empty valid
PipelineIDin both upload methods before local bundle staging, validation, archiving, or HTTP requests. - Use the same accepted pipeline id syntax as server config ids: starts with an
ASCII letter or digit and then contains ASCII letters, digits,
.,_, or-. - Build upload URLs as
/v1/pipelines/{pipeline_id}/upload. - Keep
Status(ctx, runID)unchanged. - Update package tests:
- missing
PipelineIDfails before local file work or HTTP request; - invalid
PipelineIDfails before HTTP request; UploadFilesandUploadBundlepost to the v1 route;- retry behavior reuses the same idempotency key and v1 route;
- token redaction still works.
- missing
- Update
pkg/uploadpackage documentation to explain the four-part producer contract: token,PipelineID, manifestID, idempotency key.
Acceptance:
go test ./pkg/upload ./pkg/bundlepasses.- Existing
Statustests pass without endpoint changes.
Stage 5: Examples And End-To-End App Coverage
Goal: prove the new server and client API work together across realistic upload pipelines.
Implementation:
- Update
examples/http-upload-local.ymlto use top-levelupload_tokens. - Update
examples/upload-clientto require or default a pipeline id and pass it topkg/upload. - Update app integration tests:
- one token authorized for two upload pipelines can upload to both;
- two tokens authorized for one upload pipeline can upload to that pipeline;
- a valid token rejected for a disallowed pipeline returns
403; - removed
/uploadendpoint does not enqueue work; - full upload publishes through the selected pipeline and records the selected pipeline id in status/report output.
- Update helper config builders in tests to use
upload_tokens.
Acceptance:
go test ./internal/apppasses.- Example config loading tests pass.
go run ./examples/upload-clientremains documented as an example that targets a configured pipeline.
Stage 6: Implemented-Behavior Documentation
Goal: move the feature from roadmap-only language into current-behavior docs after the code is implemented.
Implementation:
- Update
docs/config.md:- document top-level
upload_tokens; - remove
source.token_env; - document
http_uploadsource fieldsstaging_pathandmax_upload_size; - document token allowlist semantics.
- document top-level
- Update
docs/integrations/http-upload.md:- replace
POST /uploadwithPOST /v1/pipelines/{pipeline_id}/upload; - document
401versus403; - document idempotency scope by token id and pipeline id.
- replace
- Update
docs/consumers/api.mdanddocs/consumers/pkg-upload.md:- show
PipelineIDinUploadFilesandUploadBundle; - explain token authentication versus pipeline routing.
- show
- Update
docs/operations.mdanddocs/troubleshooting.mdfor the new curl path, upload token config, and forbidden-pipeline diagnosis. - Update
README.mdonly if its producer integration links or summary become stale. - Revise
docs/roadmap/api.mdso it no longer presents implemented behavior as future work. Either mark the pipeline-scoped upload API as implemented and leave only deferred ideas, or remove implemented sections.
Acceptance:
rg -n "POST /upload|source.token_env|token_env.*http_upload|maps each resolved bearer token to exactly one" README.md docs examplesreturns no stale current-behavior references outside historical roadmap context.- Documentation outside
docs/roadmap/describes only implemented behavior.
Final Verification
Run these commands after all stages are implemented:
go test ./internal/config
go test ./internal/app
go test ./pkg/bundle ./pkg/upload
go test ./...
Also run:
rg -n "POST /upload|source.token_env|/v1/pipelines|upload_tokens|PipelineID" README.md docs examples internal pkg
Review the output for stale references, missing docs, and tests that still expect legacy upload routing.
Non-Goals
- Do not let producers specify destination ids, destination paths, transforms, links, publish policy, transfer policy, or storage backends through upload requests.
- Do not add durable upload status, durable idempotency, retry endpoints,
cancellation endpoints, long polling, or
UploadAndWait. - Do not add in-app TLS, public exposure policy, or rate limiting.
- Do not introduce new public package families beyond existing
pkg/bundleandpkg/upload.