-
-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Example of using pgwire as a postgres proxy #80
Comments
hi @osawyerr , it's possible to write such a proxy but we need to define the purpose of it so we can choose at which layer we will proxy the traffic. For example, we can write a Layer-4 proxy by simply forward any tcp traffic to backend, or a Layer-7 one that understands postgresql's protocol or even sql statements. If I'm creating a basic Layer-7 example, I will let the proxy to finish the startup and forward further query traffic to backend. I will find time for that. |
My vote is for Layer-7. Personally, I'd like to be able to fundamentally understand the request, execute the query, apply transforms to the result rows, then hand them back out. |
I'll 3rd the request for a l7 proxy example, @sunng87 . My use case is an auth n/z aware proxy that can make authorization decisions based on the query. |
Let me do this in weekend if everything goes well. |
Thank you, looking forward to it! |
I have an unfinished proxy example that uses tokio_postgres in However, for a complete proxy solution, we will need to implement tokio layer for using |
I'll +1 this request. My use case is to intercept every message and validate incoming queries. |
We also need this for https://github.com/twentyhq/twenty I've never tried Replit bounties but thought it could be an occasion to give it a shot... Let's see if it works! |
https://github.com/usocoder/felix/tree/main/twenty-postgres-proxy Hey there! My name its Ritchie from New Zealand i have developed a program that acts like a security guard for a database I created a new folder called twenty postgres proxy to organize key files. The core of our solution is a Rust-based program that performs several crucial tasks. It listens for incoming database connection attempts, verifies if the user trying to connect has permission, and if authorized, restricts the user to only the sections of the database they’re allowed to access. It also forwards their queries to the actual database and returns the responses. I created a "config.json" file that allows easy customization of where the program should listen for connections, the location of the real database, and who is allowed to connect and what parts of the database they can access. 0x819ffeE0e30BBB4309282297C7F26D11a9cD3350 |
Thanks @usocoder - tbh I think the bounty was a mistake (apologies @sunng87 for the spam it just created), we got low quality contributions and I wouldn't do it this way again. @usocoder your code doesn't work on my side, it doesn't have any test / no readme and relies on an old version of pgwire (0.12 vs 0.25 today) |
@FelixMalfait no worry. I'm quite interested in your progress with pgwire on a postgres proxy. I've listed it in my projects for pgwire #204 . I just don't have enough bandwidth for building this project. But for anyone who is or will be working on this direction with pgwire, I will offer support. |
@sunng87 would love to work on this .need some guide line and steps to do this. |
@kernel-loophole Great to hear! This I shared my idea of building Postgres middleware in here. In the initial version, we can have StartupHandler, SimpleQueryHandler and ExtendedQueryHandler simply forward incoming messages to upstream. This requires us to:
Once we finished 1 and 2, it should be a working layer-7 proxy. We can start to add:
|
@sunng87 Thanks for sharing the details and the plan for building the Postgres middleware! I’ll take a look at the sqlite example for a basic usage reference. The approach you outlined for implementing the client logic and handlers to create a working layer-7 proxy makes sense. Once the initial setup is complete, adding connection management and monitoring APIs will definitely enhance the middleware. I'll start by exploring the traits you mentioned and keep you posted on the progress. Looking forward to collaborating on this! |
hi @sunng87 make some changes in proxy for postgres. implemented |
hello @kernel-loophole could you rebase latest master? |
yes sure @sunng87 will do |
I found that making proxy with So I use
|
@tbicr That's true. That's why I only use tokio-postgres for a POC. If we are going to build a proxy on top of pgwire, we will need to implement a low level client using pgwire's codec. It will have access to every message between frontend and backend. |
IMHO |
Was looking at the examples and there isn't one that actually connects to a real postgres instance in the backend. For example to use pgwire as a proxy to a 'real' postgres server. i.e. maintaining different client sessions and forwarding them to a real postgres instance.
The text was updated successfully, but these errors were encountered: