Allowing a listing of IPs for database connections
With the PostgREST middleware I’ve shown you, you can block out any requests from specific IPs at the API level. Although this is covered in the link provided in the Adding middleware for PostgREST section’s note box), let me quickly show you the necessary code to get the IP of a user who makes a request:
ip := SELECT split_part( current_setting( 'request.headers', true )::json->>'x-forwarded-for', ',', 1);
However, since this is at the PostgREST level, this isn’t useful when we want to restrict direct database connections. For that, we need network-level restrictions.
Say, for example, your server builds direct connections to the database of Supabase and your IPv4 server is just static, 123.123.123.1
. This means that your subnet for this IP is 123.123.123.1/32
, as you only have one IP (https://mxtoolbox.com/subnetcalculator.aspx...