Repository navigation
fix(db): make legacy Data API grants explicit #70
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
31 changes: 31 additions & 0 deletions
31
supabase/migrations/20260923191320_explicit_legacy_table_grants.sql
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| -- Older table-creation migrations relied on Supabase's automatic public grants. | ||
| -- Make their final Data API permissions explicit for new projects and db reset. | ||
|
|
||
| GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE | ||
| public.user_settings, | ||
| public.cases, public.attacks, public.brainstorms, public.factoids, | ||
| public.chats, public.messages, public.sources, public.source_files, | ||
| public.ai_requests, public.api_keys, | ||
| public.user_roles, public.rate_limits, public.global_prompts, | ||
| public.flowcharts, | ||
| public.subscriptions, public.promo_codes, public.user_promos, | ||
| public.admin_grants, public.shared_items, public.source_folders, | ||
| public.daily_usage_counters | ||
| TO service_role; | ||
|
|
||
| GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE | ||
| public.cases, public.attacks, public.brainstorms, public.factoids, | ||
| public.chats, public.messages, public.sources, public.source_files, | ||
| public.api_keys, public.flowcharts, public.source_folders | ||
| TO authenticated; | ||
|
|
||
| GRANT SELECT ON TABLE | ||
| public.user_roles, public.rate_limits, public.subscriptions, | ||
| public.user_promos, public.admin_grants, public.ai_requests | ||
| TO authenticated; | ||
|
|
||
| -- Settings keep their existing SELECT and column-limited UPDATE grants; | ||
| -- shared items and global prompts remain server-owned. | ||
|
|
||
| -- The existing anonymous keepalive insert uses this sequence's nextval(). | ||
| GRANT USAGE ON SEQUENCE public.keepalive_events_id_seq TO anon, service_role; | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| BEGIN; | ||
| SELECT plan(6); | ||
|
|
||
| SELECT ok( | ||
| has_table_privilege('authenticated', 'public.flowcharts', 'SELECT') | ||
| AND has_table_privilege('authenticated', 'public.flowcharts', 'INSERT') | ||
| AND has_table_privilege('authenticated', 'public.flowcharts', 'UPDATE') | ||
| AND has_table_privilege('authenticated', 'public.flowcharts', 'DELETE') | ||
| AND has_table_privilege('authenticated', 'public.source_folders', 'SELECT') | ||
| AND has_table_privilege('authenticated', 'public.source_folders', 'INSERT'), | ||
| 'client-owned legacy tables remain writable after a fresh migration replay' | ||
| ); | ||
| SELECT ok( | ||
| has_table_privilege('service_role', 'public.promo_codes', 'SELECT') | ||
| AND has_table_privilege('service_role', 'public.promo_codes', 'INSERT') | ||
| AND has_table_privilege('service_role', 'public.promo_codes', 'UPDATE') | ||
| AND has_table_privilege('service_role', 'public.daily_usage_counters', 'INSERT') | ||
| AND has_table_privilege('service_role', 'public.daily_usage_counters', 'UPDATE'), | ||
| 'server-owned legacy tables remain reachable to the service role' | ||
| ); | ||
| SELECT ok( | ||
| has_table_privilege('authenticated', 'public.user_settings', 'SELECT') | ||
| AND has_column_privilege('authenticated', 'public.user_settings', 'language', 'UPDATE') | ||
| AND NOT has_table_privilege('authenticated', 'public.user_settings', 'INSERT,UPDATE,DELETE'), | ||
| 'settings keep their column-limited client permissions' | ||
| ); | ||
| SELECT ok( | ||
| has_table_privilege('authenticated', 'public.subscriptions', 'SELECT') | ||
| AND has_table_privilege('authenticated', 'public.user_promos', 'SELECT') | ||
| AND has_table_privilege('authenticated', 'public.ai_requests', 'SELECT'), | ||
| 'subscription status, redeemed promos, and usage remain client-readable' | ||
| ); | ||
| SELECT ok( | ||
| has_sequence_privilege('anon', 'public.keepalive_events_id_seq', 'USAGE'), | ||
| 'anonymous keepalive inserts can generate an event id' | ||
| ); | ||
|
|
||
| INSERT INTO auth.users (id) VALUES | ||
| ('f1111111-1111-4111-8111-111111111111'), | ||
| ('f2222222-2222-4222-8222-222222222222'); | ||
| INSERT INTO public.ai_requests (user_id, feature, provider, model) VALUES | ||
| ('f1111111-1111-4111-8111-111111111111', 'ask', 'test', 'test'), | ||
| ('f2222222-2222-4222-8222-222222222222', 'ask', 'test', 'test'); | ||
| SET LOCAL ROLE authenticated; | ||
| SELECT set_config('request.jwt.claim.sub', 'f1111111-1111-4111-8111-111111111111', true); | ||
| SELECT is( | ||
| (SELECT count(*) FROM public.ai_requests), | ||
| 1::bigint, | ||
| 'signed-in usage reads see only their own requests' | ||
| ); | ||
| RESET ROLE; | ||
|
|
||
| SELECT * FROM finish(); | ||
| ROLLBACK; |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.