The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
chore: disable role impersonation for edge functions (#36599)
Alaister Young8c8110a34cd3
diff --git a/apps/studio/components/interfaces/Functions/EdgeFunctionDetails/EdgeFunctionTesterSheet.tsx b/apps/studio/components/interfaces/Functions/EdgeFunctionDetails/EdgeFunctionTesterSheet.tsxindex 11cd1dd9e04..7c65503db22 100644--- a/apps/studio/components/interfaces/Functions/EdgeFunctionDetails/EdgeFunctionTesterSheet.tsx+++ b/apps/studio/components/interfaces/Functions/EdgeFunctionDetails/EdgeFunctionTesterSheet.tsx@@ -15,7 +15,10 @@ import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization'import { IS_PLATFORM } from 'lib/constants'import { prettifyJSON } from 'lib/helpers'import { getRoleImpersonationJWT } from 'lib/role-impersonation'-import { useGetImpersonatedRoleState } from 'state/role-impersonation-state'+import {+ RoleImpersonationStateContextProvider,+ useGetImpersonatedRoleState,+} from 'state/role-impersonation-state'import {Badge,Button,@@ -416,7 +419,12 @@ export const EdgeFunctionTesterSheet = ({ visible, onClose }: EdgeFunctionTester<SheetFooter className="px-5 py-3 border-t"><div className="flex items-center gap-2">- <RoleImpersonationPopover portal={false} />+ {/* [Alaister]: We're using a fresh context here as edge functions don't allow impersonating users. */}+ <RoleImpersonationStateContextProvider+ key={`role-impersonation-state-${projectRef}`}+ >+ <RoleImpersonationPopover portal={false} disallowAuthenticatedOption={true} />+ </RoleImpersonationStateContextProvider><Buttontype="primary"htmlType="submit"diff --git a/apps/studio/components/interfaces/RoleImpersonationSelector/RoleImpersonationPopover.tsx b/apps/studio/components/interfaces/RoleImpersonationSelector/RoleImpersonationPopover.tsxindex 318f03e3546..adbe74201f6 100644--- a/apps/studio/components/interfaces/RoleImpersonationSelector/RoleImpersonationPopover.tsx+++ b/apps/studio/components/interfaces/RoleImpersonationSelector/RoleImpersonationPopover.tsx@@ -12,6 +12,7 @@ export interface RoleImpersonationPopoverProps {serviceRoleLabel?: stringvariant?: 'regular' | 'connected-on-right' | 'connected-on-left' | 'connected-on-both'align?: 'center' | 'start' | 'end'+ disallowAuthenticatedOption?: boolean}const RoleImpersonationPopover = ({@@ -19,6 +20,7 @@ const RoleImpersonationPopover = ({serviceRoleLabel,variant = 'regular',align = 'end',+ disallowAuthenticatedOption = false,}: RoleImpersonationPopoverProps) => {const state = useRoleImpersonationStateSnapshot()@@ -64,7 +66,10 @@ const RoleImpersonationPopover = ({side="bottom"align={align}>- <RoleImpersonationSelector serviceRoleLabel={serviceRoleLabel} />+ <RoleImpersonationSelector+ serviceRoleLabel={serviceRoleLabel}+ disallowAuthenticatedOption={disallowAuthenticatedOption}+ /></PopoverContent_Shadcn_></Popover_Shadcn_>)diff --git a/apps/studio/components/interfaces/RoleImpersonationSelector/RoleImpersonationSelector.tsx b/apps/studio/components/interfaces/RoleImpersonationSelector/RoleImpersonationSelector.tsxindex 17b121074ca..fa591e1e8a0 100644--- a/apps/studio/components/interfaces/RoleImpersonationSelector/RoleImpersonationSelector.tsx+++ b/apps/studio/components/interfaces/RoleImpersonationSelector/RoleImpersonationSelector.tsx@@ -10,11 +10,13 @@ import UserImpersonationSelector from './UserImpersonationSelector'export interface RoleImpersonationSelectorProps {serviceRoleLabel?: stringpadded?: boolean+ disallowAuthenticatedOption?: boolean}const RoleImpersonationSelector = ({serviceRoleLabel,padded = true,+ disallowAuthenticatedOption = false,}: RoleImpersonationSelectorProps) => {const state = useRoleImpersonationStateSnapshot()@@ -81,21 +83,25 @@ const RoleImpersonationSelector = ({icon={<AnonIcon isSelected={selectedOption === 'anon'} />}/>- <RoleImpersonationRadio- value="authenticated"- isSelected={- selectedOption === 'authenticated' &&- (isAuthenticatedOptionFullySelected || 'partially')- }- onSelectedChange={onSelectedChange}- icon={<AuthenticatedIcon isSelected={selectedOption === 'authenticated'} />}- />+ {!disallowAuthenticatedOption && (+ <RoleImpersonationRadio+ value="authenticated"+ isSelected={+ selectedOption === 'authenticated' &&+ (isAuthenticatedOptionFullySelected || 'partially')+ }+ onSelectedChange={onSelectedChange}+ icon={<AuthenticatedIcon isSelected={selectedOption === 'authenticated'} />}+ />+ )}</fieldset></form>{selectedOption === 'service_role' && (<p className="text-foreground-light text-sm">- The default Postgres/superuser role. This has admin privileges.+ The default Postgres/superuser role.+ {disallowAuthenticatedOption ? <br /> : ' '}+ This has admin privileges.<br />It will bypass Row Level Security (RLS) policies.</p>@@ -103,16 +109,21 @@ const RoleImpersonationSelector = ({{selectedOption === 'anon' && (<p className="text-foreground-light text-sm">- For "anonymous access". This is the role which the API (PostgREST) will use when a user+ For "anonymous access".+ {disallowAuthenticatedOption ? <br /> : ' '}+ This is the role which the API (PostgREST)<br />- is not logged in. It will respect Row Level Security (RLS) policies.+ will use when a user is not logged in.+ {disallowAuthenticatedOption ? <br /> : ' '}+ It will respect Row Level Security (RLS) policies.</p>)}{selectedOption === 'authenticated' && (<p className="text-foreground-light text-sm">- For "authenticated access". This is the role which the API (PostgREST) will use when- <br /> a user is logged in. It will respect Row Level Security (RLS) policies.+ For "authenticated access". This is the role which the API (PostgREST)+ <br />+ will use when a user is logged in. It will respect Row Level Security (RLS) policies.</p>)}</div>