vault 0.10.1 → 0.11.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: 67e962a186f0ed717155a0bdd57111cc2dbb6044
4
- data.tar.gz: '09fdeb8585d32bb6642f289a12afda06716a04e2'
3
+ metadata.gz: dcb5948ae3d3f53115a8e0aef77b70d18c042550
4
+ data.tar.gz: 143ffc1b71f99550e83548ba92f1edb0e7e4ef0a
5
5
  SHA512:
6
- metadata.gz: 90f28655a32c55316aa9436abf4dee09aa36ab25db6b0277b43a48cb86385a8a758fbbb14dd634a94f3887637dfc3e40ecdff4ef1db8db510d6d6257a99b9dab
7
- data.tar.gz: 75b038d03764889b0301b9ff318c59be6fa85fddc9931fdbbdd9f902daf1bb7e467bb77a70f6a06be2cc87951c269d57179ca3a4901a87d380ef983bf9cc2255
6
+ metadata.gz: a7473e4c1791e62f8814a677d0c71bce2ca9b51a32c534dfd11830bcbbd3a2b8e993dacf3df52bc747fc1473931801733731de5e3a00c1078a9e59f2cbaa75b8
7
+ data.tar.gz: 7c7a6793019c4f67a7927f01e839cbe9d0ac288dea9affe6e564d6482eedb4da5553cf01a823b9615c572e06a937bef532fd4a80777feb2488e5b3f41cd7e9a6
@@ -4,13 +4,15 @@ language: ruby
4
4
  cache: bundler
5
5
 
6
6
  env:
7
- - VAULT_VERSION=0.6.4
7
+ - VAULT_VERSION=0.8.3
8
+ - VAULT_VERSION=0.7.3
9
+ - VAULT_VERSION=0.6.5
8
10
  - VAULT_VERSION=0.5.3
9
11
 
10
12
  before_install:
11
13
  - curl -sLo vault.zip https://releases.hashicorp.com/vault/${VAULT_VERSION}/vault_${VAULT_VERSION}_linux_amd64.zip
12
14
  - unzip vault.zip
13
- - mkdir ~/bin
15
+ - mkdir -p ~/bin
14
16
  - mv vault ~/bin
15
17
  - export PATH="~/bin:$PATH"
16
18
 
@@ -1,11 +1,21 @@
1
1
  # Vault Ruby Changelog
2
2
 
3
+ ## v0.11.0 (March 19, 2018)
4
+
5
+ IMPROVEMENTS
6
+
7
+ - Access to health has been added.
8
+ - Added ability to handle a Base64 encoded PEM (useful for certs in environment variables)
9
+ - Added IAM EC2 authentication support
10
+ - Add custom mount path support to TLS authentication
11
+
3
12
  ## v0.10.1 (May 8, 2017)
4
13
 
5
14
  IMPROVEMENTS
6
15
 
7
16
  - `vault-ruby` is licensed under Mozilla Public License 2.0, and has been for over 2 years. This patch release updates the gemspec to use the correct SPDX ID string for reporting this license, but **no change to the licensing of this gem has occurred**.
8
17
 
18
+
9
19
  ## v0.10.0 (April 19, 2017)
10
20
 
11
21
  IMPROVEMENTS
data/README.md CHANGED
@@ -53,6 +53,10 @@ Vault.configure do |config|
53
53
  # Custom SSL PEM, also read as ENV["VAULT_SSL_CERT"]
54
54
  config.ssl_pem_file = "/path/on/disk.pem"
55
55
 
56
+ # As an alternative to a pem file, you can provide the raw PEM string, also read in the following order of preference:
57
+ # ENV["VAULT_SSL_PEM_CONTENTS_BASE64"] then ENV["VAULT_SSL_PEM_CONTENTS"]
58
+ config.ssl_pem_contents = "-----BEGIN ENCRYPTED..."
59
+
56
60
  # Use SSL verification, also read as ENV["VAULT_SSL_VERIFY"]
57
61
  config.ssl_verify = false
58
62
 
@@ -75,6 +79,16 @@ client_1 = Vault::Client.new(address: "https://vault.mycompany.com")
75
79
  client_2 = Vault::Client.new(address: "https://other-vault.mycompany.com")
