Chef:如何从加密数据包中设置用户密码

Chef: How to set a user's password from an encrypted data bag

我正在使用 Chef with kitchen (1.5.0) 和 vagrant (1.8.1) 通过新服务器一致地管理用户。我的用户食谱如下所示:

include_recipe "users"

group 'sudo'

password_secret = Chef::EncryptedDataBagItem.load_secret(node['enterprise_sp']['secret_file'])

jays_password = Chef::EncryptedDataBagItem.load('user_secrets','jgodse', password_secret)['password']
shadow_password = `openssl passwd -1 -salt xyz #{jays_password}`.strip

user 'jgodse' do
  action :create
  group 'sudo'
  system true
  shell '/bin/bash'
  home '/home/jgodse'
  manage_home true
  password shadow_password  #added to /etc/shadow when chef runs
end

未加密的数据包是我明文配置密码的地方。然后我用 knife 命令加密了数据包。

这行得通,但这似乎是解决密码设置问题的一种非常肮脏的方法。我必须这样做,因为 user 块的 password 指令只采用影子密码,并且只能通过炮击生成openssl 命令。

是否有更简洁的方法来获取影子密码,而无需使用生成密码的 openssl 命令?

您根本不应该存储密码,只需预先对其进行散列,然后将散列放在数据包中。而且像这样使用加密的数据包是非常不安全的,请花点时间熟悉一下Chef的加密工具的威胁模型,不是吗。

至少预先计算好密码哈希值,放入数据包中

请参阅 https://github.com/chef-cookbooks/users 以获取灵感。