Skip to main content
Supabase Storage uses PostgreSQL Row Level Security (RLS) to control access to files. This provides fine-grained control over who can upload, download, and delete files.

How Storage RLS Works

Files in Storage are stored as rows in the storage.objects table. RLS policies on this table control access:

Enable RLS

RLS is automatically enabled on the storage.objects table. You need to create policies to allow access:
Without any policies, no one can access files in private buckets. You must create policies to grant access.

Public Buckets

Public buckets allow anyone to read files, but you still need policies for write operations:
Create a public bucket:

Basic Policies

Allow Authenticated Users to Upload

Users Can Access Their Own Files

Folder-Based Access

Organize files in folders and control access per folder:

Public Folder

Authenticated Folder

User-Specific Folders

Advanced Policies

Team-Based Access

Allow team members to access shared files:

File Type Restrictions

Size-Based Restrictions

Time-Based Access

Common Policy Examples

Avatar Upload Pattern

Shared Files with Owner

Helper Functions

Supabase provides helper functions for storage policies:

storage.foldername()

Extract folder path from file name:

storage.filename()

Extract file name:

storage.extension()

Get file extension:

Testing Policies

Test Upload Access

Test Download Access

Bypass RLS with Service Role

Use the service role key to bypass RLS (server-side only):
Never expose the service role key in client-side code. Only use it in secure server environments.

Signed URLs for Private Files

Generate temporary access URLs for private files:

Bucket Policies Dashboard

View and edit policies in the Supabase dashboard:
  1. Navigate to Storage > Policies
  2. Select your bucket
  3. View existing policies
  4. Create new policies using the policy editor

Complete Example: Photo Sharing App

Debugging RLS Policies

Check which policies are active:

Best Practices

Test Policies Thoroughly

Test as different users to ensure policies work correctly

Use Folder Structures

Organize files in folders for easier policy management

Principle of Least Privilege

Grant minimum necessary permissions

Audit File Access

Regularly review and update policies

Common Errors

Next Steps

Row Level Security

Learn more about RLS for database tables

Storage Overview

Back to Storage overview