Files
supabase/studio/components/interfaces/Settings/Database/SSLConfiguration.tsx
T
8057309e51 chore: upgrade next 13 + react 18 (#17839)
* update deps + image codemod (studio)

* update next links (studio)

* update deps

* update links (ui)

* remove next-transpile-modules

* move next-themes dependency

* chore: update ConfirmDialog

* chore: remove old ConfirmModal js file. migrated to TS

* dependency wrangling

* remove empty page

* update next links (www)

* First run bump react-data-grid-v7 beta 4

* fix package-lock.json

* more deps wrangling

* update recharts

* update sentry options

* fix some broken things in www

* studio fixes

* fix graphiql

* fix studio build

* fix menu hydration

* small build error

* update turbo

* fix www typescript errors

* docs image codemod

* links codemod docs

* fix docs typescript errors

* move useConsent to ui to prevent circular deps

* Fix links

* Fix homepage

* Fix links

* move studio/ to apps/

* Revert "move studio/ to apps/"

This reverts commit 1b0a985fcb.

* disable outputFileTracingRoot

* remove outputFileTracingRoot

* fix homepage product cards

* fix PrivacySettings links

* Fix links

* Fix the build for www.

* Minor fixes for JWTGenerator.

* Fix the docs and ui tests.

* Revert codehike back to 0.8.3

* remove ConfirmAlert()

* reenable babel because mobx hates me

* fix blog image and comparison page avatar

* Fix svg errors

* update image synthax

* Fix code hike

* Move the button in a div so that it doesn't inherit its parent height and make the button look weird.

* When components are defined in a component, they get recreated on each render. This makes them unstable in certain cases and causes infinite rerenders.

* Replace the next/head usage with next/script.

* Chore/upgrade next 13 fix table editor (#18431)

* fix table editor styling and fix row deletion logic

* Fix deleting selected rows from header, and fix checkboxes not clearing up

* Fix deleting all rows when filter applied, and fix deleting all rows

* Fix grid size styling issue

* Fix TS error

* Hydration errors

* studio org pages fixes

* fix more studio links

* audit logs fixes

* dropdown icon styling fixes

* fix some images in www

* upgrade to next 14

* try new sentry wrapper for api

* see if this is even invoked

* Revert "see if this is even invoked"

This reverts commit 86c3973ffa.

* Revert "try new sentry wrapper for api"

This reverts commit f67623ebad.

* Revert "upgrade to next 14"

This reverts commit a24dd6131e.

* chore: allow node version 19/20

* Try to fix the LogTable so that it renders with the newer "react-data-grid" version.

* Fix type errors in the log renderer code.

* Fix the replication screen.

* Add the CSS for the GraphiQL.

* Fix SQL editor results rendering

* Lint

* Fix SQL editor results height issue

* Fix auth RLS not invalidating RQ when toggling RLS

* Fix database tables new/edit column regressed

* Fix migrations page empty state if migrations schema not yet created

* Fix API side panel docs temp remove postgrest text for column description PK and FK

* Fix + improve timeout handling in SQL editor

---------

Co-authored-by: Jonathan Summers-Muir <MildTomato@users.noreply.github.com>
Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
Co-authored-by: Francesco Sansalvadore <f.sansalvadore@gmail.com>
Co-authored-by: Terry Sutton <saltcod@gmail.com>
Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
Co-authored-by: Kevin Grüneberg <k.grueneberg1994@gmail.com>
2023-10-31 05:51:46 +00:00

221 lines
8.2 KiB
TypeScript

import * as Tooltip from '@radix-ui/react-tooltip'
import { PermissionAction } from '@supabase/shared-types/out/constants'
import { useParams } from 'common'
import Link from 'next/link'
import { useEffect, useState } from 'react'
import { Alert, Button, IconDownload, IconExternalLink, IconLoader, Toggle } from 'ui'
import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
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'
import { useCheckPermissions, useStore } from 'hooks'
const SSLConfiguration = () => {
const { ui } = useStore()
const { ref } = useParams()
const [isEnforced, setIsEnforced] = useState(false)
const { data: projectSettings } = useProjectSettingsQuery({ projectRef: ref })
const {
data: sslEnforcementConfiguration,
isLoading,
isSuccess,
} = useSSLEnforcementQuery({
projectRef: ref,
})
const { mutate: updateSSLEnforcement, isLoading: isSubmitting } = useSSLEnforcementUpdateMutation(
{
onSuccess: () => {
ui.setNotification({
category: 'success',
message: 'Successfully updated SSL configuration',
})
},
onError: (error) => {
setIsEnforced(initialIsEnforced)
ui.setNotification({
error,
category: 'error',
message: `Failed to update SSL enforcement: ${error.message}`,
})
},
}
)
const { project } = useProjectContext()
const canUpdateSSLEnforcement = useCheckPermissions(PermissionAction.UPDATE, 'projects', {
resource: {
project_id: project?.id,
},
})
const initialIsEnforced = isSuccess
? sslEnforcementConfiguration.appliedSuccessfully &&
sslEnforcementConfiguration.currentConfig.database
: false
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(initialIsEnforced)
}
}, [isLoading])
const toggleSSLEnforcement = async () => {
if (!ref) return console.error('Project ref is required')
setIsEnforced(!isEnforced)
updateSSLEnforcement({ projectRef: ref, requestedConfig: { database: !isEnforced } })
}
return (
<div id="ssl-configuration">
<div className="flex items-center justify-between">
<FormHeader title="SSL Configuration" description="" />
<div className="flex items-center space-x-2 mb-6">
<Button asChild type="default" icon={<IconExternalLink />}>
<Link href="https://supabase.com/docs/guides/platform/ssl-enforcement" target="_blank">
Documentation
</Link>
</Button>
</div>
</div>
<FormPanel>
<FormSection
header={
<FormSectionLabel
className="lg:col-span-7"
description={
<div className="space-y-4">
<p className="text-sm text-foreground-light">
Reject non-SSL connections to your database
</p>
{isSuccess && !sslEnforcementConfiguration?.appliedSuccessfully && (
<Alert
withIcon
variant="warning"
title="SSL enforcement was not updated successfully"
>
Please try updating again, or contact{' '}
<Link
href="/support/new"
target="_blank"
rel="noreferrer"
className="underline"
>
support
</Link>{' '}
if this error persists
</Alert>
)}
</div>
}
>
Enforce SSL on incoming connections
</FormSectionLabel>
}
>
<FormSectionContent loading={false} className="lg:!col-span-5">
<div className="flex items-center justify-end mt-2.5 space-x-2">
{(isLoading || isSubmitting) && (
<IconLoader className="animate-spin" strokeWidth={1.5} size={16} />
)}
<Tooltip.Root delayDuration={0}>
<Tooltip.Trigger>
<Toggle
checked={isEnforced}
disabled={
isLoading ||
isSubmitting ||
!canUpdateSSLEnforcement ||
!hasAccessToSSLEnforcement
}
onChange={toggleSSLEnforcement}
/>
</Tooltip.Trigger>
{(!canUpdateSSLEnforcement || !hasAccessToSSLEnforcement) && (
<Tooltip.Portal>
<Tooltip.Content align="center" side="bottom">
<Tooltip.Arrow className="radix-tooltip-arrow" />
<div
className={[
'rounded bg-scale-100 py-1 px-2 leading-none shadow',
'border border-scale-200 w-[250px]',
].join(' ')}
>
<span className="text-xs text-foreground text-center flex items-center justify-center">
{!canUpdateSSLEnforcement
? 'You need additional permissions to update SSL enforcement for your project'
: !hasAccessToSSLEnforcement
? 'Your project does not have access to SSL enforcement'
: ''}
</span>
</div>
</Tooltip.Content>
</Tooltip.Portal>
)}
</Tooltip.Root>
</div>
</FormSectionContent>
</FormSection>
<div className="grid grid-cols-1 items-center lg:grid-cols-2 p-8">
<div className="space-y-2">
<p className="block text-sm">SSL Certificate</p>
<div style={{ maxWidth: '420px' }}>
<p className="text-sm opacity-50">
Use this certificate when connecting to your database to prevent snooping and
man-in-the-middle attacks.
</p>
</div>
</div>
<div className="flex items-end justify-end">
<Tooltip.Root delayDuration={0}>
<Tooltip.Trigger>
<Button type="default" disabled={!hasSSLCertificate} icon={<IconDownload />}>
<a
href={`https://supabase-downloads.s3-ap-southeast-1.amazonaws.com/${env}/ssl/${env}-ca-2021.crt`}
>
Download Certificate
</a>
</Button>
</Tooltip.Trigger>
{!hasSSLCertificate && (
<Tooltip.Portal>
<Tooltip.Content align="center" side="bottom">
<Tooltip.Arrow className="radix-tooltip-arrow" />
<div
className={[
'rounded bg-scale-100 py-1 px-2 leading-none shadow',
'border border-scale-200 w-[250px]',
].join(' ')}
>
<span className="text-xs text-foreground">
Projects before 15:08 (GMT+08), 29th April 2021 do not have SSL certificates
installed
</span>
</div>
</Tooltip.Content>
</Tooltip.Portal>
)}
</Tooltip.Root>
</div>
</div>
</FormPanel>
</div>
)
}
export default SSLConfiguration