chef-encrypted-attributes 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.yardopts +8 -0
  5. data/CHANGELOG.md +40 -4
  6. data/CONTRIBUTING.md +7 -6
  7. data/KNIFE.md +151 -0
  8. data/README.md +70 -192
  9. data/Rakefile +27 -14
  10. data/TESTING.md +18 -7
  11. data/TODO.md +2 -5
  12. data/lib/chef-encrypted-attributes.rb +7 -1
  13. data/lib/chef/encrypted_attribute.rb +282 -121
  14. data/lib/chef/encrypted_attribute/api.rb +521 -0
  15. data/lib/chef/encrypted_attribute/assertions.rb +16 -6
  16. data/lib/chef/encrypted_attribute/cache_lru.rb +54 -13
  17. data/lib/chef/encrypted_attribute/config.rb +198 -89
  18. data/lib/chef/encrypted_attribute/encrypted_mash.rb +127 -33
  19. data/lib/chef/encrypted_attribute/encrypted_mash/version0.rb +236 -48
  20. data/lib/chef/encrypted_attribute/encrypted_mash/version1.rb +249 -36
  21. data/lib/chef/encrypted_attribute/encrypted_mash/version2.rb +133 -19
  22. data/lib/chef/encrypted_attribute/exceptions.rb +19 -3
  23. data/lib/chef/encrypted_attribute/local_node.rb +15 -4
  24. data/lib/chef/encrypted_attribute/remote_clients.rb +33 -17
  25. data/lib/chef/encrypted_attribute/remote_node.rb +84 -29
  26. data/lib/chef/encrypted_attribute/remote_nodes.rb +62 -11
  27. data/lib/chef/encrypted_attribute/remote_users.rb +58 -19
  28. data/lib/chef/encrypted_attribute/search_helper.rb +214 -74
  29. data/lib/chef/encrypted_attribute/version.rb +3 -1
  30. data/lib/chef/encrypted_attributes.rb +20 -0
  31. data/lib/chef/knife/core/config.rb +4 -1
  32. data/lib/chef/knife/core/encrypted_attribute_base.rb +179 -0
  33. data/lib/chef/knife/core/encrypted_attribute_depends.rb +43 -0
  34. data/lib/chef/knife/core/encrypted_attribute_editor_options.rb +125 -61
  35. data/lib/chef/knife/encrypted_attribute_create.rb +51 -31
  36. data/lib/chef/knife/encrypted_attribute_delete.rb +32 -40
  37. data/lib/chef/knife/encrypted_attribute_edit.rb +51 -32
  38. data/lib/chef/knife/encrypted_attribute_show.rb +30 -55
  39. data/lib/chef/knife/encrypted_attribute_update.rb +43 -28
  40. data/spec/benchmark_helper.rb +2 -1
  41. data/spec/integration_helper.rb +1 -0
  42. data/spec/spec_helper.rb +21 -7
  43. metadata +75 -36
  44. metadata.gz.sig +1 -1
  45. data/API.md +0 -174
  46. data/INTERNAL.md +0 -166
