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

Support connecting through a socks proxy #19

Merged
merged 1 commit into from
Aug 20, 2021

Conversation

sworisbreathing
Copy link
Contributor

This PR registers a custom driver name for pq, per lib/pq#470 (comment), and uses it to override the default dialer with one that can transparently handle socks proxy configuration through environment variables.

The environment variable is named ALL_PROXY (all_proxy also works) and has the format socks5[h]://[<socks-user>:<socks-password>@]<socks-host>[:<socks-port>]
There is also support for a NO_PROXY/no_proxy environment variable which lists hostnames, IP addresses, CIDR blocks, and wildcard domain names which should not go through the proxy.

@sworisbreathing
Copy link
Contributor Author

sworisbreathing commented Aug 20, 2021

For some weird reason, code coverage isn't being captured, however I can tell this change actually makes a difference. When Redshift is in a VPC and not publicly accessible, and ALL_PROXY points to a valid socks5 proxy into the VPC:

  • when you include this PR, all tests pass
  • When you omit this PR, all tests fail, and report errors connecting to redshift.

@winglot winglot added the enhancement New feature or request label Aug 20, 2021
@winglot winglot merged commit cf50382 into brainly:master Aug 20, 2021
@sworisbreathing sworisbreathing deleted the socks-proxy-support branch August 20, 2021 11:15
Tenzer added a commit to Tenzer/terraform-provider-postgresql that referenced this pull request Mar 30, 2022
This copies the implentation from the Redshift provider:
brainly/terraform-provider-redshift#19.

It allows users to proxy the requests to the database server through a SOCKS
proxy, in case the database server cannot be reached directly.
Tenzer added a commit to Tenzer/terraform-provider-postgresql that referenced this pull request Apr 21, 2022
This copies the implentation from the Redshift provider:
brainly/terraform-provider-redshift#19.

It allows users to proxy the requests to the database server through a SOCKS
proxy, in case the database server cannot be reached directly.
cyrilgdn added a commit to cyrilgdn/terraform-provider-postgresql that referenced this pull request May 4, 2022
* Add SOCKS proxy support

This copies the implentation from the Redshift provider:
brainly/terraform-provider-redshift#19.

It allows users to proxy the requests to the database server through a SOCKS
proxy, in case the database server cannot be reached directly.

* Mention SOCKS5 proxy support to usage documentation

As part of this I found out the format of the values in the environment
variables isn't standardized, so there only place we potentially could link to
about the format of the values would be the source code for
`golang.org/x/net/proxy`. I thought that was a bit much, so I've instead
included a simple example instead.

Co-authored-by: Cyril Gaudin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants