You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Storage: declarative policies and cacheable delivery #7
Guiding rule for this phase: every capability ships as an open-source interface with a working zero-configuration default. Hosted infrastructure is a different implementation behind that same interface — never the only implementation, and never a different API.
Storage runs on S3, GCS and local disk, with resumable uploads and image transforms. Two things are worth adding: policies that are declared rather than coded, and delivery that something can cache.
Work
Declarative per-path policies, so storage access is described the same way collection access is. storageAuthorize stays as the escape hatch for rules that need code
Cacheable delivery. Emit correct Cache-Control, ETag and range handling on the direct-serve path, so a reverse proxy or CDN works in front of it without changing how the server behaves — packages/server/src/storage/routes.ts:606
Durable transform cache. Derived renditions are held in an in-process LRU today, so they are per-instance and cold after every deploy. Write them back to the storage source instead
An S3-compatible protocol endpoint, so existing S3 tooling can talk to a Rebase bucket
Upload and finalize triggers, so a function can run when an object lands
Second item is done in #13, plus part of the third.
Cacheable delivery: all four response paths now carry a weak ETag and Last-Modified and answer 304, so a reverse proxy or CDN works in front of the existing proxying behaviour without changing it.
Two bugs surfaced while doing it and are fixed in the same PR:
every response said Cache-Control: public, including for objects that required credentials — permission for a shared cache to hand one user's private object to the next caller;
immutable was claimed on keys that can be overwritten, so a replaced file stayed invisible for up to a year.
Part of the transform-cache item too: the cache key now carries the source's version, so a replaced image no longer serves its old rendition. The cache is still per-instance and still cold after a deploy — moving renditions into the storage source is the rest of that item.
Untouched: declarative per-path policies, the S3-compatible endpoint, and upload/finalize triggers.
Delivery half is complete across #13 and #17 (#17 is stacked on #13 — merge #13 first).
#17 adds byte-range requests: Accept-Ranges, 206 with Content-Range, 416 for an unsatisfiable range, and conditional-wins-over-range ordering. Without it a browser wouldn't offer to seek in media served from here, and Safari refuses to play a video whose first response isn't a 206.
Local storage reads only the requested slice; S3 and GCS still fetch the object whole, because StorageController has no ranged read — the saving there is the response body, not the upstream fetch.
Untouched: declarative per-path policies, the S3-compatible endpoint, upload/finalize triggers, and making the transform cache durable across instances (its staleness is fixed, its locality isn't).
Four of the five items are done; the S3-compatible endpoint is the one left.
Durable transform cache — renditions are written back to the source's own bucket, under the reserved prefix _rebase/renditions/, keyed by the same string the memory cache uses. That key already carries the source object's size and mtime, so replacing an image serves the new rendition and abandons the old one rather than serving it.
It is opt-in (storageRenditionCache: { enabled: true }, or STORAGE_RENDITION_CACHE=true), and that is the one decision here worth disagreeing with if you want to. Turning it on makes a GET write to the operator's bucket: it costs per object, it puts files nobody uploaded into a place they own, and on read-only credentials it cannot work at all. None of those seemed like a choice to make on an operator's behalf, so the default stays off and a failed write degrades to the in-process cache with the reason logged once rather than once per transform. One line changes the default if you would rather it were on.
The prefix is refused as a caller-supplied key in both directions — reading or writing it directly answers 400 INVALID_STORAGE_KEY. Every access rule in the product, storageAuthorize and the declarative policies alike, is written against the source key; a rendition addressable under its own path would serve a derivative of a private object with nothing having authorised it.
Upload and finalize triggers — storageTriggers, fired on finalize and delete, matched with the same pattern language storagePolicies uses:
Fires for the resumable path too, once per upload rather than once per chunk. A TUS upload finishes on a much later request than the one that authorised it, so the upload now carries the principal that was checked and the trigger reports that one instead of whoever sent the last chunk.
Three semantics, each with a test:
handlers are awaited, in declaration order, before the response — a floating promise is one a serverless runtime is free to freeze mid-flight;
a throwing handler does not fail the request. The object is already stored, and an error would tell the client to repeat a write that succeeded. Enqueue a job for anything that must happen;
internal writes fire nothing. The rendition cache writes straight to the controller, and a ** trigger firing on those would be firing on its own output.
The pattern matcher moved out of policies.ts into path-pattern.ts, used by both. Two copies of a matcher that access control depends on is one too many: the day they drift, a policy and a trigger disagree about what users/:uid/** means and only one of them is enforcing anything.
Left: the S3-compatible protocol endpoint. That is SigV4 verification plus enough of the REST API to satisfy real tooling, and it wants its own change.
Both landed on main locally and are not pushed — pushing to main publishes a canary, which is yours to trigger.
Activity
fgatti675 commentedon Aug 21, 2026
Second item is done in #13, plus part of the third.
Cacheable delivery: all four response paths now carry a weak
ETagandLast-Modifiedand answer 304, so a reverse proxy or CDN works in front of the existing proxying behaviour without changing it.Two bugs surfaced while doing it and are fixed in the same PR:
Cache-Control: public, including for objects that required credentials — permission for a shared cache to hand one user's private object to the next caller;immutablewas claimed on keys that can be overwritten, so a replaced file stayed invisible for up to a year.Part of the transform-cache item too: the cache key now carries the source's version, so a replaced image no longer serves its old rendition. The cache is still per-instance and still cold after a deploy — moving renditions into the storage source is the rest of that item.
Untouched: declarative per-path policies, the S3-compatible endpoint, and upload/finalize triggers.
fgatti675 commentedon Aug 22, 2026
Delivery half is complete across #13 and #17 (#17 is stacked on #13 — merge #13 first).
#17 adds byte-range requests:
Accept-Ranges,206withContent-Range,416for an unsatisfiable range, and conditional-wins-over-range ordering. Without it a browser wouldn't offer to seek in media served from here, and Safari refuses to play a video whose first response isn't a 206.Local storage reads only the requested slice; S3 and GCS still fetch the object whole, because
StorageControllerhas no ranged read — the saving there is the response body, not the upstream fetch.Untouched: declarative per-path policies, the S3-compatible endpoint, upload/finalize triggers, and making the transform cache durable across instances (its staleness is fixed, its locality isn't).
fgatti675 commentedon Aug 25, 2026
Four of the five items are done; the S3-compatible endpoint is the one left.
Durable transform cache — renditions are written back to the source's own bucket, under the reserved prefix
_rebase/renditions/, keyed by the same string the memory cache uses. That key already carries the source object's size and mtime, so replacing an image serves the new rendition and abandons the old one rather than serving it.It is opt-in (
storageRenditionCache: { enabled: true }, orSTORAGE_RENDITION_CACHE=true), and that is the one decision here worth disagreeing with if you want to. Turning it on makes aGETwrite to the operator's bucket: it costs per object, it puts files nobody uploaded into a place they own, and on read-only credentials it cannot work at all. None of those seemed like a choice to make on an operator's behalf, so the default stays off and a failed write degrades to the in-process cache with the reason logged once rather than once per transform. One line changes the default if you would rather it were on.The prefix is refused as a caller-supplied key in both directions — reading or writing it directly answers
400 INVALID_STORAGE_KEY. Every access rule in the product,storageAuthorizeand the declarative policies alike, is written against the source key; a rendition addressable under its own path would serve a derivative of a private object with nothing having authorised it.Upload and finalize triggers —
storageTriggers, fired onfinalizeanddelete, matched with the same pattern languagestoragePoliciesuses:Fires for the resumable path too, once per upload rather than once per chunk. A TUS upload finishes on a much later request than the one that authorised it, so the upload now carries the principal that was checked and the trigger reports that one instead of whoever sent the last chunk.
Three semantics, each with a test:
**trigger firing on those would be firing on its own output.The pattern matcher moved out of
policies.tsintopath-pattern.ts, used by both. Two copies of a matcher that access control depends on is one too many: the day they drift, a policy and a trigger disagree about whatusers/:uid/**means and only one of them is enforcing anything.Left: the S3-compatible protocol endpoint. That is SigV4 verification plus enough of the REST API to satisfy real tooling, and it wants its own change.
Both landed on
mainlocally and are not pushed — pushing to main publishes a canary, which is yours to trigger.feat(storage): keep image renditions in the bucket, not in one proces…
feat(storage): run something when an object lands
fix(studio): the SQL console offers "Open <collection> #id" only on r…