---
id: 'storage-access-control'
title: 'Storage access control'
description: 'Learn how to restrict Supabase file uploads.'
sidebar_label: 'Uploads'
tocVideo: '4ERX__Y908k'
---
Supabase Storage works with Postgres [Row Level Security](/docs/guides/database/postgres/row-level-security) (RLS).
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
By default Storage does not allow any uploads to buckets without RLS policies. You selectively allow certain operations by creating RLS policies on the `storage.objects` table.
Policies on `storage.objects` control every file operation: upload, download, list, move, copy, update, delete, and creating signed URLs. This works the same way in private and public buckets. File operations don't need any policy on `storage.buckets`.
Storage skips the policy check in two cases: a download through the public URL of a [public bucket](/docs/guides/storage/buckets/fundamentals#access-model), and a download or upload through a signed URL, because Storage checked the policies when it created the URL.
To let users read their own files in a private bucket, add a `SELECT` policy on `storage.objects`, such as the "Individual user Access" policy in [Policy examples](#policy-examples).
You need policies on `storage.buckets` only when clients call bucket methods. Each bucket operation needs these permissions:
| Bucket operation | Permissions on `storage.buckets` | Permissions on `storage.objects` |
| ----------------- | -------------------------------- | -------------------------------- |
| Create a bucket | `INSERT` | None |
| Retrieve a bucket | `SELECT` | None |
| List all buckets | `SELECT` | None |
| Update a bucket | `SELECT` and `UPDATE` | None |
| Delete a bucket | `SELECT` and `DELETE` | None |
| Empty a bucket | `SELECT` | `SELECT` and `DELETE` |
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).
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 let users overwrite files with `upsert`, also grant the `SELECT` and `UPDATE` permissions.
## Policy examples
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"
ON storage.objects
for insert with check (
true
);
```
and modify it to only allow authenticated users to upload assets to a specific bucket by changing it to:
```sql
create policy "policy_name"
on storage.objects for insert to authenticated with check (
-- restrict bucket
bucket_id = 'my_bucket_id'
);
```
This example demonstrates how you would allow authenticated users to upload files to a folder called `private` inside `my_bucket_id`:
```sql
create policy "Allow authenticated uploads"
on storage.objects
for insert
to authenticated
with check (
bucket_id = 'my_bucket_id' and
(storage.foldername(name))[1] = 'private'
);
```
This example demonstrates how you would allow authenticated users to upload files to a folder called with their `users.id` inside `my_bucket_id`:
```sql
create policy "Allow authenticated uploads"
on storage.objects
for insert
to authenticated
with check (
bucket_id = 'my_bucket_id' and
(storage.foldername(name))[1] = (select auth.jwt()->>'sub')
);
```
Allow a user to access a file that was previously uploaded by the same user:
```sql
create policy "Individual user Access"
on storage.objects for select
to authenticated
using ( (select auth.jwt()->>'sub') = owner_id );
```
Allow anyone to access objects in the `avatars` bucket via publishable key. The `allow_any_operation()` filter is critical here as without it users would be able to list the bucket contents.
This is not needed for public buckets, as they are already publicly accessible
```sql
create policy "Avatar images are publicly accessible." on storage.objects
for select using (bucket_id = 'avatars' and storage.allow_any_operation(array['object.get_authenticated_info', 'object.get_authenticated']));
```
---
{/* Finish with a video. This also appears in the Sidebar via the "tocVideo" metadata */}
## Bypassing access controls
If you exclusively use Storage from trusted clients, such as your own servers, and need to bypass the RLS policies, you can use the `service key` in the `Authorization` header. Service keys entirely bypass RLS policies, granting you unrestricted access to all Storage APIs.
Remember you should not share the service key publicly.