Skip to content

Restrict Connections to a Service

Choose which networks can connect to a Managed PostgreSQL service, and change that list without cutting off the clients that already use it.

How the IP Filter Works

Each service has one IP filter: a list of CIDR blocks allowed to open a connection. A connection from an address that matches no entry is dropped, so the client times out instead of receiving an error.

  • A single host is written with a /32 suffix.
  • The filter is replaced as a whole on every update. Whatever you send becomes the entire filter.
  • An empty filter allows nothing. It does not mean “allow all”.

Connections are always encrypted with TLS and authenticated; the IP filter adds network access control on top of that.

The address to allow is the one the service sees. Behind a NAT gateway, a VPN or a CI runner, it is rarely the address of your workstation. Do not use 0.0.0.0/0: it matches every IPv4 address on the internet. Even for a short debugging session, allow the /32 of the host you work from.

Important

Do not rely on the IP filter to isolate the Database Services of your organization from each other: another service of the same organization can be able to connect even when its address is not in the filter. Give each application its own user and password, and treat those credentials as the boundary between your own services.

Set the IP Filter

Set the filter when you create the service, so it is never reachable from an address you did not intend:

exo dbaas create pg startup-4 my-postgresql -z ch-gva-2 \
  --pg-ip-filter=198.51.100.10/32

To replace the filter of an existing service:

exo dbaas update SERVICE_NAME -z ZONE -f --pg-ip-filter=CIDR_LIST

Parameters:

  • SERVICE_NAME: name of the Managed PostgreSQL service, for example my-postgresql.
  • ZONE: zone the service runs in, for example ch-gva-2.
  • CIDR_LIST: comma-separated list of CIDR blocks, with no spaces.

For example, to allow a single host and a /24 network:

exo dbaas update my-postgresql -z ch-gva-2 -f \
  --pg-ip-filter=198.51.100.10/32,203.0.113.0/24

The same change through the API, where the filter is a JSON array:

echo '{"ip-filter":["198.51.100.10/32","203.0.113.0/24"]}' | \
  exo api update-dbaas-service-pg my-postgresql -z ch-gva-2

Add or Remove an Address

Warning

Every update overwrites the whole list. Sending only a new address removes all the others and cuts off the clients that use them. Read the current filter first, then send the complete list.

  1. Read the current filter:

    exo api get-dbaas-service-pg SERVICE_NAME -z ZONE -q '"ip-filter"'

    The filter is also shown in the IP Filter row of exo dbaas show SERVICE_NAME -z ZONE.

  2. Send the complete new list. For example, if the filter of my-postgresql contains 198.51.100.10/32 and 203.0.113.0/24, adding 192.0.2.42/32 means sending all three:

    exo dbaas update my-postgresql -z ch-gva-2 -f \
      --pg-ip-filter=198.51.100.10/32,203.0.113.0/24,192.0.2.42/32

To remove an address, send the list without it.

Block Every Connection

An empty filter blocks all incoming connections, which cuts a service off the network without deleting it:

echo '{"ip-filter":[]}' | \
  exo api update-dbaas-service-pg my-postgresql -z ch-gva-2

The service keeps running and keeps its data. Restore access by sending the list of CIDR blocks again.

Read Replicas

A read replica is a separate service with its own IP filter. It does not inherit the filter of its primary, and a replica created without one starts with an empty filter, so it is unreachable. Set it on the replica exactly as on any service:

exo dbaas update REPLICA_SERVICE_NAME -z REPLICA_ZONE -f --pg-ip-filter=CIDR_LIST

Parameters:

  • REPLICA_SERVICE_NAME: name of the read replica service.
  • REPLICA_ZONE: zone the replica runs in.
  • CIDR_LIST: comma-separated list of CIDR blocks, with no spaces.

See Use Read Replicas.

Keep the Filter in Sync with Changing Sources

Clients whose address changes, such as autoscaled nodes, ephemeral CI runners or a rotating NAT pool, need the filter updated when their address changes. Two approaches:

  • Route the clients through a stable egress address, such as a NAT gateway or a bastion, and allow only that address.
  • Automate the update. For Exoscale SKS clusters, see Sync SKS IP Filters, which keeps the database IP filter aligned with the node addresses of the cluster.

If you manage the service with Terraform, the IP filter is part of the service resource, so changes made with the CLI are reverted on the next apply. See Use Terraform for DBaaS.

Related Pages

Last updated on