The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
fix(docs) Use CLI instead of curl for Network Restrictions topic (#47476)
Miranda Limonczenkoc790bd44a338
diff --git a/apps/docs/content/guides/platform/network-restrictions.mdx b/apps/docs/content/guides/platform/network-restrictions.mdxindex 9785743fb4b..b91a0ddc290 100644--- a/apps/docs/content/guides/platform/network-restrictions.mdx+++ b/apps/docs/content/guides/platform/network-restrictions.mdx@@ -4,99 +4,102 @@ title: 'Network Restrictions'description: "Apply network restrictions for your project's database."---+This topic explains how to configure network restrictions for your Supabase project's database. Network restrictions let you control which IP ranges can connect to Postgres and its pooler, reducing your project's exposure to unauthorized access.+<Admonition type="note">-If you can't find the Network Restrictions section at the bottom of your [Database Settings](/dashboard/project/_/database/settings), update your version of Postgres in the [Infrastructure Settings](/dashboard/project/_/settings/infrastructure).+If you can't find the Network Restrictions section in your [Database Settings](/dashboard/project/_/database/settings), update your Postgres version in [Infrastructure Settings](/dashboard/project/_/settings/infrastructure).</Admonition>-Each Supabase project comes with configurable restrictions on the IP ranges that are allowed to connect to Postgres and its pooler ("your database"). These restrictions are enforced before traffic reaches your database. If a connection is not restricted by IP, it still needs to authenticate successfully with valid database credentials.--If direct connections to your database [resolve to a IPv6 address](/dashboard/project/_/database/settings), you need to add both IPv4 and IPv6 CIDRs to the list of allowed CIDRs. Network Restrictions will be applied to all database connection routes, whether pooled or direct. You will need to add both the IPv4 and IPv6 networks you want to allow. There are two exceptions: If you have been granted an extension on the IPv6 migration OR if you have purchased the [IPv4 add-on](/dashboard/project/_/settings/addons), you need only add IPv4 CIDRs.--## To get started via the Dashboard:+Each Supabase project supports configurable restrictions on the IP ranges allowed to connect to Postgres and its pooler. These restrictions are enforced before traffic reaches your database. Connections that aren't restricted by IP still need to authenticate with valid database credentials.-Network restrictions can be configured in the [Database Settings](/dashboard/project/_/database/settings) page. Ensure that you have [Owner or Admin permissions](/docs/guides/platform/access-control#manage-team-members) for the project that you are enabling network restrictions.+If direct connections to your database [resolve to an IPv6 address](/dashboard/project/_/database/settings), add both IPv4 and IPv6 CIDRs to your allowlist. Network restrictions apply to all connection routes, whether pooled or direct. There are two exceptions: if you have an extension on the IPv6 migration, or if you have the [IPv4 add-on](/dashboard/project/_/settings/addons), you only need to add IPv4 CIDRs.-## To get started via the Management API:+## Configure with the dashboard [#to-get-started-via-the-dashboard]-You can also manage network restrictions using the Management API:+To configure network restrictions with the dashboard:-```bash-# Get your access token from https://supabase.com/dashboard/account/tokens-export SUPABASE_ACCESS_TOKEN="your-access-token"-export PROJECT_REF="your-project-ref"+1. Open your project's [Database Settings](/dashboard/project/_/database/settings) page.+1. In the Network Restrictions section, make your changes. You need [Owner or Admin permissions](/docs/guides/platform/access-control#manage-team-members) to make changes.-# Get current network restrictions-curl -X GET "https://api.supabase.com/v1/projects/$PROJECT_REF/network-restrictions" \- -H "Authorization: Bearer $SUPABASE_ACCESS_TOKEN"+## Configure with the CLI [#to-get-started-via-the-cli]-# Update network restrictions-curl -X POST "https://api.supabase.com/v1/projects/$PROJECT_REF/network-restrictions/apply" \- -H "Authorization: Bearer $SUPABASE_ACCESS_TOKEN" \- -H "Content-Type: application/json" \- -d '{- "db_allowed_cidrs": [- "192.168.0.1/24",- ]- }'-```--## To get started via the CLI:+To configure network restrictions with the CLI:1. [Install](/docs/guides/cli) the Supabase CLI 1.22.0+.-1. [Log in](/docs/guides/cli/local-development#log-in-to-the-supabase-cli) to your Supabase account using the CLI.-1. If your project was created before 23rd December 2022, it will need to be [upgraded to the latest Supabase version](/docs/guides/platform/migrating-and-upgrading-projects) before Network Restrictions can be used.-1. Ensure that you have [Owner or Admin permissions](/docs/guides/platform/access-control#manage-team-members) for the project that you are enabling network restrictions.+1. [Log in](/docs/guides/cli/local-development#log-in-to-the-supabase-cli) to your Supabase account.+1. If your project was created before December 23, 2022, [upgrade it to the latest Supabase version](/docs/guides/platform/migrating-and-upgrading-projects) before using network restrictions.+1. Ensure you have [Owner or Admin permissions](/docs/guides/platform/access-control#manage-team-members) for the project.### Check restrictions-You can use the `get` subcommand of the CLI to retrieve the restrictions currently in effect.+To check your current network restrictions:-If restrictions have been applied, the output of the `get` command will reflect the IP ranges allowed to connect:+1. Complete the steps in [Configure with the CLI](#to-get-started-via-the-cli).+1. Run the `get` subcommand to retrieve the restrictions currently in effect:-```bash-> supabase network-restrictions --project-ref {ref} get --experimental-DB Allowed IPv4 CIDRs: &[183.12.1.1/24]-DB Allowed IPv6 CIDRs: &[2001:db8:3333:4444:5555:6666:7777:8888/64]-Restrictions applied successfully: true-```+ ```bash+ > supabase network-restrictions get --project-ref {ref} --experimental+ DB Allowed IPv4 CIDRs: &[183.12.1.1/24]+ DB Allowed IPv6 CIDRs: &[2001:db8:3333:4444:5555:6666:7777:8888/64]+ Restrictions applied successfully: true+ ```-If restrictions have never been applied to your project, the list of allowed CIDRs will be empty, but they will also not have been applied ("Restrictions applied successfully: false"). As a result, all IPs are allowed to connect to your database:+ If restrictions have never been applied, the allowed CIDRs list is empty and `Restrictions applied successfully` is `false`. All IPs can connect:-```bash-> supabase network-restrictions --project-ref {ref} get --experimental-DB Allowed IPv4 CIDRs: []-DB Allowed IPv6 CIDRs: []-Restrictions applied successfully: false-```+ ```bash+ > supabase network-restrictions get --project-ref {ref} --experimental+ DB Allowed IPv4 CIDRs: []+ DB Allowed IPv6 CIDRs: []+ Restrictions applied successfully: false+ ```### Update restrictions-The `update` subcommand is used to apply network restrictions to your project:+To update your network restrictions:++1. Complete the steps in [Configure with the CLI](#to-get-started-via-the-cli).+1. Run the `update` subcommand with the CIDRs you want to allow:-```bash-> supabase network-restrictions --project-ref {ref} update --db-allow-cidr 183.12.1.1/24 --db-allow-cidr 2001:db8:3333:4444:5555:6666:7777:8888/64 --experimental-DB Allowed IPv4 CIDRs: &[183.12.1.1/24]-DB Allowed IPv6 CIDRs: &[2001:db8:3333:4444:5555:6666:7777:8888/64]-Restrictions applied successfully: true-```+ ```bash+ > supabase network-restrictions update --project-ref {ref} --db-allow-cidr 183.12.1.1/24 --db-allow-cidr 2001:db8:3333:4444:5555:6666:7777:8888/64 --experimental+ DB Allowed IPv4 CIDRs: &[183.12.1.1/24]+ DB Allowed IPv6 CIDRs: &[2001:db8:3333:4444:5555:6666:7777:8888/64]+ Restrictions applied successfully: true+ ```-The restrictions specified (in the form of CIDRs) replaces any restrictions that might have been applied in the past.-To add to the existing restrictions, you must include the existing restrictions within the list of CIDRs provided to the `update` command.+ The CIDRs you provide replace any previously applied restrictions. To keep existing restrictions, include them alongside any new CIDRs in the `update` command.++### Append a CIDR to existing restrictions++To append a CIDR to your existing restrictions:++1. Complete the steps in [Configure with the CLI](#to-get-started-via-the-cli).+1. Run the `update` subcommand with the `--append` flag to add a CIDR without replacing existing restrictions:++ ```bash+ > supabase network-restrictions update --project-ref {ref} --db-allow-cidr 1.2.3.4/32 --append --experimental+ DB Allowed IPv4 CIDRs: &[183.12.1.1/24 1.2.3.4/32]+ DB Allowed IPv6 CIDRs: &[2001:db8:3333:4444:5555:6666:7777:8888/64]+ Restrictions applied successfully: true+ ```### Remove restrictions-To remove all restrictions on your project, you can use the `update` subcommand with the CIDR `0.0.0.0/0`:+To remove all network restrictions:++1. Complete the steps in [Configure with the CLI](#to-get-started-via-the-cli).+1. Run the `update` subcommand with the CIDR `0.0.0.0/0` to remove all restrictions:-```bash-> supabase network-restrictions --project-ref {ref} update --db-allow-cidr 0.0.0.0/0 --db-allow-cidr ::/0 --experimental-DB Allowed IPv4 CIDRs: &[0.0.0.0/0]-DB Allowed IPv6 CIDRs: &[::/0]-Restrictions applied successfully: true-```+ ```bash+ > supabase network-restrictions update --project-ref {ref} --db-allow-cidr 0.0.0.0/0 --db-allow-cidr ::/0 --experimental+ DB Allowed IPv4 CIDRs: &[0.0.0.0/0]+ DB Allowed IPv6 CIDRs: &[::/0]+ Restrictions applied successfully: true+ ```## Limitations-- The current iteration of Network Restrictions applies to connections to Postgres and the database pooler; it doesn't currently apply to APIs offered over HTTPS (e.g., PostgREST, Storage, and Auth). This includes using Supabase client libraries like [supabase-js](/docs/reference/javascript).-- If network restrictions are enabled, direct access to your database from Edge Functions will always be blocked. Using the Supabase client library [supabase-js](/docs/reference/javascript) is recommended to connect to a database with network restrictions from Edge Functions.+- Network restrictions apply to Postgres and the database pooler. They don't apply to HTTPS APIs such as PostgREST, Storage, and Auth, or to Supabase client libraries like [supabase-js](/docs/reference/javascript).+- With network restrictions applied, Edge functions lose direct access to the database. Use [supabase-js](/docs/reference/javascript) to connect to the database from Edge Functions instead.