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 proxy listening on localhost on the host #82

Open
copumpkin opened this issue Aug 28, 2014 · 6 comments
Open

Support proxy listening on localhost on the host #82

copumpkin opened this issue Aug 28, 2014 · 6 comments

Comments

@copumpkin
Copy link

I have a proxy listening on localhost on my Vagrant host. The issue is that localhost becomes 10.0.2.2 from the guest's perspective. When I log into my guest, the http_proxy variables are set to "localhost", which thus point to the guest and don't work.

I imagine we'd just need some special logic that looks for localhost/127.0.0.1 and rewrites it to the host IP when setting the variables in the guest.

@tmatilai tmatilai changed the title Support proxy listening on localhost Support proxy listening on localhost on the host Aug 29, 2014
@otahi
Copy link
Collaborator

otahi commented Aug 30, 2014

Hi, @copumpkin .

I am afraid that I do not understand what your issue is.

If your issue is only to access proxy on the host,
a solution is just setting with your host ip like config.proxy.http = "http://10.0.2.2:3128/".
(Proxy server need to listen not only localhost but also 10.0.2.2.)

If you want a simple solution to use a proxy on the host like as followings, it will need development.

VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "centos70"
  config.proxy.http  = "http://localhost:3128/"
  config.proxy.https = "http://localhost:3128/"
  config.proxy.using_host_proxy = true
end

or

VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "centos70"
  config.proxy.http  = "http://$vagrant_host:3128/"
  config.proxy.https = "http://$vagrant_host:3128/"
end

Which is your issue? Or your have another issue?

@ruipires
Copy link

ruipires commented Nov 4, 2014

Hi @copumpkin, @otahi , I also have this issue.

In my work environment I need to use cntlm to effectively go around the corporate proxy (requires authentication). Storing my personal credentials in the (eventually checked-in) Vagrantfile is a deal breaker, so I'm looking for alternatives.

For me personally the second option would be the best (using $vagrant_host), since it seems like the most straightforward to read and understand what exactly is being configured.

@tmatilai
Copy link
Owner

tmatilai commented Nov 4, 2014

@ruipires a common way to handle secrets is to use environment variables and access them in Vagrantfile like:

config.proxy.http = "http://#{ENV['PROXY_CREDENTIALS']}@proxy.example.com:3128`

Often you also want configure the proxy for all VMs in ~/.vagrant.d/Vagrantfile instead of project specific Vagrantfiles.

But I still understand that this feature would be useful. Unfortunately I don't know any reliable way to know the host IP as it's very provider specific. A hack to try could be to ssh into the VM and try to figure out the source IP for that connection. This would still require that the proxy on the host is accessible from that interface (no way to access the host's loopback directly from the VM).

Sorry, but I can't promise that I'll work on this in the near future. As always, I'm happy to review pull requests though. =)

@ruipires
Copy link

ruipires commented Nov 5, 2014

I'm still getting used to vagrant, so no pull requests in the near future from me ;)
Thanks for the tip, I can work with that for now (it just works!).

@otahi
Copy link
Collaborator

otahi commented Nov 5, 2014

I want to try this impl, when I have time.

@tmatilai says:

But I still understand that this feature would be useful. Unfortunately I don't know any reliable way to know the host IP as it's very provider specific.

I think so too`. But we can get the default gateway or some specific IP addresses.
In NAT case, the default gateway could be handled as a host IP address.

I welcome not only pull requests but also ideas like this 😄

@JPvRiel
Copy link

JPvRiel commented Dec 16, 2016

One workaround is to simply let your local proxy also listen on the virtual network, be it virtualbox, libvirt/kvm, lxc or docker (worked for me with all).

E.g. snippet from /etc/cntlm.conf (A similar concept can be done with squid.)

Listen       127.0.0.1:8080
Listen       192.168.56.1:8080
Gateway      yes
Allow        127.0.0.1
Allow        192.168.56.0/24
Deny         0/0

Then instead of pointing to 127.0.0.1, use the proxy interface on the host for bridge/nat network created for the VM guests., e.g. 192.168.56.1. That works from both the host and the guest VMs.

I'm not sure it's reasonable to expect the plugin dev to try manage this complexity.

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

5 participants