rls-templates
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.
What this skill does
# 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:**
```bash
# 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:**
```bash
# 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:**
```bash
# 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:**
```bash
# 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**
```sql
-- 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**
```sql
-- 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**
```sql
-- 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
Related in AI Agents
skill-development
IncludedComprehensive meta-skill for creating, managing, validating, auditing, and distributing Claude Code skills and slash commands (unified in v2.1.3+). Provides skill templates, creation workflows, validation patterns, audit checklists, naming conventions, YAML frontmatter guidance, progressive disclosure examples, and best practices lookup. Use when creating new skills, validating existing skills, auditing skill quality, understanding skill architecture, needing skill templates, learning about YAML frontmatter requirements, progressive disclosure patterns, tool restrictions (allowed-tools), skill composition, skill naming conventions, troubleshooting skill activation issues, creating custom slash commands, configuring command frontmatter, using command arguments ($ARGUMENTS, $1, $2), bash execution in commands, file references in commands, command namespacing, plugin commands, MCP slash commands, Skill tool configuration, or deciding between skills vs slash commands. Delegates to docs-management skill for official documentation.
reprompter
IncludedTransform messy prompts into well-structured, effective prompts — single or multi-agent. Use when: "reprompt", "reprompt this", "clean up this prompt", "structure my prompt", rough text needing XML tags and best practices, "reprompter teams", "repromptception", "run with quality", "smart run", "smart agents", multi-agent tasks, audits, parallel work, anything going to agent teams. Don't use when: simple Q&A, pure chat, immediate execution-only tasks. See "Don't Use When" section for details. Outputs: Structured XML/Markdown prompt, quality score (before/after), optional team brief + per-agent sub-prompts, agent team output files. Success criteria: Single mode quality score ≥ 7/10; Repromptception per-agent prompt quality score 8+/10; all required sections present, actionable and specific.
adaptive-compaction
IncludedAdaptive add-on policy and recovery layer that decides WHEN to compact, prune, snapshot, or fork -- replacing fixed-percent auto-compaction across Claude Code, Codex, and MCP-capable hosts. Trigger on auto-compact timing or damage: "when should I compact", "is it safe to compact now or start a fresh session", "auto-compact fires too early/mid-task", "switching to an unrelated task but the window still has space", "context rot", "answers get worse the longer the session runs", "the agent forgot the plan or my decisions after it summarized", "add a layer on top that manages context without changing the agent", raising autoCompactWindow to give the policy room, or installing/tuning a cross-tool compaction policy or PreCompact hook -- even when "compaction" is never said but the problem is context-window pressure or post-summarization memory loss. Do NOT use to summarize a conversation, build RAG, write a summarization prompt (decides WHEN not HOW), or answer max-context-length trivia.
agent-skill-creator
IncludedCreate cross-platform agent skills from workflow descriptions. Activates when users ask to create an agent, automate a repetitive workflow, create a custom skill, or need advanced agent creation. Triggers on phrases like create agent for, automate workflow, create skill for, every day I have to, daily I need to, turn process into agent, need to automate, create a cross-platform skill, validate this skill, export this skill, migrate this skill. Supports single skills, multi-agent suites, transcript processing, template-based creation, interactive configuration, cross-platform export, and spec validation.
llm-wiki
IncludedUse when building or maintaining a persistent personal knowledge base (second brain) in Obsidian where an LLM incrementally ingests sources, updates entity/concept pages, maintains cross-references, and keeps a synthesis current. Triggers include "second brain", "Obsidian wiki", "personal knowledge management", "ingest this paper/article/book", "build a research wiki", "compound knowledge", "Memex", or whenever the user wants knowledge to accumulate across sessions instead of being re-derived by RAG on every query.
skill-master
IncludedAgent Skills authoring, evaluation, and optimization. Create, edit, validate, benchmark, and improve skills following the agentskills.io specification. Use when designing SKILL.md files, structuring skill folders (references, scripts, assets), ingesting external documentation into skills, running trigger evals, benchmarking skill quality, optimizing descriptions, or performing blind A/B comparisons. Keywords: agentskills.io, SKILL.md, skill authoring, eval, benchmark, trigger optimization.