76
80
  ```
77
81
 
82
+ And if you want to authenticate with a `AWS EC2` :
83
+
84
+ ```ruby
85
+ # Export VAULT_ADDR to ENV then
86
+ # Get the pkcs7 value from AWS
87
+ signature = `curl http://169.254.169.254/latest/dynamic/instance-identity/pkcs7`
88
+ vault_token = Vault.auth.aws_ec2(ENV['EC2_ROLE'], signature, nil)
89
+ vault_client = Vault::Client.new(address: ENV["VAULT_ADDR"], token: vault_token.auth.client_token)
90
+ ```
91
+
78
92
  ### Making requests
79
93
  All of the methods and API calls are heavily documented with examples inline using YARD. In order to keep the examples versioned with the code, the README only lists a few examples for using the Vault gem. Please see the inline documentation for the full API documentation. The tests in the 'spec' directory are an additional source of examples.
80
94
 
@@ -173,12 +173,70 @@ module Vault
173
173
  # @param [String] role
174
174
  # @param [String] pkcs7
175
175
  # pkcs7 returned by the instance identity document (with line breaks removed)
176
- # @param [String] nonce
176
+ # @param [String] nonce optional
177
+ # @param [String] route optional
177
178
  #
178
179
  # @return [Secret]
179
- def aws_ec2(role, pkcs7, nonce)
180
- payload = { role: role, pkcs7: pkcs7, nonce: nonce }
181
- json = client.post('/v1/auth/aws-ec2/login', JSON.fast_generate(payload))
180
+ def aws_ec2(role, pkcs7, nonce = nil, route = nil)
181
+ route ||= '/v1/auth/aws-ec2/login'
182
+ payload = { role: role, pkcs7: pkcs7 }
183
+ # Set a custom nonce if client is providing one
184
+ payload[:nonce] = nonce if nonce
185
+ json = client.post(route, JSON.fast_generate(payload))
186
+ secret = Secret.decode(json)
187
+ client.token = secret.auth.client_token
188
+ return secret
189
+ end
190
+
191
+ # Authenticate via AWS IAM auth method by providing a AWS CredentialProvider (either ECS, AssumeRole, etc.)
192
+ # If authentication is successful, the resulting token will be stored on the client and used
193
+ # for future requests.
194
+ #
195
+ # @example
196
+ # Vault.auth.aws_iam("dev-role-iam", Aws::AssumeRoleCredentials.new, "vault.example.com", "https://sts.us-east-2.amazonaws.com") #=> #<Vault::Secret lease_id="">
197
+ #
198
+ # @param [String] role
199
+ # @param [CredentialProvider] credentials_provider
200
+ # https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/CredentialProvider.html
201
+ # @param [String] iam_auth_header_value optional
202
+ # As of Jan 2018, Vault will accept ANY or NO header if none is configured by the Vault server admin
203
+ # @param [String] sts_endpoint optional
204
+ # https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_enable-regions.html
205
+ # @return [Secret]
206
+ def aws_iam(role, credentials_provider, iam_auth_header_value = nil, sts_endpoint = 'https://sts.amazonaws.com')
207
+ require "aws-sigv4"
208
+ require "base64"
209
+
210
+ request_body = 'Action=GetCallerIdentity&Version=2011-06-15'
211
+ request_method = 'POST'
212
+
213
+ vault_headers = {
214
+ 'User-Agent' => Vault::Client::USER_AGENT,
215
+ 'Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8'
216
+ }
217
+
218
+ vault_headers['X-Vault-AWS-IAM-Server-ID'] = iam_auth_header_value if iam_auth_header_value
219
+
220
+ sig4_headers = Aws::Sigv4::Signer.new(
221
+ service: 'sts',
222
+ region: region_from_sts_endpoint(sts_endpoint),
223
+ credentials_provider: credentials_provider
224
+ ).sign_request(
225
+ http_method: request_method,
226
+ url: sts_endpoint,
227
+ headers: vault_headers,
228
+ body: request_body
229
+ ).headers
230
+
231
+ payload = {
232
+ role: role,
233
+ iam_http_request_method: request_method,
234
+ iam_request_url: Base64.strict_encode64(sts_endpoint),
235
+ iam_request_headers: Base64.strict_encode64(vault_headers.merge(sig4_headers).to_json),
236
+ iam_request_body: Base64.strict_encode64(request_body)
237
+ }
238
+
239
+ json = client.post('/v1/auth/aws/login', JSON.fast_generate(payload))
182
240
  secret = Secret.decode(json)
183
241
  client.token = secret.auth.client_token
184
242
  return secret
@@ -194,18 +252,40 @@ module Vault
194
252
  # @example Reading a pem from disk
195
253
  # Vault.auth.tls(File.read("/path/to/my/certificate.pem")) #=> #<Vault::Secret lease_id="">
196
254
  #
255
+ # @example Sending to a cert authentication backend mounted at a custom location
256
+ # Vault.auth.tls(pem_contents, 'custom/location') #=> #<Vault::Secret lease_id="">
257
+ #
197
258
  # @param [String] pem (default: the configured SSL pem file or contents)
198
259
  # The raw pem contents to use for the login procedure.
199
260
  #
261
+ # @param [String] path (default: 'cert')
262
+ # The path to the auth backend to use for the login procedure.
263
+ #
200
264
  # @return [Secret]
201
- def tls(pem = nil)
265
+ def tls(pem = nil, path = 'cert')
202
266
  new_client = client.dup
203
267
  new_client.ssl_pem_contents = pem if !pem.nil?
204
268
 
205
- json = new_client.post("/v1/auth/cert/login")
269
+ json = new_client.post("/v1/auth/#{CGI.escape(path)}/login")
206
270
  secret = Secret.decode(json)
207
271
  client.token = secret.auth.client_token
208
272
  return secret
209
273
  end
274
+
275
+ private
276
+
277
+ # Parse an AWS region from a STS endpoint
278
+ # STS in the China (Beijing) region (cn-north-1) is sts.cn-north-1.amazonaws.com.cn
279
+ # Take care changing below regex with that edge case in mind
280
+ #
281
+ # @param [String] sts_endpoint
282
+ # https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_enable-regions.html
283
+ #
284
+ # @return [String] aws region
285
+ def region_from_sts_endpoint(sts_endpoint)
286
+ valid_sts_endpoint = %r{https:\/\/sts\.?(.*).amazonaws.com}.match(sts_endpoint)
287
+ raise "Unable to parse STS endpoint #{sts_endpoint}" unless valid_sts_endpoint
288
+ valid_sts_endpoint[1].empty? ? 'us-east-1' : valid_sts_endpoint[1]
289
+ end
210
290
  end
211
291
  end
@@ -102,7 +102,7 @@ module Vault
102
102
  # Lookup information about the current token.
103
103
  #
104
104
  # @example
105
- # Vault.auth_token.lookup_self("abcd-...") #=> #<Vault::Secret lease_id="">
105
+ # Vault.auth_token.lookup("abcd-...") #=> #<Vault::Secret lease_id="">
106
106
  #
107
107
  # @param [String] token
108
108
  # @param [Hash] options
@@ -215,7 +215,7 @@ module Vault
215
215
  # @return [true]
216
216
  def revoke_accessor(accessor, options = {})
217
217
  headers = extract_headers!(options)
218
- client.put("/v1/auth/accessor/revoke-accessor", JSON.fast_generate(
218
+ client.put("/v1/auth/token/revoke-accessor", JSON.fast_generate(
219
219
  accessor: accessor,
220
220
  ), headers)
221
221
  return true
@@ -16,6 +16,7 @@ end
16
16
 
17
17
  require_relative "sys/audit"
18
18
  require_relative "sys/auth"
19
+ require_relative "sys/health"
19
20
  require_relative "sys/init"
20
21
  require_relative "sys/leader"
21
22
  require_relative "sys/lease"
@@ -19,7 +19,7 @@ module Vault
19
19
  end
20
20
 
21
21
  class Sys
22
- # List all audis for the vault.
22
+ # List all audits for the vault.
23
23
  #
24
24
  # @example
25
25
  # Vault.sys.audits #=> { :file => #<Audit> }
@@ -70,5 +70,22 @@ module Vault
70
70
  client.delete("/v1/sys/audit/#{encode_path(path)}")
71
71
  return true
72
72
  end
73
+
74
+ # Generates a HMAC verifier for a given input.
75
+ #
76
+ # @example
77
+ # Vault.sys.audit_hash("file-audit", "my input") #=> "hmac-sha256:30aa7de18a5e90bbc1063db91e7c387b32b9fa895977eb8c177bbc91e7d7c542"
78
+ #
79
+ # @param [String] path
80
+ # the path of the audit backend
81
+ # @param [String] input
82
+ # the input to generate a HMAC for
83
+ #
84
+ # @return [String]
85
+ def audit_hash(path, input)
86
+ json = client.post("/v1/sys/audit-hash/#{encode_path(path)}", JSON.fast_generate(input: input))
87
+ json = json[:data] if json[:data]
88
+ json[:hash]
89
+ end
73
90
  end
74
91
  end
@@ -0,0 +1,63 @@
1
+ require "json"
2
+
3
+ module Vault
4
+ class HealthStatus < Response
5
+ # @!attribute [r] initialized
6
+ # Whether the Vault server is Initialized.
7
+ # @return [Boolean]
8
+ field :initialized, as: :initialized?
9
+
10
+ # @!attribute [r] sealed
11
+ # Whether the Vault server is Sealed.
12
+ # @return [Boolean]
13
+ field :sealed, as: :sealed?
14
+
15
+ # @!attribute [r] standby
16
+ # Whether the Vault server is in Standby mode.
17
+ # @return [Boolean]
18
+ field :standby, as: :standby?
19
+
20
+ # @!attribute [r] replication_performance_mode
21
+ # Verbose description of DR mode (added in 0.9.2)
22
+ # @return [String]
23
+ field :replication_performance_mode
24
+
25
+ # @!attribute [r] replication_dr_mode
26
+ # Verbose description of DR mode (added in 0.9.2)
27
+ # @return [String]
28
+ field :replication_dr_mode
29
+
30
+ # @!attribute [r] server_time_utc
31
+ # Server time in Unix seconds, UTC
32
+ # @return [Fixnum]
33
+ field :server_time_utc
34
+
35
+ # @!attribute [r] version
36
+ # Server Vault version string (added in 0.6.1)
37
+ # @return [String]
38
+ field :version
39
+
40
+ # @!attribute [r] cluster_name
41
+ # Server cluster name
42
+ # @return [String]
43
+ field :cluster_name
44
+
45
+ # @!attribute [r] cluster_id
46
+ # Server cluster UUID
47
+ # @return [String]
48
+ field :cluster_id
49
+ end
50
+
51
+ class Sys
52
+ # Show the health status for this vault.
53
+ #
54
+ # @example
55
+ # Vault.sys.health_status #=> #Vault::HealthStatus @initialized=true, @sealed=false, @standby=false, @replication_performance_mode="disabled", @replication_dr_mode="disabled", @server_time_utc=1519776728, @version="0.9.3", @cluster_name="vault-cluster-997f514e", @cluster_id="c2dad70a-6d88-a06d-69f6-9ae7f5485998">
56
+ #
57
+ # @return [HealthStatus]
58
+ def health_status
59
+ json = client.get("/v1/sys/health", {:sealedcode => 200, :uninitcode => 200, :standbycode => 200})
60
+ return HealthStatus.decode(json)
61
+ end
62
+ end
63
+ end
@@ -1,4 +1,5 @@
1
1
  require "pathname"
2
+ require "base64"
2
3
 
3
4
  module Vault
4
5
  module Defaults
@@ -126,7 +127,11 @@ module Vault
126
127
  # the value for {#ssl_pem_file}, if set.
127
128
  # @return [String, nil]
128
129
  def ssl_pem_contents
129
- ENV["VAULT_SSL_PEM_CONTENTS"]
130
+ if ENV["VAULT_SSL_PEM_CONTENTS_BASE64"]
131
+ Base64.decode64(ENV["VAULT_SSL_PEM_CONTENTS_BASE64"])
132
+ else
133
+ ENV["VAULT_SSL_PEM_CONTENTS"]
134
+ end
130
135
  end
131
136
 
132
137
  # The path to a pem on disk to use with custom SSL verification
@@ -1,3 +1,3 @@
1
1
  module Vault
2
- VERSION = "0.10.1"
2
+ VERSION = "0.11.0"
3
3
  end
@@ -19,6 +19,8 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
+ spec.add_runtime_dependency "aws-sigv4"
23
+
22
24
  spec.add_development_dependency "bundler"
23
25
  spec.add_development_dependency "pry"
24
26
  spec.add_development_dependency "rake", "~> 12.0"
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vault
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.1
4
+ version: 0.11.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: 2017-05-10 00:00:00.000000000 Z
11
+ date: 2018-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sigv4
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'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -121,6 +135,7 @@ files:
121
135
  - lib/vault/api/sys.rb
122
136
  - lib/vault/api/sys/audit.rb
123
137
  - lib/vault/api/sys/auth.rb
138
+ - lib/vault/api/sys/health.rb
124
139
  - lib/vault/api/sys/init.rb
125
140
  - lib/vault/api/sys/leader.rb
126
141
  - lib/vault/api/sys/lease.rb
@@ -163,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
178
  version: '0'
164
179
  requirements: []
165
180
  rubyforge_project:
166
- rubygems_version: 2.6.10
181
+ rubygems_version: 2.6.14
167
182
  signing_key:
168
183
  specification_version: 4
169
184
  summary: Vault is a Ruby API client for interacting with a Vault server.