Skip to content

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

Update RLS warning

Terry Sutton5d1cfff01a96
diff --git a/studio/components/grid/components/header/RLSBannerWarning.tsx b/studio/components/grid/components/header/RLSBannerWarning.tsx
index 9d5e16f422f..28fabaecc1e 100644
--- a/studio/components/grid/components/header/RLSBannerWarning.tsx
+++ b/studio/components/grid/components/header/RLSBannerWarning.tsx
@@ -1,5 +1,13 @@
import { useState } from 'react'
-import { Button, IconAlertCircle, IconExternalLink, Modal } from 'ui'
+import {
+ Alert,
+ Button,
+ IconAlertCircle,
+ IconBookOpen,
+ IconExternalLink,
+ IconUnlock,
+ Modal,
+} from 'ui'
import Link from 'next/link'
import { useParams, useStore } from 'hooks'
import ConfirmationModal from 'components/ui/ConfirmationModal'
@@ -29,10 +37,10 @@ export default function RLSBannerWarning() {
<>
{!isAcknowledged && !rlsEnabled && isPublicTable ? (
<div>
- <div className="text-center bg-amber-500 text-amber-900 text-xs py-2.5 flex items-center justify-center relative">
+ <div className="text-center bg-amber-500 text-amber-1100 dark:text-amber-900 text-xs py-2.5 flex items-center justify-center relative">
<IconAlertCircle size={16} strokeWidth={2} />
- <span className="uppercase font-bold ml-2">Warning</span>: This table is publicly
- readable and writable.{' '}
+ <span className="uppercase font-bold ml-2">Warning</span>: You are allowing anonymous
+ access to your table.{' '}
<Link href={`/project/${projectRef}/auth/policies?search=${tableID}`}>
<a className="underline ml-2 opacity-80 hover:opacity-100 transition">
Enable Row Level Security
@@ -41,7 +49,7 @@ export default function RLSBannerWarning() {
<div className="ml-20 absolute right-2">
<Button
type="outline"
- className="text-white hover:text-scale-1200"
+ className="text-amber-1100 dark:text-white hover:text-scale-1200"
onClick={() => setIsOpen(true)}
>
Dismiss
@@ -50,28 +58,50 @@ export default function RLSBannerWarning() {
</div>
<ConfirmationModal
- danger
visible={isOpen}
- header="Warning: Your data is public"
- buttonLabel="I understand, dismiss this warning"
+ header="Confirm"
+ buttonLabel="Confirm"
+ size="medium"
onSelectCancel={() => setIsOpen(false)}
onSelectConfirm={handleDismissWarning}
children={
<Modal.Content>
- <div className="mt-4 mb-6 space-y-4">
- <p className="text-sm text-scale-1100">
- Data in this table is publicly <u>readable and writable</u> by anyone with the
- anon key. We strongly recommend creating RLS (Row-Level Security) policies to
- allow access to this table.
- </p>
+ <div className="flex gap-4 my-6">
<div>
- <Link href="https://supabase.com/docs/guides/auth/row-level-security">
- <a target="_blank">
- <Button type="default" icon={<IconExternalLink strokeWidth={1.5} />}>
- About RLS Policies
- </Button>
- </a>
- </Link>
+ <div className="w-16 h-16 bg-scale-300 flex flex-col justify-center text-center items-center rounded-full">
+ <IconUnlock strokeWidth={2} size={24} />
+ </div>
+ </div>
+ <div className="text-sm text-scale-1100 grid gap-4">
+ <div className="grid gap-1">
+ <p>
+ Row Level Security will be turned <u>off</u> for this table.
+ </p>
+
+ <Alert
+ variant="warning"
+ className="!px-4 !py-3 mt-3"
+ title=" You are allowing anonymous access to your table"
+ >
+ <p>
+ Anyone with the anon key can modify or delete data. <br />
+ We recommend using RLS policies to control access to your data.
+ </p>
+ </Alert>
+ </div>
+
+ <div className="mt-3">
+ <p>Learn more about RLS:</p>
+ <p className="mt-2">
+ <Link href="https://supabase.com/docs/guides/auth/row-level-security">
+ <a target="_blank">
+ <Button type="default" icon={<IconBookOpen strokeWidth={1.5} />}>
+ RLS Documentation
+ </Button>
+ </a>
+ </Link>
+ </p>
+ </div>
</div>
</div>
</Modal.Content>
diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableEditor.tsx b/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableEditor.tsx
index 5a13c096dc8..1123665af4f 100644
--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableEditor.tsx
+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableEditor.tsx
@@ -243,7 +243,11 @@ const TableEditor: FC<Props> = ({
}
checked={tableFields.isRLSEnabled}
onChange={() => {
- setRlsConfirmVisible(true)
+ // if isEnabled, show confirm modal to turn off
+ // if not enabled, allow turning on without modal confirmation
+ tableFields.isRLSEnabled
+ ? setRlsConfirmVisible(true)
+ : onUpdateField({ isRLSEnabled: !tableFields.isRLSEnabled })
}}
size="medium"
/>
@@ -252,9 +256,7 @@ const TableEditor: FC<Props> = ({
withIcon
variant="info"
className="!px-4 !py-3 mt-3"
- title={`${
- isNewRecord ? 'Turning on RLS' : 'RLS is on'
- }. Policies are required to query data.`}
+ title="Policies are required to query data"
>
<p>
You need to write an access policy before you can query data from this table.
@@ -274,11 +276,9 @@ const TableEditor: FC<Props> = ({
) : (
<Alert
withIcon
- variant="danger"
+ variant="warning"
className="!px-4 !py-3 mt-3"
- title={`${
- isNewRecord ? 'Turning off RLS' : 'RLS is off'
- }. You are allowing anonymous access to your table.`}
+ title="You are allowing anonymous access to your table"
>
<p>Anyone with the anon key will be able to modify or delete your data.</p>
<p className="mt-4">
@@ -346,9 +346,7 @@ const TableEditor: FC<Props> = ({
<ConfirmationModal
visible={rlsConfirmVisible}
- header={`Confirm turning RLS ${
- tableFields.isRLSEnabled ? 'off' : 'on'
- } for this table`}
+ header="Confirm"
buttonLabel="Confirm"
size="medium"
onSelectCancel={() => setRlsConfirmVisible(false)}
@@ -361,43 +359,26 @@ const TableEditor: FC<Props> = ({
<div className="flex gap-4 my-6">
<div>
<div className="w-16 h-16 bg-scale-300 flex flex-col justify-center text-center items-center rounded-full">
- {tableFields.isRLSEnabled ? (
- <IconUnlock strokeWidth={2} size={24} />
- ) : (
- <IconLock strokeWidth={2} size={24} />
- )}
+ <IconUnlock strokeWidth={2} size={24} />
</div>
</div>
<div className="text-sm text-scale-1100 grid gap-4">
- {tableFields.isRLSEnabled ? (
- <div className="grid gap-3">
- <p>
- You are turning Row Level Security(RLS) <u>off</u> for this table.
- </p>
+ <div className="grid gap-1">
+ <p>
+ Row Level Security will be turned <u>off</u> for this table.
+ </p>
- <div className="mt-4 bg-scale-300 dark:bg-scale-500 p-4">
- <h3 className="text-base text-scale-1200">Important</h3>
+ <Alert
+ variant="warning"
+ className="!px-4 !py-3 mt-3"
+ title=" You are allowing anonymous access to your table"
+ >
+ <p>
Anyone with the anon key can modify or delete data. <br />
We recommend using RLS policies to control access to your data.
- </div>
- </div>
- ) : (
- <div className="grid gap-3">
- <p>
- You are turning Row Level Security(RLS){' '}
- <u>
- <strong>on</strong>
- </u>{' '}
- for this table.
</p>
- <div className="mt-4 bg-scale-300 dark:bg-scale-500 p-4">
- <h3 className="text-base text-scale-1200">Important</h3>
- Before querying data from this table, it is necessary to write RLS
- policies. If access policies are not in place, your queries will always
- return an <u>empty array</u> of results.
- </div>
- </div>
- )}
+ </Alert>
+ </div>
<div className="mt-3">
<p>Learn more about RLS:</p>