Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Comprehensive Postgres performance optimization and best practices guide maintained by Supabase
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/security-privileges.md
1---2title: Apply Principle of Least Privilege3impact: MEDIUM4impactDescription: Reduced attack surface, better audit trail5tags: privileges, security, roles, permissions6---78## Apply Principle of Least Privilege910Grant only the minimum permissions required. Never use superuser for application queries.1112**Incorrect (overly broad permissions):**1314```sql15-- Application uses superuser connection16-- Or grants ALL to application role17grant all privileges on all tables in schema public to app_user;18grant all privileges on all sequences in schema public to app_user;1920-- Any SQL injection becomes catastrophic21-- drop table users; cascades to everything22```2324**Correct (minimal, specific grants):**2526```sql27-- Create role with no default privileges28create role app_readonly nologin;2930-- Grant only SELECT on specific tables31grant usage on schema public to app_readonly;32grant select on public.products, public.categories to app_readonly;3334-- Create role for writes with limited scope35create role app_writer nologin;36grant usage on schema public to app_writer;37grant select, insert, update on public.orders to app_writer;38grant usage on sequence orders_id_seq to app_writer;39-- No DELETE permission4041-- Login role inherits from these42create role app_user login password 'xxx';43grant app_writer to app_user;44```4546Revoke public defaults:4748```sql49-- Revoke default public access50revoke all on schema public from public;51revoke all on all tables in schema public from public;52```5354Reference: [Roles and Privileges](https://supabase.com/blog/postgres-roles-and-privileges)55