Skip to content

Commit

Permalink
[COOK-3056] Allowing custom prefix for sudoers and sudoers.d
Browse files Browse the repository at this point in the history
Signed-off-by: Seth Vargo <sethvargo@gmail.com>
  • Loading branch information
Dan Buch authored and sethvargo committed Aug 24, 2013
1 parent a503303 commit f3a595c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
7 changes: 7 additions & 0 deletions attributes/default.rb
Expand Up @@ -23,3 +23,10 @@
default['authorization']['sudo']['include_sudoers_d'] = false
default['authorization']['sudo']['agent_forwarding'] = false
default['authorization']['sudo']['sudoers_defaults'] = ['!lecture,tty_tickets,!fqdn']

case node['platform_family']
when 'smartos'
default['authorization']['sudo']['prefix'] = '/opt/local/etc'
else
default['authorization']['sudo']['prefix'] = '/etc'
end
8 changes: 5 additions & 3 deletions recipes/default.rb
Expand Up @@ -17,19 +17,21 @@
# limitations under the License.
#

prefix = node['authorization']['sudo']['prefix']

package 'sudo' do
action :install
end

if node['authorization']['sudo']['include_sudoers_d']
directory '/etc/sudoers.d' do
directory "#{prefix}/sudoers.d" do
mode '0755'
owner 'root'
group 'root'
action :create
end

cookbook_file '/etc/sudoers.d/README' do
cookbook_file "#{prefix}/sudoers.d/README" do
source 'README'
mode '0440'
owner 'root'
Expand All @@ -38,7 +40,7 @@
end
end

template '/etc/sudoers' do
template "#{prefix}/sudoers" do
source 'sudoers.erb'
mode '0440'
owner 'root'
Expand Down
23 changes: 20 additions & 3 deletions spec/default_spec.rb
Expand Up @@ -2,8 +2,9 @@

describe 'sudo::default' do
context 'usual business' do
before { Fauxhai.mock :platform => 'ubuntu' }
let(:runner) { ChefSpec::ChefRunner.new.converge 'sudo::default' }
let(:runner) do
ChefSpec::ChefRunner.new(platform: 'ubuntu', version: '12.04').converge 'sudo::default'
end

it 'installs the sudo package' do
runner.should install_package 'sudo'
Expand All @@ -14,9 +15,25 @@
end
end

context 'with custom prefix' do
let(:runner) do
ChefSpec::ChefRunner.new(platform: 'ubuntu', version: '12.04') do |node|
node.set['authorization'] = {
'sudo' => {
'prefix' => '/secret/etc'
}
}
end.converge 'sudo::default'
end

it 'creates the sudoers file in the custom location' do
runner.should create_file_with_content '/secret/etc/sudoers', 'Defaults !lecture,tty_tickets,!fqdn'
end
end

context 'sudoers.d' do
let(:runner) do
ChefSpec::ChefRunner.new do |node|
ChefSpec::ChefRunner.new(platform: 'ubuntu', version: '12.04') do |node|
node.set['authorization'] = {
'sudo' => {
'include_sudoers_d' => 'true'
Expand Down

0 comments on commit f3a595c

Please sign in to comment.