diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts index f1af1ea6dc4..e8505417b3d 100644 --- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts +++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts @@ -2112,7 +2112,7 @@ export const storage: NavMenuConstant = { { name: 'Quickstart', url: '/guides/storage/quickstart' }, { name: 'Fundamentals', url: '/guides/storage/buckets/fundamentals' }, { - name: 'Creating Buckets', + name: 'Creating buckets', url: '/guides/storage/buckets/creating-buckets' as `/${string}`, }, { diff --git a/apps/docs/content/guides/storage/buckets/creating-buckets.mdx b/apps/docs/content/guides/storage/buckets/creating-buckets.mdx index 27f7dcd82fd..72a5fce5a37 100644 --- a/apps/docs/content/guides/storage/buckets/creating-buckets.mdx +++ b/apps/docs/content/guides/storage/buckets/creating-buckets.mdx @@ -1,13 +1,13 @@ --- id: 'storage-creating-buckets' -title: 'Creating Buckets' +title: 'Creating buckets' description: 'Learn how to create Supabase Storage buckets.' sidebar_label: 'Buckets' tocVideo: ch2UGHMreB0 --- You can create a bucket using the Supabase Dashboard. Since storage is interoperable with your Postgres database, you can also use SQL or our client libraries. -Here we create a bucket called "avatars": +The following code examples create a bucket called `avatars`: 1. Go to the [Storage](/dashboard/project/_/storage/buckets) page in the Dashboard. -2. Click **New Bucket** and enter a name for the bucket. -3. Click **Create Bucket**. +2. Click **New bucket** and enter a name for the bucket. +3. Click **Create**. @@ -115,7 +115,7 @@ var bucket = await supabase.Storage.CreateBucket("avatars", new BucketUpsertOpti When creating a bucket you can add additional configurations to restrict the type or size of files you want this bucket to contain. -For example, imagine you want to allow your users to upload only images to the `avatars` bucket and the size must not be greater than 1MB. You can achieve the following by providing `allowedMimeTypes` and `maxFileSize`: +For example, to allow only images of up to 1 MB in the `avatars` bucket, set `allowedMimeTypes` and `fileSizeLimit`: ```js import { createClient } from '@supabase/supabase-js' @@ -131,4 +131,19 @@ const { data, error } = await supabase.storage.createBucket('avatars', { }) ``` -If an upload request doesn't meet the above restrictions it will be rejected. See [File Limits](/docs/guides/storage/uploads/file-limits) for more information. +Storage rejects an upload that doesn't meet the bucket's restrictions. For more information, see [Storage upload limits](/docs/guides/storage/uploads/file-limits). + +To change the restrictions of an existing bucket, call `updateBucket`. The JavaScript SDK requires `public`, so pass the bucket's current value to keep its visibility. `getBucket` returns that value. + +```js +import { createClient } from '@supabase/supabase-js' + +const supabase = createClient('your_project_url', 'your_supabase_api_key') + +// ---cut--- +await supabase.storage.updateBucket('avatars', { + public: true, + allowedMimeTypes: ['image/*'], + fileSizeLimit: '1MB', +}) +``` diff --git a/apps/docs/content/guides/storage/buckets/fundamentals.mdx b/apps/docs/content/guides/storage/buckets/fundamentals.mdx index 977341c0349..bf137ba826c 100644 --- a/apps/docs/content/guides/storage/buckets/fundamentals.mdx +++ b/apps/docs/content/guides/storage/buckets/fundamentals.mdx @@ -35,9 +35,9 @@ The following are example use cases for private buckets: ## Public buckets -When a bucket is set to **Public**, it bypasses access controls for both retrieving and serving files within the bucket. Anyone with the asset URL can access the file. +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](/kb/troubleshooting/why-cant-i-uploadlistetc-my-public-bucket-Z6CmGt) for other types of operations including uploading, deleting, moving, and copying. +[Access control is still enforced](#control-access-to-a-public-bucket) for other operations, including uploading, listing, deleting, moving, and copying. The following are example use cases for public buckets: @@ -47,8 +47,14 @@ The following are example use cases for public buckets: Public buckets get a better cache hit rate than private buckets, because they're [cached differently](/docs/guides/storage/cdn/fundamentals#public-vs-private-buckets). +### 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](/docs/guides/storage/security/access-control#access-policies). The [Security Advisor](/docs/guides/observability/advisors?lint=0025_public_bucket_allows_listing) flags a public bucket that allows listing. + ## Related resources - [Creating buckets](/docs/guides/storage/buckets/creating-buckets): create a bucket and set upload restrictions. -- [Storage access control](/docs/guides/storage/security/access-control): write the RLS policies that private buckets use. +- [Storage access control](/docs/guides/storage/security/access-control): write the RLS policies that control file operations in your buckets. - [Storage CDN](/docs/guides/storage/cdn/fundamentals): how public and private buckets are cached. diff --git a/apps/docs/content/guides/storage/quickstart.mdx b/apps/docs/content/guides/storage/quickstart.mdx index 26bc63cabb3..b3516e07932 100644 --- a/apps/docs/content/guides/storage/quickstart.mdx +++ b/apps/docs/content/guides/storage/quickstart.mdx @@ -45,8 +45,8 @@ You can create a bucket using the Supabase Dashboard. Since the storage is inter 1. Go to the [Storage](/dashboard/project/_/storage/buckets) page in the Dashboard. -2. Click **New Bucket** and enter a name for the bucket. -3. Click **Create Bucket**. +2. Click **New bucket** and enter a name for the bucket. +3. Click **Create**. diff --git a/apps/docs/content/guides/storage/security/access-control.mdx b/apps/docs/content/guides/storage/security/access-control.mdx index 2415214f10f..16e4407ce87 100644 --- a/apps/docs/content/guides/storage/security/access-control.mdx +++ b/apps/docs/content/guides/storage/security/access-control.mdx @@ -1,14 +1,14 @@ --- id: 'storage-access-control' -title: 'Storage Access Control' +title: 'Storage access control' description: 'Learn how to restrict Supabase file uploads.' sidebar_label: 'Uploads' tocVideo: '4ERX__Y908k' --- -Supabase Storage is designed to work perfectly with Postgres [Row Level Security](/docs/guides/database/postgres/row-level-security) (RLS). +Supabase Storage works with Postgres [Row Level Security](/docs/guides/database/postgres/row-level-security) (RLS). -You can use RLS to create [Security Access Policies](https://www.postgresql.org/docs/current/sql-createpolicy.html) that are incredibly powerful and flexible, allowing you to restrict access based on your business needs. +Use RLS to create [access policies](https://www.postgresql.org/docs/current/sql-createpolicy.html) that restrict access to match your app's requirements. ## Access policies @@ -31,23 +31,23 @@ You need policies on `storage.buckets` only when clients call bucket methods. Ea | Delete a bucket | `SELECT` and `DELETE` | None | | Empty a bucket | `SELECT` | `SELECT` and `DELETE` | -You can find the documentation for the storage schema [here](/docs/guides/storage/schema/design) , and to simplify the process of crafting your policies, you can use these [helper functions](/docs/guides/storage/schema/helper-functions) . +For the tables and columns that policies check, see [Storage schema](/docs/guides/storage/schema/design). -If you need different `SELECT` policies for different Storage actions, such as listing objects versus reading authenticated objects, use the operation-aware helpers `storage.allow_only_operation()` and `storage.allow_any_operation()` documented in [Storage Helper Functions](/docs/guides/storage/schema/helper-functions). +If you need different `SELECT` policies for different Storage actions, such as listing objects versus reading authenticated objects, use the operation-aware helpers `storage.allow_only_operation()` and `storage.allow_any_operation()` documented in [Storage helper functions](/docs/guides/storage/schema/helper-functions). -The RLS policies required for different operations are documented [here](/docs/reference/javascript/file-buckets-createbucket) +The [JavaScript Storage reference](/docs/reference/javascript/file-buckets-createbucket) lists the RLS policies for each operation. For example, the only RLS policy required for [uploading](/docs/reference/javascript/file-buckets-upload) objects is to grant the `INSERT` permission to the `storage.objects` table. -To allow overwriting files using the `upsert` functionality you will need to additionally grant `SELECT` and `UPDATE` permissions. +To let users overwrite files with `upsert`, also grant the `SELECT` and `UPDATE` permissions. ## Policy examples -An easy way to get started would be to create RLS policies for `SELECT`, `INSERT`, `UPDATE`, `DELETE` operations and restrict the policies to meet your security requirements. For example, one can start with the following `INSERT` policy: +To get started, create RLS policies for `SELECT`, `INSERT`, `UPDATE`, and `DELETE` operations, and restrict them to meet your security requirements. For example, start with the following `INSERT` policy: ```sql create policy "policy_name" diff --git a/apps/docs/content/guides/storage/uploads/file-limits.mdx b/apps/docs/content/guides/storage/uploads/file-limits.mdx index 3b99d5ddfe8..10d0546dc77 100644 --- a/apps/docs/content/guides/storage/uploads/file-limits.mdx +++ b/apps/docs/content/guides/storage/uploads/file-limits.mdx @@ -27,7 +27,7 @@ Additionally, you can specify the [maximum file size](/kb/troubleshooting/upload ## Per bucket restrictions -You can have different restrictions on a per bucket level such as restricting the file types (e.g. `pdf`, `images`, `videos`) or the maximum file size, which should be lower than the global limit. To apply these limits on a bucket level see [Creating Buckets](/docs/guides/storage/buckets/creating-buckets#restricting-uploads). +You can have different restrictions on a per bucket level such as restricting the file types (e.g. `pdf`, `images`, `videos`) or the maximum file size, which should be lower than the global limit. To apply these limits on a bucket level see [Creating buckets](/docs/guides/storage/buckets/creating-buckets#restricting-uploads). ## File name restrictions