supabase / supavisor

A cloud-native, multi-tenant Postgres connection pooler.
https://supabase.github.io/supavisor/
Apache License 2.0
1.66k stars 55 forks source link

Supabase IP Ban Issue with Connection Pooling #331

Open fredericenard opened 4 months ago

fredericenard commented 4 months ago

Bug report

Describe the bug

I recently added new tests in my backend directly using the connection string (with pooling) to:

When running tests, I frequently observe an IP address being banned in Network Restrictions. It's always the same: 2600:1f18:2e13:9d01:19c9:c8a9:9833:652d

This occurs both when running tests locally and in my CI environment and prevent any subsequent query to run against the db. If I remove this IP from Network Restrictions it just reappears few seconds later. But if I wait around 30 minutes, I can run my tests 1 or 2 times before it starts happening again.

What is this IP? It seems it's located in Virginia, next to my Supabase instance. Does it have something to do with pooling?

Expected behavior

I expect to execute the operations outlined in my test suite without experiencing repeated bans of this IP:

System information

This occurs both when running tests locally and in my CI environment.

fredericenard commented 4 months ago

@encima thanks for looking at it! Happy to have a quick call with you to provide more details.

encima commented 4 months ago

Let me check internally first and see if we can find anything odd. Will come back to you soon :)

encima commented 4 months ago

You say that this IP ban prevents you from running subsequent queries but it is not yours or the runner, so it is related to your infra (or ours) somehow.

First, are you connecting to the DB via Supavisor or directly?

fredericenard commented 4 months ago

I'm using the connection string appearing below this:

image

It's happening in transaction and session mode.

I don't think this could be in my infra given I got the same problem when using this connection string with psql.

encima commented 4 months ago

Thanks for the additional info, this looks to be an issue with Supavisor (the connection pooler); logic is in place for this not to get banned but there may be some of your tests that are an edge case.

The unauthorized statements that you try, are they unauthorized actions based on your schema or are there also tests for items that may not exist?

fredericenard commented 4 months ago

Hey sorry for the late reply. The unauthorized statements I tried were actions based on my schema. But I think I have a better understanding of the problem now.

During my testing, I can create and interact with databases and roles seamlessly. Yet, I encounter issues when attempting to delete them. Although no errors are reported in my code, Postgres logs indicate problems with non-existent databases or roles.

Specifically, when I attempt to delete a role, the action is mistakenly interpreted as a password error, leading to the banning of an unidentified IP address. This is puzzling because I can successfully connect using the role in question. After ceasing the deletion of roles at the end of my tests, the IP banning issue stopped, but I still observe log entries concerning non-existent databases:

image

Additionally, after updating a role's password, I found that it was still possible to log in using the old password, while the new password was not recognized.

Is it possible that there's a delay or caching issue within Supavisor that affects the immediate recognition of changes to database objects?