From f3a595c63d7fc4eb19270074b56a4218cbb3cff8 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Sat, 24 Aug 2013 14:53:53 -0400 Subject: [PATCH] [COOK-3056] Allowing custom prefix for sudoers and sudoers.d Signed-off-by: Seth Vargo --- attributes/default.rb | 7 +++++++ recipes/default.rb | 8 +++++--- spec/default_spec.rb | 23 ++++++++++++++++++++--- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/attributes/default.rb b/attributes/default.rb index 95d5ff4..924645e 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -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 diff --git a/recipes/default.rb b/recipes/default.rb index bd060dc..aaaf52d 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -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' @@ -38,7 +40,7 @@ end end -template '/etc/sudoers' do +template "#{prefix}/sudoers" do source 'sudoers.erb' mode '0440' owner 'root' diff --git a/spec/default_spec.rb b/spec/default_spec.rb index 557cb6e..93a5180 100644 --- a/spec/default_spec.rb +++ b/spec/default_spec.rb @@ -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' @@ -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'