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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: efbf977407c93919ed45ceff129bc3df6088d462
4
- data.tar.gz: 7b3a458357a1a3a9eef3606eb5d1a8160d1d04c5
3
+ metadata.gz: 7c5b5358811dba9b5864bc118f19b2cb0c9b7925
4
+ data.tar.gz: 41acb15b4a2148910f3c7fb8a01f7b51ce31e8aa
5
5
  SHA512:
6
- metadata.gz: ef87eb90b77096ce92ab3f2c765f9b897bac05ec82da49ac600b62b05847ab02cfa9f29f2d09244527be308be61e1f24b3bfa99cac7df5aef45d458c993d76d2
7
- data.tar.gz: 01b3384ce315cfc0e30ee11fdc020327172cde312de1f89bff1b63bf6eacd8f18425234d742b76d5551428212315424612420969c2d16edaa09bb500dea75e21
6
+ metadata.gz: d6ec85927a497e7dcef985d8b32b59db6c5169c1c95820e311c3f3c6617c893e520c592b411806cf81a18d03d5a1dfab9988fb319a43330a4137d18dee7b61d0
7
+ data.tar.gz: 787597e6f6315e2620c766d5f83e625f520401399221bc0774d9f76b6a08d342baea5fe09d061fa6dc892876167af750800b7660dc6afff99abb15b025d6c33d
@@ -2,20 +2,25 @@ language: ruby
2
2
  cache: bundler
3
3
  sudo: false
4
4
 
5
- before_install: |-
6
- curl -so vault.zip https://releases.hashicorp.com/vault/0.6.0/vault_0.6.0_linux_amd64.zip
7
- unzip vault.zip
8
- mkdir ~/bin
9
- mv vault ~/bin
10
- export PATH="~/bin:$PATH"
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.0
25
+ - 2.2.5
26
+ - 2.3.1
@@ -1,6 +1,24 @@
1
1
  # Vault Ruby Changelog
2
2
 
3
- ## v0.4.0.dev (Unreleased)
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
 
@@ -1,6 +1,7 @@
1
1
  module Vault
2
2
  module API
3
3
  require_relative "api/auth_token"
4
+ require_relative "api/auth_tls"
4
5
  require_relative "api/auth"
5
6
  require_relative "api/help"
6
7
  require_relative "api/logical"
@@ -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
@@ -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
@@ -27,6 +27,7 @@ module Vault
27
27
  # @return [Hash<Symbol, Audit>]
28
28
  def audits
29
29
  json = client.get("/v1/sys/audit")
30
+ json = json[:data] if json[:data]
30
31
  return Hash[*json.map do |k,v|
31
32
  [k.to_s.chomp("/").to_sym, Audit.decode(v)]
32
33
  end.flatten]
@@ -22,6 +22,7 @@ module Vault
22
22
  # @return [Hash<Symbol, Auth>]
23
23
  def auths
24
24
  json = client.get("/v1/sys/auth")
25
+ json = json[:data] if json[:data]
25
26
  return Hash[*json.map do |k,v|
26
27
  [k.to_s.chomp("/").to_sym, Auth.decode(v)]
27
28
  end.flatten]
@@ -27,6 +27,7 @@ module Vault
27
27
  # @return [Hash<Symbol, Mount>]
28
28
  def mounts
29
29
  json = client.get("/v1/sys/mounts")
30
+ json = json[:data] if json[:data]
30
31
  return Hash[*json.map do |k,v|
31
32
  [k.to_s.chomp("/").to_sym, Mount.decode(v)]
32
33
  end.flatten]
@@ -202,8 +202,8 @@ module Vault
202
202
  connection.ciphers = ssl_ciphers
203
203
 
204
204
  # Custom pem files, no problem!
205
- if ssl_pem_file
206
- pem = File.read(ssl_pem_file)
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
@@ -13,6 +13,7 @@ module Vault
13
13
  :proxy_username,
14
14
  :read_timeout,
15
15
  :ssl_ciphers,
16
+ :ssl_pem_contents,
16
17
  :ssl_pem_file,
17
18
  :ssl_pem_passphrase,
18
19
  :ssl_ca_cert,
@@ -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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Vault
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -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.2"
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.5.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-16 00:00:00.000000000 Z
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.2'
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.2'
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