-
Notifications
You must be signed in to change notification settings - Fork 189
✨ feat: add RLS policy to Project table #1304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
… control Co-Authored-By: noritaka.ikeda@route06.co.jp <noritaka.ikeda@route06.co.jp>
|
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
Updates to Preview Branch (devin/1744287102-add-project-table-rls) ↗︎
Tasks are run on every commit but only new migration files are pushed.
View logs for this Workflow Run ↗︎. |
|
This PR adds Row Level Security policies to the Project table along with modifications to environment scripts and query filters. The most critical issues concern migration safety and especially the exposure of the Supabase service role key and the removal of status filters without clear performance rationale. Overall, the migration shows strong adherence to project conventions and data integrity patterns, but clarifying testing strategies and key handling will further strengthen the review. Migration URL: https://liam-erd-web.vercel.app/app/projects/6/ref/devin%2F1744287102-add-project-table-rls/migrations/181 ER Diagram:
|
Co-Authored-By: noritaka.ikeda@route06.co.jp <noritaka.ikeda@route06.co.jp>
Co-Authored-By: noritaka.ikeda@route06.co.jp <noritaka.ikeda@route06.co.jp>
Co-Authored-By: noritaka.ikeda@route06.co.jp <noritaka.ikeda@route06.co.jp>
…ed users to insert projects Co-Authored-By: noritaka.ikeda@route06.co.jp <noritaka.ikeda@route06.co.jp>
Co-Authored-By: noritaka.ikeda@route06.co.jp <noritaka.ikeda@route06.co.jp>
Co-Authored-By: noritaka.ikeda@route06.co.jp <noritaka.ikeda@route06.co.jp>
This reverts commit 3948998.
This reverts commit 3948998.
This reverts commit d564c5f.
…ub.com/liam-hq/liam into devin/1744287102-add-project-table-rls
|
This migration adds comprehensive RLS policies to the Project table while also modifying query filters. The most pressing issue is the potential security risk from exposing the service role key and the skipped tests that may affect migration safety and data integrity. Overall, adherence to naming conventions and atomic migration design is commendable, though addressing these concerns is critical. Migration URL: https://liam-app-git-staging-route-06-core.vercel.app/app/projects/6/ref/devin%2F1744287102-add-project-table-rls/migrations/181 ER Diagram:
|
Co-Authored-By: noritaka.ikeda@route06.co.jp <noritaka.ikeda@route06.co.jp>
…ub.com/liam-hq/liam into devin/1744287102-add-project-table-rls
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
NoritakaIkeda
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, but since I built it with Devin, I'd like to have one more person review it.
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||||||||
| - name: Make scripts executable | ||
| run: chmod +x ./scripts/extract-supabase-anon-key.sh ./scripts/extract-supabase-service-key.sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CI threw an error because extract-supabase-service-key.sh didn't have execute permission, so I added it.
| #!/bin/bash | ||
|
|
||
| # Execute the supabase status command and capture its output | ||
| STATUS_OUTPUT=$(pnpm --filter @liam-hq/db exec supabase status) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nits
pnpm supabase status --output json might be useful for that purpose. But in this PR for now, this sh is ok.
| CREATE POLICY "authenticated_users_can_insert_projects" ON "public"."Project" | ||
| FOR INSERT | ||
| TO authenticated | ||
| WITH CHECK (true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% sure, but I think there might be a small concern with the current INSERT policy.
Since there's no check for whether the user belongs to the organization, it might allow someone to create a project under an org they’re not part of.
Maybe adding a WITH CHECK like this could help? (postgres can this?)
| WITH CHECK (true); | |
| WITH CHECK ( | |
| "organizationId" IN ( | |
| SELECT "organizationId" | |
| FROM "public"."OrganizationMember" | |
| WHERE "userId" = auth.uid() | |
| ) | |
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🐛 fix: update RLS policy for project insertion to restrict by organiz…
The approach you suggested worked perfectly, thank you 🙏
I was a bit concerned that the RLS policy might not work for INSERTs since the record hadn’t been created yet, but that turned out to be unnecessary worry.
I've confirmed it works as expected locally.
MH4GF
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍🏻
| COMMENT ON POLICY "authenticated_users_can_select_org_projects" ON "public"."Project" IS 'Authenticated users can only view projects belonging to organizations they are members of'; | ||
| COMMENT ON POLICY "authenticated_users_can_insert_projects" ON "public"."Project" IS 'Authenticated users can create any project'; | ||
| COMMENT ON POLICY "authenticated_users_can_update_org_projects" ON "public"."Project" IS 'Authenticated users can only update projects in organizations they are members of'; | ||
| COMMENT ON POLICY "authenticated_users_can_delete_org_projects" ON "public"."Project" IS 'Authenticated users can only delete projects in organizations they are members of'; | ||
| COMMENT ON POLICY "service_role_can_select_all_projects" ON "public"."Project" IS 'Service role can view all projects (for jobs)'; | ||
| COMMENT ON POLICY "service_role_can_insert_all_projects" ON "public"."Project" IS 'Service role can create any project (for jobs)'; | ||
| COMMENT ON POLICY "service_role_can_update_all_projects" ON "public"."Project" IS 'Service role can update any project (for jobs)'; | ||
| COMMENT ON POLICY "service_role_can_delete_all_projects" ON "public"."Project" IS 'Service role can delete any project (for jobs)'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(aside) nice comments 👍🏻
| CREATE POLICY "authenticated_users_can_select_org_projects" ON "public"."Project" | ||
| FOR SELECT | ||
| TO authenticated | ||
| USING ( | ||
| "organizationId" IN ( | ||
| SELECT "organizationId" | ||
| FROM "public"."OrganizationMember" | ||
| WHERE "userId" = auth.uid() | ||
| ) | ||
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 (aside)
- When working with the Project table, this subquery is automatically evaluated.
- Since this process is evaluated separately for each row of the Project table, it may affect performance for large or frequently accessed tables.
hoshinotsuyoshi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!!



Project Table RLS Policy Implementation
This PR adds Row Level Security (RLS) policies to the Project table to ensure proper access control:
Changes
The project with ID 2 is not part of my organization, so it's being blocked by RLS.
default.mov
I set the Supabase service role key as an environment variable in Trigger.dev and Vercel, and confirmed that the job runs successfully.

Implementation Details
Link to Devin run: https://app.devin.ai/sessions/84ee11eab6fd45359d17cd76110cdcb7
Requested by: noritaka.ikeda@route06.co.jp