-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update rls policies to be case-insensitive
- Loading branch information
Showing
4 changed files
with
125 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
115 changes: 115 additions & 0 deletions
115
supabase/migrations/20231104084907_make_rls_policies_case_insensitive.sql
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
drop policy "Only owners of registry can add a blueprint to it" on "public"."blueprints"; | ||
|
||
drop policy "Owners of blueprint or minters of blueprint can delete" on "public"."blueprints"; | ||
|
||
drop policy "Delete claims when you are the owner" on "public"."claims"; | ||
|
||
drop policy "Only allow for owner of hyperboard" on "public"."hyperboard_registries"; | ||
|
||
drop policy "Only allow for owner of the hyperboard" on "public"."hyperboard_registries"; | ||
|
||
drop policy "Enable delete for users based on address" on "public"."hyperboards"; | ||
|
||
drop policy "Enable update for users based on address" on "public"."hyperboards"; | ||
|
||
drop policy "Allow owners of registries to delete them based on address" on "public"."registries"; | ||
|
||
drop policy "Allow owners of registries to update based on address" on "public"."registries"; | ||
|
||
alter table "public"."hyperboard_registries" drop constraint "hyperboard_registries_hyperboard_id_fkey"; | ||
|
||
alter table "public"."hyperboard_registries" add constraint "hyperboard_registries_hyperboard_id_fkey" FOREIGN KEY (hyperboard_id) REFERENCES hyperboards(id) ON UPDATE CASCADE ON DELETE CASCADE not valid; | ||
|
||
alter table "public"."hyperboard_registries" validate constraint "hyperboard_registries_hyperboard_id_fkey"; | ||
|
||
create policy "Only allow update for owner of hyperboard" | ||
on "public"."hyperboard_registries" | ||
as permissive | ||
for update | ||
to public | ||
using ((lower((auth.jwt() ->> 'address'::text)) IN ( SELECT lower((hyperboards.admin_id)::text) AS lower | ||
FROM hyperboards | ||
WHERE (hyperboard_registries.hyperboard_id = hyperboards.id)))) | ||
with check ((lower((auth.jwt() ->> 'address'::text)) IN ( SELECT lower((hyperboards.admin_id)::text) AS lower | ||
FROM hyperboards | ||
WHERE (hyperboard_registries.hyperboard_id = hyperboards.id)))); | ||
|
||
|
||
create policy "Only owners of registry can add a blueprint to it" | ||
on "public"."blueprints" | ||
as permissive | ||
for insert | ||
to public | ||
with check ((lower((auth.jwt() ->> 'address'::text)) IN ( SELECT lower((registries.admin_id)::text) AS lower | ||
FROM registries | ||
WHERE (registries.id = blueprints.registry_id)))); | ||
|
||
|
||
create policy "Owners of blueprint or minters of blueprint can delete" | ||
on "public"."blueprints" | ||
as permissive | ||
for delete | ||
to public | ||
using (((lower((auth.jwt() ->> 'address'::text)) = lower((admin_id)::text)) OR (lower((auth.jwt() ->> 'address'::text)) = lower((minter_address)::text)))); | ||
|
||
|
||
create policy "Delete claims when you are the owner" | ||
on "public"."claims" | ||
as permissive | ||
for delete | ||
to public | ||
using ((lower((auth.jwt() ->> 'address'::text)) = lower((admin_id)::text))); | ||
|
||
|
||
create policy "Only allow for owner of hyperboard" | ||
on "public"."hyperboard_registries" | ||
as permissive | ||
for delete | ||
to public | ||
using ((lower((auth.jwt() ->> 'address'::text)) IN ( SELECT lower((hyperboards.admin_id)::text) AS lower | ||
FROM hyperboards | ||
WHERE (hyperboard_registries.hyperboard_id = hyperboards.id)))); | ||
|
||
|
||
create policy "Only allow for owner of the hyperboard" | ||
on "public"."hyperboard_registries" | ||
as permissive | ||
for insert | ||
to public | ||
with check ((lower((auth.jwt() ->> 'address'::text)) IN ( SELECT lower((hyperboards.admin_id)::text) AS lower | ||
FROM hyperboards | ||
WHERE (hyperboard_registries.hyperboard_id = hyperboards.id)))); | ||
|
||
|
||
create policy "Enable delete for users based on address" | ||
on "public"."hyperboards" | ||
as permissive | ||
for delete | ||
to public | ||
using ((lower((auth.jwt() ->> 'address'::text)) = lower((admin_id)::text))); | ||
|
||
|
||
create policy "Enable update for users based on address" | ||
on "public"."hyperboards" | ||
as permissive | ||
for update | ||
to public | ||
using ((lower((auth.jwt() ->> 'address'::text)) = lower((admin_id)::text))) | ||
with check ((lower((auth.jwt() ->> 'address'::text)) = lower((admin_id)::text))); | ||
|
||
|
||
create policy "Allow owners of registries to delete them based on address" | ||
on "public"."registries" | ||
as permissive | ||
for delete | ||
to public | ||
using ((lower((auth.jwt() ->> 'address'::text)) = lower((admin_id)::text))); | ||
|
||
|
||
create policy "Allow owners of registries to update based on address" | ||
on "public"."registries" | ||
as permissive | ||
for update | ||
to public | ||
using ((lower((auth.jwt() ->> 'address'::text)) = lower((admin_id)::text))) | ||
with check ((lower((auth.jwt() ->> 'address'::text)) = lower((admin_id)::text))); |