diff --git a/apps/docs/content/guides/platform/ssl-enforcement.mdx b/apps/docs/content/guides/platform/ssl-enforcement.mdx index cd2d230f9af..56c2d9b0c9a 100644 --- a/apps/docs/content/guides/platform/ssl-enforcement.mdx +++ b/apps/docs/content/guides/platform/ssl-enforcement.mdx @@ -13,7 +13,7 @@ If clients fail with a `no pg_hba.conf entry ... ssl off` error after you enforc -Applying or updating SSL enforcement triggers a fast database reboot. On small projects this usually completes in a few seconds, but larger databases may see a longer interruption. +Enforcing SSL immediately closes existing connections that don't use SSL. Clients must reconnect with SSL. Exising SSL enabled connections are unaffected. @@ -21,12 +21,6 @@ Applying or updating SSL enforcement triggers a fast database reboot. On small p SSL enforcement can be configured via the "Enforce SSL on incoming connections" setting under the SSL Configuration section in [Database Settings page](/dashboard/project/_/database/settings) of the dashboard. - - -Updating SSL enforcement requires a brief database reboot. This restarts only the database and involves a few minutes of downtime. - - - ## Manage SSL enforcement via the Management API You can also manage SSL enforcement using the Management API: diff --git a/apps/studio/components/interfaces/Settings/Database/JitDatabaseAccess/JitDbAccessConfiguration.tsx b/apps/studio/components/interfaces/Settings/Database/JitDatabaseAccess/JitDbAccessConfiguration.tsx index 2811d127b2a..02b5a172118 100644 --- a/apps/studio/components/interfaces/Settings/Database/JitDatabaseAccess/JitDbAccessConfiguration.tsx +++ b/apps/studio/components/interfaces/Settings/Database/JitDatabaseAccess/JitDbAccessConfiguration.tsx @@ -396,7 +396,6 @@ export const JitDbAccessConfiguration = () => { ) : unavailableReason === 'ssl_enforcement_required' && ref ? ( diff --git a/apps/studio/components/interfaces/Settings/Database/SSLConfiguration.test.tsx b/apps/studio/components/interfaces/Settings/Database/SSLConfiguration.test.tsx index 6fcb9bf4ebe..f6437543de7 100644 --- a/apps/studio/components/interfaces/Settings/Database/SSLConfiguration.test.tsx +++ b/apps/studio/components/interfaces/Settings/Database/SSLConfiguration.test.tsx @@ -157,8 +157,8 @@ describe('SSLConfiguration', () => { await userEvent.click(sslSwitch) const dialog = await screen.findByRole('alertdialog') - expect(dialog).toHaveTextContent('Updating SSL enforcement involves a brief downtime') - expect(screen.getByRole('button', { name: 'Enable SSL' })).toBeInTheDocument() + expect(dialog).toHaveTextContent('Enforce SSL on connections?') + expect(screen.getByRole('button', { name: 'Enforce SSL' })).toBeInTheDocument() // Controlled switch must not flip while the dialog is open expect(sslSwitch).not.toBeChecked() @@ -167,4 +167,30 @@ describe('SSLConfiguration', () => { await waitFor(() => expect(screen.queryByRole('alertdialog')).not.toBeInTheDocument()) expect(sslSwitch).not.toBeChecked() }) + + it('disables SSL enforcement without a confirm dialog', async () => { + mockUseHighAvailability.mockReturnValue({ isHighAvailability: false, isPending: false }) + mockSSLEnforcement({ appliedSuccessfully: true, currentConfig: { database: true } }) + const updateRequests: unknown[] = [] + addAPIMock({ + method: 'put', + path: '/v1/projects/:ref/ssl-enforcement', + response: async ({ request }) => { + updateRequests.push(await request.json()) + return HttpResponse.json({ + appliedSuccessfully: true, + currentConfig: { database: false }, + }) + }, + }) + + customRender() + + const sslSwitch = await screen.findByRole('switch') + expect(sslSwitch).toBeChecked() + await userEvent.click(sslSwitch) + + await waitFor(() => expect(updateRequests).toEqual([{ requestedConfig: { database: false } }])) + expect(screen.queryByRole('alertdialog')).not.toBeInTheDocument() + }) }) diff --git a/apps/studio/components/interfaces/Settings/Database/SSLConfiguration.tsx b/apps/studio/components/interfaces/Settings/Database/SSLConfiguration.tsx index 33e87eff0b7..d60b3912599 100644 --- a/apps/studio/components/interfaces/Settings/Database/SSLConfiguration.tsx +++ b/apps/studio/components/interfaces/Settings/Database/SSLConfiguration.tsx @@ -48,15 +48,16 @@ export const SSLConfiguration = () => { const isLoading = isHighAvailabilityPending || (!isHighAvailability && isSSLEnforcementPending) const isSuccess = isHighAvailability || isSSLEnforcementSuccess const { data: jitDbAccessConfiguration } = useJitDbAccessQuery({ projectRef: ref }) - const { mutateAsync: updateSSLEnforcement, isPending: isSubmitting } = - useSSLEnforcementUpdateMutation({ + const { mutate: updateSSLEnforcement, isPending: isSubmitting } = useSSLEnforcementUpdateMutation( + { onSuccess: () => { toast.success('Successfully updated SSL configuration') }, onError: (error) => { toast.error(`Failed to update SSL enforcement: ${error.message}`) }, - }) + } + ) const { can: canUpdateSSLEnforcement } = useAsyncCheckPermissionsV2( FGA_PERMISSIONS.PROJECT.DATABASE_SSL_CONFIG_WRITE @@ -121,9 +122,18 @@ export const SSLConfiguration = () => { [sslCertificateUrlTemplate, env] ) - const toggleSSLEnforcement = async () => { + const setSSLEnforcement = (isTargetEnforced: boolean) => { if (!ref) return console.error('Project ref is required') - await updateSSLEnforcement({ projectRef: ref, requestedConfig: { database: !isEnforced } }) + updateSSLEnforcement({ projectRef: ref, requestedConfig: { database: isTargetEnforced } }) + } + + // Only enabling enforcement closes existing connections, so only enabling needs a confirmation + const handleSwitchChange = (isChecked: boolean) => { + if (isChecked) { + setIsConfirmDialogOpen(true) + } else { + setSSLEnforcement(false) + } } return ( @@ -164,7 +174,7 @@ export const SSLConfiguration = () => { size="large" checked={isEnforced} disabled={isSwitchDisabled} - onCheckedChange={() => setIsConfirmDialogOpen(true)} + onCheckedChange={handleSwitchChange} /> @@ -183,9 +193,8 @@ export const SSLConfiguration = () => { setSSLEnforcement(true)} /> {isSSLEnforcementSuccess && !sslEnforcementConfiguration.appliedSuccessfully && ( diff --git a/apps/studio/components/interfaces/Settings/Database/SSLEnforcementConfirmDialog.tsx b/apps/studio/components/interfaces/Settings/Database/SSLEnforcementConfirmDialog.tsx index 9a716cfec8c..22ec33b0448 100644 --- a/apps/studio/components/interfaces/Settings/Database/SSLEnforcementConfirmDialog.tsx +++ b/apps/studio/components/interfaces/Settings/Database/SSLEnforcementConfirmDialog.tsx @@ -12,9 +12,8 @@ import { } from 'ui' interface SSLEnforcementConfirmDialogProps { - isTargetEnforced: boolean isSubmitting: boolean - onConfirm: () => Promise + onConfirm: () => void /** * Controlled mode for callers whose control can't act as the dialog trigger * (e.g. a switch, where a disabled control must never open the dialog). @@ -25,7 +24,6 @@ interface SSLEnforcementConfirmDialogProps { } export const SSLEnforcementConfirmDialog = ({ - isTargetEnforced, isSubmitting, onConfirm, open, @@ -37,16 +35,16 @@ export const SSLEnforcementConfirmDialog = ({ {children !== undefined && {children}} - Updating SSL enforcement involves a brief downtime + Enforce SSL on connections? - A database restart is required for SSL enforcement changes to take place, and this - involves a few minutes of downtime. Confirm to proceed now? + Enforcing SSL immediately closes existing connections that don't use SSL. Clients must + reconnect with SSL. Existing SSL enabled connections are unaffected. Cancel - {isTargetEnforced ? 'Enable SSL' : 'Disable SSL'} + Enforce SSL