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

Configure sudo to preserve the *_proxy environment variables #25

Merged
merged 3 commits into from
Sep 13, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# 0.5.1 / _Unreleased_

- Configure sudo to preserve the `*_proxy` environment variables ([GH-23][], [GH-25][])
* Requires that sudo in VM is configured to support "sudoers.d", i.e. _/etc/sudoers_ contains line `#includedir /etc/sudoers.d`
- Fix Chef provisioner configuration if a proxy is set to `false` ([GH-24][])
- Create the directories for configuration files if they don't exist ([GH-25][])

# 0.5.0 / 2013-09-11

Expand Down Expand Up @@ -55,4 +58,6 @@
[GH-17]: https://github.com/tmatilai/vagrant-proxyconf/issues/17 "Issue 17"
[GH-19]: https://github.com/tmatilai/vagrant-proxyconf/issues/19 "Issue 19"
[GH-21]: https://github.com/tmatilai/vagrant-proxyconf/issues/21 "Issue 21"
[GH-23]: https://github.com/tmatilai/vagrant-proxyconf/issues/23 "Issue 23"
[GH-24]: https://github.com/tmatilai/vagrant-proxyconf/issues/24 "Issue 24"
[GH-25]: https://github.com/tmatilai/vagrant-proxyconf/issues/25 "Issue 25"
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ VAGRANT_HTTP_PROXY="http://proxy.example.com:8080" vagrant up

Many programs (wget, curl, yum, etc.) can be configured to use proxies with `<protocol>_proxy` or `<PROTOCOL>_PROXY` environment variables. This configuration will be written to _/etc/profile.d/proxy.sh_ on the guest.

Also sudo will be configured to preserve the variables. This requires that sudo in the VM is configured to support "sudoers.d", i.e. _/etc/sudoers_ contains line `#includedir /etc/sudoers.d`.

#### Example Vagrantfile

```ruby
Expand Down
21 changes: 17 additions & 4 deletions lib/vagrant-proxyconf/action/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def call(env)
env[:ui].info I18n.t("vagrant_proxyconf.#{config_name}.not_supported")
else
env[:ui].info I18n.t("vagrant_proxyconf.#{config_name}.configuring")
write_config(machine, config)
configure_machine(machine, config)
end
end

Expand Down Expand Up @@ -58,8 +58,19 @@ def finalize_config(config)
config
end

def write_config(machine, config)
logger.debug "Configuration:\n#{config}"
# Configures the VM based on the config
def configure_machine(machine, config)
write_config(machine, config)
end

# Writes the config to the VM
#
# @param opts [Hash] optional file options
# @option opts [String] :path (#config_path) the path of the configuration file
# @option opts [String] :mode the mode of the file
def write_config(machine, config, opts = {})
path = opts[:path] || config_path(machine)
logger.debug "Configuration (#{path}):\n#{config}"

temp = Tempfile.new("vagrant")
temp.binmode
Expand All @@ -68,7 +79,9 @@ def write_config(machine, config)

machine.communicate.tap do |comm|
comm.upload(temp.path, "/tmp/vagrant-proxyconf")
comm.sudo("cat /tmp/vagrant-proxyconf > #{config_path(machine)}")
comm.sudo("mkdir -p #{File.dirname(path)}")
comm.sudo("cat /tmp/vagrant-proxyconf > #{path}")
comm.sudo("chmod #{opts[:mode]} #{path}") if opts[:mode]
comm.sudo("rm /tmp/vagrant-proxyconf")
end
end
Expand Down
14 changes: 14 additions & 0 deletions lib/vagrant-proxyconf/action/configure_env_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ class ConfigureEnvProxy < Base
def config_name
'env_proxy'
end

private

def configure_machine(machine, config)
super
write_config(machine, sudo_config, path: '/etc/sudoers.d/proxy', mode: '0440')
end

def sudo_config
<<-CONFIG.gsub(/^\s+/, '')
Defaults env_keep += "HTTP_PROXY HTTPS_PROXY FTP_PROXY NO_PROXY"
Defaults env_keep += "http_proxy https_proxy ftp_proxy no_proxy"
CONFIG
end
end
end
end
Expand Down