Skip to content

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

Hook up network restrictions

Joshen Lim25f714df45e5
diff --git a/package-lock.json b/package-lock.json
index 49ce07f0d47..9746c433cef 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -38330,6 +38330,7 @@
"generate-password": "^1.7.0",
"html-to-image": "^1.10.8",
"immutability-helper": "^3.1.1",
+ "ipaddr.js": "^2.0.1",
"json-logic-js": "^2.0.2",
"lodash": "^4.17.21",
"lottie-react": "^2.2.1",
@@ -38661,6 +38662,14 @@
"resolved": "https://registry.npmjs.org/internmap/-/internmap-1.0.1.tgz",
"integrity": "sha512-lDB5YccMydFBtasVtxnZ3MRBHuaoE8GKsppq+EchKL2U4nK/DmEpPHNH8MZe5HkMtpSiTSOZwfN0tzYjO/lJEw=="
},
+ "studio/node_modules/ipaddr.js": {
+ "version": "2.0.1",
+ "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-2.0.1.tgz",
+ "integrity": "sha512-1qTgH9NG+IIJ4yfKs2e6Pp1bZg8wbDbKHT21HrLIeYBTRLgMYKnMTPAuI3Lcs61nfx5h1xlXnbJtH1kX5/d/ng==",
+ "engines": {
+ "node": ">= 10"
+ }
+ },
"studio/node_modules/openapi-types": {
"version": "9.3.1",
"resolved": "https://registry.npmjs.org/openapi-types/-/openapi-types-9.3.1.tgz",
@@ -64872,6 +64881,7 @@
"generate-password": "^1.7.0",
"html-to-image": "^1.10.8",
"immutability-helper": "^3.1.1",
+ "ipaddr.js": "^2.0.1",
"jest": "^27.4.0",
"jest-canvas-mock": "^2.3.1",
"json-logic-js": "^2.0.2",
@@ -65101,6 +65111,11 @@
"resolved": "https://registry.npmjs.org/internmap/-/internmap-1.0.1.tgz",
"integrity": "sha512-lDB5YccMydFBtasVtxnZ3MRBHuaoE8GKsppq+EchKL2U4nK/DmEpPHNH8MZe5HkMtpSiTSOZwfN0tzYjO/lJEw=="
},
+ "ipaddr.js": {
+ "version": "2.0.1",
+ "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-2.0.1.tgz",
+ "integrity": "sha512-1qTgH9NG+IIJ4yfKs2e6Pp1bZg8wbDbKHT21HrLIeYBTRLgMYKnMTPAuI3Lcs61nfx5h1xlXnbJtH1kX5/d/ng=="
+ },
"openapi-types": {
"version": "9.3.1",
"resolved": "https://registry.npmjs.org/openapi-types/-/openapi-types-9.3.1.tgz",
diff --git a/studio/components/interfaces/Settings/General/NetworkRestrictions/AddRestrictionModal.tsx b/studio/components/interfaces/Settings/General/NetworkRestrictions/AddRestrictionModal.tsx
new file mode 100644
index 00000000000..6b93314d01a
--- /dev/null
+++ b/studio/components/interfaces/Settings/General/NetworkRestrictions/AddRestrictionModal.tsx
@@ -0,0 +1,126 @@
+import { FC } from 'react'
+import ipaddr from 'ipaddr.js'
+import { Alert, Button, Form, Input, Modal } from 'ui'
+
+import { useStore, useParams } from 'hooks'
+import { useNetworkRestrictionsApplyMutation } from 'data/network-restrictions/network-retrictions-apply-mutation'
+
+interface Props {
+ restrictedIps: string[]
+ visible: boolean
+ hasOverachingRestriction: boolean
+ onClose: () => void
+}
+
+const AddRestrictionModal: FC<Props> = ({
+ restrictedIps,
+ visible,
+ hasOverachingRestriction,
+ onClose,
+}) => {
+ const formId = 'add-restriction-form'
+ const { ui } = useStore()
+ const { ref } = useParams()
+ const { mutateAsync: applyNetworkRestrictions } = useNetworkRestrictionsApplyMutation()
+
+ const validate = (values: any) => {
+ const errors: any = {}
+
+ try {
+ // Check if already exists
+ const alreadyExists = restrictedIps.includes(values.address)
+ if (alreadyExists) {
+ errors.address = 'This restriction already exists'
+ return errors
+ }
+ // Check if valid IP address
+ const [address, range] = ipaddr.IPv4.parseCIDR(values.address)
+ // Check if private range
+ const isPrivate = ipaddr.parse(address.octets.join('.')).range() === 'private'
+ if (isPrivate) errors.address = 'Private IP addresses are not supported'
+ } catch (error: any) {
+ if (error.message.includes('string is not formatted like an IPv4 CIDR range')) {
+ try {
+ // Check if IPv6 format
+ ipaddr.IPv6.parseCIDR(values.address)
+ errors.address = 'Only IPv4 addresses are supported at the moment'
+ } catch (error: any) {
+ errors.address = 'Please enter a valid address in CIDR notation'
+ }
+ }
+ }
+ return errors
+ }
+
+ const onSubmit = async (values: any, { setSubmitting }: any) => {
+ if (!ref) return console.error('Project ref is required')
+
+ setSubmitting(true)
+ const dbAllowedCidrs = hasOverachingRestriction
+ ? [values.address]
+ : [...restrictedIps, values.address]
+
+ try {
+ await applyNetworkRestrictions({ projectRef: ref, dbAllowedCidrs })
+ onClose()
+ } catch (error: any) {
+ ui.setNotification({
+ category: 'error',
+ message: `Failed to add restriction: ${error.message}`,
+ })
+ } finally {
+ setSubmitting(false)
+ }
+ }
+
+ return (
+ <Modal
+ closable
+ hideFooter
+ size="small"
+ visible={visible}
+ onCancel={onClose}
+ header="Add a new restriction"
+ >
+ <Form
+ validateOnBlur
+ id={formId}
+ className="!border-t-0"
+ initialValues={{ address: '' }}
+ validate={validate}
+ onSubmit={onSubmit}
+ >
+ {({ isSubmitting }: any) => {
+ return (
+ <>
+ <Modal.Content>
+ <div className="py-6 space-y-4">
+ <p className="text-sm text-scale-1100">
+ This will add an IP address range to a list of allowed ranges that can access
+ your project's database.
+ </p>
+ <Input
+ label="IPv4 address in CIDR notation"
+ id="address"
+ name="address"
+ placeholder="0.0.0.0/0"
+ />
+ </div>
+ </Modal.Content>
+ <div className="flex items-center justify-end px-6 py-4 border-t space-x-2">
+ <Button type="default" disabled={isSubmitting} onClick={() => onClose()}>
+ Cancel
+ </Button>
+ <Button htmlType="submit" loading={isSubmitting} disabled={isSubmitting}>
+ Save restriction
+ </Button>
+ </div>
+ </>
+ )
+ }}
+ </Form>
+ </Modal>
+ )
+}
+
+export default AddRestrictionModal
diff --git a/studio/components/interfaces/Settings/General/NetworkRestrictions/AllowAllModal.tsx b/studio/components/interfaces/Settings/General/NetworkRestrictions/AllowAllModal.tsx
new file mode 100644
index 00000000000..084d12c3d89
--- /dev/null
+++ b/studio/components/interfaces/Settings/General/NetworkRestrictions/AllowAllModal.tsx
@@ -0,0 +1,63 @@
+import { FC, useState } from 'react'
+import { Modal, Button } from 'ui'
+
+import { useStore, useParams } from 'hooks'
+import { useNetworkRestrictionsApplyMutation } from 'data/network-restrictions/network-retrictions-apply-mutation'
+
+interface Props {
+ visible: boolean
+ onClose: () => void
+}
+
+const AllowAllModal: FC<Props> = ({ visible, onClose }) => {
+ const { ui } = useStore()
+ const { ref } = useParams()
+ const [isSubmitting, setIsSubmitting] = useState(false)
+ const { mutateAsync: applyNetworkRestrictions } = useNetworkRestrictionsApplyMutation()
+
+ const onSubmit = async () => {
+ if (!ref) return console.error('Project ref is required')
+
+ setIsSubmitting(true)
+ try {
+ await applyNetworkRestrictions({ projectRef: ref, dbAllowedCidrs: ['0.0.0.0/0'] })
+ onClose()
+ } catch (error: any) {
+ ui.setNotification({
+ category: 'error',
+ message: `Failed to update restriction: ${error.message}`,
+ })
+ } finally {
+ setIsSubmitting(false)
+ }
+ }
+
+ return (
+ <Modal
+ closable
+ hideFooter
+ size="small"
+ visible={visible}
+ onCancel={onClose}
+ header="Allow access from all IP addresses"
+ >
+ <Modal.Content>
+ <div className="py-6 space-y-4">
+ <p className="text-sm text-scale-1100">
+ This will allow any IP address to access your project's database. Are you sure?
+ </p>
+ </div>
+ </Modal.Content>
+ <div className="flex items-center justify-end px-6 py-4 border-t space-x-2">
+ <Button type="default" disabled={isSubmitting} onClick={() => onClose()}>
+ Cancel
+ </Button>
+ <Button loading={isSubmitting} disabled={isSubmitting} onClick={() => onSubmit()}>
+ Confirm
+ </Button>
+ </div>
+ </Modal>
+ )
+}
+
+export default AllowAllModal
diff --git a/studio/components/interfaces/Settings/General/NetworkRestrictions/DisallowAllModal.tsx b/studio/components/interfaces/Settings/General/NetworkRestrictions/DisallowAllModal.tsx
new file mode 100644
index 00000000000..126c81b6bb1
--- /dev/null
+++ b/studio/components/interfaces/Settings/General/NetworkRestrictions/DisallowAllModal.tsx
@@ -0,0 +1,64 @@
+import { FC, useState } from 'react'
+import { Modal, Button } from 'ui'
+
+import { useStore, useParams } from 'hooks'
+import { useNetworkRestrictionsApplyMutation } from 'data/network-restrictions/network-retrictions-apply-mutation'
+
+interface Props {
+ visible: boolean
+ onClose: () => void
+}
+
+const DisallowAllModal: FC<Props> = ({ visible, onClose }) => {
+ const { ui } = useStore()
+ const { ref } = useParams()
+ const [isSubmitting, setIsSubmitting] = useState(false)
+ const { mutateAsync: applyNetworkRestrictions } = useNetworkRestrictionsApplyMutation()
+
+ const onSubmit = async () => {
+ if (!ref) return console.error('Project ref is required')
+
+ setIsSubmitting(true)
+ try {
+ await applyNetworkRestrictions({ projectRef: ref, dbAllowedCidrs: ['127.0.0.1/32'] })
+ onClose()
+ } catch (error: any) {
+ ui.setNotification({
+ category: 'error',
+ message: `Failed to update restriction: ${error.message}`,
+ })
+ } finally {
+ setIsSubmitting(false)
+ }
+ }
+
+ return (
+ <Modal
+ closable
+ hideFooter
+ size="small"
+ visible={visible}
+ onCancel={onClose}
+ header="Restrict access from all IP addresses"
+ >
+ <Modal.Content>
+ <div className="py-6 space-y-4">
+ <p className="text-sm text-scale-1100">
+ This will prevent any IP address other than your local machine from accessing your
+ project's database. Are you sure?
+ </p>
+ </div>
+ </Modal.Content>
+ <div className="flex items-center justify-end px-6 py-4 border-t space-x-2">
+ <Button type="default" disabled={isSubmitting} onClick={() => onClose()}>
+ Cancel
+ </Button>
+ <Button loading={isSubmitting} disabled={isSubmitting} onClick={() => onSubmit()}>
+ Confirm
+ </Button>
+ </div>
+ </Modal>
+ )
+}
+
+export default DisallowAllModal
diff --git a/studio/components/interfaces/Settings/General/NetworkRestrictions/NetworkRestrictions.tsx b/studio/components/interfaces/Settings/General/NetworkRestrictions/NetworkRestrictions.tsx
index 683e20114be..bd6f745867a 100644
--- a/studio/components/interfaces/Settings/General/NetworkRestrictions/NetworkRestrictions.tsx
+++ b/studio/components/interfaces/Settings/General/NetworkRestrictions/NetworkRestrictions.tsx
@@ -1,21 +1,188 @@
-import { FormHeader } from 'components/ui/Forms'
+import Link from 'next/link'
+import { useState } from 'react'
+import { Button, IconAlertCircle, IconExternalLink, IconGlobe, IconLock } from 'ui'
-import { useNetworkRestrictionsQuery } from 'data/network-restrictions/network-restrictions-query'
import { useParams } from 'hooks'
+import Panel from 'components/ui/Panel'
+import { FormPanel, FormHeader } from 'components/ui/Forms'
+import ShimmeringLoader from 'components/ui/ShimmeringLoader'
+import AddRestrictionModal from './AddRestrictionModal'
+import RemoveRestrictionModal from './RemoveRestrictionModal'
+import DisallowAllModal from './DisallowAllModal'
+import AllowAllModal from './AllowAllModal'
+import { useNetworkRestrictionsQuery } from 'data/network-restrictions/network-restrictions-query'
const NetworkRestrictions = ({}) => {
const { ref } = useParams()
- const { data, isLoading, isError, isSuccess } = useNetworkRestrictionsQuery({ projectRef: ref })
- console.log(data)
+ const [isAddingAddress, setIsAddingAddress] = useState(false)
+ const [isAllowingAll, setIsAllowingAll] = useState(false)
+ const [isDisallowingAll, setIsDisallowingAll] = useState(false)
+ const [selectedRestrictionToRemove, setSelectedRestrictionToRemove] = useState<string>()
+ const { data, isLoading } = useNetworkRestrictionsQuery({ projectRef: ref })
+
+ const hasAccessToRestrictions = data?.entitlement === 'allowed'
+ const restrictedIps = data?.config.dbAllowedCidrs ?? []
+ const restrictionStatus = data?.status ?? ''
+
+ const hasApplyError = restrictedIps.length === 0 && restrictionStatus === 'stored'
+ const isUninitialized = restrictedIps.length === 0 && restrictionStatus.length === 0
+ const isAllowedAll = restrictedIps.includes('0.0.0.0/0')
+ const isDisallowedAll = restrictedIps.length === 1 && restrictedIps[0] === '127.0.0.1/32'
+
+ if (!hasAccessToRestrictions) return <></>
return (
- <section>
- <FormHeader
- title="Network Restrictions"
- description="Control access to your database via IP addresses"
+ <>
+ <section>
+ <div className="flex items-center justify-between">
+ <FormHeader
+ title="Network Restrictions"
+ description="Allow specific IP ranges to have access to your database."
+ />
+ <div className="flex items-center space-x-2">
+ <Link href="https://supabase.com/docs/guides/platform/network-restrictions">
+ <a target="_blank">
+ <Button type="default" icon={<IconExternalLink />}>
+ Documentation
+ </Button>
+ </a>
+ </Link>
+ <Button onClick={() => setIsAddingAddress(true)}>Add restriction</Button>
+ </div>
+ </div>
+ {isLoading ? (
+ <Panel>
+ <Panel.Content>
+ <div className="space-y-2">
+ <ShimmeringLoader />
+ <ShimmeringLoader className="w-[70%]" />
+ <ShimmeringLoader className="w-[50%]" />
+ </div>
+ </Panel.Content>
+ </Panel>
+ ) : hasApplyError ? (
+ <Panel>
+ <Panel.Content>
+ <div className="flex items-center justify-between">
+ <div className="space-y-2">
+ <div className="flex items-center space-x-2">
+ <IconAlertCircle strokeWidth={1.5} className="text-scale-1000" />
+ <p className="text-sm">Your network restrictions were not applied correctly</p>
+ </div>
+ <p className="text-sm text-scale-1000">
+ Please try to add your network restrictions again
+ </p>
+ </div>
+ <div className="flex items-center space-x-2">
+ <Button type="default" onClick={() => setIsAllowingAll(true)}>
+ Allow all access
+ </Button>
+ <Button type="default" onClick={() => setIsDisallowingAll(true)}>
+ Restrict all access
+ </Button>
+ </div>
+ </div>
+ </Panel.Content>
+ </Panel>
+ ) : (
+ <FormPanel>
+ {isUninitialized || isAllowedAll ? (
+ <div className="px-8 py-8 flex items-center justify-between">
+ <div className="flex items-start space-x-4">
+ <div className="space-y-1">
+ <p className="text-scale-1100 text-sm">
+ Your database can be accessed by all IP addresses
+ </p>
+ <p className="text-scale-1000 text-sm">
+ You may start limiting access to your database by adding a network
+ restriction.
+ </p>
+ </div>
+ </div>
+ <div>
+ <Button type="default" onClick={() => setIsDisallowingAll(true)}>
+ Restrict all access
+ </Button>
+ </div>
+ </div>
+ ) : isDisallowedAll ? (
+ <div className="px-8 py-8 flex items-center justify-between">
+ <div className="flex items-start space-x-4">
+ <IconLock className="text-scale-1100" strokeWidth={1.5} />
+ <div className="space-y-1">
+ <p className="text-scale-1100 text-sm">
+ Your database <span className="text-amber-900 opacity-80">cannot</span> be
+ accessed externally
+ </p>
+ <p className="text-scale-1000 text-sm w-3/5">
+ Only your local machine is able to access your project's database as all IP
+ addresses have been disallowed.
+ </p>
+ </div>
+ </div>
+ <div>
+ <Button type="default" onClick={() => setIsAllowingAll(true)}>
+ Allow all access
+ </Button>
+ </div>
+ </div>
+ ) : (
+ <div className="divide-y">
+ <div className="px-8 py-3 flex items-center justify-between">
+ <div>
+ <p className="text-scale-1100 text-sm">
+ Only the following IP addresses have access to your database
+ </p>
+ <p className="text-scale-1000 text-sm">
+ You may remove all of them to allow all IP addresses to have access to your
+ database
+ </p>
+ </div>
+ <div className="flex items-center space-x-2">
+ <Button type="default" onClick={() => setIsAllowingAll(true)}>
+ Allow all access
+ </Button>
+ <Button type="default" onClick={() => setIsDisallowingAll(true)}>
+ Restrict all access
+ </Button>
+ </div>
+ </div>
+ {restrictedIps.map((ip) => {
+ return (
+ <div key={ip} className="px-8 py-4 flex items-center justify-between">
+ <div className="flex items-center space-x-5">
+ <IconGlobe size={16} className="text-scale-1000" />
+ <p className="text-sm font-mono">{ip}</p>
+ </div>
+ <Button type="default" onClick={() => setSelectedRestrictionToRemove(ip)}>
+ Remove
+ </Button>
+ </div>
+ )
+ })}
+ </div>
+ )}
+ </FormPanel>
+ )}
+ </section>
+
+ <AllowAllModal visible={isAllowingAll} onClose={() => setIsAllowingAll(false)} />
+ <DisallowAllModal visible={isDisallowingAll} onClose={() => setIsDisallowingAll(false)} />
+
+ <AddRestrictionModal
+ visible={isAddingAddress}
+ restrictedIps={restrictedIps}
+ hasOverachingRestriction={isAllowedAll || isDisallowedAll}
+ onClose={() => setIsAddingAddress(false)}
+ />
+ <RemoveRestrictionModal
+ visible={selectedRestrictionToRemove !== undefined}
+ restrictedIps={restrictedIps}
+ selectedRestriction={selectedRestrictionToRemove}
+ onClose={() => setSelectedRestrictionToRemove(undefined)}
/>
- </section>
+ </>
)
}
diff --git a/studio/components/interfaces/Settings/General/NetworkRestrictions/RemoveRestrictionModal.tsx b/studio/components/interfaces/Settings/General/NetworkRestrictions/RemoveRestrictionModal.tsx
new file mode 100644
index 00000000000..cd2a4f7f654
--- /dev/null
+++ b/studio/components/interfaces/Settings/General/NetworkRestrictions/RemoveRestrictionModal.tsx
@@ -0,0 +1,89 @@
+import { FC, useState } from 'react'
+import { Alert, Button, Form, Input, Modal } from 'ui'
+
+import { useStore, useParams } from 'hooks'
+import { useNetworkRestrictionsApplyMutation } from 'data/network-restrictions/network-retrictions-apply-mutation'
+
+interface Props {
+ visible: boolean
+ restrictedIps: string[]
+ selectedRestriction?: string
+ onClose: () => void
+}
+
+const RemoveRestrictionModal: FC<Props> = ({
+ visible,
+ restrictedIps,
+ selectedRestriction,
+ onClose,
+}) => {
+ const { ui } = useStore()
+ const { ref } = useParams()
+ const [isSubmitting, setIsSubmitting] = useState(false)
+ const { mutateAsync: applyNetworkRestrictions } = useNetworkRestrictionsApplyMutation()
+
+ const isRemovingOnlyRestriction =
+ restrictedIps.length === 1 && restrictedIps[0] === selectedRestriction
+
+ const onSubmit = async () => {
+ if (!ref) return console.error('Project ref is required')
+
+ setIsSubmitting(true)
+ const dbAllowedCidrs = restrictedIps.filter((ip) => ip !== selectedRestriction)
+
+ try {
+ if (dbAllowedCidrs.length === 0) {
+ await applyNetworkRestrictions({ projectRef: ref, dbAllowedCidrs: ['0.0.0.0/0'] })
+ } else {
+ await applyNetworkRestrictions({ projectRef: ref, dbAllowedCidrs })
+ }
+ onClose()
+ } catch (error: any) {
+ ui.setNotification({
+ category: 'error',
+ message: `Failed to remove restriction: ${error.message}`,
+ })
+ } finally {
+ setIsSubmitting(false)
+ }
+ }
+
+ return (
+ <Modal
+ closable
+ hideFooter
+ size="medium"
+ visible={visible}
+ onCancel={onClose}
+ header="Confirm to remove restriction"
+ >
+ <Modal.Content>
+ <div className="py-6 space-y-4">
+ <p className="text-sm text-scale-1100">
+ The IPv4 address <code className="text-xs">{selectedRestriction}</code> will be removed
+ from your list of network restrictions
+ {isRemovingOnlyRestriction
+ ? '.'
+ : ", and no longer have access to your project's database."}
+ </p>
+ {isRemovingOnlyRestriction && (
+ <Alert withIcon variant="warning" title="Database access will no longer be restricted">
+ Removing all network restrictions will default to your database being accessible from
+ all IP addresses.
+ </Alert>
+ )}
+ </div>
+ </Modal.Content>
+ <div className="flex items-center justify-end px-6 py-4 border-t space-x-2">
+ <Button type="default" disabled={isSubmitting} onClick={() => onClose()}>
+ Cancel
+ </Button>
+ <Button loading={isSubmitting} disabled={isSubmitting} onClick={() => onSubmit()}>
+ Remove restriction
+ </Button>
+ </div>
+ </Modal>
+ )
+}
+
+export default RemoveRestrictionModal
diff --git a/studio/data/network-restrictions/network-restrictions-query.ts b/studio/data/network-restrictions/network-restrictions-query.ts
index 727148372cd..41b70733b8f 100644
--- a/studio/data/network-restrictions/network-restrictions-query.ts
+++ b/studio/data/network-restrictions/network-restrictions-query.ts
@@ -9,8 +9,10 @@ export type NetworkRestrictionsVariables = { projectRef?: string }
export type NetworkRestrictionsResponse = {
entitlement: 'disallowed' | 'allowed'
- status: 'stored' | 'applied'
- config: any
+ status: '' | 'stored' | 'applied'
+ config: { dbAllowedCidrs: string[] }
+ old_config?: { dbAllowedCidrs: string[] }
+ error?: any
}
export async function getNetworkRestrictions(
@@ -19,25 +21,29 @@ export async function getNetworkRestrictions(
) {
if (!projectRef) throw new Error('projectRef is required')
- const response = await get(`${API_ADMIN_URL}/projects/${projectRef}/network-restrictions`, {
+ const response = (await get(`${API_ADMIN_URL}/projects/${projectRef}/network-restrictions`, {
signal,
- })
+ })) as NetworkRestrictionsResponse
// Not allowed error is a valid response to denote if a project
// has access to the network restrictions UI, so we'll handle it here
if (response.error) {
const isNotAllowedError =
(response.error as any)?.code === 400 &&
- (response.error as any)?.message?.includes('to be updated')
+ (response.error as any)?.message?.includes('not allowed to set up network restrictions')
if (isNotAllowedError) {
- return {}
+ return {
+ entitlement: 'disallowed',
+ config: { dbAllowedCidrs: [] },
+ status: '',
+ } as NetworkRestrictionsResponse
} else {
throw response.error
}
}
- return response as NetworkRestrictionsResponse[]
+ return response
}
export type NetworkRestrictionsData = Awaited<ReturnType<typeof getNetworkRestrictions>>
diff --git a/studio/data/network-restrictions/network-retrictions-apply-mutation.ts b/studio/data/network-restrictions/network-retrictions-apply-mutation.ts
index 1adc146c9b3..7321b5d9f64 100644
--- a/studio/data/network-restrictions/network-retrictions-apply-mutation.ts
+++ b/studio/data/network-restrictions/network-retrictions-apply-mutation.ts
@@ -1,27 +1,24 @@
import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'
-import { patch } from 'lib/common/fetch'
+import { post } from 'lib/common/fetch'
import { API_ADMIN_URL } from 'lib/constants'
import { networkRestrictionKeys } from './keys'
export type NetworkRestrictionsApplyVariables = {
projectRef: string
- id: string
- updatedParam: string
+ dbAllowedCidrs: string[]
}
export async function applyNetworkRestrictions({
projectRef,
- updatedParam,
+ dbAllowedCidrs,
}: NetworkRestrictionsApplyVariables) {
if (!projectRef) throw new Error('projectRef is required')
- const response = await patch(
+ const response = await post(
`${API_ADMIN_URL}/projects/${projectRef}/network-restrictions/apply`,
- { updated_param: updatedParam }
+ { dbAllowedCidrs }
)
- if (response.error) {
- throw response.error
- }
+ if (response.error) throw response.error
return response
}
diff --git a/studio/package.json b/studio/package.json
index 0e6a6fc37a7..4bcbb3b9072 100644
--- a/studio/package.json
+++ b/studio/package.json
@@ -45,6 +45,7 @@
"generate-password": "^1.7.0",
"html-to-image": "^1.10.8",
"immutability-helper": "^3.1.1",
+ "ipaddr.js": "^2.0.1",
"json-logic-js": "^2.0.2",
"lodash": "^4.17.21",
"lottie-react": "^2.2.1",
diff --git a/studio/pages/project/[ref]/settings/general.tsx b/studio/pages/project/[ref]/settings/general.tsx
index 3b722c4c841..d86bd8a0d5a 100644
--- a/studio/pages/project/[ref]/settings/general.tsx
+++ b/studio/pages/project/[ref]/settings/general.tsx
@@ -1,5 +1,7 @@
import { observer } from 'mobx-react-lite'
+
import { NextPageWithLayout } from 'types'
+import { useFlag } from 'hooks'
import { SettingsLayout } from 'components/layouts'
import {
General,
@@ -10,12 +12,15 @@ import {
} from 'components/interfaces/Settings/General'
const ProjectSettings: NextPageWithLayout = () => {
+ const networkRestrictions = useFlag('networkRestrictions')
+
+ // [Joshen] Opting for larger gap instead of gap-8 as compared to other pages for better grouping of content
return (
- <div className="1xl:px-28 mx-auto flex flex-col gap-8 px-5 py-6 lg:px-16 xl:px-24 2xl:px-32 ">
+ <div className="1xl:px-28 mx-auto flex flex-col gap-10 px-5 py-6 lg:px-16 xl:px-24 2xl:px-32 ">
<General />
<Infrastructure />
<CustomDomainConfig />
- <NetworkRestrictions />
+ {networkRestrictions && <NetworkRestrictions />}
<DeleteProjectPanel />
</div>
)