diff --git a/proxy/README.md b/proxy/README.md index 8d850737bede..d5cc6eb2151b 100644 --- a/proxy/README.md +++ b/proxy/README.md @@ -122,3 +122,43 @@ and connect to it ```sh PGSSLROOTCERT=./server.crt psql 'postgres://my-cluster-42.localtest.me:1234?sslmode=verify-full' ``` + +## Test proxy locally + +Firstly, we need to build proxy with 'testing' feature and run, e.g.: + +``` +RUST_LOG=proxy cargo run --release -p proxy --bin proxy --features testing -- --auth-backend postgres --auth-endpoint 'postgresql://proxy:password@127.0.0.1:5432/postgres' --is-private-access-proxy true +``` + +We will also need to have a postgres instance. Assuming that we have setted up docker we can set it up as follows: +```sh +mkdir -p "$HOME/.pgdata/proxy-postgres" + +docker network create proxy-net + +exec docker \ + run \ + --platform linux/aarch64 \ + --detach \ + --name proxy-postgres \ + --env POSTGRES_PASSWORD=proxy-postgres \ + --env PGDATA=/var/lib/postgresql/data/pgdata \ + --volume "$HOME/.pgdata/proxy-postgres":/var/lib/postgresql/data \ + --publish 5432:5432 \ + --network proxy-net \ + postgres:17-bookworm +``` + +Next step is setting up auth table and schema as well as creating role: +```sh +docker exec -it proxy-postgres psql -U postgres -c "CREATE SCHEMA IF NOT EXISTS neon_control_plane" +docker exec -it proxy-postgres psql -U postgres -c "CREATE TABLE neon_control_plane.endpoints "(endpoint_id VARCHAR(255) PRIMARY KEY, allowed_ips VARCHAR(255))" +docker exec -it proxy-postgres psql -U postgres -c "CREATE ROLE proxy WITH SUPERUSER LOGIN PASSWORD 'password';" +``` + +Now from client you can start a new session: + +```sh +psql "postgresql://proxy:password@127.0.0.1:4432/postgres?options=endpoint%3D" +``` \ No newline at end of file