fix(rbac): scope forced-device policies to channels#2193
Conversation
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThis PR migrates ChangesChannel Devices RLS Policy RBAC Authorization
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 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 |
Merging this PR will not alter performance
Comparing Footnotes
|
bad06de to
9a1ad35
Compare
|
There is a policy-name mismatch that looks security-relevant here. The migration drops If production has the schema-snapshot name, the old broad SELECT policy will not be dropped. PostgreSQL combines permissive RLS policies with OR semantics, so the new I would drop both legacy names in the migration and add a regression assertion that no |
9a1ad35 to
b424d9a
Compare
|
Addressed in
|
b424d9a to
586f69f
Compare
|
|
I think this still needs a regression that the row's The new That means a mismatched row can satisfy |
KCDaemon
left a comment
There was a problem hiding this comment.
Rechecked the latest head (586f69f) and I think this still needs one more authorization/data-integrity guard before merge. The new channel_devices policies pass the row's owner_org, app_id, and channel_id into rbac_check_permission_request(), but rbac_check_permission_direct() resolves p_channel_id back through public.channels and then uses the channel's own owner_org/app_id as the effective permission scope.
That means the permission check can succeed for channel A while the channel_devices row being inserted/updated still carries an independent app_id for app B. The table currently has separate FKs to apps(app_id) and channels(id), and the auto_owner_org_by_app_id trigger only normalizes owner_org from the row's app_id; it does not prove that the submitted channel belongs to that same app/org.
The added pgTAP test verifies the policy text uses channel_id and that old check_min_rights grants are gone, but it does not exercise a mismatched channel/app row. I would keep this blocked until either a composite FK/trigger enforces channel_devices.(app_id, owner_org) matches the referenced channel, or the RLS policy explicitly checks that relationship, with a regression covering the mismatch case. git diff --check origin/main...origin/pr-2193 passes locally.



Summary
channel_devicesRLS to use request-aware channel-scoped forced-device permissionschannel.read_forced_devicesfor direct reads andchannel.manage_forced_devicesfor direct writessupabase/schemas/prod.sqland add a pgTAP policy regression testTest plan
git diff --checkRun testspassed, including the Supabase pgTAP suite withsupabase/tests/55_test_channel_devices_forced_device_rbac.sqlRun Playwright testspassedI could not run the Supabase pgTAP suite locally because this environment does not have
bun,supabase, orpsqlinstalled. The first CI run exposed a pgTAP compatibility issue in the new policy test; I fixed it and the latest CI run is green.Summary by CodeRabbit