Skip to content

Instantly share code, notes, and snippets.

@workmad3
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save workmad3/8804159 to your computer and use it in GitHub Desktop.
Save workmad3/8804159 to your computer and use it in GitHub Desktop.
# Generate your password in your preferred manner, such as SecureRandom.base64(30)
node[:my_super_secret_password] ||= NodeEncryption.encrypt_value("super_secret!")
# Later on, recover the password
my_super_secret_password = NodeEncryption.decrypt_value(node[:my_super_secret_password])
module NodeEncryption
def self.encrypt_value(value)
secret = Chef::EncryptedDataBagItem.load_secret("/etc/chef/secret")
Chef::EncryptedDataBagItem::Encryptor.new(value, secret).for_encrypted_item
end
def self.decrypt_value(value, item_name)
secret = Chef::EncryptedDataBagItem.load_secret("/etc/chef/secret")
Chef::EncryptedDataBagItem::Decryptor.for(value, secret).for_decrypted_item
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment