-
-
Notifications
You must be signed in to change notification settings - Fork 122
fix(api): allow scoped keys past cli warnings #2075
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
Open
riderx
wants to merge
3
commits into
main
Choose a base branch
from
codex/fix-cli-warning-scoped-api-keys
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+164
−0
Open
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
82 changes: 82 additions & 0 deletions
82
supabase/migrations/20260507171200_skip_cli_warning_read_fatal_for_scoped_keys.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,82 @@ | ||
| CREATE OR REPLACE FUNCTION public.get_organization_cli_warnings( | ||
| orgid uuid, | ||
| cli_version text | ||
| ) | ||
| RETURNS jsonb [] | ||
| LANGUAGE plpgsql | ||
| SECURITY DEFINER | ||
| SET search_path = '' | ||
| AS $$ | ||
| DECLARE | ||
| messages jsonb[] := ARRAY[]::jsonb[]; | ||
| has_read_access boolean; | ||
| api_key_text text; | ||
| api_key public.apikeys%ROWTYPE; | ||
| BEGIN | ||
| PERFORM cli_version; | ||
|
|
||
| SELECT public.get_apikey_header() | ||
| INTO api_key_text; | ||
|
|
||
| IF api_key_text IS NOT NULL THEN | ||
| SELECT * | ||
| INTO api_key | ||
| FROM public.find_apikey_by_value(api_key_text) | ||
| LIMIT 1; | ||
| END IF; | ||
|
|
||
| SELECT public.check_min_rights( | ||
| 'read'::public.user_min_right, | ||
| public.get_identity_apikey_only('{write,all,upload,read}'::public.key_mode[]), | ||
| orgid, | ||
| NULL::varchar, | ||
| NULL::bigint | ||
| ) | ||
| INTO has_read_access; | ||
|
|
||
| IF NOT COALESCE(has_read_access, false) THEN | ||
| IF api_key_text IS NULL OR api_key.id IS NULL OR public.is_apikey_expired(api_key.expires_at) THEN | ||
| messages := pg_catalog.array_append(messages, pg_catalog.jsonb_build_object( | ||
| 'message', | ||
| 'API key does not have read access to this organization', | ||
| 'fatal', | ||
| true | ||
| )); | ||
| END IF; | ||
|
|
||
| -- Upload performs app-scoped permission and plan checks after this RPC. | ||
| -- App-scoped API keys may legitimately upload without org-level read access, | ||
| -- so skip org warnings instead of blocking the upload here. | ||
| RETURN messages; | ||
|
riderx marked this conversation as resolved.
|
||
| END IF; | ||
|
|
||
| IF ( | ||
| public.is_paying_and_good_plan_org_action(orgid, ARRAY['mau']::public.action_type[]) = true | ||
| AND public.is_paying_and_good_plan_org_action(orgid, ARRAY['bandwidth']::public.action_type[]) = true | ||
| AND public.is_paying_and_good_plan_org_action(orgid, ARRAY['storage']::public.action_type[]) = false | ||
| ) THEN | ||
| messages := pg_catalog.array_append(messages, pg_catalog.jsonb_build_object( | ||
| 'message', | ||
| 'You have exceeded your storage limit. | ||
|
Check failure on line 60 in supabase/migrations/20260507171200_skip_cli_warning_read_fatal_for_scoped_keys.sql
|
||
| Upload will fail, but you can still download your data. | ||
| MAU and bandwidth limits are not exceeded. | ||
| In order to upload your plan, please upgrade your plan here: https://console.capgo.app/settings/plans.', | ||
| 'fatal', | ||
| true | ||
| )); | ||
| END IF; | ||
|
|
||
| RETURN messages; | ||
| END; | ||
| $$; | ||
|
|
||
| ALTER FUNCTION public.get_organization_cli_warnings(uuid, text) | ||
| OWNER TO postgres; | ||
| REVOKE ALL ON FUNCTION public.get_organization_cli_warnings(uuid, text) | ||
| FROM public; | ||
| GRANT ALL ON FUNCTION public.get_organization_cli_warnings(uuid, text) | ||
| TO anon; | ||
| GRANT ALL ON FUNCTION public.get_organization_cli_warnings(uuid, text) | ||
| TO authenticated; | ||
| GRANT ALL ON FUNCTION public.get_organization_cli_warnings(uuid, text) | ||
| TO 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
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.