vault 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +15 -10
- data/CHANGELOG.md +19 -1
- data/lib/vault/api.rb +1 -0
- data/lib/vault/api/auth.rb +24 -0
- data/lib/vault/api/auth_tls.rb +92 -0
- data/lib/vault/api/auth_token.rb +24 -0
- data/lib/vault/api/sys/audit.rb +1 -0
- data/lib/vault/api/sys/auth.rb +1 -0
- data/lib/vault/api/sys/mount.rb +1 -0
- data/lib/vault/client.rb +2 -2
- data/lib/vault/configurable.rb +1 -0
- data/lib/vault/defaults.rb +9 -1
- data/lib/vault/response.rb +23 -0
- data/lib/vault/version.rb +1 -1
- data/vault.gemspec +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c5b5358811dba9b5864bc118f19b2cb0c9b7925
|
4
|
+
data.tar.gz: 41acb15b4a2148910f3c7fb8a01f7b51ce31e8aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6ec85927a497e7dcef985d8b32b59db6c5169c1c95820e311c3f3c6617c893e520c592b411806cf81a18d03d5a1dfab9988fb319a43330a4137d18dee7b61d0
|
7
|
+
data.tar.gz: 787597e6f6315e2620c766d5f83e625f520401399221bc0774d9f76b6a08d342baea5fe09d061fa6dc892876167af750800b7660dc6afff99abb15b025d6c33d
|
data/.travis.yml
CHANGED
@@ -2,20 +2,25 @@ language: ruby
|
|
2
2
|
cache: bundler
|
3
3
|
sudo: false
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
env:
|
6
|
+
- VAULT_VERSION=0.6.1
|
7
|
+
- VAULT_VERSION=0.6.0
|
8
|
+
- VAULT_VERSION=0.5.3
|
9
|
+
- VAULT_VERSION=0.4.1
|
10
|
+
- VAULT_VERSION=0.3.1
|
11
|
+
|
12
|
+
before_install:
|
13
|
+
- wget -O vault.zip -q https://releases.hashicorp.com/vault/${VAULT_VERSION}/vault_${VAULT_VERSION}_linux_amd64.zip
|
14
|
+
- unzip vault.zip
|
15
|
+
- mkdir ~/bin
|
16
|
+
- mv vault ~/bin
|
17
|
+
- export PATH="~/bin:$PATH"
|
11
18
|
|
12
19
|
branches:
|
13
20
|
only:
|
14
21
|
- master
|
15
22
|
|
16
23
|
rvm:
|
17
|
-
- 1.9.3
|
18
|
-
- 2.0
|
19
24
|
- 2.1
|
20
|
-
- 2.2
|
21
|
-
- 2.3.
|
25
|
+
- 2.2.5
|
26
|
+
- 2.3.1
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,24 @@
|
|
1
1
|
# Vault Ruby Changelog
|
2
2
|
|
3
|
-
## v0.
|
3
|
+
## v0.6.0.dev (Unreleased)
|
4
|
+
|
5
|
+
## v0.6.0 (August 30, 2016)
|
6
|
+
|
7
|
+
NEW FEATURES
|
8
|
+
|
9
|
+
- Add support for Vault 0.6.1 APIs
|
10
|
+
- Add new token `accessors` API method
|
11
|
+
- Add TLS authentication endpoints
|
12
|
+
|
13
|
+
BUG FIXES
|
14
|
+
|
15
|
+
- Restore old `to_h` behavior on response objects
|
16
|
+
|
17
|
+
IMPROVEMENTS
|
18
|
+
|
19
|
+
- Bootstrap full testing harness against old Vault versions
|
20
|
+
|
21
|
+
## v0.5.0 (August 16, 2016)
|
4
22
|
|
5
23
|
NEW FEATURES
|
6
24
|
|
data/lib/vault/api.rb
CHANGED
data/lib/vault/api/auth.rb
CHANGED
@@ -138,5 +138,29 @@ module Vault
|
|
138
138
|
client.token = secret.auth.client_token
|
139
139
|
return secret
|
140
140
|
end
|
141
|
+
|
142
|
+
# Authenticate via a TLS authentication method. If authentication is
|
143
|
+
# successful, the resulting token will be stored on the client and used
|
144
|
+
# for future requests.
|
145
|
+
#
|
146
|
+
# @example Sending raw pem contents
|
147
|
+
# Vault.auth.tls(pem_contents) #=> #<Vault::Secret lease_id="">
|
148
|
+
#
|
149
|
+
# @example Reading a pem from disk
|
150
|
+
# Vault.auth.tls(File.read("/path/to/my/certificate.pem")) #=> #<Vault::Secret lease_id="">
|
151
|
+
#
|
152
|
+
# @param [String] pem (default: the configured SSL pem file or contents)
|
153
|
+
# The raw pem contents to use for the login procedure.
|
154
|
+
#
|
155
|
+
# @return [Secret]
|
156
|
+
def tls(pem = nil)
|
157
|
+
new_client = client.dup
|
158
|
+
new_client.ssl_pem_contents = pem if !pem.nil?
|
159
|
+
|
160
|
+
json = new_client.post("/v1/auth/cert/login")
|
161
|
+
secret = Secret.decode(json)
|
162
|
+
client.token = secret.auth.client_token
|
163
|
+
return secret
|
164
|
+
end
|
141
165
|
end
|
142
166
|
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require "json"
|
2
|
+
|
3
|
+
require_relative "secret"
|
4
|
+
require_relative "../client"
|
5
|
+
require_relative "../request"
|
6
|
+
require_relative "../response"
|
7
|
+
|
8
|
+
module Vault
|
9
|
+
class Client
|
10
|
+
# A proxy to the {AuthTLS} methods.
|
11
|
+
# @return [AuthTLS]
|
12
|
+
def auth_tls
|
13
|
+
@auth_tls ||= AuthTLS.new(self)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class AuthTLS < Request
|
18
|
+
# Saves a certificate with the given name and attributes. The certificate
|
19
|
+
# with the given name must already exist.
|
20
|
+
#
|
21
|
+
# @example
|
22
|
+
# Vault.auth_tls.set_certificate("web", {
|
23
|
+
# display_name: "web-cert",
|
24
|
+
# certificate: "-----BEGIN CERTIFICATE...",
|
25
|
+
# policies: "default",
|
26
|
+
# ttl: 3600,
|
27
|
+
# }) #=> true
|
28
|
+
#
|
29
|
+
# @param [String] name
|
30
|
+
# the name of the certificate
|
31
|
+
# @param [Hash] options
|
32
|
+
# @option options [String] :certificate
|
33
|
+
# The PEM-formatted CA certificate.
|
34
|
+
# @option options [String] :policies
|
35
|
+
# A comma-separated list of policies issued when authenticating with this
|
36
|
+
# CA.
|
37
|
+
# @option options [String] :display_name
|
38
|
+
# The name to display on tokens issued against this CA.
|
39
|
+
# @option options [Fixnum] :ttl
|
40
|
+
# The TTL period of the token, provided as a number of seconds.
|
41
|
+
#
|
42
|
+
# @return [true]
|
43
|
+
def set_certificate(name, options = {})
|
44
|
+
headers = extract_headers!(options)
|
45
|
+
client.post("/v1/auth/cert/certs/#{CGI.escape(name)}", JSON.fast_generate(options), headers)
|
46
|
+
return true
|
47
|
+
end
|
48
|
+
|
49
|
+
# Get the certificate by the given name. If a certificate does not exist by that name,
|
50
|
+
# +nil+ is returned.
|
51
|
+
#
|
52
|
+
# @example
|
53
|
+
# Vault.auth_tls.certificate("web") #=> #<Vault::Secret lease_id="...">
|
54
|
+
#
|
55
|
+
# @return [Secret, nil]
|
56
|
+
def certificate(name)
|
57
|
+
json = client.get("/v1/auth/cert/certs/#{CGI.escape(name)}")
|
58
|
+
return Secret.decode(json)
|
59
|
+
rescue HTTPError => e
|
60
|
+
return nil if e.code == 404
|
61
|
+
raise
|
62
|
+
end
|
63
|
+
|
64
|
+
# The list of certificates in vault auth backend.
|
65
|
+
#
|
66
|
+
# @example
|
67
|
+
# Vault.auth_tls.certificates #=> ["web"]
|
68
|
+
#
|
69
|
+
# @return [Array<String>]
|
70
|
+
def certificates(options = {})
|
71
|
+
headers = extract_headers!(options)
|
72
|
+
json = client.list("/v1/auth/cert/certs", options, headers)
|
73
|
+
return Secret.decode(json).data[:keys] || []
|
74
|
+
rescue HTTPError => e
|
75
|
+
return [] if e.code == 404
|
76
|
+
raise
|
77
|
+
end
|
78
|
+
|
79
|
+
# Delete the certificate with the given name. If a certificate does not exist, vault
|
80
|
+
# will not return an error.
|
81
|
+
#
|
82
|
+
# @example
|
83
|
+
# Vault.auth_tls.delete_certificate("web") #=> true
|
84
|
+
#
|
85
|
+
# @param [String] name
|
86
|
+
# the name of the certificate
|
87
|
+
def delete_certificate(name)
|
88
|
+
client.delete("/v1/auth/cert/certs/#{CGI.escape(name)}")
|
89
|
+
return true
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
data/lib/vault/api/auth_token.rb
CHANGED
@@ -15,6 +15,19 @@ module Vault
|
|
15
15
|
end
|
16
16
|
|
17
17
|
class AuthToken < Request
|
18
|
+
# Lists all token accessors.
|
19
|
+
#
|
20
|
+
# @example Listing token accessors
|
21
|
+
# result = Vault.auth_token.accessors #=> #<Vault::Secret>
|
22
|
+
# result.data[:keys] #=> ["476ea048-ded5-4d07-eeea-938c6b4e43ec", "bb00c093-b7d3-b0e9-69cc-c4d85081165b"]
|
23
|
+
#
|
24
|
+
# @return [Array<Secret>]
|
25
|
+
def accessors(options = {})
|
26
|
+
headers = extract_headers!(options)
|
27
|
+
json = client.list("/v1/auth/token/accessors", options, headers)
|
28
|
+
return Secret.decode(json)
|
29
|
+
end
|
30
|
+
|
18
31
|
# Create an authentication token. Note that the parameters specified below
|
19
32
|
# are not validated and passed directly to the Vault server. Depending on
|
20
33
|
# the version of Vault in operation, some of these options may not work, and
|
@@ -99,6 +112,17 @@ module Vault
|
|
99
112
|
return Secret.decode(json)
|
100
113
|
end
|
101
114
|
|
115
|
+
# Lookup information about the given token accessor.
|
116
|
+
#
|
117
|
+
# @example
|
118
|
+
# Vault.auth_token.lookup_accessor("acbd-...") #=> #<Vault::Secret lease_id="">
|
119
|
+
def lookup_accessor(accessor)
|
120
|
+
json = client.post("/v1/auth/token/lookup-accessor", JSON.fast_generate(
|
121
|
+
accessor: accessor,
|
122
|
+
))
|
123
|
+
return Secret.decode(json)
|
124
|
+
end
|
125
|
+
|
102
126
|
# Lookup information about the given token.
|
103
127
|
#
|
104
128
|
# @example
|
data/lib/vault/api/sys/audit.rb
CHANGED
data/lib/vault/api/sys/auth.rb
CHANGED
data/lib/vault/api/sys/mount.rb
CHANGED
data/lib/vault/client.rb
CHANGED
@@ -202,8 +202,8 @@ module Vault
|
|
202
202
|
connection.ciphers = ssl_ciphers
|
203
203
|
|
204
204
|
# Custom pem files, no problem!
|
205
|
-
|
206
|
-
|
205
|
+
pem = ssl_pem_contents || ssl_pem_file ? File.read(ssl_pem_file) : nil
|
206
|
+
if pem
|
207
207
|
connection.cert = OpenSSL::X509::Certificate.new(pem)
|
208
208
|
connection.key = OpenSSL::PKey::RSA.new(pem, ssl_pem_passphrase)
|
209
209
|
connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
data/lib/vault/configurable.rb
CHANGED
data/lib/vault/defaults.rb
CHANGED
@@ -98,10 +98,18 @@ module Vault
|
|
98
98
|
ENV["VAULT_SSL_CIPHERS"] || SSL_CIPHERS
|
99
99
|
end
|
100
100
|
|
101
|
+
# The raw contents (as a string) for the pem file. To specify the path to
|
102
|
+
# the pem file, use {#ssl_pem_file} instead. This value is preferred over
|
103
|
+
# the value for {#ssl_pem_file}, if set.
|
104
|
+
# @return [String, nil]
|
105
|
+
def ssl_pem_contents
|
106
|
+
ENV["VAULT_SSL_PEM_CONTENTS"]
|
107
|
+
end
|
108
|
+
|
101
109
|
# The path to a pem on disk to use with custom SSL verification
|
102
110
|
# @return [String, nil]
|
103
111
|
def ssl_pem_file
|
104
|
-
ENV["VAULT_SSL_CERT"]
|
112
|
+
ENV["VAULT_SSL_CERT"] || ENV["VAULT_SSL_PEM_FILE"]
|
105
113
|
end
|
106
114
|
|
107
115
|
# Passphrase to the pem file on disk to use with custom SSL verification
|
data/lib/vault/response.rb
CHANGED
@@ -62,5 +62,28 @@ module Vault
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
65
|
+
|
66
|
+
# Create a hash-bashed representation of this response.
|
67
|
+
#
|
68
|
+
# @return [Hash]
|
69
|
+
def to_h
|
70
|
+
self.class.fields.inject({}) do |h, (k, opts)|
|
71
|
+
if opts[:as].nil?
|
72
|
+
h[k] = self.public_send(k)
|
73
|
+
else
|
74
|
+
h[k] = self.public_send(opts[:as])
|
75
|
+
end
|
76
|
+
|
77
|
+
if !h[k].nil? && h[k].respond_to?(:to_h)
|
78
|
+
h[k] = h[k].to_h
|
79
|
+
end
|
80
|
+
|
81
|
+
h
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def ==(other)
|
86
|
+
self.to_h == other.to_h
|
87
|
+
end
|
65
88
|
end
|
66
89
|
end
|
data/lib/vault/version.rb
CHANGED
data/vault.gemspec
CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency "bundler"
|
23
23
|
spec.add_development_dependency "pry"
|
24
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
-
spec.add_development_dependency "rspec", "~> 3.
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.5"
|
26
26
|
spec.add_development_dependency "yard"
|
27
27
|
spec.add_development_dependency "webmock", "~> 1.22"
|
28
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vault
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Seth Vargo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '3.
|
61
|
+
version: '3.5'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '3.
|
68
|
+
version: '3.5'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: yard
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,6 +112,7 @@ files:
|
|
112
112
|
- lib/vault.rb
|
113
113
|
- lib/vault/api.rb
|
114
114
|
- lib/vault/api/auth.rb
|
115
|
+
- lib/vault/api/auth_tls.rb
|
115
116
|
- lib/vault/api/auth_token.rb
|
116
117
|
- lib/vault/api/help.rb
|
117
118
|
- lib/vault/api/logical.rb
|