From 1387f0c14bfc8514da470aec909058a15cbd161f Mon Sep 17 00:00:00 2001 From: Copple <10214025+kiwicopple@users.noreply.github.com> Date: Tue, 22 Aug 2023 15:18:39 +0200 Subject: [PATCH 01/60] removes deprecated section --- .../pages/guides/auth/row-level-security.mdx | 38 ------------------- 1 file changed, 38 deletions(-) diff --git a/apps/docs/pages/guides/auth/row-level-security.mdx b/apps/docs/pages/guides/auth/row-level-security.mdx index 04207975b8171..148c62ad2152f 100644 --- a/apps/docs/pages/guides/auth/row-level-security.mdx +++ b/apps/docs/pages/guides/auth/row-level-security.mdx @@ -437,44 +437,6 @@ postgres=> table public.profiles; -## Deprecated features - -We have deprecate some functions to ensure better performance and extensibilty of RLS policies. - -### `auth.role()` - - - -Deprecated: The `auth.role()` function has been deprecated in favour of using the `TO` field, natively supported within Postgres. - - - -```sql --- DEPRECATED -create policy "Public profiles are viewable by everyone." -on profiles for select using ( - auth.role() = 'authenticated' or auth.role() = 'anon' -); - --- RECOMMENDED -create policy "Public profiles are viewable by everyone." -on profiles for select -to authenticated, anon -using ( - true -); -``` - -### `auth.email()` - - - -Deprecated. Use `auth.jwt() ->> 'email'` instead. - - - -Returns the email of the user making the request. - export const Page = ({ children }) => export default Page From 4defada6a7225dce97edab00eaba3362944a4311 Mon Sep 17 00:00:00 2001 From: Copple <10214025+kiwicopple@users.noreply.github.com> Date: Tue, 22 Aug 2023 15:55:37 +0200 Subject: [PATCH 02/60] adds some docs on postgres roles, cleans up the Self-hosting section --- .../NavigationMenu.constants.ts | 15 +-- .../pages/guides/database/postgres-roles.mdx | 109 ++++++++++++++++++ apps/docs/pages/guides/self-hosting.mdx | 41 +------ 3 files changed, 118 insertions(+), 47 deletions(-) create mode 100644 apps/docs/pages/guides/database/postgres-roles.mdx diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts index 37803d4823b99..0ae5226d020fe 100644 --- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts +++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts @@ -556,19 +556,20 @@ export const database: NavMenuConstant = { name: 'Postgres Guides', url: undefined, items: [ - { - name: 'Analyzing efficiency and performance', - url: '/guides/database/inspect', - }, { name: 'JSON and unstructured data', url: '/guides/database/json', }, - { name: 'Implementing Full Text Search', url: '/guides/database/full-text-search' }, + { name: 'Using Full Text Search', url: '/guides/database/full-text-search' }, { name: 'Implementing Cascade Deletes', url: '/guides/database/postgres/cascade-deletes' }, - { name: 'Implementing column encryption', url: '/guides/database/column-encryption' }, - { name: 'Partitioning your tables', url: '/guides/database/partitions' }, { name: 'Query Optimization', url: '/guides/database/query-optimization' }, + { + name: 'Analyzing efficiency and performance', + url: '/guides/database/inspect', + }, + { name: 'Managing Postgres Roles', url: '/guides/database/postgres-roles' }, + { name: 'Partitioning your tables', url: '/guides/database/partitions' }, + { name: 'Implementing column encryption', url: '/guides/database/column-encryption' }, { name: 'Testing your database', url: '/guides/database/testing' }, { name: 'Managing Timeouts', url: '/guides/database/timeouts' }, { name: 'Managing Passwords', url: '/guides/database/managing-passwords' }, diff --git a/apps/docs/pages/guides/database/postgres-roles.mdx b/apps/docs/pages/guides/database/postgres-roles.mdx new file mode 100644 index 0000000000000..b2e68cc71651c --- /dev/null +++ b/apps/docs/pages/guides/database/postgres-roles.mdx @@ -0,0 +1,109 @@ +import Layout from '~/layouts/DefaultGuideLayout' + +export const meta = { + id: 'postgres-roles', + title: 'Postgres Roles', + description: 'Managing access to your Postgres database and configuring permissions.', + subtitle: 'Managing access to your Postgres database and configuring permissions.', +} + +PostgreSQL manages database access permissions using the concept of roles. Generally you wouldn't use these roles for your own application - they are mostly for configuring _system access_ to your database. If you want to confgure _application access_, then you should use Row Level Security (although in some cases, you can mix RLS and Postgres Roles to build an extremely powerful Auth system). + +## Users vs Roles + +In PostgreSQL, roles can function as users or groups of users. Users are roles with login privileges, while groups (also known as role groups) are roles that don't have login privileges but can be used to manage permissions for multiple users. + +## Superuser Roles + +The superuser role has unrestricted access to the database system. Typically these roles will be able to bypass all security measures (like Row Level Security). Be cautious when granting superuser privileges as it can potentially lead to security risks. + +## Creating Roles + +You can create a role using the `create role` command: + +```sql +create role "role_name"; +``` + +## Granting Permissions + +Roles can be granted various permissions on database objects using the `GRANT` command. Permissions include `SELECT`, `INSERT`, `UPDATE`, and `DELETE`. You can configure access to almost any object inside your database - including tables, views, functions, and triggers. + +## Revoking Permissions + +Permissions can be revoked using the `REVOKE` command: + +```sql +REVOKE permission_type ON object_name FROM role_name; +``` + +## Role Hierarchy + +Roles can be organized in a hierarchy, where one role can inherit permissions from another. This simplifies permission management, as you can define permissions at a higher level and have them automatically apply to all child roles. + +### Role inheritance + +To create a role hierarchy, you first need to create the parent and child roles. The child role will inherit permissions from its parent. Child roles can be added using the INHERIT option when creating the role: + +```sql +create role "child_role_name" inherit "parent_role_name"; +``` + +### Preventing inheritance + +In some cases, you might want to prevent a role from having a child relationship (typically superuser roles). You can prevent inheritance relations using NOINHERIT: + +```sql +alter role "child_role_name" noinherit; +``` + +## Supabase Roles + +Postgres comes with a set of [predefined roles](https://www.postgresql.org/docs/current/predefined-roles.html). Supabase extends this with a default set of roles which are configured on your database when you start a new project: + +### `postgres` + +The default Postgres role. This has admin privileges. + +### `anon` + +For "anonymous access". This is the role which the API (PostgREST) will use when a user _is not_ logged in. + +### `authenticator` + +A special role for the API (PostgREST). It has very limited access, and is used to validate a JWT and then +"change into" another role determined by the JWT verification. + +### `authenticated` + +For "authenticated access". This is the role which the API (PostgREST) will use when a user _is_ logged in. + +### `service_role` + +For elevated access. This role is used by the API (PostgREST) to bypass Row Level Security. + +### `supabase_auth_admin` + +Used by the Auth middleware to connect to the database and run migration. Access is scoped to the `auth` schema. + +### `supabase_storage_admin` + +Used by the Auth middleware to connect to the database and run migration. Access is scoped to the `storage` schema. + +### `dashboard_user` + +For running commands via the Supabase UI. + +### `supabase_admin` + +Supabase Administrative role for maintaining your database. + +## Resources + +- Official Postgres docs: [Database Roles](https://www.postgresql.org/docs/current/database-roles.html) +- Official Postgres docs: [Role Membership](https://www.postgresql.org/docs/current/role-membership.html) +- Official Postgres docs: [Function Permissions](https://www.postgresql.org/docs/current/perm-functions.html) + +export const Page = ({ children }) => + +export default Page diff --git a/apps/docs/pages/guides/self-hosting.mdx b/apps/docs/pages/guides/self-hosting.mdx index aadf096723b24..1ad426b229b83 100644 --- a/apps/docs/pages/guides/self-hosting.mdx +++ b/apps/docs/pages/guides/self-hosting.mdx @@ -138,46 +138,7 @@ For working with JWT and Auth functions. ### Roles -Supabase creates several default roles in your Postgres database. To restore defaults at any time you can run the commands inside the -[schema initialization scripts](https://github.com/supabase/postgres/tree/develop/migrations/db/init-scripts). Remember to change your -[role passwords](/docs/guides/self-hosting/docker#securing-your-setup) before deploying to production environments. - -##### `postgres` - -The default PostgreSQL role. This has admin privileges. - -##### `anon` - -For "anonymous access". This is the role which the API (PostgREST) will use when a user _is not_ logged in. - -##### `authenticator` - -A special role for the API (PostgREST). It has very limited access, and is used to validate a JWT and then -"change into" another role determined by the JWT verification. - -##### `authenticated` - -For "authenticated access". This is the role which the API (PostgREST) will use when a user _is_ logged in. - -##### `service_role` - -For elevated access. This role is used by the API (PostgREST) to bypass Row Level Security. - -##### `supabase_auth_admin` - -Used by the Auth middleware to connect to the database and run migration. Access is scoped to the `auth` schema. - -##### `supabase_storage_admin` - -Used by the Auth middleware to connect to the database and run migration. Access is scoped to the `storage` schema. - -##### `dashboard_user` - -For running commands via the Supabase UI. - -##### `supabase_admin` - -Supabase Administrative role for maintaining your database. +Supabase creates several [default roles](/docs/guides/database/postgres-roles) in your Postgres database. To restore defaults at any time you can run the commands inside the [schema initialization scripts](https://github.com/supabase/postgres/tree/develop/migrations/db/init-scripts). Remember to change your [role passwords](/docs/guides/self-hosting/docker#securing-your-setup) before deploying to production environments. ### Realtime Logs From c04fb1d0c02c15f82f0f3d5028e652a73f056359 Mon Sep 17 00:00:00 2001 From: Copple <10214025+kiwicopple@users.noreply.github.com> Date: Tue, 22 Aug 2023 16:02:27 +0200 Subject: [PATCH 03/60] fix up some extremely outdated content --- apps/docs/pages/guides/database.mdx | 30 +++++++++++------------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/apps/docs/pages/guides/database.mdx b/apps/docs/pages/guides/database.mdx index 440277b9a8b6e..4694813acf354 100644 --- a/apps/docs/pages/guides/database.mdx +++ b/apps/docs/pages/guides/database.mdx @@ -3,25 +3,24 @@ import Layout from '~/layouts/DefaultGuideLayout' export const meta = { id: 'database', title: 'Database', - description: 'Use Supabase to manage your data.', + description: 'Using Supabase to manage your data.', + subtitle: 'Using Supabase to manage your data.', sidebar_label: 'Overview', } -Every Supabase project comes with a full [Postgres](https://www.postgresql.org/) database, a free and open source -database which is considered one of the world's most stable and advanced databases. +Every Supabase project comes with a full [Postgres](https://www.postgresql.org/) database, a free and open source database which is considered one of the world's most stable and advanced databases. ## Postgres or PostgreSQL? -PostgreSQL the database was derived from the POSTGRES Project, a package written at the University of California at Berkeley in 1986. -This package included a query language called "PostQUEL". +PostgreSQL the database was derived from the POSTGRES Project, a package written at the University of California at Berkeley in 1986. This package included a query language called "PostQUEL". -In 1994, Postgres95 was built on top of POSTGRES code, adding an SQL language interpreter as a replacement for PostQUEL. -Eventually, Postgres95 was renamed to PostgreSQL to reflect the SQL query capability. +In 1994, Postgres95 was built on top of POSTGRES code, adding an SQL language interpreter as a replacement for PostQUEL. Eventually, Postgres95 was renamed to PostgreSQL to reflect the SQL query capability. -After this, many people referred to it as Postgres since it's less prone to confusion. Supabase is all about -simplicity, so we also refer to it as Postgres. +After this, many people referred to it as Postgres since it's less prone to confusion. Supabase is all about simplicity, so we also refer to it as Postgres. -## Features +## Supabase Studio + +Postgres is known to be one of the most extensible databases available, so you can use it to build almost any application. The Supabase platform simply makes this easier with a simple-to-use dashboard called "Supabase Studio". ### Table View @@ -71,16 +70,13 @@ Supabase comes with a SQL Editor. You can also save your favorite queries to run -Database backups **do not** include objects stored via the Storage API, as the database only -includes metadata about these objects. Restoring an old backup does not restore objects that have -been deleted since then. +Database backups **do not** include objects stored via the Storage API, as the database only includes metadata about these objects. Restoring an old backup does not restore objects that have been deleted since then. ### Extensions -To expand the functionality of your Postgres database, you can use extensions. -You can enable Postgres extensions with the click of a button within the Supabase dashboard. +To expand the functionality of your Postgres database, you can use extensions. You can enable Postgres extensions with the click of a button within the Supabase dashboard.