1

I intend to encrypt "users" databag with chef-vault and use the same with chef provided "users" cookbook. "users_manage" resource provided by "users" cookbook accepts one of the attributes as "databag" (with username, group_id and search_group properties). To my knowledge chef-vault allows you to decrypt one item at a time

vault = chef_vault_item(:mydatabbag, ‘item1’)

ideally I would expect chef-vault to provide similar function to decrypt entire vault (encrypted databag) and I could pass the same to "uses_manage" resource:

decrypted_data_bag = chef_vault(:mydatabbag) #Something similar

users_manage "#{search_group}" do
  group_id search_group
  action [ :remove, :create ]
  data_bag "#{decrypted_data_bag}"
end

Since chef-vault does not provide an ability to decrypt the entire databag, am I left with the only solution to call "users_manage" in a loop and pass each item (as hash)?

mydatabag.each do |myuser|
  decrypted_user = vault = chef_vault_item(:mydatabbag, "#{myuser}")
  users_manage "#{search_group}" do
    group_id search_group
    action [ :remove, :create ]
    data_bag "#{decrypted_user}"
  end
end

Is there a better solution?

Haris Farooqui
  • 944
  • 3
  • 12
  • 28

1 Answers1

0

The data_bag property is the name of a data bag, not the bag itself. You cannot use users_manage with chef-vault, you'll have to write something similar yourself.

That said, nothing in a user object should need to be private in the first place unless you're trying to set passwords or something (don't do that) so this is probably not needed.

coderanger
  • 52,400
  • 4
  • 52
  • 75
  • Thanks @coderanger. I need to store ssh-keys and password in the user object, hence the need for encryption. – Haris Farooqui Jul 06 '17 at 17:10
  • 1
    Don't use Chef to distribute user passwords, look in to things like LDAP for that, and the only keys Chef should be putting in place for most users should be public keys, i.e. things for `authorized_keys`, which do not need to be secret. – coderanger Jul 06 '17 at 17:26
  • 1
    +1 This is just an interim solution until we get to LDAP. PS: There seems to be PR already opened for the same: https://github.com/chef-cookbooks/users/pull/91 – Haris Farooqui Jul 06 '17 at 17:31