puppet-decrypt 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 248058bd4e4965701c01ff8037984487ea5db344
4
+ data.tar.gz: bfd65eec21ba36b8c3d8081e3f442c4f1adc980c
5
+ SHA512:
6
+ metadata.gz: e9b7548c7c93147d6aa8a81f4a9a1cf1374ed5cdb18fc4a0ad50530fa956ed316cba19cad58fb0f7e84609a9d04b1cefb262a549a807761cffb4a47a46e25a11
7
+ data.tar.gz: c2d3f32d32879c01aba7ca764280ec2422e81d3c69841bc256f0333ff90dfa3c7e6ef37341f8f6e593819cf4f5aa27b078bd643c1078be0afca10aae4dcbc699
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --backtrace
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use --create 1.9.3@puppet-decrypt
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 1.9.2
5
+ - jruby-19mode
6
+ - 2.0.0
7
+ gemfile:
8
+ - Gemfile
9
+ - bundles/puppet_3_0.gemfile
10
+ - bundles/puppet_2_7.gemfile
data/ChangeLog.md ADDED
@@ -0,0 +1,18 @@
1
+ ## 0.1.0 (July 10, 2013)
2
+
3
+ Features:
4
+
5
+ - support alternate secret keys
6
+ - override the key as part of the string in the format ENC:another_key[...]
7
+ - override the key by passing a hash containing value and secret_key
8
+
9
+ Bugfixes:
10
+
11
+ - Explicitly remove Ruby 1.8.7 support. Previously it would install but not work with Ruby 1.8.7.
12
+
13
+ ## 0.0.4 (March 8, 2013)
14
+
15
+ Features:
16
+
17
+ - puppet face for encrypting/decrypting secrets
18
+ - basic puppet function for decrypting a secret, using a master key
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in puppet-decrypt.gemspec
4
+ gem 'puppet'
5
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,16 @@
1
+ Puppet-Decrypt
2
+
3
+ Copyright (c) 2013 mlincoln
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+
data/Modulefile ADDED
@@ -0,0 +1,13 @@
1
+ name 'devopsy/puppet_decrypt'
2
+ version '0.1.0'
3
+ source 'https://github.com/maxlinc/puppet-decrypt'
4
+ author 'Max Lincoln'
5
+ license 'Apache License, Version 2.0'
6
+ summary 'Simple encryption/decryption of secret data for Puppet'
7
+ description 'Simple encryption/decryption of secret data for Puppet'
8
+ project_page 'https://github.com/maxlinc/puppet-decrypt'
9
+
10
+ ## Add dependencies, if any:
11
+ # don't think gem dependencies can be declared...
12
+ # dependency gem 'encryptor'
13
+
data/README.md ADDED
@@ -0,0 +1,166 @@
1
+ **Table of Contents** *generated with [DocToc](http://doctoc.herokuapp.com/)*
2
+
3
+ - [Puppet-Decrypt](#puppet-decrypt)
4
+ - [Comparison with Hiera-GPG](#comparison-with-hiera-gpg)
5
+ - [Installation](#installation)
6
+ - [Via Gem](#via-gem)
7
+ - [Installing as a Module](#installing-as-a-module)
8
+ - [Usage](#usage)
9
+ - [Basic Usage](#basic-usage)
10
+ - [Overriding the secret key](#overriding-the-secret-key)
11
+ - [Contributing](#contributing)
12
+
13
+ [![Build Status](https://secure.travis-ci.org/maxlinc/puppet-decrypt.png?branch=master)](http://travis-ci.org/maxlinc/puppet-decrypt)
14
+ [![Dependency Status](https://gemnasium.com/maxlinc/puppet-decrypt.png?travis)](https://gemnasium.com/maxlinc/puppet-decrypt)
15
+ [![Code Climate](https://codeclimate.com/github/maxlinc/puppet-decrypt.png)](https://codeclimate.com/github/maxlinc/puppet-decrypt)
16
+
17
+ # Puppet-Decrypt
18
+
19
+ *Notice: The default secret key location is now /etc/puppet-decrypt/encryptor_secret_key*
20
+
21
+ Puppet Decrypt is a gem that gives puppet the ability to encrypt and decrypt strings. This is useful for making sure secret data - like database passwords - remains secret. It uses a model similar to [jasypt Encrypting Application Configuration Files](http://www.jasypt.org/encrypting-configuration.html) or [Maven Password Encryption](http://maven.apache.org/guides/mini/guide-encryption.html). It is a simple alternative to the [Secret variables in Puppet with Hiera and GPG](http://www.craigdunn.org/2011/10/secret-variables-in-puppet-with-hiera-and-gpg/) approach.
22
+
23
+ ## Comparison with Hiera-GPG
24
+
25
+ Advantages:
26
+
27
+ * Store encrypted secret variables and related non-secret variables in the same file.
28
+ * Version control friendly - you can easily see when a variable was added, changed, or removed even if you don't know the exact value.
29
+ * Works with any data source. Combine it with Hiera, extlookup, external node classifiers, exported resources, or any other source of data.
30
+ * Simple administration - no keyring management.
31
+
32
+ Disadvantages:
33
+
34
+ * Uses a shared secret instead of asymetric keypairs. This means that the "master password" is shared by all admins. It is also shared by all machines that need to decrypt the same value (usually machines in the same environment).
35
+ * Less integrated with Hiera. You need to wrap calls as decrypt(hiera('my_db_password')).
36
+
37
+ The shared secret "master password" may seem more difficult to grant and revoke access than the asymetric keypair approach used by hiera-gpg. However both systems are protecting shared secret data! So if you want to fully revoke someone's access you need to change or revoke their decryption key (which is easier with hiera-gpg) *AND* to change any secrets that key protected (e.g.: your production database passwords).
38
+
39
+ ## Installation
40
+
41
+ ### Via Gem
42
+
43
+ It should be possible to install via a Gem in Puppet 3+. However, this method is easier, but does seem to have some quirks. If you have any issues, try installing as a module instead.
44
+
45
+ Add this line to your application's Gemfile:
46
+
47
+ gem 'puppet-decrypt'
48
+
49
+ And then execute:
50
+
51
+ $ bundle
52
+
53
+ Or install it yourself as:
54
+
55
+ $ gem install puppet-decrypt
56
+
57
+ ### Installing as a Module
58
+
59
+ If installing as a module, you'll need to deal with the Gem prerequisites manually.
60
+
61
+ ``` shell
62
+ $ gem install encryptor
63
+ ```
64
+
65
+ Puppet Decrypt can be installed with the puppet module subcommand, which is included in Puppet 2.7.14 and later.
66
+
67
+ ``` shell
68
+ $ sudo puppet module install puppet_decrypt
69
+ ```
70
+ The command will tell you where it is installing the module; take note:
71
+
72
+ ``` shell
73
+ $ sudo puppet module install devopsy/puppet_decrypt
74
+ warning: iconv couldn't be loaded, which is required for UTF-8/UTF-16 conversions
75
+ Preparing to install into /etc/puppet/modules ...
76
+ Downloading from http://forge.puppetlabs.com ...
77
+ Installing -- do not interrupt ...
78
+ /etc/puppet/modules
79
+ └── devopsy-puppet_decrypt (v0.1.0)
80
+ ```
81
+
82
+ After installing it, you must add the lib directory of the module to your $RUBYLIB. Add the following to your .profile file (replacing /etc/puppet/modules with the directory from the install command, if necessary), then run source ~/.profile to re-load it in the current shell:
83
+
84
+ ``` shell
85
+ export RUBYLIB=/etc/puppet/modules/puppet_decrypt/lib:$RUBYLIB
86
+ ```
87
+
88
+ You can verify that it is installed and usable by running:
89
+
90
+ ``` shell
91
+ # puppet help crypt
92
+ ```
93
+
94
+ ## Usage
95
+
96
+ ### Basic Usage
97
+ Put the secret key in /etc/puppet-decrypt/encryptor_secret_key on machines where puppet needs to decrypt the value. Make sure the file's read permissions are restricted!
98
+
99
+ Use the puppet face to encrypt a value
100
+
101
+ ``` shell
102
+ $ puppet crypt encrypt my_secret_value
103
+ ENC[ANN3I3AWxXWmr5QAW3qgxw==]
104
+ ```
105
+
106
+ Or to decrypt a value
107
+ ``` shell
108
+ $ puppet crypt decrypt ENC[ANN3I3AWxXWmr5QAW3qgxw==]
109
+ my_secret_value
110
+ ```
111
+
112
+ Put that value into hiera, extlookup, or any other data source you want. Hiera example:
113
+ ``` yaml
114
+ database_password: ENC[ANN3I3AWxXWmr5QAW3qgxw==]
115
+ ```
116
+
117
+ In your puppet code, load the value normally and then pass it to decrypt.
118
+ ``` ruby
119
+ decrypt(hiera('database_password'))
120
+ ```
121
+
122
+ ### Overriding the secret key
123
+
124
+ Puppet Decrypt now supports using more than just the default secret key location. You can easily use multiple secret keys for the same project.
125
+
126
+ For the Puppet face, you just use the --secretkey option to pass an alternate secret key location.
127
+
128
+ ``` shell
129
+ $ echo 'example' > alt_key.txt
130
+ $ puppet crypt encrypt abc123 --secretkey alt_key
131
+ ENC[c4S4hMCDv1b7FkZgOBRTOA==]
132
+ $ puppet crypt decrypt ENC[c4S4hMCDv1b7FkZgOBRTOA==] --secretkey alt_key
133
+ abc123
134
+ ```
135
+
136
+ There are two ways to use the alternate keys from the function. You can pass it it as part of the string in this format:
137
+ ``` yaml
138
+ database_password: ENC:alt_key[c4S4hMCDv1b7FkZgOBRTOA==]
139
+ ```
140
+
141
+ If you do that, instead of using the default secret key, it will look for alt_key in the same directory. So instead of
142
+ /etc/puppet-decrypt/encryptor_secret_key it will use /etc/puppet-decrypt/alt_key.
143
+
144
+ Alternately, you can pass a hash to the function, containing a value and a secret key, like this:
145
+ ``` yaml
146
+ db_password:
147
+ value: 'ENC[G6MjBDDFcapYLaKBFJvPSg==]'
148
+ secretkey: '/any/path/you/another/key'
149
+ ```
150
+
151
+ This has the advantage of letting you place keys in alternate directories, not just /etc/puppet-decrypt.
152
+
153
+ If you use this alongside hiera, you can just switch the lookup from hiera to hiera-hash:
154
+ ``` ruby
155
+ decrypt(hiera_hash('db_password'))
156
+ ```
157
+
158
+ See [features/hiera.feature](features/hiera.feature) for complete examples.
159
+
160
+ ## Contributing
161
+
162
+ 1. Fork it
163
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
164
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
165
+ 4. Push to the branch (`git push origin my-new-feature`)
166
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'cucumber'
4
+ require 'cucumber/rake/task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task :default => [:spec, :integration]
9
+
10
+ Cucumber::Rake::Task.new(:integration) do |t|
11
+ t.cucumber_opts = "features --format pretty"
12
+ end
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in puppet-decrypt.gemspec
4
+ gem 'puppet', '~> 2.7.0'
5
+ gem 'hiera-puppet'
6
+ gemspec(:path => '../')
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in puppet-decrypt.gemspec
4
+ gem 'puppet', '~> 3.0.0'
5
+ gemspec(:path => '../')
@@ -0,0 +1,4 @@
1
+ ---
2
+ db_password:
3
+ value: 'ENC[blablabla==]'
4
+ secretkey: '/etc/some_other_key'
@@ -0,0 +1,2 @@
1
+ ---
2
+ db_password: 'ENC[okoNBVDGyHQaQQPKnTTJvA==]'
@@ -0,0 +1,8 @@
1
+ ---
2
+ :backends: yaml
3
+ :yaml:
4
+ :datadir: features/fixtures/data
5
+ :hierarchy:
6
+ - '%{::hiera_file}'
7
+ - common
8
+ :logger: console
@@ -0,0 +1,5 @@
1
+ $decrypted = decrypt(hiera('db_password'))
2
+ notice($decrypted)
3
+ unless($decrypted == 'expected') {
4
+ fail("Expected 'expected', found $unexpected")
5
+ }
@@ -0,0 +1,6 @@
1
+ $decrypted = decrypt(hiera('db_password'))
2
+ notice($decrypted)
3
+ $expected = 'blablabla'
4
+ unless($decrypted == $expected) {
5
+ fail("Expected '$expected', found $unexpected")
6
+ }
@@ -0,0 +1,11 @@
1
+ 1ExtSQ4kg4a4rsp7J0RlquK5Y+h5b4TeEzHX24sDxURY4LLX6J5bwTZueg1PBhiI
2
+ EenV11LGhRvUDrw53dG7j+UuMxGJv/R2cdnGxq1ztjN1ozp8xSRUTcbzpd9uijLe
3
+ FhEZHVjAIzBNj9RLl13Dw5zVPvxRuPcQBsnRIyG8YMMCgZMgZ90yBMhJmp5M3hw/
4
+ q88nDZGlZeclkIg+9QTtjywz4crvHpnQrC1ViyaIVT+lZfHPMg4TipXlDXPrlFea
5
+ x/X7v/EYXvSvY6gSVs7/ZAfFnC1K30nCaPnAbIiwsdjh7t3dV7ymHY/TvXfZQHGO
6
+ BXMFu9jdJl+nptZZp/4x4xb569s0do1Y/Z6DHqeIi31pS4hwjw8j6zHWpPrnTgRw
7
+ vcv0Di3iCjFAbTbSadgFuuybUCeZQArRYO0J03IKHNqW9UWim7tN08LOmvGuoQKf
8
+ 6IAhKT0Yc4y1Mk6jtDsPlkxJvdVzTRlv07FnWWi3R2kkLWqdeFz6YB8PDCSLMXL0
9
+ qNDDOfv1MuUfKlGgqigIkbMpbqd6KUU1qLQ0js1RTq9iO6XR8wHIXqKX5r0Mp0D6
10
+ aMO1a7gvjHJFqr3nkeZvDAbGeJMJtx99OrfuUH8FImvJZ22jOP4plcC1U1u2VZGp
11
+ Rx2AoLYyiWuzP948FmvruvXMn7WxvDrU7N/wF52L3/Q=
@@ -0,0 +1 @@
1
+ example
@@ -0,0 +1,11 @@
1
+ idZdWf3d7s97FVG0iytPj03c2LhrumdUqk4T+aa1VVzp8vFmtQb7Vyy7SbjV4v4y
2
+ CLEat8x8jFb7IBl2yjW3KmC0TW1q1cKaeP8eHuYeqm9ZIQoUtDH+q+8KM5xso358
3
+ PAkDtxJcFmcRvD2SL47WYTd+xFjYEW5VxWhGCcNi/FRlmRSLL29sBcRGfJNhPBit
4
+ j3PiXxPrNIu4E1Ikm94C911x4YD/PO5yNOuhDQW5rs1z8G8TGmzXV64Vxg7rYcXc
5
+ 8XK0auzDm+qTdSpP6vaLhFROcGgFVzFu5WWHZ0dpRL1UfDdjlQbHojRCfb4jZB+I
6
+ bXTS5BQFzClttcPYSwf44am3zwYCuLeZ5oWif2sxPBwUIubzPIoBObcdj/uIjljx
7
+ BBPcoPDW+zIbghVWxjoHkLinRdqtXQzMCS0pp8znRsT7v5mp7FZvzMLDO6belz+Q
8
+ LEd3YefLkOFU6B7kJq7XDrVP18G691SwhY08rSq0LyNlwEZ4E9ZD6hrUduHd3Bs7
9
+ yGNhGjvAEItfDv7MBcavkLZSO/q1QElbz5B7/3aiu2HPRfUmS/hiywJ3S1cxZp8Y
10
+ wVr0kqIxRxMoNfl4IqCaRsvlwGBeTHmpXqkcviQsQOuddMStGXKKptrXKxvhn4ca
11
+ 72SUKYg7mvyCWD44mAxJyTfTso93Pkn95klRtyBunu0=
@@ -0,0 +1,43 @@
1
+ Feature: Puppet works
2
+
3
+ Scenario: Default test
4
+ Given I have the following hiera data:
5
+ """
6
+ ---
7
+ db_password: ENC[wx0qTorBqPrTrgkbzYirlA==]
8
+ """
9
+ When I execute this puppet manifest:
10
+ """
11
+ $password = decrypt(hiera('db_password'))
12
+ notice("Decrypted: $password")
13
+ """
14
+ Then the output should include "Decrypted: max"
15
+
16
+ Scenario: Overriden key (string)
17
+ Given I have the following hiera data:
18
+ """
19
+ ---
20
+ db_password: ENC:alt_key[c4S4hMCDv1b7FkZgOBRTOA==]
21
+ """
22
+ When I execute this puppet manifest:
23
+ """
24
+ $password = decrypt(hiera('db_password'))
25
+ notice("Decrypted: $password")
26
+ """
27
+ Then the output should include "Decrypted: abc123"
28
+
29
+ Scenario: Overridden key (hash)
30
+ Given I have the following hiera data:
31
+ """
32
+ ---
33
+ db_password:
34
+ value: 'ENC[G6MjBDDFcapYLaKBFJvPSg==]'
35
+ secretkey: 'features/fixtures/other_secretkeys/secondary_key'
36
+ """
37
+ When I execute this puppet manifest:
38
+ """
39
+ notice(hiera_hash('db_password'))
40
+ $password = decrypt(hiera_hash('db_password'))
41
+ notice("Decrypted: $password")
42
+ """
43
+ Then the output should include "Decrypted: overridden"
@@ -0,0 +1,31 @@
1
+ require 'tempfile'
2
+
3
+ Given /^I have the following hiera data:$/ do |hieradata|
4
+ hierafile = Thread.current[:hierafile]
5
+ hierafile.write(hieradata)
6
+ hierafile.close
7
+ end
8
+
9
+ When /^I execute this puppet manifest:$/ do |manifest|
10
+ hierafile = Thread.current[:hierafile]
11
+ file = Tempfile.new('test_manifest')
12
+ begin
13
+ file.write(manifest)
14
+ file.close
15
+ ENV['FACTER_HIERA_FILE'] = File.basename(hierafile, '.yaml')
16
+ ENV['PUPPET_DECRYPT_KEYDIR'] = 'features/fixtures/secretkeys'
17
+ puppet_version = `bundle exec puppet --version`
18
+ puppet_command = "bundle exec puppet apply --noop #{file.path}"
19
+ puppet_command = "#{puppet_command} --hiera_config=features/fixtures/hiera.yaml" if puppet_version.match /^3/
20
+ puppet_command = "#{puppet_command} --confdir=features/fixtures" if puppet_version.match /^2/
21
+ @output = `#{puppet_command}`
22
+ puts @output
23
+ ensure
24
+ file.unlink
25
+ end
26
+ $?.success?
27
+ end
28
+
29
+ Then /^the output should include "([^"]*)"$/ do |content|
30
+ @output.should include content
31
+ end
@@ -0,0 +1,10 @@
1
+ Around do | scenario, block |
2
+ hierafile = Tempfile.new(['hierafile', '.yaml'], 'features/fixtures/data')
3
+ Thread.current[:hierafile] = hierafile
4
+ begin
5
+ block.call
6
+ ensure
7
+ hierafile.close
8
+ hierafile.unlink
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ require 'puppet-decrypt/version'
2
+ require 'puppet-decrypt/decryptor'
3
+ require 'encryptor'
4
+ require 'base64'
5
+
6
+ module Puppet
7
+ module Decrypt
8
+ end
9
+ end
@@ -0,0 +1,83 @@
1
+ module Puppet
2
+ module Decrypt
3
+
4
+ class Decryptor
5
+ ENCRYPTED_PATTERN = /^ENC:?(?<key>\w*)\[(?<value>.*)\]$/
6
+ KEY_DIR = ENV['PUPPET_DECRYPT_KEYDIR'] || '/etc/puppet-decrypt'
7
+ DEFAULT_KEY = 'encryptor_secret_key'
8
+ DEFAULT_FILE = File.join(KEY_DIR, DEFAULT_KEY)
9
+
10
+ def initialize(options = {})
11
+ @raw = options[:raw] || false
12
+ end
13
+
14
+ def decrypt_hash(hash)
15
+ puts "Decrypting value: #{hash['value']}, secretkey: #{hash['secretkey']}"
16
+ decrypt(hash['value'], hash['secretkey'])
17
+ end
18
+
19
+ def decrypt(value, secret_key_file)
20
+ secret_key_file ||= secret_key_for value
21
+ secret_key_digest = digest_from secret_key_file
22
+ if @raw
23
+ match = true
24
+ else
25
+ match = value.match(ENCRYPTED_PATTERN)
26
+ if match
27
+ value = match[:value]
28
+ end
29
+ end
30
+ if match
31
+ value = strict_decode64(value)
32
+ value = value.decrypt(:key => secret_key_digest)
33
+ end
34
+ value
35
+ end
36
+
37
+ def encrypt(value, secret_key_file = nil)
38
+ secret_key_file ||= secret_key_for value
39
+ secret_key_digest = digest_from secret_key_file
40
+ result = value.encrypt(:key => secret_key_digest)
41
+ encrypted_value = strict_encode64(result).strip
42
+ encrypted_value = "ENC[#{encrypted_value}]" unless @raw
43
+ raise "Value can't be encrypted properly" unless decrypt(encrypted_value, secret_key_file) == value
44
+ encrypted_value
45
+ end
46
+
47
+ private
48
+ def secret_key_for(value)
49
+ match = value.match(ENCRYPTED_PATTERN)
50
+ if match
51
+ key = match[:key]
52
+ key = DEFAULT_KEY if key.empty?
53
+ end
54
+ key ||= DEFAULT_KEY
55
+ File.join(KEY_DIR, key)
56
+ end
57
+
58
+ def digest_from(secret_key_file)
59
+ raise "Secret key file: #{secret_key_file} is not readable!" unless File.readable?(secret_key_file)
60
+ secret_key = File.open(secret_key_file, &:readline).chomp
61
+ Digest::SHA256.hexdigest(secret_key)
62
+ end
63
+
64
+ # Backported for ruby 1.8.7
65
+ def strict_decode64(str)
66
+ return Base64.strict_decode64(str) if Base64.respond_to? :strict_decode64
67
+
68
+ unless str.include?("\n")
69
+ Base64.decode64(str)
70
+ else
71
+ raise(ArgumentError,"invalid base64")
72
+ end
73
+ end
74
+
75
+ # Backported for ruby 1.8.7
76
+ def strict_encode64(bin)
77
+ return Base64.strict_encode64(bin) if Base64.respond_to? :strict_encode64
78
+ Base64.encode64(bin).tr("\n",'')
79
+ end
80
+
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,5 @@
1
+ module Puppet
2
+ module Decrypt
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'puppet/face'
2
+ require 'puppet/application/face_base'
3
+
4
+ class Puppet::Application::Crypt < Puppet::Application::FaceBase
5
+ end
@@ -0,0 +1,49 @@
1
+ require 'puppet-decrypt'
2
+ require 'puppet/face'
3
+ require 'stringio'
4
+
5
+ Puppet::Face.define(:crypt, Puppet::Decrypt::VERSION) do
6
+ copyright "Max Lincoln", 2013
7
+ license "MIT; see LICENSE"
8
+
9
+ summary "Encrypt or decrypt secret values."
10
+ description <<-EOT
11
+ This subcommand provides a command line interface to encrypt or decrypt values
12
+ that are intended for use with the puppet decrypt function.
13
+ EOT
14
+
15
+ option "--raw" do
16
+ summary "Use raw parse/display"
17
+ description <<-EOT
18
+ Parse or display the value in raw format, instead of using ENC[...] block
19
+ EOT
20
+ end
21
+
22
+ option "--secretkey SECRET_KEY_PATH" do
23
+ summary "The path to the secret key file (default: #{Puppet::Decrypt::Decryptor::DEFAULT_FILE}"
24
+ end
25
+
26
+ action :encrypt do
27
+ summary 'Encrypt a secret value.'
28
+ arguments "<plaintext_secret>"
29
+ description <<-EOT
30
+ This action encrypts a value using the secret key.
31
+ EOT
32
+ when_invoked do |plaintext_secret, options|
33
+ secretkey = options[:secretkey]
34
+ Puppet::Decrypt::Decryptor.new(options).encrypt(plaintext_secret, secretkey)
35
+ end
36
+ end
37
+
38
+ action :decrypt do
39
+ summary 'Decrypt a secret value.'
40
+ arguments "<encrypted_secret>"
41
+ description <<-EOT
42
+ This action decrypts a value using the secret key.
43
+ EOT
44
+ when_invoked do |encrypted_secret, options|
45
+ secretkey = options[:secretkey]
46
+ Puppet::Decrypt::Decryptor.new(options).decrypt(encrypted_secret, secretkey)
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,15 @@
1
+ require 'puppet-decrypt'
2
+
3
+ module Puppet::Parser::Functions
4
+ newfunction(:decrypt, :type => :rvalue) do |args|
5
+ options = {}
6
+ decrypt_args = {}
7
+ if args[0].is_a? String
8
+ decrypt_args['value'] = args[0]
9
+ else
10
+ decrypt_args = args[0]
11
+ puts "Using hash: #{decrypt_args}"
12
+ end
13
+ Puppet::Decrypt::Decryptor.new(options).decrypt_hash(decrypt_args)
14
+ end
15
+ end
@@ -0,0 +1,39 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'puppet-decrypt/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "puppet-decrypt"
8
+ gem.version = Puppet::Decrypt::VERSION
9
+ gem.authors = ["mlincoln"]
10
+ gem.email = ["max@devopsy.com"]
11
+ gem.description = %q{A gem for encrypting/decrypting secret values for use with Puppet}
12
+ gem.summary = %q{A shared secret strategy that works with any data source}
13
+ gem.homepage = "https://github.com/maxlinc/puppet-decrypt"
14
+ gem.required_ruby_version = '>= 1.9.0'
15
+ notice = """
16
+
17
+ Notice: The default master key location is now /etc/puppet-decrypt/encryptor_secret_key
18
+
19
+ This was done to more easily support multiple keys. If you are upgrading from a version older than
20
+ 0.1.0 you should move /etc/encryptor_secret_key to /etc/puppet-decrypt/encryptor_secret_key.
21
+
22
+ """
23
+ gem.post_install_message = notice
24
+
25
+ gem.files = `git ls-files`.split($/)
26
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
27
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
28
+ gem.require_paths = ["lib"]
29
+
30
+ gem.add_dependency('encryptor')
31
+ gem.add_development_dependency('rake')
32
+ gem.add_development_dependency('cucumber')
33
+ gem.add_development_dependency('relish')
34
+ gem.add_development_dependency('rspec')
35
+ gem.add_development_dependency('rspec-puppet')
36
+ gem.add_development_dependency('puppetlabs_spec_helper')
37
+ gem.add_development_dependency('pry')
38
+ gem.add_development_dependency('pry-nav')
39
+ end
@@ -0,0 +1,43 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'spec_helper'
3
+ require 'puppet/face'
4
+
5
+ describe Puppet::Face[:crypt, :current] do
6
+ before :all do
7
+ mock_secret_key(Puppet::Decrypt::Decryptor::DEFAULT_FILE, 'masterkey')
8
+ end
9
+
10
+ describe 'encrypt' do
11
+ describe 'should encrypt a value' do
12
+ it 'with ENC[...]' do
13
+ subject.encrypt('flabberghaster').should == 'ENC[3xzy8fiXlaJqv3m+aXIJNA==]'
14
+ end
15
+
16
+ it 'with --raw' do
17
+ subject.encrypt('flabberghaster', {:raw => true}).should == '3xzy8fiXlaJqv3m+aXIJNA=='
18
+ end
19
+
20
+ it 'with --secretkey' do
21
+ mock_secret_key('/etc/another_key', 'anotherkey')
22
+ subject.encrypt('flabberghaster', {:secretkey => '/etc/another_key'}).should == 'ENC[8MaZYHPdj9IpnzcuBLlMdg==]'
23
+ end
24
+ end
25
+ end
26
+
27
+ describe 'decrypt' do
28
+ describe 'should decrypt a value' do
29
+ it 'with ENC[...]' do
30
+ subject.decrypt('ENC[3xzy8fiXlaJqv3m+aXIJNA==]').should == 'flabberghaster'
31
+ end
32
+
33
+ it 'with --raw' do
34
+ subject.decrypt('3xzy8fiXlaJqv3m+aXIJNA==', {:raw => true}).should == 'flabberghaster'
35
+ end
36
+
37
+ it 'with --secretkey' do
38
+ mock_secret_key('/etc/another_key', 'anotherkey')
39
+ subject.decrypt('ENC[8MaZYHPdj9IpnzcuBLlMdg==]', {:secretkey => '/etc/another_key'}).should == 'flabberghaster'
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,53 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe 'decrypt' do
5
+ before(:all) do
6
+ mock_secret_key(Puppet::Decrypt::Decryptor::DEFAULT_FILE, 'masterkey')
7
+ end
8
+
9
+ let(:node) { 'testhost.example.com' }
10
+ extdata_path = File.expand_path(File.join(File.dirname(__FILE__), '../../puppet/manifests/extdata'))
11
+ let(:pre_condition) { "$extlookup_datadir = '#{extdata_path}' $extlookup_precedence = ['common', 'env_vagrant']" }
12
+
13
+ context "unencrypted key" do
14
+ it { should run.with_params('blah').and_return("blah") }
15
+ end
16
+
17
+ context "encrypted key" do
18
+ it "should decrypt exact matches" do
19
+ should run.with_params('ENC[3xzy8fiXlaJqv3m+aXIJNA==]').and_return("flabberghaster")
20
+ end
21
+
22
+ it "should not decrypt partial matches" do
23
+ should run.with_params('fooENC[3xzy8fiXlaJqv3m+aXIJNA==]bar').and_return('fooENC[3xzy8fiXlaJqv3m+aXIJNA==]bar')
24
+ end
25
+ end
26
+
27
+ context "with secret key in string" do
28
+ it "should decrypt exact matches" do
29
+ mock_secret_key('/etc/puppet-decrypt/another_key', 'anotherkey')
30
+ should run.with_params('ENC:another_key[8MaZYHPdj9IpnzcuBLlMdg==]').and_return('flabberghaster')
31
+ end
32
+
33
+ it "should not decrypt partial matches" do
34
+ should run.with_params('fooENC:max[3xzy8fiXlaJqv3m+aXIJNA==]bar').and_return('fooENC:max[3xzy8fiXlaJqv3m+aXIJNA==]bar')
35
+ end
36
+ end
37
+
38
+ context "with secret key file" do
39
+ it "should decrypt exact matches" do
40
+ mock_secret_key('/etc/another_key', 'anotherkey')
41
+ should run.with_params({ 'value' => 'ENC[8MaZYHPdj9IpnzcuBLlMdg==]', 'secretkey' => '/etc/another_key'}).and_return('flabberghaster')
42
+ end
43
+
44
+ it "should override a key in the string" do
45
+ mock_secret_key('/etc/another_key', 'anotherkey')
46
+ should run.with_params({ 'value' => 'ENC:max[8MaZYHPdj9IpnzcuBLlMdg==]', 'secretkey' => '/etc/another_key'}).and_return('flabberghaster')
47
+ end
48
+
49
+ it "should not decrypt partial matches" do
50
+ should run.with_params({ 'value' => 'fooENC[3xzy8fiXlaJqv3m+aXIJNA==]bar', 'secretkey' => '/etc/another_key'}).and_return('fooENC[3xzy8fiXlaJqv3m+aXIJNA==]bar')
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'rspec-puppet'
3
+ require 'puppet-decrypt'
4
+ require 'rspec/mocks'
5
+
6
+ module SecretKeyHelper
7
+ def mock_secret_key(filename, secret)
8
+ File.should_receive(:readable?).with(filename).and_return(true)
9
+ File.should_receive(:open).with(filename).and_return(secret)
10
+ end
11
+ end
12
+
13
+ RSpec::Mocks::setup(self)
14
+
15
+ RSpec.configure do |c|
16
+ c.include SecretKeyHelper
17
+ end
18
+
19
+ if ENV['PUPPET_DEBUG']
20
+ Puppet::Util::Log.level = :debug
21
+ Puppet::Util::Log.newdestination(:console)
22
+ end
metadata ADDED
@@ -0,0 +1,223 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: puppet-decrypt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - mlincoln
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: encryptor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: cucumber
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: relish
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-puppet
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: puppetlabs_spec_helper
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry-nav
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: A gem for encrypting/decrypting secret values for use with Puppet
140
+ email:
141
+ - max@devopsy.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - .gitignore
147
+ - .rspec
148
+ - .rvmrc
149
+ - .travis.yml
150
+ - ChangeLog.md
151
+ - Gemfile
152
+ - LICENSE.txt
153
+ - Modulefile
154
+ - README.md
155
+ - Rakefile
156
+ - bundles/puppet_2_7.gemfile
157
+ - bundles/puppet_3_0.gemfile
158
+ - features/fixtures/data/overridden_secret_key.yaml
159
+ - features/fixtures/data/simple.yaml
160
+ - features/fixtures/hiera.yaml
161
+ - features/fixtures/manifests/overridden_secret_key.pp.bak
162
+ - features/fixtures/manifests/simple.pp
163
+ - features/fixtures/other_secretkeys/secondary_key
164
+ - features/fixtures/secretkeys/alt_key
165
+ - features/fixtures/secretkeys/encryptor_secret_key
166
+ - features/hiera.feature
167
+ - features/step_definitions/puppet_steps.rb
168
+ - features/support/env.rb
169
+ - lib/puppet-decrypt.rb
170
+ - lib/puppet-decrypt/decryptor.rb
171
+ - lib/puppet-decrypt/version.rb
172
+ - lib/puppet/application/crypt.rb
173
+ - lib/puppet/face/crypt.rb
174
+ - lib/puppet/parser/functions/decrypt.rb
175
+ - puppet-decrypt.gemspec
176
+ - spec/faces/crypt_spec.rb
177
+ - spec/functions/decrypt_spec.rb
178
+ - spec/spec_helper.rb
179
+ homepage: https://github.com/maxlinc/puppet-decrypt
180
+ licenses: []
181
+ metadata: {}
182
+ post_install_message: |2+
183
+
184
+
185
+ Notice: The default master key location is now /etc/puppet-decrypt/encryptor_secret_key
186
+
187
+ This was done to more easily support multiple keys. If you are upgrading from a version older than
188
+ 0.1.0 you should move /etc/encryptor_secret_key to /etc/puppet-decrypt/encryptor_secret_key.
189
+
190
+ rdoc_options: []
191
+ require_paths:
192
+ - lib
193
+ required_ruby_version: !ruby/object:Gem::Requirement
194
+ requirements:
195
+ - - '>='
196
+ - !ruby/object:Gem::Version
197
+ version: 1.9.0
198
+ required_rubygems_version: !ruby/object:Gem::Requirement
199
+ requirements:
200
+ - - '>='
201
+ - !ruby/object:Gem::Version
202
+ version: '0'
203
+ requirements: []
204
+ rubyforge_project:
205
+ rubygems_version: 2.0.4
206
+ signing_key:
207
+ specification_version: 4
208
+ summary: A shared secret strategy that works with any data source
209
+ test_files:
210
+ - features/fixtures/data/overridden_secret_key.yaml
211
+ - features/fixtures/data/simple.yaml
212
+ - features/fixtures/hiera.yaml
213
+ - features/fixtures/manifests/overridden_secret_key.pp.bak
214
+ - features/fixtures/manifests/simple.pp
215
+ - features/fixtures/other_secretkeys/secondary_key
216
+ - features/fixtures/secretkeys/alt_key
217
+ - features/fixtures/secretkeys/encryptor_secret_key
218
+ - features/hiera.feature
219
+ - features/step_definitions/puppet_steps.rb
220
+ - features/support/env.rb
221
+ - spec/faces/crypt_spec.rb
222
+ - spec/functions/decrypt_spec.rb
223
+ - spec/spec_helper.rb