Skip to content

Instantly share code, notes, and snippets.

@sameei
Last active October 13, 2019 06:07
Show Gist options
  • Save sameei/8bc4ce00ff451b44ec8026d078e9d7b0 to your computer and use it in GitHub Desktop.
Save sameei/8bc4ce00ff451b44ec8026d078e9d7b0 to your computer and use it in GitHub Desktop.

Setup Proxies for Dev

Requirements

brew install stunnel
brew install socat

Your stunnel config file in client (/etc/stunnel/stunnel.conf, /usr/local/etc/stunnel/stunnel.conf) :

client = yes
foreground = yes
debug = debug

[proxy]
accept = <stunnel-local-port-to-listen>
connect = <stunnel-server-ip>:<stunnel-server-port>
cert = <absolute-path-to-stunnel-cert.pem>

For Git

git config --global http.proxy http://127.0.01:<stunnel-local-port-to-listen>
git config --global https.proxy http://127.0.0.1:<stunnel-local-port-to-listen>

& through SSH

# used like : git clone git@github-special-user:user-or-org/repo.git
Host github-special-user
  HostName github.com
  User git
  proxycommand socat - PROXY:127.0.01:%h:%p,proxyport=<stunnel-local-port-to-listen>
  IdentityFile <path-to-private-key>
  IdentitiesOnly yes
  

Host github.com
  HostName github.com
  User git
  proxycommand socat - PROXY:127.0.01:%h:%p,proxyport=<stunnel-local-port-to-listen>
  IdentityFile <path-to-private-key>
  IdentitiesOnly yes

For Docker

Docker Desktop provide this in a easy way; just open the Preferences of Docker Desktop, then you can find it at RESOURCES/PROXIES

Google Cloud

from (here)[https://cloud.google.com/sdk/docs/proxy-settings]

gcloud config set proxy/type http
gcloud config set proxy/address 127.0.0.1
gcloud config set proxy/port <stunnel-local-port-to-listen>

For Google Chrome

open -a "Google Chrome" --args --proxy-server=http://127.0.0.1:<stunnel-local-port-to-listen>

What I did:

$ cd /Applications/Google Chrome.app/Contents/MacOS
$ mv "Google Chrome" GoogleChrome-Main
$ cat > Google\ Chrome
#! /bin/sh
/Applications/Google\ Chrome.app/Contents/MacOS/GoogleChrome-Main --proxy-server=http://127.0.0.1:<stunnel-local-port-to-listen>
$ chmod +x Google\ Chrome

IntelliJ

In Preferences you can find Proxy page/section.

How to Run

By the config params that we have set for stunnel, it's not going to be run in background. It needs to be run in foreground and it makes it more explicit. Non of the configured software could not connect to anyplace till you, explicitly run stunnel. Also in this way you can test all your configs by running your application when stunnel is running ro not, and see logs when it's running.

@reezaras
Copy link

Nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment