From ce3e5ecf86bd51595a75f6dc431a70107edeea1f Mon Sep 17 00:00:00 2001 From: BekahHW Date: Fri, 19 Dec 2025 14:17:33 -0500 Subject: [PATCH] Simplify supabase --- .../mission-control/integrations/supabase.mdx | 603 ++++-------------- 1 file changed, 108 insertions(+), 495 deletions(-) diff --git a/docs/mission-control/integrations/supabase.mdx b/docs/mission-control/integrations/supabase.mdx index c29d35b6f..4f8ea2187 100644 --- a/docs/mission-control/integrations/supabase.mdx +++ b/docs/mission-control/integrations/supabase.mdx @@ -3,524 +3,137 @@ title: "Supabase Integration" description: "Monitor database security, generate migrations, and optimize queries with Continue Agents connected to Supabase" --- -## Overview - -Connect Supabase to Continue Mission Control to enable AI-powered database workflows. When Supabase is enabled, Continue can audit Row Level Security (RLS) policies, generate secure migrations, optimize queries, and maintain database security automatically. - - - - - Automatically audit RLS policies on every PR - - Generate secure migrations for missing security policies - - Identify and fix critical security gaps - - Optimize database queries and schemas - - Monitor database performance and security - - Validate schema changes before deployment +Connect **Supabase** to Mission Control so agents can automatically review **Row Level Security (RLS)** when pull requests touch database-related code. The official workflow focuses on the tables your PR actually references, fixes high-impact gaps, and reports results back in a single PR comment. + + - Audit RLS policies for tables referenced in PR changes + - Generate SQL migrations to remediate missing or unsafe policies + - Commit fixes for **Critical / High / Medium** issues to the PR branch + - Post (or update) a single PR comment with scope, findings, and changes -## Setup - - - - - - Go to the [Supabase Integration](https://hub.continue.dev/integrations/supabase). - - - - - - Click "Connect" to Supabase. - - - - - - You'll be redirected to Supabase to authorize Continue: - 1. Select the Supabase organization and project to connect - 2. Review the requested permissions - 3. Click "Authorize" to complete the connection - - - - - - After connecting, set up your first workflow. The integration supports: - - **On PR open**: Audit RLS policies when PRs are created - - **Manual tasks**: Run database operations on-demand - - **Scheduled jobs**: Periodic security audits and performance checks - - - - - -## Workflows - -### Supabase security review - -**Trigger**: On PR open -**Description**: Connect your Supabase workspace to agents that can explore schemas, run queries, create and update documents, and handle migrations using natural language - -When a pull request is opened, this security-focused workflow automatically: - -1. **Analyzes PR Changes** - Identifies affected tables from: - - Migration files (`supabase/migrations/*.sql`) - - SDK/library usage (`.from('table_name')` calls) - - Schema references in type definitions - -2. **Audits RLS Policies** - Uses Supabase MCP to inspect: - - Whether RLS is enabled on affected tables - - Existing policy configurations - - Potential security gaps - -3. **Classifies Security Risks** - Prioritizes findings by severity: - - πŸ”΄ **Critical**: No RLS on tables with sensitive data - - 🟠 **High**: Overly permissive policies (e.g., `USING (true)`) - - 🟑 **Medium**: Missing standard access patterns - - 🟒 **Low**: Policy optimization opportunities - -4. **Generates SQL Migrations** - Creates fixes for Critical/High/Medium issues: - - Enables RLS on unprotected tables - - Adds missing user-scoped policies - - Implements proper access controls - - Includes rollback commands - -5. **Commits Fixes to PR Branch** - Automatically pushes security fixes -6. **Posts Comprehensive Comment** - Explains all findings and changes - - - - Row Level Security (RLS) is Supabase's primary security mechanism. Without proper RLS policies: - - Users can access other users' private data - - Unauthorized modifications can occur - - Sensitive information may be exposed - - This workflow automatically catches these issues before they reach production. - - - - - - **Smart Scoping**: The agent only audits tables directly referenced in your PR changes, not your entire database. This keeps audits focused and efficient. - - - -#### Example PR Comment - -After auditing RLS policies, the agent posts a comprehensive comment like this: - -```markdown -## πŸ”’ Supabase RLS Policy Audit - -### Scope -This audit covers **3 tables** referenced in this PR: -- user_profiles (detected in: migration file) -- comments (detected in: SDK usage in src/api/comments.ts) -- posts (detected in: migration file) - -### Summary -- βœ… 1 table with proper RLS -- ⚠️ 2 tables requiring attention -- πŸ”΄ 1 critical security gap found - -### Findings - -| Table | Risk Level | Issue | Status | -|-------|------------|-------|--------| -| `user_profiles` | πŸ”΄ Critical | No RLS enabled | βœ… Fixed in commit abc123 | -| `comments` | 🟑 Medium | Missing delete policy | βœ… Fixed in commit abc123 | -| `posts` | 🟒 Low | Policy optimization possible | πŸ’‘ Recommendation | - -### Changes Made - -- Enabled RLS on `user_profiles` -- Added policies: `user_profiles_select_own`, `user_profiles_update_own`, `comments_delete_own` -- See full migration: `supabase/migrations/20241118120000_rls_security_fixes.sql` - -### Recommendations (Low Priority) - -- **posts table**: Consider renaming policy `posts_policy_1` to `posts_select_owner` for clarity - -### Policy Patterns Used - -**User-scoped access** (users access only their own data): -\```sql -USING (auth.uid() = user_id) -WITH CHECK (auth.uid() = user_id) -\``` - -### Next Steps - -- βœ… Review the migration file and committed changes -- βœ… Test the policies in your development environment -- βœ… Merge this PR once you've verified the security improvements -``` - -### Security Risk Levels Explained - - - - **What it means**: Tables with no RLS that contain sensitive data - - **Examples**: - - User profiles, emails, or authentication data - - Financial information or payment details - - Private messages or personal content - - New tables created without RLS - - **What the agent does**: Automatically enables RLS and adds basic policies - - - - - - **What it means**: Overly permissive policies that could allow unauthorized access - - **Examples**: - - Policies using `USING (true)` without justification - - Write access without proper validation - - Admin policies that don't verify admin status - - Missing `WITH CHECK` clauses - - **What the agent does**: Generates restrictive policies with proper checks - - - - - - **What it means**: Partial RLS coverage or missing standard patterns - - **Examples**: - - SELECT policy exists but no UPDATE/DELETE - - No user-scoped policies for personal data - - Missing public read policies where appropriate - - Incomplete CRUD policy coverage - - **What the agent does**: Adds missing policies following standard patterns - - - - - - **What it means**: Policies work but could be improved - - **Examples**: - - Poor policy naming conventions - - Inefficient policy logic - - Missing documentation - - Duplicate or redundant policies - - **What the agent does**: Suggests improvements in PR comment (no auto-fix) - - - -## Use Cases - -### Automated Security Audits - -Catch security issues before they reach production: - - - - **Task Example**: Automatically audit RLS on every PR that touches database schema or queries - - **What the Agent Does**: - - Scans PR for database-related changes - - Identifies all affected tables - - Checks RLS status and policies - - Generates fixes for security gaps - - Commits migrations to the PR branch - - **Run in Mission Control**: Triggered automatically on PR open - - - -### Database Migration Generation - -Create secure migrations automatically: - - - - **Task Example**: "Generate a migration to add RLS policies for the new messages table" - - **What the Agent Does**: - - Analyzes table structure and purpose - - Determines appropriate access patterns - - Generates SQL with RLS policies - - Includes proper naming and comments - - Adds rollback commands - - **Run in Mission Control**: Run manually or on schema changes - - - -### Query Optimization - -Improve database performance: - - - - **Task Example**: "Analyze slow queries and suggest optimizations" - - **What the Agent Does**: - - Identifies queries in your codebase - - Checks for missing indexes - - Suggests query rewrites - - Recommends schema changes - - Estimates performance impact - - **Run in Mission Control**: Schedule weekly performance reviews - - - -### Schema Validation - -Ensure schema changes follow best practices: - - - - **Task Example**: "Validate that all new tables follow our schema standards" - - **What the Agent Does**: - - Checks naming conventions - - Validates data types and constraints - - Ensures proper indexes exist - - Verifies RLS is enabled - - Reviews foreign key relationships - - **Run in Mission Control**: Triggered on migration file changes - - - -### Access Pattern Analysis - -Understand how your database is used: - - - - **Task Example**: "Analyze SDK usage patterns and suggest RLS policies" - - **What the Agent Does**: - - Scans codebase for Supabase client calls - - Identifies data access patterns - - Detects security anti-patterns - - Recommends appropriate RLS policies - - Generates migration files - - **Run in Mission Control**: Run before major releases - - - -### Development Environment Sync - -Keep dev and production schemas aligned: - - - - **Task Example**: "Compare dev and production schemas and generate sync migrations" - - **What the Agent Does**: - - Connects to multiple Supabase projects - - Compares schema definitions - - Identifies differences - - Generates sync migrations - - Validates compatibility - - **Run in Mission Control**: Schedule or run manually - - - -## Running Supabase Agents in Mission Control - -You can run Supabase-connected agents in two ways as [one-off tasks](../tasks) or automated [workflows](../workflows): +--- + +## Official Workflow Templates + +The following **official workflow template** is maintained by the Continue team and is available directly in the Mission Control Hub. This workflow is designed to work out of the box and represents the recommended way to automate Supabase security reviews. + + + + When a pull request is opened, automatically audits RLS for tables referenced in that PR, commits fixes for Critical/High/Medium issues, and posts (or updates) a single PR comment with results. + + + +### Risk Levels Explained + + + Tables with sensitive data that have **no RLS enabled**. + + **Examples** + - User profiles or authentication-related tables + - Financial or billing data + - Private messages or personal content + + **What happens** + - RLS is enabled automatically + - Baseline access policies are generated + - Fixes are committed directly to the PR branch + + + + Policies exist but are **overly permissive** or unsafe. + + **Examples** + - Policies using `USING (true)` + - Write access without proper ownership checks + - Admin policies without role validation + + **What happens** + - Restrictive policies are generated + - Unsafe rules are replaced + - Fixes are committed to the PR branch + + + + Partial or incomplete RLS coverage. + + **Examples** + - SELECT policy exists but UPDATE or DELETE is missing + - Missing user-scoped access patterns + - Incomplete CRUD coverage + + **What happens** + - Missing policies are added + - Fixes are committed to the PR branch + + + + Policies work, but could be improved. + + **Examples** + - Poor policy naming + - Redundant or inefficient rules + - Missing documentation + + **What happens** + - No automatic fixes + - Suggestions are included in the PR comment only + + - - Start with manual tasks to refine your content queries, then automate repetitive content management and validation tasks. - +Official workflow templates may expand over time as new patterns are validated. You can view, enable, and configure this workflow in **[Mission Control β†’ Integrations β†’ Supabase](https://hub.continue.dev/integrations/supabase)**. -## Common RLS Policy Patterns +## Advanced Use Cases -The agent recognizes and implements these standard security patterns: - -### User-Scoped Access - -Users can only access their own data: - -```sql --- SELECT: Users can read their own records -CREATE POLICY "users_select_own" ON user_profiles -FOR SELECT USING (auth.uid() = user_id); - --- UPDATE: Users can update their own records -CREATE POLICY "users_update_own" ON user_profiles -FOR UPDATE USING (auth.uid() = user_id) -WITH CHECK (auth.uid() = user_id); - --- DELETE: Users can delete their own records -CREATE POLICY "users_delete_own" ON user_profiles -FOR DELETE USING (auth.uid() = user_id); -``` - -### Admin Override - -Admins can access all data while users access only their own: - -```sql -CREATE POLICY "posts_select_owner_or_admin" ON posts -FOR SELECT USING ( - auth.uid() = user_id OR - auth.jwt() ->> 'role' = 'admin' -); -``` - -### Public Read, Authenticated Write - -Anyone can read, only authenticated users can write: - -```sql --- Public read access -CREATE POLICY "public_posts_select" ON public_posts -FOR SELECT USING (true); - --- Authenticated insert only -CREATE POLICY "public_posts_insert_auth" ON public_posts -FOR INSERT WITH CHECK (auth.role() = 'authenticated'); -``` - -### Soft Delete Handling - -Exclude soft-deleted records from queries: - -```sql -CREATE POLICY "posts_select_not_deleted" ON posts -FOR SELECT USING ( - deleted_at IS NULL AND - (auth.uid() = user_id OR is_published = true) -); -``` - -## Troubleshooting - - - - **Problem**: Agent can't connect to Supabase - - **Solutions**: - - Re-authenticate through the integrations page - - Verify OAuth token hasn't expired (expires after 7 days) - - Check project permissions - - Ensure Supabase project is accessible - - For CI/CD, verify environment variables are set + +These examples are not officially maintained by the Continue team, but illustrate what’s possible with custom workflows. +- Run scheduled audits across high-risk tables (beyond PR scope) +- Generate migration suggestions for schema changes even when no issues are Critical/High/Medium +- Review SQL performance risks (missing indexes, expensive queries) before merge +- Enforce schema conventions (naming, constraints, standard columns) +- Generate β€œsecurity notes” summaries for release PRs or weekly reports - +--- - **Problem**: Agent reports no tables found to audit +## Access & Permissions - **Solutions**: - - Verify PR contains database-related changes - - Check that migration files use standard naming - - Ensure SDK calls use `.from('table_name')` pattern - - Review PR for schema/type definition changes +When connecting Supabase, you’ll authorize Continue to access your Supabase project(s) through the integration. - +- **Project selection** + Choose the Supabase organization and project you want Mission Control to connect to. - +- **Permissions** + Approved permissions allow Continue to inspect RLS and policies, generate recommended migrations, and support workflows that comment on PRs and commit fixes. - **Problem**: Agent identifies issues but doesn't create fixes +You can update or revoke access at any time from Supabase or the Mission Control Hub. - **Solutions**: - - Check if issues are Low priority (agent suggests only) - - Verify agent has write access to repository - - Review error messages in agent logs - - Ensure Supabase MCP connection is working - - Check if migration directory exists - - - - - - **Problem**: Auto-generated RLS policies block legitimate access - - **Solutions**: - - Review and adjust policies in the generated migration - - Add custom logic for your specific access patterns - - Mark tables for manual policy creation if needed - - Provide feedback to improve future policy generation - - - - - - **Problem**: Generated migration conflicts with existing changes - - **Solutions**: - - Review both migrations and merge manually - - Ensure migration timestamps are unique - - Check for duplicate policy names - - Adjust generated migration as needed - - - -## Security Best Practices - - - - **Development vs. Production**: - - Always test RLS policies in development first - - Use separate Supabase projects for dev/staging/prod - - Never disable RLS on production tables - - Review all generated policies before deploying - - Test policies with different user roles - - - - - - Before deploying RLS changes, verify: - - [ ] RLS is enabled on all sensitive tables - - [ ] Policies cover all CRUD operations (SELECT, INSERT, UPDATE, DELETE) - - [ ] User-scoped data includes `auth.uid()` checks - - [ ] Admin overrides verify admin role properly - - [ ] Public access is intentional and documented - - [ ] Policies include `WITH CHECK` clauses for writes - - [ ] Soft deletes filter out `deleted_at IS NOT NULL` - - [ ] Policy names follow naming conventions - - [ ] Rollback commands are included - - [ ] Policies are tested with different user scenarios - - +--- ## Support & Resources - - - - Complete guide to database security automation with Supabase and Continue - + + Combine Supabase with GitHub for PR-triggered security workflows. - - - Combine Supabase with GitHub for automated security workflows - + + Learn more about Row Level Security and recommended policy patterns. - - - - Official Supabase Row Level Security documentation - - - - - - Learn about the Supabase MCP Server. - - -