Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Project create security section updates (#42021)

Saxon Fletcher0760733a40d4
diff --git a/apps/studio/components/interfaces/ProjectCreation/ProjectCreation.schema.ts b/apps/studio/components/interfaces/ProjectCreation/ProjectCreation.schema.ts
index d2e25ceb266..a9daa97a7b2 100644
--- a/apps/studio/components/interfaces/ProjectCreation/ProjectCreation.schema.ts
+++ b/apps/studio/components/interfaces/ProjectCreation/ProjectCreation.schema.ts
@@ -32,7 +32,7 @@ export const FormSchema = z
dbPassStrengthWarning: z.string().default(''),
instanceSize: z.string().optional(),
dataApi: z.boolean(),
- useApiSchema: z.boolean(),
+ enableRlsEventTrigger: z.boolean(),
postgresVersionSelection: z.string(),
useOrioleDb: z.boolean(),
})
diff --git a/apps/studio/components/interfaces/ProjectCreation/SecurityOptions.tsx b/apps/studio/components/interfaces/ProjectCreation/SecurityOptions.tsx
index 19a556777a5..7e41b66222c 100644
--- a/apps/studio/components/interfaces/ProjectCreation/SecurityOptions.tsx
+++ b/apps/studio/components/interfaces/ProjectCreation/SecurityOptions.tsx
@@ -1,18 +1,16 @@
-import { ChevronRight } from 'lucide-react'
import { UseFormReturn } from 'react-hook-form'
import Panel from 'components/ui/Panel'
+import { usePHFlag } from 'hooks/ui/useFlag'
+import Link from 'next/link'
import {
- Badge,
- cn,
- Collapsible_Shadcn_,
- CollapsibleContent_Shadcn_,
- CollapsibleTrigger_Shadcn_,
+ Checkbox_Shadcn_,
FormControl_Shadcn_,
+ FormDescription_Shadcn_,
FormField_Shadcn_,
FormItem_Shadcn_,
- RadioGroupStacked,
- RadioGroupStackedItem,
+ FormLabel_Shadcn_,
+ useWatch_Shadcn_,
} from 'ui'
import { Admonition } from 'ui-patterns'
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
@@ -21,159 +19,87 @@ import { CreateProjectForm } from './ProjectCreation.schema'
interface SecurityOptionsProps {
form: UseFormReturn<CreateProjectForm>
layout?: 'vertical' | 'horizontal'
- collapsible?: boolean
}
-export const SecurityOptions = ({
- form,
- layout = 'horizontal',
- collapsible = true,
-}: SecurityOptionsProps) => {
- const content = (
- <>
- <FormField_Shadcn_
- name="dataApi"
- control={form.control}
- render={({ field }) => (
- <>
- <FormItemLayout
- layout={layout}
- className="[&>div>label]:!break-normal"
- label="What connections do you plan to use?"
- >
- <FormControl_Shadcn_>
- <RadioGroupStacked
- // Due to radio group not supporting boolean values
- // value is converted to boolean
- onValueChange={(value) => field.onChange(value === 'true')}
- defaultValue={field.value.toString()}
- >
- <FormItem_Shadcn_ asChild>
- <FormControl_Shadcn_>
- <RadioGroupStackedItem
- value="true"
- className="[&>div>div>p]:text-left [&>div>div>p]:text-xs"
- label="Data API + Connection String"
- description="Connect to Postgres via autogenerated HTTP APIs or the Postgres protocol"
- />
- </FormControl_Shadcn_>
- </FormItem_Shadcn_>
- <FormItem_Shadcn_ asChild>
- <FormControl_Shadcn_>
- <RadioGroupStackedItem
- label="Only Connection String"
- value="false"
- description="Use Postgres without the autogenerated APIs"
- className={cn(
- !form.getValues('dataApi') && '!rounded-b-none',
- '[&>div>div>p]:text-left [&>div>div>p]:text-xs'
- )}
- onClick={() => form.setValue('useApiSchema', false)}
- />
- </FormControl_Shadcn_>
- </FormItem_Shadcn_>
- </RadioGroupStacked>
- </FormControl_Shadcn_>
- {!form.getValues('dataApi') && (
- <Admonition
- className="rounded-t-none"
- type="warning"
- title="Data API will effectively be disabled"
- >
- PostgREST which powers the Data API will have no schemas available to it.
- </Admonition>
- )}
- </FormItemLayout>
- </>
- )}
- />
+export const SecurityOptions = ({ form, layout = 'horizontal' }: SecurityOptionsProps) => {
+ const rlsExperimentVariant = usePHFlag<'control' | 'test' | false | undefined>(
+ 'projectCreationEnableRlsEventTrigger'
+ )
+ const shouldShowEnableRlsEventTrigger = rlsExperimentVariant === 'test'
+ const dataApi = useWatch_Shadcn_({ control: form.control, name: 'dataApi' })
- {form.getValues('dataApi') && (
- <FormField_Shadcn_
- name="useApiSchema"
- control={form.control}
- render={({ field }) => (
- <>
- <FormItemLayout className="mt-6" layout={layout} label="Data API configuration">
+ return (
+ <Panel.Content className="pb-8">
+ <FormItemLayout layout={layout} label="Security" isReactForm={false}>
+ <div className="flex flex-col gap-4">
+ <FormField_Shadcn_
+ name="dataApi"
+ control={form.control}
+ render={({ field }) => (
+ <FormItem_Shadcn_ className="flex items-start gap-3">
<FormControl_Shadcn_>
- <RadioGroupStacked
- defaultValue={field.value.toString()}
- onValueChange={(value) => field.onChange(value === 'true')}
- >
- <FormItem_Shadcn_ asChild>
- <FormControl_Shadcn_>
- <RadioGroupStackedItem
- value="false"
- // @ts-ignore
- label={
- <div className="flex items-center gap-2">
- <span>Use public schema for Data API</span>
- <Badge>Default</Badge>
- </div>
- }
- // @ts-ignore
- description={
- <>
- Query all tables in the{' '}
- <code className="text-code-inline !text-[11px]">public</code> schema
- </>
- }
- className="[&>div>div>p]:text-left [&>div>div>p]:text-xs"
- />
- </FormControl_Shadcn_>
- </FormItem_Shadcn_>
- <FormItem_Shadcn_ asChild>
- <FormControl_Shadcn_>
- <RadioGroupStackedItem
- value="true"
- label="Use dedicated API schema for Data API"
- // @ts-ignore
- description={
- <>
- Query allowlisted tables in a dedicated{' '}
- <code className="text-code-inline !text-[11px]">api</code> schema
- </>
- }
- className="[&>div>div>p]:text-left [&>div>div>p]:text-xs"
- />
- </FormControl_Shadcn_>
- </FormItem_Shadcn_>
- </RadioGroupStacked>
+ <Checkbox_Shadcn_
+ checked={field.value}
+ disabled={field.disabled}
+ onCheckedChange={(value) => field.onChange(value === true)}
+ />
</FormControl_Shadcn_>
- </FormItemLayout>
- </>
- )}
- />
- )}
- <p className="text-xs text-foreground-lighter mt-3">
- These two security options can be changed after your project is created
- </p>
- </>
- )
+ <div className="space-y-1">
+ <FormLabel_Shadcn_ className="text-sm text-foreground">
+ Enable Data API
+ </FormLabel_Shadcn_>
+ <FormDescription_Shadcn_ className="text-foreground-lighter">
+ Autogenerate a RESTful API for your public schema. Recommended if using a client
+ library like{' '}
+ <Link
+ href="https://supabase.com/docs/reference/javascript/introduction"
+ target="_blank"
+ className="text-link"
+ >
+ supabase-js
+ </Link>
+ .
+ </FormDescription_Shadcn_>
+ </div>
+ </FormItem_Shadcn_>
+ )}
+ />
- const collapsibleContent = (
- <Collapsible_Shadcn_>
- <CollapsibleTrigger_Shadcn_ className="group/advanced-trigger font-mono uppercase tracking-widest text-xs flex items-center gap-1 text-foreground-lighter/75 hover:text-foreground-light transition data-[state=open]:text-foreground-light">
- Security options
- <ChevronRight
- size={16}
- strokeWidth={1}
- className="mr-2 group-data-[state=open]/advanced-trigger:rotate-90 group-hover/advanced-trigger:text-foreground-light transition"
- />
- </CollapsibleTrigger_Shadcn_>
- <CollapsibleContent_Shadcn_
- className={cn(
- 'pt-5 data-[state=closed]:animate-collapsible-up data-[state=open]:animate-collapsible-down'
- )}
- >
- {content}
- </CollapsibleContent_Shadcn_>
- </Collapsible_Shadcn_>
- )
+ {shouldShowEnableRlsEventTrigger && (
+ <FormField_Shadcn_
+ name="enableRlsEventTrigger"
+ control={form.control}
+ render={({ field }) => (
+ <FormItem_Shadcn_ className="flex items-start gap-3">
+ <FormControl_Shadcn_>
+ <Checkbox_Shadcn_
+ checked={field.value}
+ disabled={field.disabled}
+ onCheckedChange={(value) => field.onChange(value === true)}
+ />
+ </FormControl_Shadcn_>
+ <div className="space-y-1">
+ <FormLabel_Shadcn_ className="text-sm text-foreground">
+ Enable automatic RLS
+ </FormLabel_Shadcn_>
+ <FormDescription_Shadcn_ className="text-foreground-lighter">
+ Create an event trigger that automatically enables Row Level Security on all
+ new tables in the public schema.
+ </FormDescription_Shadcn_>
+ </div>
+ </FormItem_Shadcn_>
+ )}
+ />
+ )}
- return (
- <Panel.Content className={!collapsible ? 'p-0' : ''}>
- {collapsible ? collapsibleContent : content}
+ {!dataApi && (
+ <Admonition type="warning" title="Data API will effectively be disabled">
+ You will not be able to query or mutate data via Supabase client libraries like
+ supabase-js.
+ </Admonition>
+ )}
+ </div>
+ </FormItemLayout>
</Panel.Content>
)
}
diff --git a/apps/studio/pages/new/[slug].tsx b/apps/studio/pages/new/[slug].tsx
index 9f85f5d08e6..dab30244317 100644
--- a/apps/studio/pages/new/[slug].tsx
+++ b/apps/studio/pages/new/[slug].tsx
@@ -1,6 +1,7 @@
import { zodResolver } from '@hookform/resolvers/zod'
import { PermissionAction } from '@supabase/shared-types/out/constants'
import { LOCAL_STORAGE_KEYS, useFlag, useParams } from 'common'
+import { AUTO_ENABLE_RLS_EVENT_TRIGGER_SQL } from 'components/interfaces/Database/Triggers/EventTriggersList/EventTriggers.constants'
import { AdvancedConfiguration } from 'components/interfaces/ProjectCreation/AdvancedConfiguration'
import { CloudProviderSelector } from 'components/interfaces/ProjectCreation/CloudProviderSelector'
import { ComputeSizeSelector } from 'components/interfaces/ProjectCreation/ComputeSizeSelector'
@@ -46,10 +47,11 @@ import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization
import { withAuth } from 'hooks/misc/withAuth'
import { usePHFlag } from 'hooks/ui/useFlag'
import { DOCS_URL, PROJECT_STATUS, PROVIDERS, useDefaultProvider } from 'lib/constants'
+import { useProfile } from 'lib/profile'
import { useTrack } from 'lib/telemetry/track'
import Link from 'next/link'
import { useRouter } from 'next/router'
-import { PropsWithChildren, useEffect, useMemo, useState } from 'react'
+import { PropsWithChildren, useEffect, useMemo, useRef, useState } from 'react'
import { useForm } from 'react-hook-form'
import { AWS_REGIONS, type CloudProvider } from 'shared-data'
import { toast } from 'sonner'
@@ -66,8 +68,13 @@ const Wizard: NextPageWithLayout = () => {
const router = useRouter()
const { slug, projectName } = useParams()
const defaultProvider = useDefaultProvider()
+ const { profile } = useProfile()
const { data: currentOrg } = useSelectedOrganizationQuery()
+ const rlsExperimentVariant = usePHFlag<'control' | 'test' | false | undefined>(
+ 'projectCreationEnableRlsEventTrigger'
+ )
+ const shouldShowEnableRlsEventTrigger = rlsExperimentVariant === 'test'
const isFreePlan = currentOrg?.plan?.id === 'free'
const canChooseInstanceSize = !isFreePlan
@@ -86,6 +93,7 @@ const Wizard: NextPageWithLayout = () => {
const showNonProdFields = process.env.NEXT_PUBLIC_ENVIRONMENT !== 'prod'
const isNotOnHigherPlan = !['team', 'enterprise', 'platform'].includes(currentOrg?.plan.id ?? '')
+ const hasTrackedRlsExposure = useRef(false)
// This is to make the database.new redirect work correctly. The database.new redirect should be set to supabase.com/dashboard/new/last-visited-org
if (slug === 'last-visited-org') {
@@ -114,7 +122,7 @@ const Wizard: NextPageWithLayout = () => {
dbRegion: undefined,
instanceSize: canChooseInstanceSize ? sizes[0] : undefined,
dataApi: true,
- useApiSchema: false,
+ enableRlsEventTrigger: false,
postgresVersionSelection: '',
useOrioleDb: false,
},
@@ -223,7 +231,13 @@ const Wizard: NextPageWithLayout = () => {
{ enabled: currentOrg !== null }
)
- const shouldShowFreeProjectInfo = !!currentOrg && !isFreePlan
+ const userPrimaryEmail = profile?.primary_email?.toLowerCase()
+ const isUserAtFreeProjectLimit = userPrimaryEmail
+ ? membersExceededLimit.some(
+ (member) => member.primary_email?.toLowerCase() === userPrimaryEmail
+ )
+ : false
+ const shouldShowFreeProjectInfo = !!currentOrg && !isFreePlan && !isUserAtFreeProjectLimit
const {
mutate: createProject,
@@ -235,8 +249,11 @@ const Wizard: NextPageWithLayout = () => {
'project_creation_simple_version_submitted',
{
instanceSize: form.getValues('instanceSize'),
+ enableRlsEventTrigger: form.getValues('enableRlsEventTrigger'),
+ ...((rlsExperimentVariant === 'control' || rlsExperimentVariant === 'test') && {
+ rlsOptionVariant: rlsExperimentVariant,
+ }),
dataApiEnabled: form.getValues('dataApi'),
- useApiSchema: form.getValues('useApiSchema'),
useOrioleDb: form.getValues('useOrioleDb'),
},
{
@@ -274,7 +291,7 @@ const Wizard: NextPageWithLayout = () => {
postgresVersion,
instanceSize,
dataApi,
- useApiSchema,
+ enableRlsEventTrigger,
postgresVersionSelection,
useOrioleDb,
} = values
@@ -301,10 +318,11 @@ const Wizard: NextPageWithLayout = () => {
// only set the compute size on pro+ plans. Free plans always use micro (nano in the future) size.
dbInstanceSize: isFreePlan ? undefined : (instanceSize as DesiredInstanceSize),
dataApiExposedSchemas: !dataApi ? [] : undefined,
- dataApiUseApiSchema: !dataApi ? false : useApiSchema,
+ dataApiUseApiSchema: false,
postgresEngine: useOrioleDb ? availableOrioleVersion?.postgres_engine : postgresEngine,
releaseChannel: useOrioleDb ? availableOrioleVersion?.release_channel : releaseChannel,
...(smartRegionEnabled ? { regionSelection: selectedRegion } : { dbRegion }),
+ ...(enableRlsEventTrigger ? { dbSql: AUTO_ENABLE_RLS_EVENT_TRIGGER_SQL } : {}),
}
if (postgresVersion) {
@@ -371,6 +389,20 @@ const Wizard: NextPageWithLayout = () => {
}
}, [instanceSize, watchedInstanceSize, form])
+ // Track exposure to RLS option experiment (only when explicitly assigned to a variant)
+ useEffect(() => {
+ if (
+ !hasTrackedRlsExposure.current &&
+ currentOrg?.slug &&
+ (rlsExperimentVariant === 'control' || rlsExperimentVariant === 'test')
+ ) {
+ hasTrackedRlsExposure.current = true
+ track('project_creation_rls_option_experiment_exposed', {
+ variant: rlsExperimentVariant,
+ })
+ }
+ }, [currentOrg?.slug, rlsExperimentVariant, track])
+
return (
<Form_Shadcn_ {...form}>
<form onSubmit={form.handleSubmit(onSubmitWithComputeCostsConfirmation)}>
@@ -447,7 +479,7 @@ const Wizard: NextPageWithLayout = () => {
{shouldShowFreeProjectInfo ? (
<Admonition
- className="rounded-none border-0"
+ className="rounded-none border-0 border-t"
type="note"
title="Need a free project?"
description={
diff --git a/packages/common/telemetry-constants.ts b/packages/common/telemetry-constants.ts
index 313a635b5bf..c07fbd00e08 100644
--- a/packages/common/telemetry-constants.ts
+++ b/packages/common/telemetry-constants.ts
@@ -264,6 +264,24 @@ export interface FeaturePreviewDisabledEvent {
groups: TelemetryGroups
}
+/**
+ * User was exposed to the project creation form (exposure event for RLS option experiment).
+ *
+ * @group Events
+ * @source studio
+ * @page new/{slug}
+ */
+export interface ProjectCreationRlsOptionExperimentExposedEvent {
+ action: 'project_creation_rls_option_experiment_exposed'
+ properties: {
+ /**
+ * Experiment variant: 'control' (checkbox hidden) or 'test' (checkbox shown)
+ */
+ variant: 'control' | 'test'
+ }
+ groups: Omit<TelemetryGroups, 'project'>
+}
+
/**
* Existing project creation form was submitted and the project was created.
*
@@ -278,6 +296,14 @@ export interface ProjectCreationSimpleVersionSubmittedEvent {
*/
properties: {
instanceSize?: string
+ /**
+ * Whether the automatic RLS event trigger option was enabled
+ */
+ enableRlsEventTrigger?: boolean
+ /**
+ * Experiment variant: 'control' (checkbox not shown) or 'test' (checkbox shown)
+ */
+ rlsOptionVariant?: 'control' | 'test'
/**
* Whether Data API is enabled.
* true = "Data API + Connection String" (default)
@@ -2756,6 +2782,7 @@ export type TelemetryEvent =
| CronJobHistoryClickedEvent
| FeaturePreviewEnabledEvent
| FeaturePreviewDisabledEvent
+ | ProjectCreationRlsOptionExperimentExposedEvent
| ProjectCreationSimpleVersionSubmittedEvent
| ProjectCreationSimpleVersionConfirmModalOpenedEvent
| ProjectCreationInitialStepPromptIntendedEvent