tmatilai / vagrant-proxyconf

Vagrant plugin that configures the virtual machine to use proxies
MIT License
531 stars 74 forks source link

WIP: Always exclude the VM from the proxy #183

Closed ilpianista closed 5 years ago

ilpianista commented 5 years ago

This is more or less a request for help, but I found this workaround and thus it could makes sense to allow this behaviour in the plugin.

My corporate proxy blocks the IPs which are not recognized by it. I configure my VMs to use that proxy, but since my VMs are part of a subnet which is unknown to my corporate proxy, it blocks any connection in the VM that use my VM IP instead of e.g. localhost (curl http://192.168.0.10 fails, but curl http://localhost doesn't fail since localhost is in my no_proxy list).

The workaround found is to always add my VM IP to the no_proxy list.

In addition to this, this behaviour could be an issue only on Linux machines since Windows automatically excludes local address by using the proxy.

codylane commented 5 years ago

Hi there @ilpianista -

Thank you for reporting this problem. I'm sorry to hear that this module doesn't work for you in it's current state but I'm worried about the change you proposed will introduce a different problem(s) with this plugin the way it is currently implemented that may not work for everyone.

Instead, I would highly recommend do something like this instead, which gives you more flexibility about your environment that "passthrough" all the proxy configuration variables you may already have set in your environment.

I'm wondering if an easier solution would be do something like this in your Vagrantfile?

With the following example in your Vagrantfile the HTTP_PROXY, HTTPS_PROXY and NO_PROXY environment variables will passthrough to the Vagrantbox and auto configure this plugin and either enable the plugin if you have the variables set, or disable it if you don't. I feel like that is kind of nice.

Vagrant.configure("2") do |config|

    if Vagrant.has_plugin?("vagrant-proxyconf") && ENV['HTTP_PROXY'].nil? == false
      config.proxy.http      = "#{ENV['HTTP_PROXY']}"
      config.proxy.https     = "#{ENV['HTTPS_PROXY']}"
      config.proxy.no_proxy  = "#{ENV['NO_PROXY']}"
    else
      # this will no longer be needed after this https://github.com/tmatilai/vagrant-proxyconf/pull/182 is merged
      config.proxy.enabled = false
    end

    # config.vm.provider .... 
end

Example of global behavior

export NO_PROXY="localhost,127.0.0.1"
vagrant up

Example using a scripted approach

cat > run_at_work <<EOF
#!/bin/bash -e

export NO_PROXY="localhost,127.0.0.1"
vagrant up
EOF

./run_at_work

Or....

You can just use the environment specific variables as pointed out in the docs.

VAGRANT_ENV_NO_PROXY="localhost,127.0.0.1" vagrant up
codylane commented 5 years ago

I'd like to close out this PR if my proposal works for you. If not, let's continue to discuss ways we can make this plugin easier to use + test.

FWIW - We only currently unit test this app, there are no acceptance tests which is why I'm hesitant to merge this into the next release without significant testing of all proxy providers on different OSes.

ilpianista commented 5 years ago

@codylane hi, thank you for your reply.

I totally agree that this isn't something you can merge.

Unfortunately your isn't a viable solution for my use case, but instead I just thought that I could add any host of the subnet to config.config.no_proxy, e.g. this way:

no_proxy=""
(1..255).each do |x|
  no_proxy +=  "192.168.0." + x.to_s + ","
end
config.proxy.no_proxy  = "#{no_proxy.chop}"
codylane commented 5 years ago

Awesome, that also works. Good work! ;) Since you have a working solution do you mind if I close this pull request or would you like to discuss more ideas?