Skip to content
Snippets Groups Projects
Verified Commit fd05d34b authored by Alexander Olofsson's avatar Alexander Olofsson
Browse files

Separate host password lookup to allow reuse

parent 34c88e7a
No related branches found
No related tags found
No related merge requests found
...@@ -17,7 +17,7 @@ module ForemanPasswordstate ...@@ -17,7 +17,7 @@ module ForemanPasswordstate
delegate :passwordstate_server, to: :passwordstate_facet delegate :passwordstate_server, to: :passwordstate_facet
delegate :password_list, to: :passwordstate_facet, prefix: :passwordstate delegate :password_list, to: :passwordstate_facet, prefix: :passwordstate
def host_pass(username, create: true, **params) def password_entry(username, create: true, **params)
return nil unless passwordstate_facet return nil unless passwordstate_facet
list = passwordstate_password_list list = passwordstate_password_list
...@@ -34,16 +34,18 @@ module ForemanPasswordstate ...@@ -34,16 +34,18 @@ module ForemanPasswordstate
end end
end end
def root_pass def host_pass(username, password_hash: 'SHA256', create: true, **params)
return super unless passwordstate_facet return nil unless passwordstate_facet
# As template renders read the root password multiple times, # As template renders read the root password multiple times,
# add a short cache just to not thoroughly hammer the passwordstate server # add a short cache just to not thoroughly hammer the passwordstate server
PasswordstateCache.instance.fetch("#{cache_key}/root_pass", expires_in: 1.minute) do PasswordstateCache.instance.fetch("#{cache_key}/pass-#{username}", expires_in: 1.minute) do
pw = host_pass('root') pw = password_entry(username, create: create, **params)
alg = operatingsystem&.password_hash || 'SHA256' alg = password_hash || 'SHA256'
if alg == 'Base64' if alg == 'Base64'
pw = PasswordCrypt.passw_crypt(pw.password, alg) pw = PasswordCrypt.passw_crypt(pw.password, alg)
elsif alg == 'None'
pw = pw.password
else else
seed = "#{uuid || id}/#{pw.title}-#{pw.password_id}" seed = "#{uuid || id}/#{pw.title}-#{pw.password_id}"
rand = Random.new(seed.hash) rand = Random.new(seed.hash)
...@@ -53,5 +55,11 @@ module ForemanPasswordstate ...@@ -53,5 +55,11 @@ module ForemanPasswordstate
pw pw
end end
end end
def root_pass
return super unless passwordstate_facet
host_pass('root', password_hash: operatingsystem&.password_hash)
end
end end
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment