Skip to content
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

Proxy terminates connection when running within a docker container #2

Closed
binarydev opened this issue Jul 11, 2019 · 3 comments
Closed

Comments

@binarydev
Copy link
Contributor

binarydev commented Jul 11, 2019

Hey guys,

Awesome tool you've created here, but I've run into some snags when attempting to dockerize it.

I've gotten the tool itself running successfully within a docker container. It can see my dockerized DB, and it's able to connect according to the following output:

$ docker-compose up proxy
Recreating masquerade-proxy_proxy_1 ... done
Attaching to masquerade-proxy_proxy_1
proxy_1  | Starting Proxy...
proxy_1  | Proxy Running:
proxy_1  | 	Proxy Port: 20000
proxy_1  | 	Database Details: postgres@172.18.0.7:5432/test_db_proxy

Docker status while running shows it online and forwarding the proper port:

CONTAINER ID        IMAGE                    COMMAND                  CREATED              STATUS              PORTS                      NAMES
a7bc6476f7fe        masquerade-proxy_proxy   "/bin/sh -c ./start.…"   About a minute ago   Up About a minute   0.0.0.0:20000->20000/tcp   masquerade-proxy_proxy_1

Here's my dockerfile:

FROM mcr.microsoft.com/dotnet/core/sdk:2.2
RUN apt-get update && apt-get -y install git
WORKDIR /app
RUN git clone https://github.com/TonicAI/masquerade.git .
COPY start.sh ./
RUN chmod +x start.sh
CMD ./start.sh

the start.sh entrypoint:

#!/bin/bash
# Find the IP of the PG container and use it to populate the config.json file
POSTGRES_IP=`getent hosts postgres | awk '{ print $1 }'`
sed 's/POSTGRES_IP/'"$POSTGRES_IP"'/g' config.sample.json > config.json
dotnet run

docker-compose file:

version: "3"
services:
  proxy:
    build: .
    ports:
      - 20000:20000
    external_links:
      - postgres_db:postgres
    volumes:
      - "~/Projects/masquerade-proxy/config.sample.json:/app/config.sample.json"
networks:
  default:
    external:
      name: test_default

and config.sample.json as well:

{
  "proxy_port":20000,
  "db_connection_details": {
      "port": 5432,
      "ip": "POSTGRES_IP",
      "user":"postgres",
      "password":"dev",
      "database":"test_db_proxy"
  },
  "masking_options": {
      "preserve_keys": false,
      "column_masks": [{
          "column":"full_name",
          "table":"users",
          "schema":"public",
          "masking_function":"maskx"
      }],
      "data_type_masks": [
          {
              "data_type": "text",
              "masking_function":"maskcharacters"
          }
      ]
  }
}

However, when I try to connect to the proxy, which has port 20000 exposed to the docker host, I get the following:

$ psql "host=127.0.0.1 port=20000 dbname=test_db_proxy sslmode=disable" postgres
psql: server closed the connection unexpectedly
	This probably means the server terminated abnormally
	before or while processing the request.

When I terminate the proxy, I get the expected error of Connection refused because the PG server cannot be found, like you would if you tried to connect on a random port where nothing is listening. This would indicate that my DB clients (tried psql, Postico, and DBeaver) are able to see the proxy, but they cannot properly connect to it.

Any ideas as to what could be causing this would be appreciated!

@binarydev
Copy link
Contributor Author

After further investigation, it's caused by the proxy binding to the localhost IP of 127.0.0.1, so any connection being made by the host to the Docker container is being ignored. Will open up a PR to add a config setting for which source IP the proxy should be listening to, if you guys are willing to consider it!

@akamor
Copy link
Contributor

akamor commented Jul 15, 2019

Hi, I'll look at your PR in the next day or so. Sorry for the delay in this response and thanks for the PR!

akamor added a commit that referenced this issue Jul 15, 2019
Fix issue #2 - add support for specifying proxy source IP binding
@akamor
Copy link
Contributor

akamor commented Jul 15, 2019

Just merged PR. Thanks for your assistance.

@akamor akamor closed this as completed Jul 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants