bdwyertech/chef-wildfly

Generate encrypted management password

weevil44 opened this issue · 2 comments

When I add an attribute like this
default['wildfly']['users']['mgmt'].tap do |user| user['anotheruser'] = '2c6368f4996288fcc621c5355d3e39b7' end
the user is added to mgmt-users.properties

How can I automate the generation of this encrypted password string?
I will be setting the attribute above to a value retrieved from chef-vault.

Hmm, well if you can grab the raw password in-line in a recipe, you should be able to set the appropriate attribute in-line as well.

You can either use this library function, or implement something similar of your own.

def wildfly_user(user = nil, pass = nil, realm = 'ManagementRealm')
user ||= 'chef-wildfly-' + SecureRandom.urlsafe_base64(5)
pass ||= SecureRandom.urlsafe_base64(40)
passhash = Digest::MD5.hexdigest "#{user}:#{realm}:#{pass}"
{
user: user.to_s,
pass: pass.to_s,
passhash: passhash.to_s,
}
end

You'd be looking to grab passhash from the return, might look something like this if done in-line in a recipe:

user = WildFly::Helper.wildfly_user('anotheruser', 'mypass')
node.set['wildfly']['users']['mgmt']['anotheruser'] = user['passhash']

Thanks for the reply. I hadn't seen your response until now. I would up calling add-user.sh in an execute block to add my user.

execute 'Add management user' do
  command "#{new_resource.base_dir}/bin/add-user.sh -u #{new_resource.username} -p #{new_resource.password} -g #{new_resource.usergroup}"  
  not_if "grep #{new_resource.username} #{new_resource.base_dir}/#{new_resource.mode}/configuration/mgmt-users.properties"  
end