The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
docs: add Realtime security docs
Wen Bo Xie27042469b546
diff --git a/README.md b/README.mdindex 0f75fbb3c36..2c19e93ffed 100644--- a/README.md+++ b/README.md@@ -54,7 +54,7 @@ You can also [self-host](https://supabase.com/docs/guides/self-hosting) and [dev- [PostgreSQL](https://www.postgresql.org/) is an object-relational database system with over 30 years of active development that has earned it a strong reputation for reliability, feature robustness, and performance.-- [Realtime](https://github.com/supabase/realtime) is an Elixir server that allows you to listen to PostgreSQL inserts, updates, and deletes using websockets. Supabase listens to Postgres' built-in replication functionality, converts the replication byte stream into JSON, then broadcasts the JSON over websockets.+- [Realtime](https://github.com/supabase/realtime) is an Elixir server that allows you to listen to PostgreSQL inserts, updates, and deletes using websockets. Realtime polls Postgres' built-in replication functionality for database changes, converts changes to JSON, then broadcasts the JSON over websockets to authorized clients.- [PostgREST](http://postgrest.org/) is a web server that turns your PostgreSQL database directly into a RESTful API- [Storage](https://github.com/supabase/storage-api) provides a RESTful interface for managing Files stored in S3, using Postgres to manage permissions.- [postgres-meta](https://github.com/supabase/postgres-meta) is a RESTful API for managing your Postgres, allowing you to fetch tables, add roles, and run queries, etc.diff --git a/docker/docker-compose.yml b/docker/docker-compose.ymlindex ac54c922e0a..53f36bc21a0 100644--- a/docker/docker-compose.yml+++ b/docker/docker-compose.yml@@ -87,7 +87,7 @@ services:realtime:container_name: supabase-realtime- image: supabase/realtime:v0.15.0+ image: supabase/realtime:v0.19.0depends_on:- dbrestart: unless-stopped@@ -97,10 +97,17 @@ services:DB_NAME: postgresDB_USER: postgresDB_PASSWORD: ${POSTGRES_PASSWORD}- SLOT_NAME: supabase_realtime+ DB_SSL: "false"PORT: 4000- SECURE_CHANNELS: "true"JWT_SECRET: ${JWT_SECRET}+ REPLICATION_MODE: RLS+ REPLICATION_POLL_INTERVAL: 100+ SECURE_CHANNELS: "true"+ SLOT_NAME: supabase_realtime_rls+ TEMPORARY_SLOT: "true"+ command: >+ bash -c "./prod/rel/realtime/bin/realtime eval Realtime.Release.migrate+ && ./prod/rel/realtime/bin/realtime start"storage:container_name: supabase-storagediff --git a/docker/volumes/db/init/00-initial-schema.sql b/docker/volumes/db/init/00-initial-schema.sqlindex f3e63542a92..81a2ed4fc40 100644--- a/docker/volumes/db/init/00-initial-schema.sql+++ b/docker/volumes/db/init/00-initial-schema.sql@@ -1,4 +1,5 @@--- Set up reatime+-- Set up realtime+create schema if not exists realtime;-- create publication supabase_realtime; -- defaults to empty publicationcreate publication supabase_realtime;diff --git a/examples/nextjs-auth-tailwind/pages/index.js b/examples/nextjs-auth-tailwind/pages/index.jsindex abe68990d10..287a39a1cdb 100644--- a/examples/nextjs-auth-tailwind/pages/index.js+++ b/examples/nextjs-auth-tailwind/pages/index.js@@ -15,7 +15,7 @@ const Index = () => {</h1><p className="mt-3 text-base text-white sm:mt-5 sm:text-lg sm:max-w-xl sm:mx-auto md:mt-5 md:text-xl lg:mx-0">Create a backend in less than 2 minutes. Start your project with a Postgres Database,- Authentication, instant APIs, realtime subscriptions and Storage.+ Authentication, instant APIs, Realtime subscriptions and Storage.</p><div className="mt-5 sm:mt-8 sm:flex sm:justify-center lg:justify-start"><div className="rounded-md shadow">diff --git a/studio/components/to-be-cleaned/Docs/Pages/Authentication.js b/studio/components/to-be-cleaned/Docs/Pages/Authentication.jsindex 4ed087b5b06..30912068b0e 100644--- a/studio/components/to-be-cleaned/Docs/Pages/Authentication.js+++ b/studio/components/to-be-cleaned/Docs/Pages/Authentication.js@@ -42,18 +42,20 @@ export default function Authentication({ autoApiService, selectedLang }) {</p><h4 className="mt-8">Realtime Security</h4><p>- The realtime server doesn't provide per-user security. Until we build a more robust auth- system for websockets, you shouldn't use realtime on any client which is exposed to- users.+ Realtime server broadcasts database changes to authorized users depending on your Row Level Security (RLS) policies.+ We recommend that you create an entirely new publication and ensure that you enable row level security and set row security+ policies on tables that you add to the publication. However, you may choose to disable RLS on a table and have changes broadcast+ to all connected clients.</p><p>- For security purposes, you can run{' '}+ You can get started by running{' '}<code>begin; drop publication if exists supabase_realtime; create publicationsupabase_realtime; commit;</code>. This creates a publication which is not subscribed to any table and completely- disables realtime updates on the Supabase client.+ disables Realtime on the Supabase client. Then, you can add any table from your `public` schema and+ changes will be broadcast accordingly.</p></article><article className="code">diff --git a/studio/pages/project/[ref]/api/index.tsx b/studio/pages/project/[ref]/api/index.tsxindex 8f77c40f869..38c3914be07 100644--- a/studio/pages/project/[ref]/api/index.tsx+++ b/studio/pages/project/[ref]/api/index.tsx@@ -533,10 +533,9 @@ const ResourceContent = ({<div className="doc-section"><article className="text "><p>- Supabase provides realtime functionality. Right now we recommend only using this on a- server-side application (see our notes in the Authentication section).+ Supabase provides realtime functionality and broadcasts database changes to authorized users depending on Row Level+ Security (RLS) policies.</p>- <p>We are building advanced auth so that you can use realtime streams from anywhere.</p><p><a href="https://supabase.com/docs/client/subscribe" target="_blank">Learn more.diff --git a/web/docs/going-into-prod.mdx b/web/docs/going-into-prod.mdxindex c4fe7e50438..5ea25588196 100644--- a/web/docs/going-into-prod.mdx+++ b/web/docs/going-into-prod.mdx@@ -15,10 +15,9 @@ After developing your project, and deciding it's time to Go Live With Real Users- Ensure RLS is enabled- Tables that do not have RLS enabled with reasonable policies allow any client to access and modify their data. This is unlikely to be what you want in the majority of cases.- [Learn more about RLS](/docs/guides/auth/row-level-security)-- Ensure replication is disabled for tables containing sensitive data:- - Today, Realtime does not respect RLS policies and any client with your anon key can listen to changes on tables where replication is enabled.- - Go to the Database > Replication page in the Supabase Dashboard to manage these settings- - We are launching [RLS for realtime](https://github.com/supabase/walrus) soon, but in the meantime you should only use it for tables containing public data (scoreboards, blog posts, etc.)+- Enable replication on tables containing sensitive data by enabling Row Level Security (RLS) and setting row security policies:+ - Go to the Authentication > Policies page in the Supabase Dashboard to enable RLS and create security policies+ - Go to the Database > Replication page in the Supabase Dashboard to manage replication tables- Enable 2FA on Github- Since your Github account gives you administrative rights to your Supabase project, you should protect it with a strong password and 2FA using a U2F key or a TOTP app.- Ensure email confirmations are enabled in the Auth > Settings pagediff --git a/web/docs/guides/auth.mdx b/web/docs/guides/auth.mdxindex 624b0e8210f..0fbe3df1ebd 100644--- a/web/docs/guides/auth.mdx+++ b/web/docs/guides/auth.mdx@@ -106,14 +106,18 @@ Supabase provides a special function in Postgres, `auth.uid()`, which extracts t## Tips-#### Disable realtime for private tables+#### Enable Realtime for database tables++Realtime server broadcasts database changes to authorized users depending on your Row Level Security (RLS) policies.+We recommend that you create an entirely new publication and ensure that you enable row level security and set row security+policies on tables that you add to the publication. However, you may choose to disable RLS on a table and have changes broadcast+to all connected clients.-Our realtime server doesn't provide per-user security. Until we build a more robust auth system for WebSockets, you can disable realtime functionality for any private tables. To do this, you can manage the underlying Postgres replication publication:```sql/*** REALTIME SUBSCRIPTIONS- * Only allow realtime listening on public tables.+ * Realtime enables listening to any table in your public schema.*/begin;@@ -131,8 +135,6 @@ alter publication supabase_realtime add table products;alter publication supabase_realtime add table posts;```-We're in the process of building [enhanced realtime security](https://github.com/supabase/walrus).-## Next Steps- Read more about Auth in the [Guides](/docs/guides/auth/intro).diff --git a/web/docs/guides/auth/row-level-security.mdx b/web/docs/guides/auth/row-level-security.mdxindex 5ee6a1a7ff0..4625e45dde3 100644--- a/web/docs/guides/auth/row-level-security.mdx+++ b/web/docs/guides/auth/row-level-security.mdx@@ -270,14 +270,17 @@ using (## Tips-### Disable realtime for private tables+### Enable Realtime for database tables-Our realtime server doesn't provide per-user security. Until we build a more robust auth system for WebSockets, you can disable realtime functionality for any private tables. To do this, you can manage the underlying Postgres replication publication:+Realtime server broadcasts database changes to authorized users depending on your Row Level Security (RLS) policies.+We recommend that you create an entirely new publication and ensure that you enable row level security and set row security+policies on tables that you add to the publication. However, you may choose to disable RLS on a table and have changes broadcast+to all connected clients.```sql/*** REALTIME SUBSCRIPTIONS- * Only allow realtime listening on public tables.+ * Realtime enables listening to any table in your public schema.*/begin;@@ -295,8 +298,6 @@ alter publication supabase_realtime add table products;alter publication supabase_realtime add table posts;```-We're in the process of building [enhanced realtime security](https://github.com/supabase/walrus).-### You don't have to use policiesYou can also put your authorization rules in your middleware, similar to how you would create security rules with any other `backend <-> middleware <-> frontend` architecture.diff --git a/web/docs/guides/database.mdx b/web/docs/guides/database.mdxindex 3890adcaa01..ab35f81f1a6 100644--- a/web/docs/guides/database.mdx+++ b/web/docs/guides/database.mdx@@ -70,7 +70,13 @@ You can enable Postgres extensions with the click of a button within the Supabas### RealtimeSupabase provides a realtime engine on top of Postgres, so that you can listen to changes as they happen.-Our realtime engine uses the built-in replication functionality of Postgres.+Our realtime engine uses the built-in replication functionality of Postgres.++Realtime server broadcasts database changes to authorized users depending on your Row Level Security (RLS) policies.+We recommend that you create an entirely new publication and ensure that you enable row level security and set row security+policies on tables that you add to the publication. However, you may choose to disable RLS on a table and have changes broadcast+to all connected clients.+You can manage the realtime system, simply by[updating](/docs/guides/database/replication) the `supabase_realtime` publication.@@ -92,10 +98,6 @@ alter publication supabase_realtime add table products;alter publication supabase_realtime add table posts;```-| SECURITY WARNING |-| - |-| Please check [Disable realtime for private tables](/docs/guides/auth#disable-realtime-for-private-tables) for the current state of Realtime security. |-By default only "new" values are sent, but if you want to receive the old record (previous values) whenever you `update` or `delete` a record,you can update the replica identity of your tables, setting it to `full`:diff --git a/web/docs/guides/hosting/overview.mdx b/web/docs/guides/hosting/overview.mdxindex eab6c17b5e3..9794838b8cf 100644--- a/web/docs/guides/hosting/overview.mdx+++ b/web/docs/guides/hosting/overview.mdx@@ -24,7 +24,7 @@ If the tool doesn't exist, we build and open source it ourselves.- [PostgreSQL](https://www.postgresql.org/) is an object-relational database system with over 30 years of active development that has earned it a strong reputation for reliability, feature robustness, and performance.-- [Realtime](https://github.com/supabase/realtime) is an Elixir server that allows you to listen to PostgreSQL inserts, updates, and deletes using websockets. Supabase listens to Postgres' built-in replication functionality, converts the replication byte stream into JSON, then broadcasts the JSON over websockets.+- [Realtime](https://github.com/supabase/realtime) is an Elixir server that allows you to listen to PostgreSQL inserts, updates, and deletes using websockets. Realtime polls Postgres' built-in replication functionality for database changes, converts changes to JSON, then broadcasts the JSON over websockets to authorized clients.- [PostgREST](http://postgrest.org/) is a web server that turns your PostgreSQL database directly into a RESTful API- [Storage](https://github.com/supabase/storage-api) provides a RESTful interface for managing Files stored in S3, using Postgres to manage permissions.- [postgres-meta](https://github.com/supabase/postgres-meta) is a RESTful API for managing your Postgres, allowing you to fetch tables, add roles, and run queries, etc.diff --git a/www/components/Hero.tsx b/www/components/Hero.tsxindex a1ceafdab3e..8486d875537 100644--- a/www/components/Hero.tsx+++ b/www/components/Hero.tsx@@ -22,7 +22,7 @@ const Hero = () => {<Typography.Text><p className="mt-5 text-base sm:mt-5 lg:text-lg ">Create a backend in less than 2 minutes. Start your project with a Postgres- Database, Authentication, instant APIs, realtime subscriptions and Storage.+ Database, Authentication, instant APIs, Realtime subscriptions and Storage.</p><p className="mt-3 text-base">Serverless functions coming soon</p></Typography.Text>