hiera-backend-trocla 0.0.1 → 0.0.2
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.
- checksums.yaml +7 -0
- data/.travis.yml +4 -0
- data/Gemfile +5 -0
- data/README.md +33 -4
- data/hiera-backend-trocla.gemspec +2 -2
- data/lib/hiera/backend/trocla/version.rb +1 -1
- data/lib/hiera/backend/trocla_backend.rb +17 -16
- data/spec/config/hieradata/defaults.yaml +30 -0
- data/spec/config/troclarc.yaml +3 -1
- data/spec/hiera/backend/trocla_spec.rb +34 -0
- data/spec/spec_helper.rb +3 -6
- metadata +19 -39
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 14d2cfd20349151fe5d35196dbee05da463f489d
|
4
|
+
data.tar.gz: f91b2891bee99049b19b7bd9ea574c08c0cf729f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 38add66677b2061e5a0e5b48abae2565973366946a69ea9aedb5b90bb98313633d56d222fd061d4d86b70846a6acc6e71d1ef71c27fc76be06fd062dea886ba4
|
7
|
+
data.tar.gz: 8f4ba9d24cfd021c9deb5016dc8d0304c873c204864b0c4fda671b572a3169d4b5bb3c0dc9dc0d273d10e0556b11288c0dee6f39aa5dccecfba9860e3ffa3009
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,12 +1,18 @@
|
|
1
1
|
# Hiera Backend for Trocla
|
2
2
|
|
3
3
|
[](https://travis-ci.org/ZeroPointEnergy/hiera-backend-trocla)
|
4
|
+
[](https://codeclimate.com/github/ZeroPointEnergy/hiera-backend-trocla)
|
5
|
+
[](https://codeclimate.com/github/ZeroPointEnergy/hiera-backend-trocla/coverage)
|
4
6
|
|
5
7
|
This is a simple hiera backend to retrieve passwords from trocla.
|
6
8
|
|
7
9
|
The idea of this backend is to enable you to use secrets from trocla
|
8
10
|
directly from your hiera data via interpolation tokens.
|
9
11
|
|
12
|
+
A lot of the ideas for the improvement of this backend came from the
|
13
|
+
[trocla hiera plugin](https://github.com/duritong/puppet-trocla/pull/15)
|
14
|
+
from @michaelweiser.
|
15
|
+
|
10
16
|
## Installation
|
11
17
|
|
12
18
|
Simply install the gem and hiera will find it automatically
|
@@ -40,7 +46,7 @@ The trocla hiera backend will resolve all the variables which start with "trocla
|
|
40
46
|
The second part of the variable is used to describe the format, the last part is the variable
|
41
47
|
to lookup in trocla.
|
42
48
|
|
43
|
-
|
49
|
+
trocla_lookup::format::myvar
|
44
50
|
|
45
51
|
You can use the backend via interpolation tokens like this:
|
46
52
|
|
@@ -89,9 +95,9 @@ Here is how you would use that in hiera:
|
|
89
95
|
|
90
96
|
Trocla takes a hash of options which provides information for the password creation. This
|
91
97
|
options can be set directly in hiera globally or for every key. You can also specify options
|
92
|
-
specifically for a password format. However, keep in mind that
|
93
|
-
|
94
|
-
|
98
|
+
specifically for a password format. However, keep in mind that trocla will respect most of
|
99
|
+
the options only on the initial/first lookup, when the password is created. As most of the
|
100
|
+
options only apply for creating a password.
|
95
101
|
|
96
102
|
trocla_options:
|
97
103
|
length: 16
|
@@ -107,6 +113,29 @@ password is generated.
|
|
107
113
|
Some formats may require options to be set for creating passwords, like the
|
108
114
|
postgresql format. Check the trocla documentation for available options.
|
109
115
|
|
116
|
+
Through the options mechanism it is also possible to change the lookup key used for trocla.
|
117
|
+
This is especially interesting, if you want to pass 2 different options for the same key,
|
118
|
+
e.g. the render option. An example for that is to have trocla use the same key for 2 different
|
119
|
+
lookups, so that with the x509 format, once a certificate and once a key is returned.
|
120
|
+
|
121
|
+
|
122
|
+
var_with_x509_cert: "%{hiera('trocla_lookup::x509::my_cert')}"
|
123
|
+
trocla_options::my_cert:
|
124
|
+
x509:
|
125
|
+
CN: 'my-cert'
|
126
|
+
render:
|
127
|
+
certonly: true
|
128
|
+
var_with_x509_key: "%{hiera('trocla_lookup::x509::my_cert_only_key')}"
|
129
|
+
trocla_options::my_cert_only_key:
|
130
|
+
x509:
|
131
|
+
CN: 'my-cert'
|
132
|
+
trocla_key: my_cert
|
133
|
+
render:
|
134
|
+
keyonly: true
|
135
|
+
|
136
|
+
This will lookup one trocla key: my_cert, but with different rendering options, so that
|
137
|
+
once we only get the certificat, while on the second lookup we get the private key.
|
138
|
+
|
110
139
|
## Contributing
|
111
140
|
|
112
141
|
1. Fork it
|
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["zuber@puzzle.ch"]
|
11
11
|
spec.description = %q{This is a hiera backend for the trocla password storage tool}
|
12
12
|
spec.summary = %q{This is a hiera backend for the trocla password storage tool}
|
13
|
-
spec.homepage = ""
|
13
|
+
spec.homepage = "https://github.com/ZeroPointEnergy/hiera-backend-trocla"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency "rake"
|
23
23
|
spec.add_development_dependency "hiera"
|
24
24
|
spec.add_development_dependency "rspec"
|
25
|
-
spec.add_development_dependency "
|
25
|
+
spec.add_development_dependency "codeclimate-test-reporter" if RUBY_VERSION >= '1.9.3'
|
26
26
|
|
27
27
|
spec.add_dependency "trocla"
|
28
28
|
end
|
@@ -35,20 +35,22 @@ class Hiera
|
|
35
35
|
# This is a simple lookup which will return a password for the key
|
36
36
|
def trocla_lookup(trocla_key, format, scope, order_override)
|
37
37
|
opts = options(trocla_key, format, scope, order_override)
|
38
|
-
@trocla.password(trocla_key, format, opts)
|
38
|
+
@trocla.password(opts.delete('trocla_key')||trocla_key, format, opts)
|
39
39
|
end
|
40
40
|
|
41
41
|
def trocla_hierarchy(trocla_key, format, scope, order_override)
|
42
|
-
|
43
|
-
|
42
|
+
opts = options(trocla_key, format, scope, order_override)
|
43
|
+
tk = opts.delete('trocla_key') || trocla_key
|
44
|
+
get_password_from_hierarchy(tk, format, opts, scope, order_override) ||
|
45
|
+
set_password_in_hierarchy(tk, format, opts, scope, order_override)
|
44
46
|
end
|
45
47
|
|
46
48
|
# Try to retrieve a password from a hierarchy
|
47
|
-
def get_password_from_hierarchy(trocla_key, format, scope, order_override)
|
49
|
+
def get_password_from_hierarchy(trocla_key, format, opts, scope, order_override)
|
48
50
|
answer = nil
|
49
51
|
Backend.datasources(scope, order_override) do |source|
|
50
52
|
key = hierarchical_key(source, trocla_key)
|
51
|
-
answer = @trocla.get_password(key, format)
|
53
|
+
answer = @trocla.get_password(key, format, opts)
|
52
54
|
break unless answer.nil?
|
53
55
|
end
|
54
56
|
return answer
|
@@ -56,8 +58,7 @@ class Hiera
|
|
56
58
|
|
57
59
|
# Set the password in the hierarchy at the top level or whatever
|
58
60
|
# level is specified in the options hash with 'order_override'
|
59
|
-
def set_password_in_hierarchy(trocla_key, format, scope, order_override)
|
60
|
-
opts = options(trocla_key, format, scope, order_override)
|
61
|
+
def set_password_in_hierarchy(trocla_key, format, opts, scope, order_override)
|
61
62
|
answer = nil
|
62
63
|
Backend.datasources(scope, opts['order_override']) do |source|
|
63
64
|
key = hierarchical_key(source, trocla_key)
|
@@ -71,23 +72,23 @@ class Hiera
|
|
71
72
|
"hiera/#{source}/#{trocla_key}"
|
72
73
|
end
|
73
74
|
|
75
|
+
# retrieve options hash and merge the format specific settings into the defaults
|
76
|
+
def options(trocla_key, format, scope, order_override)
|
77
|
+
g_options = global_options(format, scope, order_override)
|
78
|
+
k_options = key_options(trocla_key, format, scope, order_override)
|
79
|
+
g_options.merge(k_options)
|
80
|
+
end
|
81
|
+
|
74
82
|
# returns global options for password generation
|
75
83
|
def global_options(format, scope, order_override)
|
76
84
|
g_options = Backend.lookup('trocla_options', {}, scope, order_override, :hash)
|
77
|
-
g_options.merge(g_options[format] || {})
|
85
|
+
Backend.parse_answer(g_options.merge(g_options[format] || {}), scope)
|
78
86
|
end
|
79
87
|
|
80
88
|
# returns per key options for password generation
|
81
89
|
def key_options(trocla_key, format, scope, order_override)
|
82
90
|
k_options = Backend.lookup('trocla_options::' + trocla_key, {}, scope, order_override, :hash)
|
83
|
-
k_options.merge(k_options[format] || {})
|
84
|
-
end
|
85
|
-
|
86
|
-
# retrieve options hash and merge the format specific settings into the defaults
|
87
|
-
def options(trocla_key, format, scope, order_override)
|
88
|
-
g_options = global_options(format, scope, order_override)
|
89
|
-
k_options = key_options(trocla_key, format, scope, order_override)
|
90
|
-
g_options.merge(k_options)
|
91
|
+
Backend.parse_answer(k_options.merge(k_options[format] || {}), scope)
|
91
92
|
end
|
92
93
|
|
93
94
|
end
|
@@ -8,6 +8,10 @@ trocla_options::special_length:
|
|
8
8
|
plain:
|
9
9
|
length: 64
|
10
10
|
|
11
|
+
very_long: 128
|
12
|
+
trocla_options::special_length2:
|
13
|
+
plain:
|
14
|
+
length: "%{hiera('very_long')}"
|
11
15
|
# fixtures for trocla_lookup tests
|
12
16
|
normal_var: "test"
|
13
17
|
var_with_password: "%{hiera('trocla_lookup::plain::my_secret_password')}"
|
@@ -23,3 +27,29 @@ trocla_options::same_role:
|
|
23
27
|
|
24
28
|
trocla_options::different_role:
|
25
29
|
order_override: "role/%{::role}"
|
30
|
+
|
31
|
+
var_with_x509: "%{hiera('trocla_lookup::x509::my_cert')}"
|
32
|
+
trocla_options::my_cert:
|
33
|
+
x509:
|
34
|
+
CN: 'my-cert'
|
35
|
+
var_with_x509_key: "%{hiera('trocla_lookup::x509::my_cert_only_key')}"
|
36
|
+
trocla_options::my_cert_only_key:
|
37
|
+
x509:
|
38
|
+
CN: 'my-cert'
|
39
|
+
trocla_key: my_cert
|
40
|
+
render:
|
41
|
+
keyonly: true
|
42
|
+
|
43
|
+
hiera_var_with_x509: "%{hiera('trocla_hierarchy::x509::hiera_my_cert')}"
|
44
|
+
trocla_options::hiera_my_cert:
|
45
|
+
order_override: "role/%{::role}"
|
46
|
+
x509:
|
47
|
+
CN: 'my-hiera-cert'
|
48
|
+
hiera_var_with_x509_key: "%{hiera('trocla_hierarchy::x509::hiera_my_cert_only_key')}"
|
49
|
+
trocla_options::hiera_my_cert_only_key:
|
50
|
+
order_override: "role/%{::role}"
|
51
|
+
x509:
|
52
|
+
CN: 'my-hiera-cert'
|
53
|
+
trocla_key: hiera_my_cert
|
54
|
+
render:
|
55
|
+
keyonly: true
|
data/spec/config/troclarc.yaml
CHANGED
@@ -5,6 +5,7 @@ describe Hiera::Backend::Trocla do
|
|
5
5
|
|
6
6
|
before :each do
|
7
7
|
@hiera = Hiera.new(:config => "spec/config/hiera.yaml")
|
8
|
+
@trocla = Trocla.new(@hiera.config[:trocla][:config])
|
8
9
|
end
|
9
10
|
|
10
11
|
describe 'trocla_lookup' do
|
@@ -33,6 +34,20 @@ describe Hiera::Backend::Trocla do
|
|
33
34
|
expect{@hiera.lookup('trocla_lookup::unexisting::my_secret_password', nil, nil)}.to raise_error StandardError
|
34
35
|
expect{@hiera.lookup('var_with_invalid_format', nil, nil)}.to raise_error StandardError
|
35
36
|
end
|
37
|
+
|
38
|
+
it 'will be able to influence the trocla key' do
|
39
|
+
x509 = @hiera.lookup('var_with_x509',nil, nil)
|
40
|
+
expect(x509).to match(/BEGIN RSA PRIVATE KEY/)
|
41
|
+
expect(x509).to match(/BEGIN CERTIFICATE/)
|
42
|
+
x509_key = @hiera.lookup('var_with_x509_key',nil, nil)
|
43
|
+
expect(x509_key).to match(/BEGIN RSA PRIVATE KEY/)
|
44
|
+
expect(x509_key).not_to match(/BEGIN CERTIFICATE/)
|
45
|
+
|
46
|
+
# given that hiera trocla options point to the same
|
47
|
+
# trocla key, it must be the same key
|
48
|
+
expect(OpenSSL::PKey::RSA.new(x509).to_pem).to eql(
|
49
|
+
OpenSSL::PKey::RSA.new(x509_key).to_pem)
|
50
|
+
end
|
36
51
|
end
|
37
52
|
|
38
53
|
describe 'trocla_hierarchy' do
|
@@ -67,6 +82,21 @@ describe Hiera::Backend::Trocla do
|
|
67
82
|
password2 = @hiera.lookup('trocla_hierarchy::plain::different_role', nil, scope2)
|
68
83
|
expect(password1).not_to eq(password2)
|
69
84
|
end
|
85
|
+
it 'will be able to influence the trocla key' do
|
86
|
+
scope1 = {'::clientcert' => 'node01.example.com', '::role' => 'role1'}
|
87
|
+
scope2 = {'::clientcert' => 'node02.example.com', '::role' => 'role1'}
|
88
|
+
x509 = @hiera.lookup('hiera_var_with_x509',nil, scope1)
|
89
|
+
expect(x509).to match(/BEGIN RSA PRIVATE KEY/)
|
90
|
+
expect(x509).to match(/BEGIN CERTIFICATE/)
|
91
|
+
x509_key = @hiera.lookup('hiera_var_with_x509_key',nil, scope2)
|
92
|
+
expect(x509_key).to match(/BEGIN RSA PRIVATE KEY/)
|
93
|
+
expect(x509_key).not_to match(/BEGIN CERTIFICATE/)
|
94
|
+
|
95
|
+
# given that hiera trocla options point to the same
|
96
|
+
# trocla key, it must be the same key
|
97
|
+
expect(OpenSSL::PKey::RSA.new(x509).to_pem).to eql(
|
98
|
+
OpenSSL::PKey::RSA.new(x509_key).to_pem)
|
99
|
+
end
|
70
100
|
end
|
71
101
|
|
72
102
|
describe 'options hash merging' do
|
@@ -85,6 +115,10 @@ describe Hiera::Backend::Trocla do
|
|
85
115
|
password = @hiera.lookup('trocla_lookup::plain::special_length', nil, nil)
|
86
116
|
expect(password.length).to eq(64)
|
87
117
|
end
|
118
|
+
it 'will create a password with the length defined for the key, derived from another option' do
|
119
|
+
password2 = @hiera.lookup('trocla_lookup::plain::special_length2', nil, nil)
|
120
|
+
expect(password2.length).to eq(128)
|
121
|
+
end
|
88
122
|
end
|
89
123
|
|
90
124
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,11 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
add_filter '/.bundle/'
|
5
|
-
add_filter '/vendor/'
|
1
|
+
if RUBY_VERSION >= '1.9.3'
|
2
|
+
require "codeclimate-test-reporter"
|
3
|
+
CodeClimate::TestReporter.start
|
6
4
|
end
|
7
5
|
|
8
|
-
|
9
6
|
require 'hiera/backend/trocla'
|
10
7
|
|
11
8
|
# This file was generated by the `rspec --init` command. Conventionally, all
|
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hiera-backend-trocla
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Andreas Zuber
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2016-02-10 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: bundler
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,81 +27,71 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: hiera
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - '>='
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - '>='
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: rspec
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - '>='
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - '>='
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
|
-
name:
|
70
|
+
name: codeclimate-test-reporter
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- -
|
73
|
+
- - '>='
|
84
74
|
- !ruby/object:Gem::Version
|
85
75
|
version: '0'
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- -
|
80
|
+
- - '>='
|
92
81
|
- !ruby/object:Gem::Version
|
93
82
|
version: '0'
|
94
83
|
- !ruby/object:Gem::Dependency
|
95
84
|
name: trocla
|
96
85
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
86
|
requirements:
|
99
|
-
- -
|
87
|
+
- - '>='
|
100
88
|
- !ruby/object:Gem::Version
|
101
89
|
version: '0'
|
102
90
|
type: :runtime
|
103
91
|
prerelease: false
|
104
92
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
93
|
requirements:
|
107
|
-
- -
|
94
|
+
- - '>='
|
108
95
|
- !ruby/object:Gem::Version
|
109
96
|
version: '0'
|
110
97
|
description: This is a hiera backend for the trocla password storage tool
|
@@ -130,36 +117,29 @@ files:
|
|
130
117
|
- spec/config/troclarc.yaml
|
131
118
|
- spec/hiera/backend/trocla_spec.rb
|
132
119
|
- spec/spec_helper.rb
|
133
|
-
homepage:
|
120
|
+
homepage: https://github.com/ZeroPointEnergy/hiera-backend-trocla
|
134
121
|
licenses:
|
135
122
|
- MIT
|
123
|
+
metadata: {}
|
136
124
|
post_install_message:
|
137
125
|
rdoc_options: []
|
138
126
|
require_paths:
|
139
127
|
- lib
|
140
128
|
required_ruby_version: !ruby/object:Gem::Requirement
|
141
|
-
none: false
|
142
129
|
requirements:
|
143
|
-
- -
|
130
|
+
- - '>='
|
144
131
|
- !ruby/object:Gem::Version
|
145
132
|
version: '0'
|
146
|
-
segments:
|
147
|
-
- 0
|
148
|
-
hash: -2728931727301270266
|
149
133
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
|
-
none: false
|
151
134
|
requirements:
|
152
|
-
- -
|
135
|
+
- - '>='
|
153
136
|
- !ruby/object:Gem::Version
|
154
137
|
version: '0'
|
155
|
-
segments:
|
156
|
-
- 0
|
157
|
-
hash: -2728931727301270266
|
158
138
|
requirements: []
|
159
139
|
rubyforge_project:
|
160
|
-
rubygems_version:
|
140
|
+
rubygems_version: 2.2.5
|
161
141
|
signing_key:
|
162
|
-
specification_version:
|
142
|
+
specification_version: 4
|
163
143
|
summary: This is a hiera backend for the trocla password storage tool
|
164
144
|
test_files:
|
165
145
|
- spec/config/hiera.yaml
|