fix(db): restrict apikey table management RLS#2134
Conversation
📝 WalkthroughWalkthroughThis PR adds Row Level Security (RLS) policies to restrict direct PostgREST access to the ChangesAPI Key Security
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@supabase/migrations/20260511023000_restrict_apikey_table_management_rls.sql`:
- Line 9: Change the policy role target from TO "anon", "authenticated" to TO
"authenticated" so the RLS/admin policy only applies to authenticated sessions;
update every occurrence of the clause (the instance that currently reads TO
"anon", "authenticated" and the other occurrence mentioned around lines 17) to
TO "authenticated" to ensure API-key identity resolution runs through the
authenticated role only.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 2c3688fb-d4cb-4329-89e0-68fca6945e65
📒 Files selected for processing (3)
supabase/migrations/20260511023000_restrict_apikey_table_management_rls.sqlsupabase/schemas/prod.sqlsupabase/tests/53_test_apikey_creation_security.sql
This comment was marked as abuse.
This comment was marked as abuse.
Merging this PR will not alter performance
Comparing Footnotes
|
|



Summary
public.apikeysSELECT/DELETE RLS to JWT callers or unrestrictedallAPI keys by reusingget_identity_for_apikey_creation()/claim #1667
Motivation
The Edge API-key management endpoints already reject org/app-limited API keys. The table policies still allowed direct PostgREST SELECT/DELETE for any owner key with broad enough legacy mode, which left a bypass around those endpoint checks.
Test Plan
git diff --check53_test_apikey_creation_security.sqlnow has 10 planned assertions and 10 assertion callsChecklist