Storage buckets
Knowing the difference between public and private buckets tells you which kind to create for each kind of file. For how to create a bucket, see Creating buckets.
Access model
Buckets keep your files organized and determine the access model for your assets. There are two access models for buckets, public and private:
| Access model | Retrieving and serving files | Other operations |
|---|---|---|
| Private | Downloads with the user's JWT are subject to RLS policies. A signed URL gives access until it expires. | Subject to RLS policies |
| Public | Anyone with the asset URL | Access control enforced |
Upload restrictions like max file size and allowed content types are also defined at the bucket level.
Private buckets
When a bucket is set to Private, all operations are subject to access control via RLS policies. This also applies when downloading assets. Buckets are private by default.
The only ways to download assets within a private bucket are:
- Use the download method by providing an authorization header containing your user's JWT. The RLS policy you create on the
storage.objectstable uses this user to determine if they have access. - Create a signed URL with the
createSignedUrlmethod that can be accessed for a limited time.
The following are example use cases for private buckets:
- Uploading users' sensitive documents
- Securing private assets by using RLS to set up fine-grain access controls
Public buckets
When a bucket is set to Public, anyone with a file's public URL can download it. Storage skips access controls when it serves a file from a public bucket.
Access control is still enforced for other operations, including uploading, listing, deleting, moving, and copying.
The following are example use cases for public buckets:
- User profile pictures
- User public media
- Blog post content
Public buckets get a better cache hit rate than private buckets, because they're cached differently.
Control access to a public bucket
A public bucket needs no policy for downloads by URL, so don't add a SELECT policy to make files readable. A SELECT policy that matches the whole bucket, such as using (bucket_id = 'avatars'), lets clients list every object in it.
Listing, overwrites, moves, copies, and deletes each need a SELECT policy. Scope it to the user's own objects with an owner_id or folder check. For the permissions each operation needs, see Access policies. The Security Advisor flags a public bucket that allows listing.
Related resources
- Creating buckets: create a bucket and set upload restrictions.
- Storage access control: write the RLS policies that control file operations in your buckets.
- Storage CDN: how public and private buckets are cached.