tmatilai / vagrant-proxyconf

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

Under OpenBSD, the group of `root` is `wheel`. #79

Closed carletes closed 4 years ago

carletes commented 10 years ago

Working with this (dirty) patch.

I set up a local Squid proxy on my workstation (10.0.0.6), and used this Vagrantfile:

Vagrant.configure("2") do |config|
  config.vm.box = "tmatilai/openbsd-5.5"
  config.ssh.shell = '/bin/sh -l'
  config.vm.synced_folder ".", "/vagrant", type: :rsync
  config.vm.provision "shell", inline: "echo hello"

  if Vagrant.has_plugin?("vagrant-proxyconf")
    config.proxy.http = "http://10.0.0.6:3128"
    config.proxy.https = "http://10.0.0.6:3128"
    config.proxy.ftp = "http://10.0.0.6:3128"
    config.proxy.no_proxy = "localhost,127.0.0.1"
  end
end

The command vagrant up worked this time:

$ vagrant up
==> default: Forcing shutdown of VM...
==> default: Destroying VM and associated drives...
==> default: Running cleanup tasks for 'shell' provisioner...
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'tmatilai/openbsd-5.5'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'tmatilai/openbsd-5.5' is up to date...
==> default: Setting the name of the VM: vagrant-openbsd_default_1407519783680_98398
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: No guest additions were detected on the base box for this VM! Guest
    default: additions are required for forwarded ports, shared folders, host only
    default: networking, and more. If SSH fails on this machine, please install
    default: the guest additions and repackage the box to continue.
    default: 
    default: This is not an error message; everything may continue to work properly,
    default: in which case you may ignore this message.
==> default: Configuring proxy environment variables...
==> default: Installing rsync to the VM...
==> default: Rsyncing folder: /home/carlos/src/vagrant-openbsd/ => /vagrant
==> default: Running provisioner: shell...
    default: Running: inline script
==> default: hello
$ 

The variables are set:

$ vagrant ssh -c "cat /etc/profile"
export HTTP_PROXY=http://marcelino.lan:3128
export http_proxy=http://marcelino.lan:3128
export HTTPS_PROXY=http://marcelino.lan:3128
export https_proxy=http://marcelino.lan:3128
export FTP_PROXY=http://marcelino.lan:3128
export ftp_proxy=http://marcelino.lan:3128
export NO_PROXY="localhost,127.0.0.1"
export no_proxy="localhost,127.0.0.1"
Connection to 127.0.0.1 closed.
$

In /var/log/squid3/access.log:

1407518822.905   2563 10.0.0.6 TCP_MISS/200 1162647 GET http://ftp.openbsd.org/pub/OpenBSD/5.5/packages/amd64/ - HIER_DIRECT/129.128.5.191 text/html
1407518823.127    149 10.0.0.6 TCP_MISS/200 6690 GET http://ftp.openbsd.org/pub/OpenBSD/5.5/packages/amd64/quirks-1.113.tgz - HIER_DIRECT/129.128.5.191 application/x-tar
1407518824.084    891 10.0.0.6 TCP_MISS/200 282891 GET http://ftp.openbsd.org/pub/OpenBSD/5.5/packages/amd64/rsync-3.1.0.tgz - HIER_DIRECT/129.128.5.191 application/x-tar

vagrant provision also works:

carlos@marcelino:~/src/vagrant-openbsd$ vagrant provision
==> default: Configuring proxy environment variables...
==> default: Running provisioner: shell...
    default: Running: inline script
==> default: hello
carlos@marcelino:~/src/vagrant-openbsd$ 
``

The line `config.ssh.shell = '/bin/sh -l'` is needed: Without it, I see no hits in Squid's access log
otahi commented 10 years ago

Hi @carletes,

Thank you for reminding me groups are different between OSs.

In your OpenBSD environment, doesn't it work without this change? If so, this change has a chance to affect to other OS environment.

To make this change care to other OSs, what do you think checking root group with using id command like id -gn root?

carletes commented 10 years ago

Hi, @otahi ! No, the command chown fails without the patch on OpenBSD.

Moreover, this patch is broken on Ubuntu guests (at least, possibly in others). Since the files under /etc/sudoers,d end up being owned by root:vagrant, it looks like sudo does not take them into account.

I'll try to make the root group configurable and commit it to this branch.

tmatilai commented 10 years ago

@carletes at least in Linux the form chown root: <path> should work.

@otahi please note that until now we only support Linux (and very limitedly Windows). OpenBSD support has not being merged to master yet.

Once again, the real solution to this problem would be to refactor most of the code from Action classes to Guest Capabilities. Then it can be as guest OS specific as needed. I also expect that FreeBSD support would be quite similar to OpenBSD.

The openbsd branch in which this is based, is a bit experimental just to gain knowledge if it would work at all. So I can merge this PR into it, but not likely to merge the branch into master in the current form. I'll make a serious attempt to allocate time for this project next week.