import Link from 'next/link' import { useState, useEffect } from 'react' import * as Tooltip from '@radix-ui/react-tooltip' import { Button, IconDownload, Toggle, IconLoader, Alert } from 'ui' import { PermissionAction } from '@supabase/shared-types/out/constants' import { checkPermissions, useStore, useFlag } from 'hooks' import { useParams } from 'common/hooks' import { FormHeader, FormPanel, FormSection, FormSectionContent, FormSectionLabel, } from 'components/ui/Forms' import { useProjectSettingsQuery } from 'data/config/project-settings-query' import { useSSLEnforcementQuery } from 'data/ssl-enforcement/ssl-enforcement-query' import { useSSLEnforcementUpdateMutation } from 'data/ssl-enforcement/ssl-enforcement-update-mutation' const SSLConfiguration = () => { const { ui } = useStore() const { ref } = useParams() const [isEnforced, setIsEnforced] = useState(false) const [isSubmitting, setIsSubmitting] = useState(false) const sslEnforcement = useFlag('sslEnforcement') const { data: projectSettings } = useProjectSettingsQuery({ projectRef: ref }) const { data: sslEnforcementConfiguration, isLoading } = useSSLEnforcementQuery({ projectRef: ref, }) const { mutateAsync: updateSSLEnforcement } = useSSLEnforcementUpdateMutation() const canUpdateSSLEnforcement = checkPermissions(PermissionAction.UPDATE, 'projects') const hasAccessToSSLEnforcement = !sslEnforcementConfiguration?.isNotAllowed const env = process.env.NEXT_PUBLIC_ENVIRONMENT === 'prod' ? 'prod' : 'staging' const hasSSLCertificate = projectSettings?.project !== undefined && new Date(projectSettings.project.inserted_at) >= new Date('2021-04-30') useEffect(() => { if (!isLoading && sslEnforcementConfiguration) { setIsEnforced( sslEnforcementConfiguration.appliedSuccessfully && sslEnforcementConfiguration.currentConfig.database ) } }, [isLoading]) const toggleSSLEnforcement = async () => { if (!ref) return console.error('Project ref is required') setIsEnforced(!isEnforced) setIsSubmitting(true) try { await updateSSLEnforcement({ projectRef: ref, requestedConfig: { database: !isEnforced }, }) } catch (error: any) { ui.setNotification({ category: 'error', message: `Failed to update SSL enforcement: ${error.message}`, }) setIsEnforced(isEnforced) } finally { setIsSubmitting(false) } } return (
{/*
*/}
{sslEnforcement && hasAccessToSSLEnforcement && (

Reject non-SSL connections to your database

{!sslEnforcementConfiguration?.appliedSuccessfully && ( Please try updating again, or contact{' '} support {' '} if this error persists )}
} > Enforce SSL on incoming connections } >
{(isLoading || isSubmitting) && ( )}
)}

SSL Certificate

Use this certificate when connecting to your database to prevent snooping and man-in-the-middle attacks.

{!hasSSLCertificate && (
Projects before 15:08 (GMT+08), 29th April 2021 do not have SSL certificates installed
)}
) } export default SSLConfiguration