fix(auth): enforce supabase least privilege and RLS for user-facing r…#3411
Open
Daksh7785 wants to merge 1 commit into
Open
fix(auth): enforce supabase least privilege and RLS for user-facing r…#3411Daksh7785 wants to merge 1 commit into
Daksh7785 wants to merge 1 commit into
Conversation
|
Someone is attempting to deploy a commit to the ritesh Team on Vercel. A member of the Team first needs to authorize it. |
|
Caution Review failedAn error occurred during the review process. Please try again later. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Enforce the principle of least privilege by separating the Supabase anon and service-role keys in the backend, preventing unauthorized bypass of Row Level Security (RLS) in user-facing endpoints.
Root Cause
The backend previously initialized a single global Supabase client using the
SUPABASE_SERVICE_KEYand reused it across all routes and services. Because the service-role key ignores RLS policies, all user operations were effectively executing with administrative database privileges.Solution
backend/supabase_client.pyto manageanon,admin, anduser_scopedclients./tickets,/tickets/search,/tickets/save) to build a dynamically scoped client using the incomingAuthorizationheader.adminclient only to background services (RAG, SLA, Notifications) where elevated permissions are needed..env.exampleto requireSUPABASE_ANON_KEY.Files Changed
backend/.env.example: AddedSUPABASE_ANON_KEY.backend/supabase_client.py(New): Client manager for least-privilege scoping.backend/main.py: Refactored to use user-scoped clients.backend/services/rag_service.py: Usesget_admin_client().backend/services/sla_service.py: Usesget_admin_client().backend/services/notification_routing.py: Usesget_admin_client().backend/services/auto_close_service.py: Usesget_admin_client().Testing
Impact
SUPABASE_ANON_KEYto be defined in the backend.env.Authorizationheader with API requests for RLS to grant access (which it should normally do).Checklist