feat: implement Row Level Security policies (#14) #42

Closed
makiolaj wants to merge 0 commits from feature/issue-14-rls-policies into develop
Owner

Overview

Implements Row Level Security (RLS) policies for all core tables.

Changes

  • Enabled RLS on all 6 tables
  • inventory_items: Shared household inventory - all authenticated users can CRUD
  • products: Read-only for users (service role manages via Edge Functions)
  • tags: Users can create/manage own tags, read all tags (inc. system tags)
  • item_tags: Authenticated users can tag/untag items
  • units: Users can create/manage custom units, read all units
  • user_profiles: Users manage only their own profile
  • Comprehensive policy comments for documentation

Security Model

  • Shared inventory: Simple household model - any authenticated user can modify items
  • System resources: System tags and default units are read-only or admin-editable
  • User resources: Custom tags and units owned by creator
  • Product cache: Managed by service role (Edge Functions), read-only for users

Migration Details

  • File: supabase/migrations/002_rls_policies.sql
  • Policies: 20 security policies across 6 tables
  • Pattern: SELECT (permissive), INSERT/UPDATE/DELETE (auth-gated)

Testing Notes

All policies follow principle of least privilege while supporting the shared household use case.

Dependencies

  • Requires migration 001 (schema) to be applied first

Closes #14

## Overview Implements Row Level Security (RLS) policies for all core tables. ## Changes - ✅ Enabled RLS on all 6 tables - ✅ **inventory_items**: Shared household inventory - all authenticated users can CRUD - ✅ **products**: Read-only for users (service role manages via Edge Functions) - ✅ **tags**: Users can create/manage own tags, read all tags (inc. system tags) - ✅ **item_tags**: Authenticated users can tag/untag items - ✅ **units**: Users can create/manage custom units, read all units - ✅ **user_profiles**: Users manage only their own profile - ✅ Comprehensive policy comments for documentation ## Security Model - **Shared inventory**: Simple household model - any authenticated user can modify items - **System resources**: System tags and default units are read-only or admin-editable - **User resources**: Custom tags and units owned by creator - **Product cache**: Managed by service role (Edge Functions), read-only for users ## Migration Details - **File**: `supabase/migrations/002_rls_policies.sql` - **Policies**: 20 security policies across 6 tables - **Pattern**: SELECT (permissive), INSERT/UPDATE/DELETE (auth-gated) ## Testing Notes All policies follow principle of least privilege while supporting the shared household use case. ## Dependencies - Requires migration 001 (schema) to be applied first Closes #14
makiolaj added 1 commit 2026-02-09 02:38:04 +00:00
feat: add Row Level Security policies (#14)
Some checks failed
Deploy to Coolify / Code Quality (pull_request) Has been cancelled
Deploy to Coolify / Run Tests (pull_request) Has been cancelled
Deploy to Coolify / Deploy to Development (pull_request) Has been cancelled
Deploy to Coolify / Deploy to Production (pull_request) Has been cancelled
Deploy to Coolify / Deploy to Test (pull_request) Has been cancelled
Pull Request Checks / Validate PR (pull_request) Has been cancelled
9f421907eb
- Enable RLS on all 6 tables
- inventory_items: shared inventory (all auth users can CRUD)
- products: read-only for users (service role for writes)
- tags: users can manage own tags, read all tags
- item_tags: auth users can tag/untag items
- units: users can create/manage custom units
- user_profiles: users manage only their own profile
- Comprehensive policy comments for documentation

Closes #14
Author
Owner

APPROVED - Ready to Merge

Reviewer: Pantry Review Bot (AI)
Date: 2026-02-09 02:40 UTC

Strengths

  • Comprehensive - RLS enabled on all 6 tables
  • Shared household model correctly implemented
  • All write operations properly auth-gated
  • Ownership logic protects user resources
  • Service role pattern correct (products read-only for users)
  • Well-documented with descriptive comments

📋 Compliance Checklist

  • RLS enabled on all tables ✓
  • Auth gating correct ✓ (auth.uid() IS NOT NULL)
  • Ownership logic ✓ (users manage own resources)
  • Shared inventory model ✓ (all auth users can CRUD items)
  • Follows DATABASE.md spec ✓ (100% accurate)
  • Policy naming consistent ✓
  • No security holes ✓

🔍 Security Review

All 20 policies reviewed - no critical issues found. Proper implementation of:

  • Shared household inventory (permissive)
  • System resource protection (default units, system tags)
  • User resource ownership (custom tags/units)
  • Service role pattern (products)

🏆 Final Recommendation

Excellent security implementation. No changes required. Ready to merge to develop.

📄 Full review: workspace/pantry-reviews/pr-42.md

## ✅ APPROVED - Ready to Merge **Reviewer**: Pantry Review Bot (AI) **Date**: 2026-02-09 02:40 UTC ### ✅ Strengths - ✅ Comprehensive - RLS enabled on all 6 tables - ✅ Shared household model correctly implemented - ✅ All write operations properly auth-gated - ✅ Ownership logic protects user resources - ✅ Service role pattern correct (products read-only for users) - ✅ Well-documented with descriptive comments ### 📋 Compliance Checklist - [x] RLS enabled on all tables ✓ - [x] Auth gating correct ✓ (auth.uid() IS NOT NULL) - [x] Ownership logic ✓ (users manage own resources) - [x] Shared inventory model ✓ (all auth users can CRUD items) - [x] Follows DATABASE.md spec ✓ (100% accurate) - [x] Policy naming consistent ✓ - [x] No security holes ✓ ### 🔍 Security Review All 20 policies reviewed - no critical issues found. Proper implementation of: - Shared household inventory (permissive) - System resource protection (default units, system tags) - User resource ownership (custom tags/units) - Service role pattern (products) ### 🏆 Final Recommendation **Excellent security implementation.** No changes required. Ready to merge to `develop`. 📄 Full review: `workspace/pantry-reviews/pr-42.md`
makiolaj closed this pull request 2026-02-09 12:36:12 +00:00
Some checks failed
Deploy to Coolify / Code Quality (pull_request) Has been cancelled
Deploy to Coolify / Run Tests (pull_request) Has been cancelled
Deploy to Coolify / Deploy to Development (pull_request) Has been cancelled
Deploy to Coolify / Deploy to Production (pull_request) Has been cancelled
Deploy to Coolify / Deploy to Test (pull_request) Has been cancelled
Pull Request Checks / Validate PR (pull_request) Has been cancelled

Pull request closed

Sign in to join this conversation.