metadata.gz.sig CHANGED
@@ -1 +1 @@
1
- (\�K{�������y�t����T�Ú%A��+�b��L�"$�=4/c�~�� ������MS;�ī�5I>�Il������q#�Б���n�8{O]���aD����܏gyc%��Q4�c�3��V����"E���OAqC0qXg�K6X�����<!eUKS���QT<�7IڬqP���Ⱦ�[6���=H8�zˍa�$���ty)m!��X<C)7vɯR����u⇹�8M�~�]S�J 6��o
1
+ ���mo�=Z&ۯ��@]��6W`�ݡ�D��q�Oau<��`��2p\�E���6ZO }c ���MJv����A&�u^� Aa��;��0�,�������rYnq}!G���s�J��B��ZB���`��]�d�Σ�ত���b
data/API.md DELETED
@@ -1,174 +0,0 @@
1
- # Chef::EncryptedAttribute API Documentation
2
-
3
- `Chef::EncryptedAttribute` has some static methods intended to be used from cookbooks.
4
-
5
- ## Static Methods
6
-
7
- ### Chef::EncryptedAttribute.load(hs [, config])
8
-
9
- Reads an encrypted attribute from a hash, usually a node attribute.
10
-
11
- * `hs` - An encrypted hash, usually a node attribute. For example: `node["myapp"]["ftp_password"]`.
12
- * `config` - A configuration hash (optional). For example: `{ :partial_search => false }`.
13
-
14
- Returns the attribute in clear text, decrypted.
15
-
16
- An exception is thrown if the attribute cannot be decrypted or no encrypted attribute is found.
17
-
18
- ### Chef::EncryptedAttribute.create(value [, config])
19
-
20
- Creates an encrypted attribute. The returned value should be saved in a node attribute, like `node.normal[...] = `.
21
-
22
- * `value` - The value to be encrypted. Can be a boolean, a number, a string, an array or a hash (the value will be converted to JSON internally).
23
- * `config` - A configuration hash (optional). For example: `{ :client_search => "admin:true" }`.
24
-
25
- Returns the encrypted attribute.
26
-
27
- An exception is thrown if any error arises in the encryption process.
28
-
29
- ### Chef::EncryptedAttribute.update(hs [, config])
30
-
31
- Updates who can read the attribute. This is intended to be used to update to the new nodes returned by `:client_search` and `:node_search` or perhaps global configuration changes.
32
-
33
- For example, in case new nodes are added or some are removed, and the clients returned by `:client_search` or `:node_search` are different, this `#update` method will decrypt the attribute and encrypt it again for the new nodes (or remove the old ones).
34
-
35
- If an update is made, the shared secrets are regenerated.
36
-
37
- * `hs` - This must be a node encrypted attribute, this attribute will be updated, so it is mandatory to specify the type (usually `normal`). For example: `node.normal["myapp"]["ftp_password"]`.
38
- * `config` - A configuration hash (optional). Surely you want this `#update` method to use the same `config` that the `#create` call.
39
-
40
- Returns `true` if the encrypted attribute has been updated, `false` if not.
41
-
42
- An exception is thrown if there is any error in the updating process.
43
-
44
- ### Chef::EncryptedAttribute.exist?(hs)
45
-
46
- Checks whether an encrypted attribute exists.
47
-
48
- * `hs` - An encrypted hash, usually a node attribute. The attribute type can be specified but is not necessary. For example: `node["myapp"]["ftp_password"]`.
49
-
50
- Returns `true` if an encrypted attribute is found, `false` if not.
51
-
52
- ### Chef::EncryptedAttribute.load_from_node(name, attr_ary [, config])
53
-
54
- Reads an encrypted attribute from a remote node.
55
-
56
- * `name` - The node name.
57
- * `attr_ary` - The attribute path as *array of strings*. For example: `[ "myapp", "ftp_password" ]`.
58
- * `config` - A configuration hash (optional). For example: `{ :partial_search => false }`.
59
-
60
- An exception is thrown if the attribute cannot be decrypted or no encrypted attribute is found.
61
-
62
- ### Chef::EncryptedAttribute.create_on_node(name, attr_ary, value [, config])
63
-
64
- Creates an encrypted attribute on a remote node.
65
-
66
- * `name` - The node name.
67
- * `attr_ary` - The attribute path as *array of strings*. For example: `[ "myapp", "ftp_password" ]`.
68
- * `value` - The value to be encrypted. Can be a boolean, a number, a string, an array or a hash (the value will be converted to JSON internally).
69
- * `config` - A configuration hash (optional). For example: `{ :client_search => "admin:true" }`.
70
-
71
- An exception is thrown if any error arises in the encryption process.
72
-
73
- This method **requires admin privileges**. So in most cases, cannot be used from cookbooks.
74
-
75
- ### Chef::EncryptedAttribute.update_on_node(name, attr_ary [, config])
76
-
77
- Updates who can read the attribute.
78
-
79
- * `name` - The node name.
80
- * `attr_ary` - The attribute path as *array of strings*. For example: `[ "myapp", "ftp_password" ]`.
81
- * `config` - A configuration hash (optional). Surely you want this `#update_on_node` method to use the same `config` that the `#create` call.
82
-
83
- Returns `true` if the encrypted attribute has been updated, `false` if not.
84
-
85
- An exception is thrown if there is any error in the updating process.
86
-
87
- This method **requires admin privileges**. So in most cases, cannot be used from cookbooks.
88
-
89
- ### Chef::EncryptedAttribute.exist_on_node?(name, attr_ary [, config])
90
-
91
- Checks whether an encrypted attribute exists in a remote node.
92
-
93
- * `name` - The node name.
94
- * `attr_ary` - The attribute path as *array of strings*. For example: `[ "myapp", "ftp_password" ]`.
95
- * `config` - A configuration hash (optional). For example: `{ :partial_search => false }`.
96
-
97
- Returns `true` if an encrypted attribute is found, `false` if not.
98
-
99
- ## Configuration
100
-
101
- All the methods read the default configuration from the `Chef::Config[:encrypted_attributes]` hash. Most of methods also support setting some configuration parameters as last argument. Both the global and the method argument configuration will be merged.
102
-
103
- If the configuration value to be merged is an array or a hash (for example `keys`), the method argument configuration value has preference over the global configuration. Arrays and hashes are not merged.
104
-
105
- Both `Chef::Config[:encrypted_attributes]` and method's `config` parameter should be a hash which may have any of the following keys:
106
-
107
- * `:version` - `EncryptedMash` format version to use, by default `1` is used which is recommended. The version `2` uses [GCM](http://en.wikipedia.org/wiki/Galois/Counter_Mode) and probably should be considered the most secure, but it is disabled by default because it has some more requirements:
108
- * Ruby `>= 2`.
109
- * OpenSSL `>= 1.0.1`.
110
- * `:partial_search` - Whether to use Chef Server partial search, enabled by default. It may not work in some old versions of Chef Server.
111
- * `:client_search` - Search query for clients allowed to read the encrypted attribute. Can be a simple string or an array of queries to be *OR*-ed.
112
- * `:node_search` - Search query for nodes allowed to read the encrypted attribute. Can be a simple string or an array of queries to be *OR*-ed.
113
- * `:users` - Array of user names to be allowed to read the encrypted attribute(s). `"*"` to allow access to all users. Keep in mind that only admin clients or admin users are allowed to read user public keys. It is **not recommended** to use this from cookbooks unless you know what you are doing.
114
- * `:keys` - raw RSA public keys to be allowed to read encrypted attributes(s), in PEM (string) format. Can be client public keys, user public keys or any other RSA public key.
115
-
116
- For example, to disable Partial Search globally:
117
-
118
- ```ruby
119
- Chef::Config[:encrypted_attributes][:partial_search] = false
120
-
121
- # ftp_pass = Chef::EncryptedAttribute.load(node["myapp"]["ftp_password"])
122
- # ...
123
- ```
124
-
125
- To disable Partial Search locally:
126
-
127
- ```ruby
128
- ftp_pass = Chef::EncryptedAttribute.load(node["myapp"]["ftp_password"], { :partial_search => false })
129
- ```
130
-
131
- To use protocol version 2 globally, which uses [GCM](http://en.wikipedia.org/wiki/Galois/Counter_Mode):
132
-
133
- ```ruby
134
- Chef::Config[:encrypted_attributes][:version] = 2
135
- # ...
136
- ```
137
-
138
- If you want to use knife to work with encrypted attributes, surely you will need to save your Chef User public keys in a Data Bag (there is no need to encrypt them because they are public) and add them to the `:keys` configuration option. See the [Example Using User Keys Data Bag](README.md#example-using-user-keys-data-bag) in the README for more information on this.
139
-
140
- ## Caches
141
-
142
- This API uses some LRU caches to avoid making many requests to the Chef Server. All the caches are global and has the following methods:
143
-
144
- * `max_size` - Gets or sets the cache maximum item size.
145
- * `clear` - To empty the cache.
146
- * `[]` - To read a cache value (used internally).
147
- * `[]=` - To set a cache value (used internally).
148
-
149
- This are the currently available caches:
150
-
151
- * `Chef::EncryptedAttribute::RemoteClients.cache` - Caches the `:client_search` query results (max_size: `1024`).
152
- * `Chef::EncryptedAttribute::RemoteNodes.cache` - Caches the `:node_search` query results (max_size: `1024`).
153
- * `Chef::EncryptedAttribute::RemoteUsers.cache` - Caches the Chef Users public keys (max_size: `1024`).
154
- * `Chef::EncryptedAttribute::RemoteNode.cache` - Caches the node (encrypted) attributes. Disabled by default (max_size: `0`).
155
-
156
- ### Clear All the Caches
157
-
158
- You can clear all the caches with the following code:
159
-
160
- ```ruby
161
- Chef::EncryptedAttribute::RemoteClients.cache.clear
162
- Chef::EncryptedAttribute::RemoteUsers.cache.clear
163
- Chef::EncryptedAttribute::RemoteNode.cache.clear
164
- ```
165
-
166
- ### Disable All the Caches
167
-
168
- You can disable all the caches with the following code:
169
-
170
- ```ruby
171
- Chef::EncryptedAttribute::RemoteClients.cache.max_size(0)
172
- Chef::EncryptedAttribute::RemoteUsers.cache.max_size(0)
173
- Chef::EncryptedAttribute::RemoteNode.cache.max_size(0)
174
- ```
@@ -1,166 +0,0 @@
1
- # Internal Documentation
2
-
3
- ## EncryptedAttribute Class
4
-
5
- This class contains both static and instance level public methods. Internally, all work with `EncryptedMash` object instances.
6
-
7
- The **static methods** are intended to be used from Cookbooks. The attributes are encrypted only for the local node by default. The static `*_on_node` methods can be used also, although they have not been designed for this purpose (have not been tested).
8
-
9
- The **instance methods** are intended to be used from `knife` or external libraries. Usually only the `*_from_node/*_on_node` instance methods will be used. These methods will grant access only to the remote node by default.
10
-
11
- ## EncryptedMash Class
12
-
13
- This is the most basic encrypted object, which inherits from `Chef::Mash`.
14
-
15
- Currently two `EncryptedMash` versions exists. But you can create your own versions and name it with the `Chef::EncryptedAttribute::EncryptedMash::Version` prefix.
16
-
17
- ### EncryptedMash::Version0
18
-
19
- This is the first version, considered old. Uses public key cryptography (PKI) to encrypt the data. There is no shared secret or HMAC for data integrity checking.
20
-
21
- #### EncryptedMash::Version0 Structure
22
-
23
- If you try to read this encrypted attribute structure, you can see a `Chef::Mash` attribute with the following content:
24
-
25
- ```
26
- EncryptedMash
27
- └── encrypted_data
28
- ├── pub_key_hash1: The data encrypted using PKI for the public key 1 (base64)
29
- ├── pub_key_hash2: The data encrypted using PKI for the public key 2 (base64)
30
- └── ...
31
- ```
32
-
33
- The `public_key_hash1` key value is the *SHA1* of the public key used for encryption.
34
-
35
- Its content is the data encoded in *JSON*, then encrypted with the public key, and finally encoded in *base64*. The encryption is done using the *RSA* algorithm (PKI).
36
-
37
- ### EncryptedMash::Version1 (default)
38
-
39
- This is the `EncryptedMash` version used by default. Uses public key cryptography (PKI) to encrypt a shared secret. Then this shared secret is used to encrypt the data.
40
-
41
- * This implementation can be improved, is not optimized either for performance or for space.
42
- * Every time the `EncryptedAttribute` is updated, all the shared secrets are regenerated.
43
-
44
- #### EncryptedMash::Version1 Structure
45
-
46
- If you try to read this encrypted attribute structure, you can see a *Mash* attribute with the following content:
47
-
48
- ```
49
- EncryptedMash
50
- ├── chef_type: "encrypted_attribute" (string).
51
- ├── x_json_class: The used `EncryptedMash` version class name (string).
52
- ├── encrypted_data
53
- │ ├── cipher: The used PKI algorithm, "aes-256-cbc" (string).
54
- │ ├── data: PKI encrypted data (base64).
55
- │ └── iv: Initialization vector (in base64).
56
- ├── encrypted_secret
57
- │ ├── pub_key_hash1: The shared secrets encrypted for the public key 1 (base64).
58
- │ ├── pub_key_hash2: The shared secrets encrypted for the public key 2 (base64).
59
- │ └── ...
60
- └── hmac
61
- ├── cipher: The used HMAC algorithm, currently ignored and always "sha256" (string).
62
- └── data: Hash-based message authentication code value (base64).
63
- ```
64
-
65
- * `x_json_class` field is used, with the `x_` prefix, to be easily integrated with Chef in the future.
66
-
67
- ##### EncryptedMash[encrypted_data][data]
68
-
69
- The data inside `encrypted_data` is symmetrically encrypted using the secret shared key. The data is converted to *JSON* before the encryption, then encrypted and finally encoded in *base64*. By default, the `"aes-256-cbc"` algorithm is used for encryption.
70
-
71
- After decryption, the *JSON* has the following structure:
72
-
73
- ```
74
- └── encrypted_data
75
- └── data (symmetrically encrypted JSON in base64)
76
- └── content: attribute content as a Mash.
77
- ```
78
-
79
- * In the future, this structure may contain some metadata like default configuration values.
80
-
81
- ##### EncryptedMash[encrypted_secret][pub_key_hash1]
82
-
83
- The `public_key_hash1` key value is the *SHA1* of the public key used for encryption.
84
-
85
- Its content is the encrypted shared secrets in *base64*. The encryption is done using the *RSA* algorithm (PKI).
86
-
87
- After decryption, you find the following structure in *JSON*:
88
-
89
- ```
90
- └── encrypted_secret
91
- └── pub_key_hash1 (PKI encrypted JSON in base64)
92
- ├── data: The shared secret used to encrypt the data (base64).
93
- └── hmac: The shared secret used for the HMAC calculation (base64).
94
- ```
95
-
96
- ##### EncryptedMash[hmac][data]
97
-
98
- The HMAC data is in *base64*. The hashing algorithm used is `"sha256"`.
99
-
100
- The following data is used in a alphabetically sorted *JSON* to calculate the HMAC:
101
-
102
- ```
103
- Data to calculate the HMAC from
104
- ├── cipher: The algorithm used for `encrypted_data` encryption ("aes-256-cbc").
105
- ├── data: The `encrypted_data` data content after the encryption (encrypt-then-mac).
106
- └── iv: The initialization vector used to encrypt the encrypted_data.
107
- ```
108
-
109
- * All the data required for decryption is included in the HMAC (except the secret key, of course): `cipher`, `data` and `iv`.
110
- * The data used to calculate the HMAC is the encrypted data, not the clear text data (**Encrypt-then-MAC**).
111
- * The secret used to calculate the HMAC is not the same as the secret used to encrypt the data.
112
- * The secret used to calculate the HMAC is shared inside `encrypted_secret` field with the data secret.
113
-
114
- ### EncryptedMash::Version2
115
-
116
- Uses public key cryptography (PKI) to encrypt a shared secret. Then this shared secret is used to encrypt the data using [GCM](http://en.wikipedia.org/wiki/Galois/Counter_Mode).
117
-
118
- * This protocol version is based on the [Chef 12 Encrypted Data Bags Version 3 implementation](https://github.com/opscode/chef/pull/1591).
119
- * To use it, the following **special requirements** must be met:
120
- * Ruby `>= 2`.
121
- * OpenSSL `>= 1.0.1`.
122
- * This implementation can be improved, is not optimized either for performance or for space.
123
- * Every time the `EncryptedAttribute` is updated, all the shared secrets are regenerated.
124
-
125
- #### EncryptedMash::Version2 Structure
126
-
127
- If you try to read this encrypted attribute structure, you can see a *Mash* attribute with the following content:
128
-
129
- ```
130
- EncryptedMash
131
- ├── chef_type: "encrypted_attribute" (string).
132
- ├── x_json_class: The used `EncryptedMash` version class name (string).
133
- ├── encrypted_data
134
- │ ├── cipher: The used PKI algorithm, "aes-256-gcm" (string).
135
- │ ├── data: PKI encrypted data (base64).
136
- │ ├── auth_tag: GCM authentication tag (base64).
137
- │ └── iv: Initialization vector (in base64).
138
- └── encrypted_secret
139
- ├── pub_key_hash1: The shared secret encrypted for the public key 1 (base64).
140
- ├── pub_key_hash2: The shared secret encrypted for the public key 2 (base64).
141
- └── ...
142
- ```
143
-
144
- * `x_json_class` field is used, with the `x_` prefix, to be easily integrated with Chef in the future.
145
-
146
- ##### EncryptedMash[encrypted_data][data]
147
-
148
- The data inside `encrypted_data` is symmetrically encrypted using the secret shared key. The data is converted to *JSON* before the encryption, then encrypted and finally encoded in *base64*. By default, the `"aes-256-gcm"` algorithm is used for encryption.
149
-
150
- After decryption, the *JSON* has the following structure:
151
-
152
- ```
153
- └── encrypted_data
154
- └── data (symmetrically encrypted JSON in base64)
155
- └── content: attribute content as a Mash.
156
- ```
157
-
158
- * In the future, this structure may contain some metadata like default configuration values.
159
-
160
- ##### EncryptedMash[encrypted_secret][pub_key_hash1]
161
-
162
- The `public_key_hash1` key value is the *SHA1* of the public key used for encryption.
163
-
164
- Its content is the encrypted shared secret in *raw*. The encryption is done using the *RSA* algorithm (PKI).
165
-
166
- After decryption, you find the the shared secret in *raw* (in *Version1* this is a *JSON* in *base64*).