hiera-eyaml 1.3.7 → 1.3.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 35b1bd91e6c23c3a0c52c99a84aa89c6e6e144ab
4
- data.tar.gz: e9f39be021a877caf772a79e0d8e145d138c0ee8
3
+ metadata.gz: 0794eaaca28f7702c08e251f54f938c06c7856fe
4
+ data.tar.gz: 505eea5b6e2bc567f5587adabb3c0aaef8b701e2
5
5
  SHA512:
6
- metadata.gz: 18fc2732feabb0946f769c38adad97d7f1f02bd9a19a7861a70a2ca00b36b8a3d7f3808a8cbed2cf58572329b6b29f3723c5aad0a378fd71e2897b9e2bdcb054
7
- data.tar.gz: b93af7d7f78bbf81cadc47656ed8bdd5286935c71ce7c19588f10fccf68016ddaa72b6e2f6b1bd4a2b4c5155bfaa5d40230b506dbdee7f7483effab80a8f5e6d
6
+ metadata.gz: b995c5e993985e4d38c0b1dfe55c0767057311cf00c75b3d3ac12538dfe7d58a9343a949005f06ccb1d1ea10628ffea2bf13e770d3ea5dad1288e2e09ba30174
7
+ data.tar.gz: b54b10584df24f60bf148bd62116e9c6b6426e67be16a4c95172b2e1776cd33a30b308dba0a17a7814ceac84268749a35737567147605714e63e85b7ac6f8fbd
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.8.7"
4
+ - "1.9.2"
5
+ - "1.9.3"
6
+ before_install:
7
+ - sudo apt-get update
8
+ - sudo apt-get install expect
9
+ script:
10
+ bundle exec cucumber -f progress
data/Gemfile CHANGED
@@ -9,4 +9,9 @@ group :development do
9
9
  gem "puppet"
10
10
  end
11
11
 
12
+ group :test do
13
+ gem "rake"
14
+ end
15
+
16
+
12
17
 
data/Gemfile.lock CHANGED
@@ -8,7 +8,7 @@ GEM
8
8
  builder (3.2.2)
9
9
  childprocess (0.3.9)
10
10
  ffi (~> 1.0, >= 1.0.11)
11
- cucumber (1.3.9)
11
+ cucumber (1.3.10)
12
12
  builder (>= 2.1.2)
13
13
  diff-lcs (>= 1.1.3)
14
14
  gherkin (~> 2.12)
@@ -21,19 +21,16 @@ GEM
21
21
  multi_json (~> 1.3)
22
22
  hiera (1.2.1)
23
23
  json_pure
24
- hiera-eyaml (1.3.4)
25
- highline (>= 1.6.19)
26
- trollop (>= 2.0)
27
- hiera-eyaml-plaintext (0.4)
28
- hiera-eyaml (>= 1.3.1)
24
+ hiera-eyaml-plaintext (0.5)
29
25
  highline (1.6.20)
30
26
  json_pure (1.8.1)
31
27
  multi_json (1.8.2)
32
28
  multi_test (0.0.2)
33
- puppet (3.3.1)
29
+ puppet (3.3.2)
34
30
  facter (~> 1.6)
35
31
  hiera (~> 1.0)
36
32
  rgen (~> 0.6.5)
33
+ rake (10.1.0)
37
34
  rgen (0.6.6)
38
35
  rspec-expectations (2.14.4)
39
36
  diff-lcs (>= 1.1.3, < 2.0)
@@ -47,4 +44,5 @@ DEPENDENCIES
47
44
  hiera-eyaml-plaintext
48
45
  highline
49
46
  puppet
47
+ rake
50
48
  trollop
data/README.md CHANGED
@@ -1,17 +1,39 @@
1
- Hiera eYaml
1
+ Hiera eyaml
2
2
  ===========
3
3
 
4
- A backend for Hiera that provides per-value asymmetric encryption of sensitive data
5
- within yaml type files to be used by Puppet.
4
+ [![Build Status](https://travis-ci.org/TomPoulton/hiera-eyaml.png?branch=master)](https://travis-ci.org/TomPoulton/hiera-eyaml)
6
5
 
7
- More info can be found [in this corresponding post](http://themettlemonkey.wordpress.com/2013/07/15/hiera-eyaml-per-value-encrypted-backend-for-hiera-and-puppet/).
6
+ hiera-eyaml is a backend for Hiera that provides per-value encryption of sensitive data within yaml files
7
+ to be used by Puppet.
8
8
 
9
- The Hiera eYaml backend uses yaml formatted files with the .eyaml extension. Simply prefix your
10
- encrypted string with the encryption method (PKCS7,) wrap it with ENC[] and place it in an eyaml file. You can mix your plain values in as well or separate them into different files.
11
9
 
12
- Example:
10
+ Advantages over hiera-gpg
11
+ -------------------------
13
12
 
14
- <pre>
13
+ A few people found that [hiera-gpg](https://github.com/crayfishx/hiera-gpg) just wasn't cutting it for all use cases,
14
+ one of the best expressed frustrations was
15
+ [written back in June 2013](http://slashdevslashrandom.wordpress.com/2013/06/03/my-griefs-with-hiera-gpg/). So
16
+ [Tom created an initial version](http://themettlemonkey.wordpress.com/2013/07/15/hiera-eyaml-per-value-encrypted-backend-for-hiera-and-puppet/)
17
+ and this was refined into an elegant solution over the following months.
18
+
19
+ Unlike `hiera-gpg`, `hiera-eyaml`:
20
+
21
+ - only encrypts the values (which allows files to be swiftly reviewed without decryption)
22
+ - encrypts the value of each key individually (this means that `git diff` is meaningful)
23
+ - includes a command line tool for encrypting, decrypting, editing and rotating keys (makes it almost as
24
+ easy as using clear text files)
25
+ - uses basic asymmetric encryption (PKCS#7) by default (doesn't require any native libraries that need to
26
+ be compiled & allows users without the private key to encrypt values that the puppet master can decrypt)
27
+ - has a pluggable encryption framework (e.g. GPG encryption ([hiera-eyaml-gpg](https://github.com/sihil/hiera-eyaml-gpg)) can be used
28
+ if you have the need for multiple keys and easier key rotation)
29
+
30
+ The Hiera eyaml backend uses yaml formatted files with the .eyaml extension. The encrypted strings are prefixed with the encryption
31
+ method, wrapped with ENC[] and placed in an eyaml file. You can mix your plain values in as well or separate them into different files.
32
+ Encrypted values can occur within arrays, hashes, nested arrays and nested hashes.
33
+
34
+ For instance:
35
+
36
+ ```yaml
15
37
  ---
16
38
  plain-property: You can see me
17
39
 
@@ -22,24 +44,19 @@ encrypted-property: >
22
44
  l5ZP119Fwq8xiREGOL0lVvFYJz2hZc1ppPCNG5lwuLnTekXN/OazNYpf4CMd
23
45
  /HjZFXwcXRtTlzewJLc+/gox2IfByQRhsI/AgogRfYQKocZgFb/DOZoXR7wm
24
46
  IZGeunzwhqfmEtGiqpvJJQ5wVRdzJVpTnANBA5qxeA==]
25
- </pre>
47
+ ```
48
+
49
+ To edit this you can use the command `eyaml -i important.eyaml` which will decrypt the file, fire up an editor with
50
+ the decrypted values and re-encrypt any edited values when you exit the editor. This tool makes editing your encrypted
51
+ files as simple as clear text files.
26
52
 
27
- eYaml supports multiple encryption types, and encrypted values can occur within arrays, hashes, nested arrays and nested hashes
28
53
 
29
54
  Setup
30
- =====
55
+ -----
31
56
 
32
57
  ### Installing hiera-eyaml
33
58
 
34
59
  $ gem install hiera-eyaml
35
-
36
- #### Installing from behind a corporate/application proxy
37
- $ export HTTP_PROXY=http://yourcorporateproxy:3128/
38
- $ export HTTPS_PROXY=http://yourcorporateproxy:3128/
39
-
40
- then run your install
41
-
42
- $ gem install hiera-eyaml
43
60
 
44
61
  ### Generate keys
45
62
 
@@ -54,11 +71,11 @@ This creates a public and private key with default names in the default location
54
71
  Since the point of using this module is to securely store sensitive information, it's important to store these keys securely.
55
72
  If using Hiera with Puppet, Your puppetmaster will need to access these keys to perform decryption when the puppet agent runs on a remote node.
56
73
  So for this reason, a suggested location might be to store them in:
57
-
74
+
58
75
  /etc/puppet/secure/keys
59
-
76
+
60
77
  (Using a secure/keys/ subfolder is so that you can still store other secure puppet files in the secure/ folder that might not be related to this module.)
61
-
78
+
62
79
  The permissions for this folder should allow the puppet user (normally 'puppet') execute access to the keys directory, read only access to the keys themselves and restrict everyone else:
63
80
 
64
81
  $ chown -R puppet:puppet /etc/puppet/secure/keys
@@ -91,37 +108,60 @@ To test decryption you can also use the eyaml tool if you have both keys
91
108
  $ eyaml -d -f filename # Decrypt a file
92
109
  $ eyaml -d -s 'ENC[PKCS7,.....]' # Decrypt a string
93
110
 
94
- ### eYaml files
111
+ ### Editing eyaml files
95
112
 
96
- Once you have created a few eyaml files, with a mixture of encrypted and non-encrypted properties, you can edit the encrypted values in place, using the special edit mode of the eyaml utility
113
+ Once you have created a few eyaml files, with a mixture of encrypted and non-encrypted properties,
114
+ you can edit the encrypted values in place, using the special edit mode of the eyaml utility. Edit
115
+ mode opens a decrypted copy of the eyaml file in your `$EDITOR` and will encrypt and modified values
116
+ when you exit the editor.
97
117
 
98
118
  $ eyaml -i filename.eyaml # Edit an eyaml file in place
99
119
 
100
- Multiple Encryption Types
101
- =========================
120
+ When editing eyaml files, you will see that the unencrypted plaintext is marked to allow the eyaml tool to
121
+ identify each encrypted block, along with the encryption method. This is used to make sure that the block
122
+ is encrypted again only if the clear text value has changed, and is encrypted using the
123
+ original encryption mechanism (see plugable encryption later).
102
124
 
103
- hiera-eyaml backend is pluggable, so that further encryption types can be added as separate gems to the general mechanism which hiera-eyaml uses. Hiera-eyaml ships with one default mechanism of 'pkcs7', the encryption type widely used to sign smime email messages.
125
+ A decrypted file might look like this:
104
126
 
105
- Other encryption types (if the gems for them have been loaded) can be specified using the following formats:
127
+ ```yaml
128
+ ---
129
+ plain-property: You can see me
106
130
 
107
- <pre>
108
- ENC[PKCS7,SOME_ENCRYPTED_VALUE] # a PKCS7 encrypted value
109
- ENC[GPG,SOME_ENCRYPTED_VALUE] # a GPG encrypted value (hiera-eyaml-gpg)
110
- ... etc ...
111
- </pre>
131
+ cipher-property : >
132
+ DEC(1)::PKCS7[You can't see me]!
112
133
 
113
- When editing eyaml files, you will see that the unencrypted plaintext is marked in such a way as to identify the encryption method. This is so that the eyaml tool knows to encrypt it back using the correct method afterwards:
134
+ environments:
135
+ development:
136
+ host: localhost
137
+ password: password
138
+ production:
139
+ host: prod.org.com
140
+ password: >
141
+ DEC(2)::PKCS7[securepassword]!
142
+
143
+ things:
144
+ - thing 1
145
+ - - nested thing 1.0
146
+ - >
147
+ DEC(3)::PKCS7[secure nested thing 1.1]!
148
+ - - nested thing 2.0
149
+ - nested thing 2.1
150
+ ```
151
+
152
+ Whilst editing you can delete existing values and add new one using the same format (as below). Note that it is important to
153
+ omit the number in brackets for new values. If any duplicate IDs are found then the re-encryption process will be abandoned
154
+ by the eyaml tool.
155
+
156
+ some_new_key: DEC::PKCS7[a new value to encrypt]!
114
157
 
115
- <pre>
116
- some_key: DEC::PKCS7[very secret password]!
117
- </pre>
118
158
 
119
159
  Hiera
120
- =====
160
+ -----
121
161
 
122
162
  To use eyaml with hiera and puppet, first configure hiera.yaml to use the eyaml backend
123
163
 
124
- <pre>
164
+ ```yaml
125
165
  ---
126
166
  :backends:
127
167
  - eyaml
@@ -139,17 +179,20 @@ To use eyaml with hiera and puppet, first configure hiera.yaml to use the eyaml
139
179
  # If using the pkcs7 encryptor (default)
140
180
  :pkcs7_private_key: /path/to/private_key.pkcs7.pem
141
181
  :pkcs7_public_key: /path/to/public_key.pkcs7.pem
182
+ ```
142
183
 
143
- </pre>
144
-
145
- Then, edit your hiera yaml files (renaming them with the .eyaml extension), and insert your encrypted values:
184
+ Then, edit your hiera yaml files, and insert your encrypted values. The default eyaml file extension is .eyaml, however this can be configured in the :eyaml block to set :extension,
146
185
 
186
+ ```yaml
187
+ :eyaml:
188
+ :extension: 'yaml'
189
+ ```
147
190
 
148
- *Important Note:*
149
- The eYaml backend will not parse internally json formatted yaml files, whereas the regular yaml backend will.
191
+ *Important Note:*
192
+ The eyaml backend will not parse internally json formatted yaml files, whereas the regular yaml backend will.
150
193
  You'll need to ensure any existing yaml files using json format are converted to syntactically correct yaml format.
151
194
 
152
- <pre>
195
+ ```yaml
153
196
  ---
154
197
  plain-property: You can see me
155
198
 
@@ -187,22 +230,36 @@ things:
187
230
  IZGeunzwhqfmEtGiqpvJJQ5wVRdzJVpTnANBA5qxeA==]
188
231
  - - nested thing 2.0
189
232
  - nested thing 2.1
190
- </pre>
233
+ ```
191
234
 
192
- Tests
193
- =====
194
235
 
195
- In order to run the tests, simply run `cucumber` in the top level directory of the project.
236
+ Pluggable Encryption
237
+ --------------------
196
238
 
197
- You'll need to have a few requirements installed:
239
+ hiera-eyaml backend is pluggable, so that further encryption types can be added as separate gems to the general mechanism which hiera-eyaml uses. Hiera-eyaml ships with one default mechanism of 'pkcs7', the encryption type widely used to sign smime email messages.
240
+
241
+ Other encryption types (if the gems for them have been loaded) can be specified using the following formats:
242
+
243
+ ENC[PKCS7,SOME_ENCRYPTED_VALUE] # a PKCS7 encrypted value
244
+ ENC[GPG,SOME_ENCRYPTED_VALUE] # a GPG encrypted value (hiera-eyaml-gpg)
245
+ ... etc ...
246
+
247
+ When editing eyaml files, you will see that the unencrypted plaintext is marked in such a way as to identify the encryption method. This is so that the eyaml tool knows to encrypt it back using the correct method afterwards:
248
+
249
+ some_key: DEC(1)::PKCS7[very secret password]!
250
+
251
+ ### Encryption plugins
252
+
253
+ This is a list of available plugins:
254
+
255
+ - [hiera-eyaml-gpg](https://github.com/sihil/hiera-eyaml-gpg) - Provide GPG encryption
256
+ - [hiera-eyaml-plaintext](https://github.com/gtmtech/hiera-eyaml-plaintext) - This is a no-op encryption plugin that
257
+ simply base64 encodes the values. It exists as an example plugin to create your own and to do integration tests on
258
+ hiera-eyaml. **THIS SHOULD NOT BE USED IN PRODUCTION**
198
259
 
199
- * `expect` (via yum/apt-get or system package)
200
- * `aruba` (gem)
201
- * `cucumber` (gem)
202
- * `puppet` (gem)
203
260
 
204
261
  Notes
205
- =====
262
+ -----
206
263
 
207
264
  If you do not specify an encryption method within ENC[] tags, it will be assumed to be PKCS7
208
265
 
@@ -214,8 +271,45 @@ access to a DEV branch will be able to read/view the contents of the PRD branch,
214
271
  Github has a great guide on removing sensitive data from repos here:
215
272
  https://help.github.com/articles/remove-sensitive-data
216
273
 
274
+
275
+ Troubleshooting
276
+ ---------------
277
+
278
+ ### Installing from behind a corporate/application proxy
279
+
280
+ $ export HTTP_PROXY=http://yourcorporateproxy:3128/
281
+ $ export HTTPS_PROXY=http://yourcorporateproxy:3128/
282
+
283
+ then run your install
284
+
285
+ $ gem install hiera-eyaml
286
+
287
+
288
+ Issues
289
+ ------
290
+
291
+ If you have found a bug then please raise an issue here on github.
292
+
293
+ Some of us hang out on #hiera-eyaml on freenode, please drop by if you want to say hi or have a question.
294
+
295
+
296
+ Tests
297
+ -----
298
+
299
+ In order to run the tests, simply run `cucumber` in the top level directory of the project.
300
+
301
+ You'll need to have a few requirements installed:
302
+
303
+ * `expect` (via yum/apt-get or system package)
304
+ * `aruba` (gem)
305
+ * `cucumber` (gem)
306
+ * `puppet` (gem)
307
+
308
+
217
309
  Authors
218
- =======
310
+ -------
219
311
 
220
312
  - [Tom Poulton](http://github.com/TomPoulton) - Initial author. eyaml backend.
221
- - [Geoff Meakin](http://github.com/gtmtech) - Major contributor. eyaml command.
313
+ - [Geoff Meakin](http://github.com/gtmtech) - Major contributor. eyaml command, tests, CI
314
+ - [Simon Hildrew](http://github.com/sihil) - Contributor. eyaml edit sub command.
315
+ - [Robert Fielding](http://github.com/rooprob) - Contributor. eyaml recrypt sub command.
@@ -2,7 +2,10 @@ class Hiera
2
2
  module Backend
3
3
  module Eyaml
4
4
 
5
- VERSION = "1.3.7"
5
+ class RecoverableError < StandardError
6
+ end
7
+
8
+ VERSION = "1.3.8"
6
9
 
7
10
  def self.default_encryption_scheme= new_encryption
8
11
  @@default_encryption_scheme = new_encryption
@@ -4,6 +4,7 @@ require 'hiera/backend/eyaml/utils'
4
4
  require 'hiera/backend/eyaml/actions/createkeys_action'
5
5
  require 'hiera/backend/eyaml/actions/decrypt_action'
6
6
  require 'hiera/backend/eyaml/actions/encrypt_action'
7
+ require 'hiera/backend/eyaml/actions/recrypt_action'
7
8
  require 'hiera/backend/eyaml/actions/edit_action'
8
9
  require 'hiera/backend/eyaml/plugins'
9
10
  require 'hiera/backend/eyaml/options'
@@ -16,25 +17,26 @@ class Hiera
16
17
  def self.parse
17
18
 
18
19
  options = Trollop::options do
19
-
20
+
20
21
  version "Hiera-eyaml version " + Hiera::Backend::Eyaml::VERSION.to_s
21
22
  banner <<-EOS
22
23
  Hiera-eyaml is a backend for Hiera which provides OpenSSL encryption/decryption for Hiera properties
23
24
 
24
25
  Usage:
25
- eyaml [options]
26
+ eyaml [options]
26
27
  eyaml -i file.eyaml # edit a file
27
28
  eyaml -e -s some-string # encrypt a string
28
- eyaml -e -p # encrypt a password
29
+ eyaml -e -p # encrypt a password
29
30
  eyaml -e -f file.txt # encrypt a file
30
31
  cat file.txt | eyaml -e # encrypt a file on a pipe
31
32
 
32
- Options:
33
+ Options:
33
34
  EOS
34
-
35
+
35
36
  opt :createkeys, "Create public and private keys for use encrypting properties", :short => 'c'
36
37
  opt :decrypt, "Decrypt something", :short => 'd'
37
38
  opt :encrypt, "Encrypt something", :short => 'e'
39
+ opt :recrypt, "Recrypt something", :short => 'r', :type => :string
38
40
  opt :edit, "Decrypt, Edit, and Reencrypt", :short => 'i', :type => :string
39
41
  opt :eyaml, "Source input is an eyaml file", :short => 'y', :type => :string
40
42
  opt :password, "Source input is a password entered on the terminal", :short => 'p'
@@ -53,8 +55,8 @@ Options:
53
55
 
54
56
  end
55
57
 
56
- actions = [:createkeys, :decrypt, :encrypt, :edit].collect {|x| x if options[x]}.compact
57
- sources = [:edit, :eyaml, :password, :string, :file, :stdin].collect {|x| x if options[x]}.compact
58
+ actions = [:createkeys, :decrypt, :recrypt, :encrypt, :edit].collect {|x| x if options[x]}.compact
59
+ sources = [:edit, :recrypt, :eyaml, :password, :string, :file, :stdin].collect {|x| x if options[x]}.compact
58
60
  # sources << :stdin if STDIN
59
61
 
60
62
  Trollop::die "You can only specify one of (#{actions.join(', ')})" if actions.count > 1
@@ -84,7 +86,11 @@ Options:
84
86
  if options[:edit]
85
87
  options[:eyaml] = options[:edit]
86
88
  options[:source] = :eyaml
87
- File.read options[:edit]
89
+ File.read options[:edit]
90
+ elsif options[:recrypt]
91
+ options[:eyaml] = options[:recrypt]
92
+ options[:source] = :eyaml
93
+ File.read options[:recrypt]
88
94
  else
89
95
  nil
90
96
  end
@@ -104,7 +110,7 @@ Options:
104
110
  return_value = action_class.execute
105
111
  puts return_value unless return_value.nil?
106
112
 
107
- end
113
+ end
108
114
 
109
115
  end
110
116
 
@@ -3,6 +3,7 @@ require 'hiera/backend/eyaml/actions/decrypt_action'
3
3
  require 'hiera/backend/eyaml/actions/encrypt_action'
4
4
  require 'hiera/backend/eyaml/options'
5
5
  require 'hiera/backend/eyaml/parser/parser'
6
+ require 'highline/import'
6
7
 
7
8
  class Hiera
8
9
  module Backend
@@ -19,50 +20,61 @@ class Hiera
19
20
  decrypted_file = Utils.write_tempfile decrypted_input
20
21
 
21
22
  editor = Utils.find_editor
22
- system editor, decrypted_file
23
- status = $?
24
23
 
25
- raise StandardError, "File was moved by editor" unless File.file? decrypted_file
26
- edited_file = File.read decrypted_file
27
- Utils.secure_file_delete :file => decrypted_file, :num_bytes => [edited_file.length, decrypted_input.length].max
24
+ begin
25
+ system "#{editor} #{decrypted_file}"
26
+ status = $?
28
27
 
29
- raise StandardError, "Editor #{editor} has not exited?" unless status.exited?
30
- raise StandardError, "Editor did not exit successfully (exit code #{status.exitstatus}), aborting" unless status.exitstatus
28
+ raise StandardError, "File was moved by editor" unless File.file? decrypted_file
29
+ edited_file = File.read decrypted_file
31
30
 
32
- raise StandardError, "Edited file is blank" if edited_file.empty?
31
+ raise StandardError, "Editor #{editor} has not exited?" unless status.exited?
32
+ raise StandardError, "Editor did not exit successfully (exit code #{status.exitstatus}), aborting" unless status.exitstatus == 0
33
33
 
34
- if edited_file == decrypted_input
35
- Utils.info "No changes detected, exiting"
36
- else
37
- decrypted_parser = Parser::ParserFactory.decrypted_parser
38
- edited_tokens = decrypted_parser.parse(edited_file)
34
+ raise StandardError, "Edited file is blank" if edited_file.empty?
39
35
 
40
- # check that the tokens haven't been copy / pasted
41
- used_ids = edited_tokens.find_all{ |t| t.class.name =~ /::EncToken$/ }.map{ |t| t.id }
42
- if used_ids.length != used_ids.uniq.length
43
- raise StandardError, "A duplicate DEC(ID) was found so I don't know how to proceed. This is probably because you copy and pasted a value - if you do this please delete the ID in parentheses"
44
- end
36
+ if edited_file == decrypted_input
37
+ Utils.info "No changes detected, exiting"
38
+ else
39
+ decrypted_parser = Parser::ParserFactory.decrypted_parser
40
+ edited_tokens = decrypted_parser.parse(edited_file)
41
+
42
+ # check that the tokens haven't been copy / pasted
43
+ used_ids = edited_tokens.find_all{ |t| t.class.name =~ /::EncToken$/ and !t.id.nil? }.map{ |t| t.id }
44
+ if used_ids.length != used_ids.uniq.length
45
+ raise RecoverableError, "A duplicate DEC(ID) was found so I don't know how to proceed. This is probably because you copy and pasted a value - if you do this please delete the ID in parentheses"
46
+ end
45
47
 
46
- # replace untouched values with the source values
47
- edited_denoised_tokens = edited_tokens.map{ |token|
48
- if token.class.name =~ /::EncToken$/ && !token.id.nil?
49
- old_token = tokens[token.id]
50
- if old_token.plain_text.eql? token.plain_text
51
- old_token
48
+ # replace untouched values with the source values
49
+ edited_denoised_tokens = edited_tokens.map{ |token|
50
+ if token.class.name =~ /::EncToken$/ && !token.id.nil?
51
+ old_token = tokens[token.id]
52
+ if old_token.plain_text.eql? token.plain_text
53
+ old_token
54
+ else
55
+ token
56
+ end
52
57
  else
53
58
  token
54
59
  end
55
- else
56
- token
57
- end
58
- }
60
+ }
59
61
 
60
- encrypted_output = edited_denoised_tokens.map{ |t| t.to_encrypted }.join
62
+ encrypted_output = edited_denoised_tokens.map{ |t| t.to_encrypted }.join
61
63
 
62
- filename = Eyaml::Options[:eyaml]
63
- File.open("#{filename}", 'w') { |file|
64
- file.write encrypted_output
65
- }
64
+ filename = Eyaml::Options[:eyaml]
65
+ File.open("#{filename}", 'w') { |file|
66
+ file.write encrypted_output
67
+ }
68
+ end
69
+ rescue RecoverableError => e
70
+ Utils.info e
71
+ if agree "Return to the editor to try again?"
72
+ retry
73
+ else
74
+ raise e
75
+ end
76
+ ensure
77
+ Utils.secure_file_delete :file => decrypted_file, :num_bytes => [edited_file.length, decrypted_input.length].max
66
78
  end
67
79
 
68
80
  nil
@@ -0,0 +1,44 @@
1
+ require 'hiera/backend/eyaml/utils'
2
+ require 'hiera/backend/eyaml/actions/decrypt_action'
3
+ require 'hiera/backend/eyaml/actions/encrypt_action'
4
+ require 'hiera/backend/eyaml/options'
5
+ require 'hiera/backend/eyaml/parser/parser'
6
+
7
+ class Hiera
8
+ module Backend
9
+ module Eyaml
10
+ module Actions
11
+
12
+ class RecryptAction
13
+
14
+ def self.execute
15
+
16
+ encrypted_parser = Parser::ParserFactory.encrypted_parser
17
+ tokens = encrypted_parser.parse Eyaml::Options[:input_data]
18
+ decrypted_input = tokens.each_with_index.to_a.map{|(t,index)| t.to_decrypted :index => index}.join
19
+ decrypted_file = Utils.write_tempfile decrypted_input
20
+
21
+ edited_file = File.read decrypted_file
22
+ Utils.secure_file_delete :file => decrypted_file, :num_bytes => [edited_file.length, decrypted_input.length].max
23
+
24
+ raise StandardError, "Edited file is blank" if edited_file.empty?
25
+
26
+ decrypted_parser = Parser::ParserFactory.decrypted_parser
27
+ edited_tokens = decrypted_parser.parse(edited_file)
28
+
29
+ encrypted_output = edited_tokens.map{ |t| t.to_encrypted }.join
30
+
31
+ filename = Eyaml::Options[:eyaml]
32
+ File.open("#{filename}", 'w') { |file|
33
+ file.write encrypted_output
34
+ }
35
+
36
+ nil
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+ end
43
+ end
44
+ end
@@ -69,7 +69,11 @@ class Hiera
69
69
  cert.serial = 0
70
70
  cert.version = 2
71
71
  cert.not_before = Time.now
72
- cert.not_after = Time.now + 50 * 365 * 24 * 60 * 60
72
+ cert.not_after = if 1.size == 8 # 64bit
73
+ Time.now + 50 * 365 * 24 * 60 * 60
74
+ else # 32bit
75
+ Time.at(0x7fffffff)
76
+ end
73
77
  cert.public_key = key.public_key
74
78
 
75
79
  ef = OpenSSL::X509::ExtensionFactory.new
@@ -7,8 +7,9 @@ require 'yaml'
7
7
  class Hiera
8
8
  module Backend
9
9
  class Eyaml_backend
10
-
10
+
11
11
  def initialize
12
+ @extension = Config[:eyaml][:extension] ? Config[:eyaml][:extension] : "eyaml"
12
13
  end
13
14
 
14
15
  def lookup(key, scope, order_override, resolution_type)
@@ -17,7 +18,7 @@ class Hiera
17
18
  answer = nil
18
19
 
19
20
  Backend.datasources(scope, order_override) do |source|
20
- eyaml_file = Backend.datafile(:eyaml, scope, source, "eyaml") || next
21
+ eyaml_file = Backend.datafile(:eyaml, scope, source, @extension) || next
21
22
 
22
23
  debug("Processing datasource: #{eyaml_file}")
23
24
 
@@ -42,7 +43,7 @@ class Hiera
42
43
  debug("Merging answer hash")
43
44
  raise Exception, "Hiera type mismatch: expected Hash and got #{parsed_answer.class}" unless parsed_answer.kind_of? Hash
44
45
  answer ||= {}
45
- answer = parsed_answer.merge answer
46
+ answer = Backend.merge_answer(parsed_answer,answer)
46
47
  else
47
48
  debug("Assigning answer variable")
48
49
  answer = parsed_answer
@@ -87,7 +88,7 @@ class Hiera
87
88
  if encrypted? value
88
89
 
89
90
  debug "Attempting to decrypt: #{key}"
90
-
91
+
91
92
  Config[:eyaml].each do |config_key, config_value|
92
93
  config_value = Backend.parse_string(Config[:eyaml][config_key], scope)
93
94
  debug "Setting: #{config_key} = #{config_value}"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hiera-eyaml
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.7
4
+ version: 1.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Poulton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-14 00:00:00.000000000 Z
11
+ date: 2013-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trollop
@@ -46,6 +46,7 @@ extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
48
  - .gitignore
49
+ - .travis.yml
49
50
  - Gemfile
50
51
  - Gemfile.lock
51
52
  - LICENSE.txt
@@ -60,6 +61,7 @@ files:
60
61
  - lib/hiera/backend/eyaml/actions/decrypt_action.rb
61
62
  - lib/hiera/backend/eyaml/actions/edit_action.rb
62
63
  - lib/hiera/backend/eyaml/actions/encrypt_action.rb
64
+ - lib/hiera/backend/eyaml/actions/recrypt_action.rb
63
65
  - lib/hiera/backend/eyaml/encryptor.rb
64
66
  - lib/hiera/backend/eyaml/encryptors/pkcs7.rb
65
67
  - lib/hiera/backend/eyaml/options.rb