ADR-0048: Signed upload links for agents: one single-use PUT per governed createupload, proxied through the API, the one upload-link route
- Status: Accepted
- Date: 2026-11-29 (decided by Halil, RFC-0048 accepted 2026-11-29 with every recommended answer; lands with rollout step 1)
- Related: RFC-0048, #250, #299, RFC-0004 / ADR-0020 (assets and media), RFC-0005 / ADR-0018 (roles, I14, I15, §10.1), RFC-0036 / ADR-0038 (playground), RFC-0044 / ADR-0045 (MCP OAuth), RFC-0047 (self-host on workerd), RFC-0008 / ADR-0023 (runs, taint, budgets), ADR-0004, ADR-0014, ADR-0015
- Sources: S3 presigned URLs · R2 presigned URLs · R2 S3 API compatibility · Workers limits · Cloudflare Images direct creator upload · Contentful uploads
Context
An agent that has a file on disk can add it to a site only through upload_asset, which carries the bytes as base64 inside the tool call (up to 4 MB). Every byte is model output: a 3 MB image costs about 4 MB of tokens, and larger files cannot be sent at all (#250). The agent usually has a shell that could send the file directly, but agents are refused on REST (RFC-0005 §10.1) and hold no REST credential in that shell. #299 added an optional sha256 to upload_asset; it does not change the cost.
Decision
- Two MCP tools.
create_upload(scopeasset:upload, gated by modes and approvals exactly asupload_asset) declaresfilename,bytes,mediaType, a requiredsha256and the asset’s text fields, and returns a PUT link.complete_upload(same scope, same key only, no second approval) creates the asset node and answers whatupload_assetanswers. A declared SHA-256 already in the library answersexistingwith no link. Both schemas follow the strict structured-output profile (every property required, optional valuesnull).upload_assetis unchanged. - The link is
PUT <admin origin>/api/sites/<siteId>/assets/agent-uploads/<uploadId>?sig=….sigis HMAC-SHA-256 overpurpose,uploadId,siteId, actor, method,bytes,mediaType,sha256andexpiresAt, with a key derived under the labelcloudhal agent upload v1(Studio’s tickets usecloudhal upload ticket v1). The secret is the optionalCLOUDHAL_UPLOAD_SECRET, else the preview secret or MCP state key. There is nokid: links live 10 minutes, so rotation voids at most that window. - The
media_uploadsrow is the authority. The link is bound to one site, one upload, one method, the exact size, the declared type and the exact SHA-256, and credited to the key that minted it. The PUT must start within 10 minutes; received bytes must be completed within 60 minutes (completeBy). Statesopen → receiving → received → completed(orabandoned) move by CAS; a failed verification reopens the row, at most 3 attempts. - The PUT is proxied through the API on every host (the admin Worker on Cloudflare and on workerd, the Node API of
cloudhal studio). It runs the RFC-0004 §5.2 pipeline up to the blob write and leases the blob untilcompleteBy; it never creates a node.complete_uploadinserts the node in one guardedbatch()that asserts the blob is still stored and leased by this upload. An uncompleted upload loses its lease and is collected by the existing media garbage collection. No direct R2 or S3 presigned URLs in v1. - I15 is amended. REST stays default-deny. One route requirement,
upload-link, is a capability rather than an actor: it is declared only onPUT …/assets/agent-uploads/:uploadId, the route guard reads no session for it, and the handler authorizes against the single-use row. The route-enumeration test pinsupload-linkto that one route, so a second use needs another RFC. RFC-0005 §10.1’s “agents remain refused on REST” gains the same exception. - Limits. 25 MB per file by default (
media.agentUploadBytes, up to 100 MB and the type’s cap), 10 open uploads per key and 50 per site,dailyLimit(100 files, 500 MB a day, counting open uploads’ declared bytes), the site quota with declared bytes reserved. Refused PUTs are not audited; accepted PUTs writeasset.upload-received; logs and audit rows never holdsig. - Capability.
get_mode.uploadsreports{signedUrl, maxBytes, linkSeconds}.signedUrlis false on stdiocloudhal mcp, on a Worker without a shared secret, and when an operator setsmedia.agentUploads: false; the tools are always listed and answersigned_upload_unsupportedthere. The playground denies the route. No newcloudhalcommand in v1.
Alternatives considered
| Alternative | Pros | Cons | Why not |
|---|---|---|---|
| Direct presigned PUT to R2 | No Worker body limit, up to 7 days | The binding cannot presign, so the Worker would hold bucket-wide S3 credentials; S3 presigned URLs are reusable until expiry; size and SHA-256 are not enforced at write; only the r2.cloudflarestorage.com host; CORS |
Loses single use and write-time binding, adds a powerful secret (RFC-0048 open question 4: not in v1) |
| Presigned PUT to the self-host S3 store | Same | Exposes the cluster-private store; signed size and checksum support unverified for SeaweedFS and RustFS | Proxying keeps the store private |
| Chunked base64 parts | No shell, no REST exception | Every byte is still model output; more failure points | Does not fix #250 |
fetch_asset_url from a local tunnel |
No server change | Third-party tool, public exposure while open | Heavier and less safe; already possible |
| The agent’s own key on the PUT | No capability exception | The shell usually lacks the credential (OAuth clients keep it) | Does not work for the main case; a key, when sent, must still match |
| Do nothing | Zero work | Cost and the 4 MB limit stay | #250 stays open |
Consequences
- Positive. Files up to the plan’s body limit reach the library without passing through the model, under the same scope, mode, approval, budget and quota as
upload_asset. One code path serves every host. - Negative. The first REST route an agent uses directly, and the first whose credential is the URL. A new migration on
media_uploads(purpose,attempts,complete_by,received,asset_id, an index). Self-host reverse proxies must allow bodies up to the agent cap. - Risks. A leaked, unused link lets whoever holds it burn the upload’s attempts (a denial of service on that upload; it can write only the declared bytes). A key holder can fill a site’s quota up to the daily and site limits, as with
upload_assettoday. Files above the Workers plan’s body limit still cannot be uploaded by agents.