Skip to content
This repository has been archived by the owner on Nov 24, 2022. It is now read-only.

Commit

Permalink
Support alternative lxcpath in sudo wrapper
Browse files Browse the repository at this point in the history
The previously hardcoded lxc path prevented the sudo wrapper from
working in environment with alternative `lxcpath`.

I had to move `sudo_wrapper` from `provider` to `LXC` because the
concept of "provider" is tied to a machine when a command sush as
`sudoers` is not.

Fixes #413 and #399
  • Loading branch information
Virgil Dupras committed Dec 11, 2017
1 parent 2ce460b commit 10c53c5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
8 changes: 8 additions & 0 deletions lib/vagrant-lxc.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "vagrant-lxc/version"
require "vagrant-lxc/plugin"
require "vagrant-lxc/sudo_wrapper"

module Vagrant
module LXC
Expand All @@ -10,5 +11,12 @@ def self.source_root
def self.sudo_wrapper_path
"/usr/local/bin/vagrant-lxc-wrapper"
end

def self.sudo_wrapper
wrapper = Pathname.new(sudo_wrapper_path).exist? &&
sudo_wrapper_path || nil
SudoWrapper.new(wrapper)
end

end
end
4 changes: 4 additions & 0 deletions lib/vagrant-lxc/command/sudoers.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require 'tempfile'

require "vagrant-lxc/driver"

module Vagrant
module LXC
module Command
Expand Down Expand Up @@ -43,11 +45,13 @@ def sudoers_path

# This requires vagrant 1.5.2+ https://github.com/mitchellh/vagrant/commit/3371c3716278071680af9b526ba19235c79c64cb
def create_wrapper!
lxc_base_path = Driver.new(0, LXC.sudo_wrapper).containers_path
wrapper = Tempfile.new('lxc-wrapper').tap do |file|
template = Vagrant::Util::TemplateRenderer.new(
'sudoers.rb',
:template_root => Vagrant::LXC.source_root.join('templates').to_s,
:cmd_paths => build_cmd_paths_hash,
:lxc_base_path => lxc_base_path,
:pipework_regex => "#{ENV['HOME']}/\.vagrant\.d/gems/(?:\\d+?\\.\\d+?\\.\\d+?/)?gems/vagrant-lxc.+/scripts/pipework"
)
file.puts template.render
Expand Down
8 changes: 1 addition & 7 deletions lib/vagrant-lxc/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require "vagrant-lxc/action"
require "vagrant-lxc/driver"
require "vagrant-lxc/sudo_wrapper"

module Vagrant
module LXC
Expand All @@ -26,12 +25,7 @@ def initialize(machine)
end

def sudo_wrapper
@shell ||= begin
wrapper = Pathname.new(LXC.sudo_wrapper_path).exist? &&
LXC.sudo_wrapper_path || nil
@logger.debug("Found sudo wrapper : #{wrapper}") if wrapper
SudoWrapper.new(wrapper)
end
@shell ||= LXC.sudo_wrapper
end

def ensure_lxc_installed!
Expand Down
2 changes: 1 addition & 1 deletion templates/sudoers.rb.erb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class Whitelist
end
end

base = "/var/lib/lxc"
base = "<%= lxc_base_path %>"
base_path = %r{\A#{base}/.*\z}

##
Expand Down

0 comments on commit 10c53c5

Please sign in to comment.