Skip to content

Commit 28265e6

Browse files
thdeflorindragos
authored andcommitted
Fix #239 local_user permission denied (#497)
* fix local user permission denied * fix offenses * fix specs
1 parent a213541 commit 28265e6

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

lib/facter/docker.rb

+12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
require 'facter'
44
require 'json'
5+
require 'etc'
56

67
Facter.add(:docker_systemroot) do
78
confine osfamily: :windows
@@ -31,6 +32,17 @@
3132
end
3233
end
3334

35+
Facter.add(:docker_home_dirs) do
36+
confine kernel: 'Linux'
37+
setcode do
38+
home_dirs = {}
39+
Etc.passwd do |user|
40+
home_dirs[user.name] = user.dir
41+
end
42+
home_dirs
43+
end
44+
end
45+
3446
docker_command = if Facter.value(:kernel) == 'windows'
3547
'powershell -NoProfile -NonInteractive -NoLogo -ExecutionPolicy Bypass -c docker'
3648
else

manifests/registry.pp

+5-2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
$exec_provider = undef
6262
$password_env = "\${password}"
6363
$exec_user = $local_user
64+
$local_user_home = $facts['docker_home_dirs'][$local_user]
6465
}
6566

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

108-
file { "/root/registry-auth-puppet_receipt_${server_strip}_${local_user}":
109+
file { "/${local_user_home}/registry-auth-puppet_receipt_${server_strip}_${local_user}":
109110
ensure => $ensure,
110111
content => $_pass_hash,
112+
owner => $local_user,
113+
group => $local_user,
111114
notify => Exec["${title} auth"],
112115
}
113116
} else {

spec/defines/registry_spec.rb

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
lsbdistcodename: 'jessie',
1111
kernelrelease: '3.2.0-4-amd64',
1212
operatingsystemmajrelease: '8',
13+
docker_home_dirs: {
14+
root: '/root',
15+
},
1316
}
1417
end
1518
let(:params) { { 'version' => '17.06', 'pass_hash' => 'test1234', 'receipt' => false } }

0 commit comments

Comments
 (0)