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

fix postgres-dev to only listen on localhost #3403

Merged
merged 1 commit into from
Oct 11, 2022

Conversation

dnephin
Copy link
Contributor

@dnephin dnephin commented Oct 6, 2022

Summary

The default for docker port mapping is 0.0.0.0 (all interfaces), which can be a security risk. If a developer laptop is ever connected to an untrusted network, someone on that network could connect to the database and use COPY and other postgres operations to read files or even run processes on the laptop.

By mapping the host port to 127.0.0.1 we ensure that no one can connect to the dev database except for the processes on the local host.

If you are using Docker for Mac I could use your help to confirm this works with that setup.

@dnephin
Copy link
Contributor Author

dnephin commented Oct 6, 2022

I missed the docker-compose.dev.yml which I think needs the same fix, I'll do that now.
Edit: done

@dnephin dnephin force-pushed the dnephin/postgres-dev-listen-addr branch from 4d61085 to d1c06eb Compare October 6, 2022 17:16
postgres:14-alpine -c fsync=off -c full_page_writes=off
-p 127.0.0.1:15432:5432 \
postgres:14-alpine -c fsync=off -c full_page_writes=off \
-c listen_addresses=127.0.0.1 -c max_connections=100
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the default settings, but I'd like to include them here to make it easier to change them.

On linux setting listen_addresses to 0.0.0.0 allows tests to bypass the port mapping proxy and connect directly to the container. Setting max_connections can be useful when testing concurrency.

@dnephin dnephin force-pushed the dnephin/postgres-dev-listen-addr branch from d1c06eb to a8925de Compare October 6, 2022 17:20
@@ -48,7 +48,7 @@ jobs:
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports: ["5432:5432"]
ports: ["127.0.0.1:5432:5432"]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this will work, let's see if CI tests pass.

@ssoroka ssoroka requested a review from mxyng October 6, 2022 17:25
Copy link
Collaborator

@BruceMacD BruceMacD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed this works on Docker Desktop for Mac

@dnephin
Copy link
Contributor Author

dnephin commented Oct 7, 2022

Thanks!

@dnephin dnephin merged commit 2469c0c into main Oct 11, 2022
@dnephin dnephin deleted the dnephin/postgres-dev-listen-addr branch October 11, 2022 16:12
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

Successfully merging this pull request may close these issues.

2 participants