Skip to content

Commit

Permalink
Change to safe working directory in external_node_v2.rb
Browse files Browse the repository at this point in the history
Change working directory to the determined home directory of
`puppetuser` before continuing to ensure we don't reside in /root or
anywhere else we don't have permissions.

Fixes issue #611.
  • Loading branch information
antaflos authored and ekohl committed Dec 25, 2017
1 parent e16aa60 commit 841f3c9
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions files/external_node_v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,10 @@ def watch_and_send_facts(parallel)
Process::UID.change_privilege(Etc.getpwnam(puppetuser).uid) unless Etc.getpwuid.name == puppetuser
# Facter (in thread_count) tries to read from $HOME, which is still /root after the UID change
ENV['HOME'] = Etc.getpwnam(puppetuser).dir
# Change CWD to the determined home directory before continuing to make
# sure we don't reside in /root or anywhere else we don't have access
# permissions
Dir.chdir ENV['HOME']
rescue
$stderr.puts "cannot switch to user #{puppetuser}, continuing as '#{Etc.getpwuid.name}'"
end
Expand Down

0 comments on commit 841f3c9

Please sign in to comment.