RLS Templates for Supabase

VerifiedCaution

Provides production-ready Row Level Security policy templates for Supabase applications. Covers multi-tenant patterns, user isolation, role-based access, and AI-specific patterns like chat and embedding security. Helps quickly implement and test RLS policies to secure user data in Supabase projects.

Sby Skills Guide Bot
SecurityIntermediate
6/2/2026
Claude Code
#supabase#row-level-security#multi-tenant#user-isolation#ai-apps

Recommended for

Automated summary

This skill provides production-ready Row Level Security (RLS) policy templates for Supabase, covering multi-tenant isolation, user-specific data, role-based access, and AI application patterns.

Strengths

  • Ready-to-use templates for multi-tenant and AI use cases
  • Automated scripts to apply, test, and audit RLS policies
  • Covers multiple patterns: user isolation, role-based, embeddings

Limitations

  • Requires prior knowledge of PostgreSQL and Supabase
  • Generic policies may need customization for specific schemas
  • Depends on a properly configured Supabase environment (env variables)
When to use it

Use this skill when you need to secure Supabase tables in multi-tenant apps, chatbots, or RAG systems with strict data isolation.

When not to use it

Do not use this skill if your database is not PostgreSQL/Supabase, or if your security needs are already covered by an existing framework.

Security analysis

Caution
Quality score88/100

The skill uses bash scripts to apply RLS policies and interact with the database using service admin keys. While the purpose is legitimate security configuration, the execution of external scripts with administrative credentials carries inherent risk if the scripts are malicious or contain errors.

Findings
  • •Requires SUPABASE_SERVICE_KEY (admin access) which can be misused if scripts are compromised
  • •Runs bash scripts that modify database security policies; script contents not verified
How this analysis is made

Examples

Secure chat conversations
Apply RLS policies to my Supabase chat tables (conversations, messages) using the user-isolation pattern so that each user only sees their own data.
Multi-tenant RAG audit
Audit my Supabase database for missing RLS and then apply the multi-tenant and embeddings policies to protect documents and vector embeddings per organization.
Role-based admin panel
Generate and apply role-based RLS policies for an admin panel where admins have full access, editors can write, and viewers can only read.

name: rls-templates description: Row Level Security policy templates for Supabase - multi-tenant patterns, user isolation, role-based access, and secure-by-default configurations. Use when securing Supabase tables, implementing RLS policies, building multi-tenant AI apps, protecting user data, creating chat/RAG systems, or when user mentions row level security, RLS, Supabase security, tenant isolation, or data access policies. allowed-tools: Bash, Read, Write, Edit

RLS Templates

Production-ready Row Level Security policy templates for Supabase applications, with focus on AI application patterns (multi-tenant chat, RAG systems, user-specific embeddings).

Instructions

1. Applying RLS Policies

Apply policies to tables:

# Apply user isolation policies
bash scripts/apply-rls-policies.sh user-isolation conversations messages

# Apply multi-tenant policies
bash scripts/apply-rls-policies.sh multi-tenant organizations org_members documents

# Apply AI-specific policies
bash scripts/apply-rls-policies.sh ai-chat conversations messages message_embeddings

Generate custom policy:

# Generate policy from template
bash scripts/generate-policy.sh user-isolation my_table user_id

# Generate with custom column
bash scripts/generate-policy.sh multi-tenant projects organization_id

2. Testing RLS Enforcement

Test policies work correctly:

# Test all policies on a table
bash scripts/test-rls-policies.sh conversations

# Test specific user context
bash scripts/test-rls-policies.sh messages --user-id "user-uuid-here"

# Test multi-tenant isolation
bash scripts/test-rls-policies.sh documents --org-id "org-uuid-here"

3. Auditing Security

Audit tables for missing RLS:

# Audit all tables in public schema
bash scripts/audit-rls.sh

# Audit specific tables
bash scripts/audit-rls.sh conversations messages embeddings

# Generate audit report
bash scripts/audit-rls.sh --report audit-report.md

4. Policy Pattern Selection

Choose the right pattern:

  • user-isolation.sql: User owns row directly (user_id column)

    • Use for: User profiles, settings, personal documents
    • Pattern: auth.uid() = user_id
  • multi-tenant.sql: Organization/team-based isolation

    • Use for: SaaS apps, team workspaces, shared resources
    • Pattern: Check organization membership via join
  • role-based-access.sql: Different permissions per role

    • Use for: Admin panels, hierarchical access, permission levels
    • Pattern: Check role from auth.jwt() claims
  • ai-chat-policies.sql: Chat/conversation data

    • Use for: AI chat apps, message history, conversation threads
    • Pattern: User owns conversation + participants table
  • embeddings-policies.sql: Vector/embedding data

    • Use for: RAG systems, semantic search, vector databases
    • Pattern: User owns source document that owns embeddings

