CtrlK
BlogDocsLog inGet started
Tessl Logo
PluginPublic

g14wxz/tenant-isolation-rls

Enforces absolute data boundaries between tenants in shared schema via RLS policies on tenant_id.

Quality

100%

Does it follow best practices?

Run evals on this skill

Adds up to 20 points to the overall score

View guide
SecuritybySnyk

Passed

No findings from the security scan

Overview
Quality
Evals
Security
Files

SKILL.mdskills/tenant-isolation-rls/

name:
tenant-isolation-rls
description:
Creates RLS policies enforcing tenant_id isolation on shared-schema tables. Verifies ALTER TABLE ENABLE ROW LEVEL SECURITY before policy creation. Requires tenant_id column and custom-access-token-hook JWT claims. Use when implementing multi-tenant data isolation, tenant-safe queries, shared schema RLS, or tenant_id policy creation.

Pre-Conditions

  • The custom-access-token-hook tile MUST already be deployed and emitting tenant_id inside app_metadata of every JWT.
  • The supabase-mcp-verification tile MUST be available to validate migration output.
  • Target table MUST exist and MUST contain a tenant_id column of type uuid (or text if legacy).
  • Agent MUST confirm no conflicting RLS policies already exist on the target table.

Execution Phases

Phase 1 -- Verify Table Structure

  1. Query information_schema.columns to confirm tenant_id column exists on the target table.
  2. HALT if the column is missing -- do NOT create it automatically without explicit user approval.

Phase 2 -- Enable Row Level Security

  1. Execute ALTER TABLE <schema>.<table> ENABLE ROW LEVEL SECURITY;.
  2. Verify RLS is enabled by querying pg_class.relrowsecurity for the target table.
  3. HALT if the verification query returns false.

Phase 3 -- Create Tenant Isolation Policies

  1. Create a SELECT policy:
    CREATE POLICY tenant_select ON <schema>.<table>
      FOR SELECT USING (
        tenant_id = (auth.jwt() -> 'app_metadata' ->> 'tenant_id')::uuid
      );
  2. Create an INSERT policy with WITH CHECK using the same tenant_id extraction.
  3. Create UPDATE and DELETE policies using the same USING clause.
  4. NEVER use TO public -- always scope policies to authenticated role.

Phase 4 -- Force-Deny Default

  1. Confirm no permissive policy exists for anon role on the target table.
  2. If a permissive policy for anon exists, HALT and report the conflict.

Phase 5 -- Verification Report

  1. Run SELECT policyname, cmd, qual, with_check FROM pg_policies WHERE tablename = '<table>';.
  2. Confirm exactly four policies exist (SELECT, INSERT, UPDATE, DELETE).
  3. Confirm each policy references auth.jwt() -> 'app_metadata' ->> 'tenant_id'.
  4. Report pass/fail for each check. HALT on any failure.

skills

tenant-isolation-rls

tile.json