Skip to content

Commit

Permalink
Add first gem, make encrypt_value a binary, and make a keys dir
Browse files Browse the repository at this point in the history
  • Loading branch information
Geoff Meakin committed Jul 12, 2013
1 parent d9264cf commit 5ec0890
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.idea
*.iml
*.gradle
keys/*.pem
pkg/*/lib
28 changes: 10 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ N.B. when using the multi-line string syntax (i.e. >) **don't wrap encrypted str
Setup
=====

### Installing hiera-eyaml

$ gem install hiera-eyaml

### Generate keys

The first step is to create a pair of keys on the Puppet master
Expand All @@ -58,16 +62,6 @@ so I don’t see that as adding much in the way of security."
Change the permissions so that the private key is only readable by the user that hiera (puppet) is
running as.

### Install eYaml backend

I'm new to ruby and tight on deadlines so I will create a gem thing when I get a chance,
but for now just copy eyaml_backend.rb to the same directory as the existing backends e.g.
/usr/lib/ruby/site_ruby/1.8/hiera/backend

You can find the directory with:

$ sudo find / -name yaml_backend.rb

### Configure Hiera

Next configure hiera.yaml to use the eyaml backend
Expand All @@ -93,20 +87,18 @@ Next configure hiera.yaml to use the eyaml backend

### Encrypt value

Copy public_key.pem created earlier to any machine where values will be encrypted and
use openssl to encrypt sensitive data.
Copy the public_key.pem created earlier to the keys subdirectory of this git repository.

There is a very basic helper file encrypt_value.rb which will do this for you. Just copy the
public key to the same directory as encrypt_value.rb (or vice versa), navigate to that
directory and run
There is a very basic helper file bin/encrypt_value.rb which will encrypt values for you
based on the public_key.pem. Run:

$ ruby encrypt_value.rb "my secret thing"
$ bin/encrypt_value.rb "my secret thing"

The encrypted value is printed to the command line
The encrypted value is printed to STDOUT

If you wish to rename your key or keep it in another directory run

$ ruby encrypt_value.rb "my secret thing" /path/to/key/my_key.pem
$ encrypt_value.rb "my secret thing" /path/to/key/my_key.pem

### Insert encrypted value

Expand Down
20 changes: 20 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'rubygems'
require 'rake/gempackagetask'

spec = Gem::Specification.new do |gem|
gem.name = "hiera-eyaml"
gem.version = "1.0.0"
gem.summary = "OpenSSL Encryption backend for Hiera"
gem.email = "[email protected]"
gem.author = "Tom Paulton"
gem.homepage = "http://github.com/TomPaulton/hiera-eyaml"
gem.description = "Hiera backend for decrypting encrypted yaml properties"
gem.require_path = "lib"
gem.files = FileList["lib/**/*"].to_a
gem.add_dependency('hiera', '>=0.2.0')
end

Rake::GemPackageTask.new(spec) do |pkg|
pkg.need_tar = true
end

3 changes: 2 additions & 1 deletion encrypt_value.rb → bin/encrypt_value.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env ruby
require 'openssl'
require 'base64'

# Run from this directory using: ruby encrypt_value.rb "value to encrypt"

public_key_path = './public_key.pem'
public_key_path = 'keys/public_key.pem'

plain_text = ARGV[0]
public_key_arg = ARGV[1]
Expand Down
Empty file added keys/.keepme
Empty file.
Binary file added pkg/hiera-eyaml-1.0.0.gem
Binary file not shown.

0 comments on commit 5ec0890

Please sign in to comment.