Examples

Example 1: Secure Chat Application

-- Apply chat policies to tables
\i templates/ai-chat-policies.sql

-- Tables: conversations, messages, participants
-- Result: Users only see conversations they participate in

Example 2: Multi-Tenant RAG System

-- Apply organization isolation
\i templates/multi-tenant.sql

-- Apply embedding security
\i templates/embeddings-policies.sql

-- Tables: organizations, documents, document_embeddings
-- Result: Each org only sees their own documents and embeddings

Example 3: Role-Based Admin Panel

-- Apply role-based policies
\i templates/role-based-access.sql

-- Roles: admin (full access), editor (read/write), viewer (read-only)
-- Result: Different permissions based on user role

Requirements

Prerequisites

  • Supabase project with database access
  • PostgreSQL client (psql) installed
  • Environment variables set:
    • SUPABASE_DB_URL: PostgreSQL connection string
    • SUPABASE_ANON_KEY: For testing anon access
    • SUPABASE_SERVICE_KEY: For admin operations

Security Checklist

  • [ ] RLS enabled on all tables in public schema
  • [ ] Policies test both authenticated and anonymous access
  • [ ] Indexes created on columns used in policies (user_id, org_id, etc.)
  • [ ] Service key never exposed to client applications
  • [ ] Policies use (SELECT auth.uid()) for performance
  • [ ] WITH CHECK clause included on INSERT/UPDATE policies
  • [ ] Testing validates isolation between users/tenants

Performance Optimization

  • Create indexes: CREATE INDEX idx_table_user_id ON table(user_id);
  • Wrap auth functions: (SELECT auth.uid()) instead of auth.uid()
  • Always filter queries: .eq('user_id', userId) in client code
  • Use security definer functions for complex authorization logic
  • Specify roles in policies: TO authenticated to skip anon checks

Best Practices:

  1. Enable RLS before adding any data
  2. Test with multiple user contexts
  3. Use audit script regularly in CI/CD
  4. Document policy decisions in migration files
  5. Monitor query performance after adding policies

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/rls-templates-for-supabase-mm78no29/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/rls-templates-for-supabase-mm78no29' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/rls-templates-for-supabase-mm78no29/download' --output '.skill-downloads/rls-templates-for-supabase-mm78no29/SKILL.md.part' && mv '.skill-downloads/rls-templates-for-supabase-mm78no29/SKILL.md.part' '.skill-downloads/rls-templates-for-supabase-mm78no29/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

Tools declared by the author (check availability in your agent): Bash, Read, Write, Edit

Original excerpt: Requirements

Prerequisites

  • Supabase project with database access
  • PostgreSQL client (psql) installed
  • Environment variables set:
    • SUPABASE_DB_URL: PostgreSQL connection string
    • SUPABASE_ANON_KEY: For testing anon access
    • SUPABASE_SERVICE_KEY: For admin operations

Security Checklist

  • RLS enabled on all tables in public schema
  • Policies test both authenticated and anonymous access
  • Indexes created on columns used in policies (user_id, org_id, etc.)
  • Service key never exposed to client applications
  • Policies use (SELECT auth.uid()) for performance
  • WITH CHECK clause included on INSERT/UPDATE policies
  • Testing validates isolation between users/tenants

Performance Optimization

  • Create indexes: CREATE INDEX idx_table_user_id ON table(user_id);
  • Wrap auth functions: (SELECT auth.uid()) instead of auth.uid()
  • Always filter queries: .eq('user_id', userId) in client code
  • Use security definer functions for complex authorization logic
  • Specify roles in policies: TO authenticated to skip anon checks

Best Practices:

  1. Enable RLS before adding any data
  2. Test with multiple user contexts
  3. Use audit script regularly in CI/CD
  4. Document policy decisions in migration files
  5. Monitor query performance after adding policies

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.

Claude Code
test -f '.skill-downloads/rls-templates-for-supabase-mm78no29/SKILL.md' && test -s '.skill-downloads/rls-templates-for-supabase-mm78no29/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/rls-templates' && cp -R '.skill-downloads/rls-templates-for-supabase-mm78no29' '.claude/skills/rls-templates'

OpenSkills

OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.

Official OpenSkills installation
openskills install './.skill-downloads/rls-templates-for-supabase-mm78no29'

openskills read 'rls-templates-for-supabase-mm78no29'

Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.

For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.

openskills sync

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/rls-templates-for-supabase-mm78no29/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills