# Static IP for Supabase

Source: https://prontaro.com/docs/integrations/supabase/

One dedicated IPv4 handles both sides of Supabase networking: outbound calls from Edge Functions and access to a locked-down Postgres database.

Inside Deno-based Edge Functions, outbound requests go through a Relay URL with standard `fetch()`, or through `Deno.createHttpClient` when you need multiple hosts or mTLS. To reach Supabase Postgres behind Network Restrictions from external apps, CI migrations, or `psql`, connect via `prontaro forward` or SOCKS5.

## Which method to choose

| Scenario | Prontaro method | Best for |
| --- | --- | --- |
| **Part 1. Edge Functions → partner REST API** | Relay URL (recommended) | Standard `fetch()` — no custom proxy client setup in Deno |
| **Part 1. Edge Functions → multiple hosts or mTLS** | HTTPS proxy (`Deno.createHttpClient`) | End-to-end TLS via HTTP CONNECT to any allowed host |
| **Part 2. External app / CI / `psql` → Supabase Postgres** | `prontaro forward` or `socks5h://` | Connects to PostgreSQL from your allowlisted static IPv4 |

A Relay URL decrypts TLS on the Prontaro server and opens a new HTTPS connection to the target API. Use HTTPS proxy when a partner requires end-to-end TLS or mTLS — see [Relay URLs](https://prontaro.com/docs/outbound/relay.md).

## Prerequisites

- A Prontaro account on Dedicated or Pro ([plans](https://prontaro.com/docs/billing/plans.md)). After subscribing, open [my.prontaro.com/ips](https://my.prontaro.com/ips), pick a location near your Supabase project’s region, and click **Add IP**.
- A Supabase project. Part 2 (Network Restrictions) requires the Supabase Pro plan or higher (not available on Supabase Free).
- No `prontaro CLI` is needed for Part 1: create Relay URLs or proxy credentials in the dashboard. Local `supabase` CLI is also optional — manage secrets and functions in the Supabase Dashboard.

## Part 1. Outbound static IP for Supabase Edge Functions

### Step 1. Create a Relay URL (recommended)

Add your dedicated IPv4 (`/32`) to the partner API’s allowlist, then create a Relay for its hostname in the dashboard:

1. Open **IP addresses** in [my.prontaro.com](https://my.prontaro.com/ips), select your IP, and click **Add relay address**.
2. Enter `api.example.com` and copy the generated URL (`https://relay-3f9c2a7e-5b1d-4c8a-9e60-1d2b3c4d5e6f.prontaro.run`).

IP addresses Relay address [Open in dashboard](https://my.prontaro.com/ips)

### Step 2. Store the secrets in Supabase

Add the secrets in the Supabase Dashboard:

**Edge Functions → Secrets → Add new secret**

- `PRONTARO_RELAY_URL`: `https://relay-3f9c2a7e-5b1d-4c8a-9e60-1d2b3c4d5e6f.prontaro.run`
- `PARTNER_API_TOKEN`: `your-partner-token`

Or with the Supabase CLI (`supabase secrets set` applies to hosted Edge Functions immediately with no redeploy required):

```bash
supabase secrets set PRONTARO_RELAY_URL="https://relay-3f9c2a7e-5b1d-4c8a-9e60-1d2b3c4d5e6f.prontaro.run"
supabase secrets set PARTNER_API_TOKEN="your-partner-token"
```

### Step 3. Call the Relay URL from your Edge Function

Use standard `fetch()` in Deno:

```ts
// supabase/functions/partner-call/index.ts
Deno.serve(async (req) => {
  const relayBase = Deno.env.get('PRONTARO_RELAY_URL');
  const token = Deno.env.get('PARTNER_API_TOKEN');

  if (!relayBase || !token) {
    return Response.json(
      { error: 'Missing PRONTARO_RELAY_URL or PARTNER_API_TOKEN' },
      { status: 500 },
    );
  }

  const targetUrl = new URL('/v1/status', relayBase);
  const upstream = await fetch(targetUrl, {
    method: req.method === 'POST' ? 'POST' : 'GET',
    headers: {
      Authorization: `Bearer ${token}`,
      'Content-Type': 'application/json',
    },
    body: req.method === 'POST' ? await req.text() : undefined,
    signal: AbortSignal.timeout(15_000),
  });

  return new Response(await upstream.text(), {
    status: upstream.status,
    headers: {
      'content-type': upstream.headers.get('content-type') ?? 'application/json',
    },
  });
});
```

Deploy via the Dashboard or `supabase functions deploy partner-call`.

### Step 4. Verify the Edge Function IP

1. Create a temporary Relay for `api.ipify.org` in the [dashboard](https://my.prontaro.com/ips) and store it in a secret named `PRONTARO_TEST_RELAY_URL`.
2. Deploy a temporary `egress-check` function that calls the root of that Relay URL (do not point `partner-call` at `api.ipify.org`, because `/v1/status` returns `404`):

```ts
// supabase/functions/egress-check/index.ts (remove after verifying)
Deno.serve(async () => {
  const res = await fetch(Deno.env.get('PRONTARO_TEST_RELAY_URL')!, {
    signal: AbortSignal.timeout(10_000),
  });
  return new Response((await res.text()).trim(), { status: res.status });
});
```

1. Copy your project’s `anon` key from **Project Settings → API** and call the function:

```
 curl -fsS "https://<project-ref>.supabase.co/functions/v1/egress-check" -H "Authorization: Bearer $SUPABASE_ANON_KEY"
203.0.113.10
```

After confirming the IP, delete the temporary `egress-check` function and temporary Relay in the dashboard.

### Alternative: HTTP proxy via `Deno.createHttpClient`

If you need end-to-end TLS via HTTP CONNECT or calls to multiple hosts from one function, create proxy credentials in the dashboard (**IP addresses → Proxy credentials**).

Save `https://u_edge:s3cr3t@<entry>.prontaro.io:443` in `PRONTARO_PROXY_URL` and reuse a module-level client:

```ts
// supabase/functions/partner-proxy/index.ts
const rawProxyUrl = Deno.env.get('PRONTARO_PROXY_URL');
const httpClient = rawProxyUrl
  ? (() => {
      const u = new URL(rawProxyUrl);
      return Deno.createHttpClient({
        proxy: {
          url: `${u.protocol}//${u.host}`,
          basicAuth: {
            username: decodeURIComponent(u.username),
            password: decodeURIComponent(u.password),
          },
        },
      });
    })()
  : null;

Deno.serve(async () => {
  if (!httpClient) {
    return Response.json({ error: 'PRONTARO_PROXY_URL is not set' }, { status: 500 });
  }

  const upstream = await fetch('https://api.example.com/v1/status', {
    client: httpClient,
    headers: { Authorization: `Bearer ${Deno.env.get('PARTNER_API_TOKEN')}` },
    signal: AbortSignal.timeout(15_000),
  });

  return new Response(await upstream.text(), {
    status: upstream.status,
    headers: { 'content-type': upstream.headers.get('content-type') ?? 'application/json' },
  });
});
```

> **Deno.createHttpClient compatibility**
>
> `Deno.createHttpClient` is a non-standard Deno API. If you hit runtime compatibility issues in hosted Supabase Edge Functions, use a Relay URL instead.

Once verified against `https://api.ipify.org`, lock the **To** list in the credentials’ **Access** tab down to `api.example.com:443`.

## Part 2. Connect to Supabase Postgres with Network Restrictions

When Network Restrictions (Supabase Pro and higher) are enabled, only allowlisted CIDRs can reach Postgres.

### Step 1. Add your static IP to Network Restrictions

**Project Settings → Database → Network Restrictions**

- `IPv4 CIDR`: `203.0.113.10/32`

### Step 2. Copy the Supavisor host and start port forwarding

From **Connect**, copy the Supavisor Session pooler host and port (for example, `aws-0-eu-central-1.pooler.supabase.com:5432`).

- **Why the Supavisor pooler:** direct `db.<ref>.supabase.co` hosts are IPv6-only without Supabase’s Dedicated IPv4 add-on. `*.pooler.supabase.com` resolves to IPv4 and works straight through your Prontaro IPv4.

Start `prontaro forward` to that host:

```bash
prontaro forward 15432 aws-0-eu-central-1.pooler.supabase.com:5432 --ip 203.0.113.10
```

```text
prontaro forward 15432 aws-0-eu-central-1.pooler.supabase.com:5432
  127.0.0.1:15432  →  aws-0-eu-central-1.pooler.supabase.com:5432 from your IP 203.0.113.10
```

### Step 3. Connect with `psql` and verify access

Pass your database password via `PGPASSWORD` (or enter it when prompted) and run a test query against `127.0.0.1:15432`:

```
 PGPASSWORD="$SUPABASE_DB_PASSWORD" psql "postgresql://postgres.<project-ref>@127.0.0.1:15432/postgres?sslmode=require" -c "SELECT 1;"
 ?column? 
----------
        1
(1 row)
```

> **Do not check your IP with SELECT inet_client_addr() through Supavisor**
>
> Supavisor terminates your client TCP connection and opens its own connection to Postgres, so `SELECT inet_client_addr()` returns an internal AWS pooler IP, not your dedicated static IPv4.
>
> Network Restrictions are enforced at the Supavisor entry point. A successful connection with restrictions enabled — plus the entry in [Logs](https://my.prontaro.com/journal) — confirms traffic exits from your static IP.
>
> Only direct connections (`db.<ref>.supabase.co` with Supabase’s IPv4 add-on) report your Prontaro IP in `inet_client_addr()`.

For apps with native SOCKS5 support, connect using `socks5h://`, verify the IP against `api.ipify.org`, and then restrict the **To** list to `*.pooler.supabase.com:5432` in the dashboard.

## Common errors

| Error | Cause | Fix |
| --- | --- | --- |
| Local `supabase functions serve` cannot read secrets | `supabase secrets set` only updates the hosted project. | Pass `--env-file .env.local` locally and keep `.env.local` out of Git. |
| Connection error or IPv6 failure on `db.<ref>.supabase.co:5432` | Direct host is IPv6-only without the Supabase IPv4 add-on. | Connect through the IPv4 Supavisor pooler (`*.pooler.supabase.com:5432`). |
| `SELECT inet_client_addr()` returns an internal IP instead of your static IP | Traffic passes through Supavisor, which opens its own connection to Postgres. | Verify by enabling Network Restrictions for your dedicated IPv4 (`/32`) or checking Prontaro [Logs](https://my.prontaro.com/journal). |
| Leaked Relay URL | Secret Relay URL appeared in client code or logs. | Delete the Relay under [IP addresses](https://my.prontaro.com/ips), create a new one, and update `PRONTARO_RELAY_URL`. |

For `407`, `403`, and general proxy or CLI issues, see [error codes](https://prontaro.com/docs/cli/errors.md) and [HTTP & SOCKS5 proxy](https://prontaro.com/docs/outbound/proxy.md).

## Next steps

- [Relay URLs](https://prontaro.com/docs/outbound/relay.md) — how Relay URLs work, password protection, and limits.
- [Local port forwarding (`prontaro forward`)](https://prontaro.com/docs/outbound/forward.md) — forward TCP database connections from your dedicated IPv4.
- [Static IP for Vercel](https://prontaro.com/docs/integrations/vercel.md) — static IP setup for Vercel Functions and Edge Runtime.
- [Static IP in GitHub Actions](https://prontaro.com/docs/integrations/github-actions.md) — run CI migrations and API calls from the same dedicated IPv4.
