Skip to content

Commit

Permalink
Update _install-windows.rb
Browse files Browse the repository at this point in the history
Prevent an issue (race condition) where Windows environment is locked by another process causing hanging chef-client runs during writing or removing the dd username or password using windows_env.
Changed the logic to node.run_state which prevents this condition and also makes sure the password isn't stored n cleartext in the environment variables.
  • Loading branch information
mwijers authored Dec 20, 2024
1 parent 42e22a5 commit 96b99e9
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions recipes/_install-windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@
module Windows
class Helper
def clean_user(context)
resource = context.resource_collection.lookup('windows_env[DDAGENTUSER_NAME]')
resource.run_action(:delete)
context.node.run_state['datadog']['windows_ddagentuser_name'] = nil
end

def clean_password(context)
resource = context.resource_collection.lookup('windows_env[DDAGENTUSER_PASSWORD]')
resource.run_action(:delete)
context.node.run_state['datadog']['windows_ddagentuser_password'] = nil
end

def unmute_host(context)
Expand All @@ -55,9 +53,12 @@ def unmute_host(context)
Windows::Helper.new.clean_user(Chef.run_context)
end
end
windows_env 'DDAGENTUSER_NAME' do
value ddagentuser_name
ruby_block 'Store Datadog User Password' do
block do
node.run_state['datadog']['windows_ddagentuser_name'] = ddagentuser_name
end
sensitive true
action :run
end
end

Expand All @@ -67,9 +68,12 @@ def unmute_host(context)
Windows::Helper.new.clean_password(Chef.run_context)
end
end
windows_env 'DDAGENTUSER_PASSWORD' do
value ddagentuser_password
ruby_block 'Store Datadog User Password' do
block do
node.run_state['datadog']['windows_ddagentuser_password'] = ddagentuser_password
end
sensitive true
action :run
end
end

Expand Down Expand Up @@ -249,17 +253,3 @@ def unmute_host(context)
unsafe
end
end

if ddagentuser_name
windows_env 'DDAGENTUSER_NAME' do
action :delete
sensitive true
end
end

if ddagentuser_password
windows_env 'DDAGENTUSER_PASSWORD' do
action :delete
sensitive true
end
end

0 comments on commit 96b99e9

Please sign in to comment.