Repository navigation
Description
Context
Follow-up of #44 (closed), whose asset stage (S28, S29, S31, S33) builds the upload as Plane's app expects it: S28 answers upload_data: {method: "PUT", url, fields: {}, headers}, the browser PUTs the file, and S29 confirms. Deviation D-035 (1) records that on every target the url is an address of this API, PUT /api/assets/v2/upload/{asset}/{token}/, and not a presigned URL of an object store. The token in the path is the credential (the browser sends no cookies): 256 random bits kept as a SHA-256, good for one use and an hour. The owner decided this for #44 and said the R2 presign is a follow-up. D-035 is still marked pending the owner.
Why that was the choice: no target has an object store the browser can reach with a signed URL today. A presign for R2 needs R2 API credentials stored as Worker secrets, which nothing here has (D-035; ADR-0047 and ADR-0080 say the same), and the self-hosted set's blob store is local disk or memory, which has no SigV4 endpoint.
What the plan already says about the end state:
- ADR-0080:
BlobStorehaspresign(op, key, opts) -> Url, "SigV4; works in wasm32". The built trait (crates/thrust-ports/src/lib.rs,BlobStore) hasput,head,get,deleteandlist, and nopresign. ADR-0080 marks "SigV4 presign from Rust/wasm32" as unverified. - ADR-0081 and ADR-0047: Option 4, a hybrid. Small files go through the API, and attachments use presigned PUT where the adapter supports it. The Worker buffers a request body and bounds it at 8 MiB, so anything larger than that cannot go through the Worker at all.
- R2 limits that bite: a presigned URL works only on the S3 API domain (
<account>.r2.cloudflarestorage.com), not on a custom domain; the browser mustPUT(no POST forms); the bucket needs CORS rules for the app's origin, and the storage hostname becomes visible to the browser.
Problem
- Every browser upload is carried by the Worker today. That fits the 5 MiB default (
CoreConfig.max_attachment_bytes; the compat upload route has its own body limit), but nothing above the Worker's 8 MiB bound can be uploaded, and each upload costs Worker CPU and wall time for bytes it only forwards. - The upload route (D-035 (1)) is a deviation from the pin's shape: the pin's
urlis the store's. The parity tests compare it through a projection (tests/common/mod.rs); with a real presigned URL the projection gets closer to the pin's. - S28's token is one-use; a presigned PUT is reusable until it expires, as the pin's is (
S3Storage.generate_presigned_put, an hour). S29's check of the object (D-035 (2): size and type must be the asset's) is then the only thing that stops a different file being uploaded, so it must stay.
Proposal
- Add
presign(PUT, and GET if the exports of ADR-0081 want it; that belongs to feat(jobs): exports and seeding as queue jobs with ajobstable (no workflow engine) #56) toBlobStore, with a SigV4 signer that builds for native andwasm32-unknown-unknown(spike 0001 left this unverified, so the first task is a spike result: which signer crate, or a small one of our own, compiles and runs in workerd). thrust-adapters-cloudflareimplements it with R2 API credentials (access key id and secret, account id, bucket) read from Worker secrets and the generated wrangler config; the other adapters answer "cannot presign", as ADR-0081 says.- S28 asks the store: when it can presign,
upload_data.urlis the store's signed URL,fieldsstays{}, and the signed headers carryContent-TypeandContent-Length, as the pin's do; when it cannot, the API-hosted PUT of D-035 (1) stays. Both flows are contract-tested on the targets that have them;worker-cfagainst a real bucket is the only target that can exercise the first. - S29 keeps
headverification of size and type. - Bucket CORS for the app's origin (
PUT, the signed headers) is part of the deploy, and the infra side (bucket, token, CORS) is the owner's; say what it needs and where the secret lives before building. - Revise D-035 (1) and the plan row; G-27's "an R2 presign that takes the bytes off the Worker" moves from "not built" to what is covered.
Acceptance criteria
- A known-answer test of the signer against AWS's published SigV4 test vectors (an independent oracle, AGENTS.md rule 9(c)), with a control: a changed header, key or expiry changes the signature.
- The signer builds and runs in workerd (
wasm32), shown by aworker-cftest, not only natively. - A real-R2 smoke run, which needs an owner-provided account and bucket (as
scripts/stage2-contract.shdid for the budget, G-24): a browser-style PUT to the presigned URL succeeds; the same URL with a differentContent-Length, a different key or after expiry is refused by R2; S29 then confirms, and refuses an object that is not the asset's. Record the run (date, commit, what was torn down) indocs/src/testing/status.md, as G-24 did. - The cover upload in a real browser (extend
e2e/journey.spec.ts, test(e2e): Playwright journey suite on the stock React app as the UI oracle #45) goes to the store's URL onworker-cfwith CORS in place, and to the API address on the targets that cannot presign. - An upload above the Worker's 8 MiB bound succeeds through the presigned path (with
max_attachment_bytesraised) on the real bucket, and is refused as today on the API-hosted path. - D-035 and G-27 are revised.
Out of scope
The reaper of assets that were never uploaded (ADR-0047's Scheduler), deletion of an asset, the nine other asset kinds, multipart uploads, a disk blob store for the native server, and the S3-compatible adapter for MinIO and S3 (P1). A MinIO testcontainer would give a local SigV4 check once that adapter exists.
References
- D-035 (
.agents/plans/contrail/DEVIATIONS.md), D-027;docs/src/testing/status.mdG-27, G-24;docs/src/architecture/app.md(assets) - ADR-0080 (the
presignsketch, R2 limits, "real-R2 smoke job", spike 0001), ADR-0081 (round-29 note on where presign exists), ADR-0047 - The pin:
apps/api/plane/settings/storage.py(S3Storage.generate_presigned_put),apps/api/plane/app/views/asset/v2.py - Cloudflare docs: R2 presigned URLs https://developers.cloudflare.com/r2/api/s3/presigned-urls/
Blocked by: the owner's R2 credentials and bucket for the smoke run (the signer and its tests are not blocked)
Activity