Skip to content

Commit 61ff553

Browse files
committed
Ensure tempfile ownership is correct
1 parent 616585d commit 61ff553

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/puppet/provider/keycloak_api.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ def convert_property_value(value)
5858

5959
def self.kcadm(action, resource, realm = nil, file = nil, fields = nil, print_id = false, params = nil)
6060
kcadm_wrapper = '/opt/keycloak/bin/kcadm-wrapper.sh'
61+
keycloak_user ||= 'keycloak'
62+
keycloak_group ||= 'keycloak'
6163

6264
arguments = [action]
6365

@@ -73,6 +75,14 @@ def self.kcadm(action, resource, realm = nil, file = nil, fields = nil, print_id
7375
arguments << escape(realm)
7476
end
7577
if file
78+
Puppet.debug("Get Keycloak user UID for #{keycloak_user}")
79+
uid = Etc.getpwnam(keycloak_user).uid
80+
Puppet.debug("Get Keycloak group GID for #{keycloak_group}")
81+
gid = Etc.getgrnam(keycloak_group).gid
82+
# Force the 0600 mode tempfile to be readable only by 'keycloak' user
83+
# so that the kcadm commands can be run as 'keycloak'
84+
Puppet.debug("Change ownership of #{file} to #{keycloak_user}(#{uid}):#{keycloak_group}(#{gid})")
85+
File.chown(uid, gid, file)
7686
arguments << '-f'
7787
arguments << file
7888
end

0 commit comments

Comments
 (0)