How can I write a chef recipe to create a new user and password in the Nodes automatically?

你离开我真会死。 提交于 2019-12-13 22:26:30

问题


I'm new to chef. Kindly help! I have tried this

user "newuser" do
  password: xyz
end

and

user 'newuser' do
  comment 'A random user'
  uid '1234567'
  gid '1234567'
  home '/home/saxuser'
  shell '/bin/bash'
  password 'newpassword'
end 

回答1:


The correct format for the user resource is the following:

user "newuser" do
  password crypt_password
end

Keep in mind that the password must be in shadow format:

The password shadow hash. This property requires that ruby-shadow be installed. This is part of the Debian package: libshadow-ruby1.8.

See the Password Shadow Hash section to see how to generate the shadow password:

$ openssl passwd -1 "theplaintextpassword"

To generate the shadow password from the cookbook, you can use the openssl cookbook helpers to generate the salt:

Chef::Recipe.send(:include, OpenSSLCookbook::RandomPassword)

password = 'xyz'
salt = random_password(length: 10)
crypt_password = password.crypt("$6$#{salt}")

user 'newuser' do
  password crypt_password
end      

Don't forget to include the openssl cookbook in your run list.

Anyway, keep in mind that this will generate a different salt in each chef run, so maybe it's not the best approach to use.

I also encourage you to read Noah's post about secrets management to learn appropriate ways to manage passwords with Chef.



来源:https://stackoverflow.com/questions/34808016/how-can-i-write-a-chef-recipe-to-create-a-new-user-and-password-in-the-nodes-aut

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!