Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding encrypted data bags support #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,20 @@ by the `data_bag` recipe to use as a database of user accounts.

The default is `"users"`.

### <a name="attributes-data-bag-encrypted"></a> data_bag_encrypted

Indicates whether data bag is encrypted or not.

The default is `"false"`.

### <a name="attributes-data-bag-encryption_key"></a> data_bag_encryption_key

Encryption key to use, if `data_bag_encrypted` attribute is set to `true`.
Key defined in `encrypted_data_bag_secret` attribute inside `knife.rb` will
be used if case of `nil` value.

The default is `nil`.

### <a name="attributes-user-array-node-attr"></a> user_array_node_attr

The node attributes containing an array of users to be managed. If a nested
Expand Down
6 changes: 4 additions & 2 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
default['user']['ssh_keygen'] = "true"
default['user']['non_unique'] = "false"

default['user']['data_bag_name'] = "users"
default['user']['user_array_node_attr'] = "users"
default['user']['data_bag_name'] = "users"
default['user']['data_bag_encrypted'] = false
default['user']['data_bag_encryption_key'] = nil
default['user']['user_array_node_attr'] = "users"

default[default['user']['user_array_node_attr']] = []
9 changes: 8 additions & 1 deletion recipes/data_bag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@

# only manage the subset of users defined
Array(user_array).each do |i|
u = data_bag_item(bag, i.gsub(/[.]/, '-'))
name = i.gsub(/[.]/, '-')

u = if node['user']['data_bag_encrypted']
Chef::EncryptedDataBagItem.load(bag, name, node['user']['data_bag_encryption_key'])
Copy link
Collaborator

@theckman theckman Nov 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should rely on the key being provided in the client's config and not here. We should remove any references to this attribute:

Chef::EncryptedDataBagItem.lad(bag, name)

else
data_bag_item(bag, name)
end

username = u['username'] || u['id']

user_account username do
Expand Down