How Storage RLS Works
Files in Storage are stored as rows in thestorage.objects table. RLS policies on this table control access:
Enable RLS
RLS is automatically enabled on thestorage.objects table. You need to create policies to allow access:
Public Buckets
Public buckets allow anyone to read files, but you still need policies for write operations: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):Signed URLs for Private Files
Generate temporary access URLs for private files:Bucket Policies Dashboard
View and edit policies in the Supabase dashboard:- Navigate to Storage > Policies
- Select your bucket
- View existing policies
- 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
