Skip to content

Commit

Permalink
Fix puppetlabs#239 local_user permission denied (puppetlabs#497)
Browse files Browse the repository at this point in the history
* fix local user permission denied

* fix offenses

* fix specs
  • Loading branch information
thde authored and florindragos committed Jun 19, 2019
1 parent a213541 commit 28265e6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
12 changes: 12 additions & 0 deletions lib/facter/docker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require 'facter'
require 'json'
require 'etc'

Facter.add(:docker_systemroot) do
confine osfamily: :windows
Expand Down Expand Up @@ -31,6 +32,17 @@
end
end

Facter.add(:docker_home_dirs) do
confine kernel: 'Linux'
setcode do
home_dirs = {}
Etc.passwd do |user|
home_dirs[user.name] = user.dir
end
home_dirs
end
end

docker_command = if Facter.value(:kernel) == 'windows'
'powershell -NoProfile -NonInteractive -NoLogo -ExecutionPolicy Bypass -c docker'
else
Expand Down
7 changes: 5 additions & 2 deletions manifests/registry.pp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
$exec_provider = undef
$password_env = "\${password}"
$exec_user = $local_user
$local_user_home = $facts['docker_home_dirs'][$local_user]
}

if $ensure == 'present' {
Expand Down Expand Up @@ -103,11 +104,13 @@
Undef => pw_hash($docker_auth, 'SHA-512', $local_user_strip),
default => $pass_hash
}
$_auth_command = "${auth_cmd} || rm -f \"/root/registry-auth-puppet_receipt_${server_strip}_${local_user}\""
$_auth_command = "${auth_cmd} || rm -f \"/${local_user_home}/registry-auth-puppet_receipt_${server_strip}_${local_user}\""

file { "/root/registry-auth-puppet_receipt_${server_strip}_${local_user}":
file { "/${local_user_home}/registry-auth-puppet_receipt_${server_strip}_${local_user}":
ensure => $ensure,
content => $_pass_hash,
owner => $local_user,
group => $local_user,
notify => Exec["${title} auth"],
}
} else {
Expand Down
3 changes: 3 additions & 0 deletions spec/defines/registry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
lsbdistcodename: 'jessie',
kernelrelease: '3.2.0-4-amd64',
operatingsystemmajrelease: '8',
docker_home_dirs: {
root: '/root',
},
}
end
let(:params) { { 'version' => '17.06', 'pass_hash' => 'test1234', 'receipt' => false } }
Expand Down

0 comments on commit 28265e6

Please sign in to comment.