summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-11-19 16:28:11 -0800
committerTim Smith <tsmith@chef.io>2018-11-20 14:16:28 -0800
commit6b12ec7fb03cb9049f5461b7f72da0ad9e2df199 (patch)
tree60c95ffa5bfd8afe474788c7342748cbd81fbdda /lib
parentabdfa74d7f34114a3584efa6f8aabe337be8d80f (diff)
downloadchef-6b12ec7fb03cb9049f5461b7f72da0ad9e2df199.tar.gz
windows_share: Fix idempotency by removing the "everyone" accessshare_idem
This resource uses powershell under the hood and calls new-smbshare, which defaults to adding read only access to the everyone group. With this change when we create the share we'll remove that permission. Once that's done we'll go about adding our desired permissions. This only runs once so the overhead is pretty low and fixes idempotency. Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/resource/windows_share.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/chef/resource/windows_share.rb b/lib/chef/resource/windows_share.rb
index 93ce6148ed..9100041df0 100644
--- a/lib/chef/resource/windows_share.rb
+++ b/lib/chef/resource/windows_share.rb
@@ -242,6 +242,10 @@ class Chef
Chef::Log.debug("Running '#{share_cmd}' to create the share")
powershell_out!(share_cmd)
+
+ # New-SmbShare adds the "Everyone" user with read access no matter what so we need to remove it
+ # before we add our permissions
+ revoke_user_permissions(["Everyone"])
end
# determine what users in the current state don't exist in the desired state
@@ -297,6 +301,8 @@ class Chef
false
end
+ # revoke user permissions from a share
+ # @param [Array] users
def revoke_user_permissions(users)
revoke_command = "Revoke-SmbShareAccess -Name '#{new_resource.share_name}' -AccountName \"#{users.join(',')}\" -Force"
Chef::Log.debug("Running '#{revoke_command}' to revoke share permissions")