settings_reader-vault_resolver 0.4.3 → 0.4.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 200d04472a50277f38b29b18a30b565588e4c5fa7c55a2b654b70bb9dbbc0e62
4
- data.tar.gz: 48ec7877b81d458ad9c22b14cdbce6ce05b1a22a141e7c978c3a19c7f6796037
3
+ metadata.gz: 5135f50633e103f09f6f30bf956295fc9290a6b75dfd7864e0296ecc9f467f35
4
+ data.tar.gz: d80b42374412c4053538af7e2ba9a984f0f53219fed76aa440a1a35494167b33
5
5
  SHA512:
6
- metadata.gz: 365fa301486b2df995dc0eacd1e5492ee2f59dd68c26e251f13d813ed49dec7bb0d295de316c3b4edee924785bc03a61e872e48ad67c75e8dc1caa993ad194d0
7
- data.tar.gz: 9129f937c54959ea99fcd99647889ccfa22b23783f33f89bdc665d5226b562dbcb6369629927076be3c4be869280a87477251b6bd63e1dc39ded8e8bbc62f22f
6
+ metadata.gz: 57f47f6d9d9cbea621fa523560129021ceb70c5c9b4175f34f367387bfc76992cae6f5761fb11d36a04bf3111ff156b2ea7c4d7c69703b0256be14e51c973849
7
+ data.tar.gz: 9789a9fe5ac8bfebb040eae0998d977806daaed20b05a35655d77cf8615aeab6f1023e933ff59c71dd3ce79061f8675f09e8da97d079c02b1b1d95377905e536
@@ -26,6 +26,10 @@ module SettingsReader
26
26
  URI.decode_www_form(@uri.query || '').to_h
27
27
  end
28
28
 
29
+ def no_cache?
30
+ options['no_cache'] == 'true'
31
+ end
32
+
29
33
  def to_s
30
34
  @uri.to_s
31
35
  end
@@ -23,7 +23,7 @@ module SettingsReader
23
23
  end
24
24
 
25
25
  def fetch(address, &block)
26
- if (exiting_entry = retrieve(address))
26
+ if !address.no_cache? && (exiting_entry = retrieve(address))
27
27
  exiting_entry
28
28
  else
29
29
  new_entry = block.call(address)
@@ -16,7 +16,7 @@ module SettingsReader
16
16
  end
17
17
 
18
18
  def get(address)
19
- return unless (vault_secret = get_secret_with_authentication(address))
19
+ return unless (vault_secret = get_and_retry_auth(address))
20
20
 
21
21
  wrap_secret(address, vault_secret)
22
22
  rescue Vault::VaultError => e
@@ -26,7 +26,7 @@ module SettingsReader
26
26
  def renew(entry)
27
27
  return unless entry.leased?
28
28
 
29
- new_secret = renew_lease_with_authentication(entry)
29
+ new_secret = renew_and_retry_auth(entry)
30
30
  entry.update_renewed(new_secret)
31
31
  true
32
32
  rescue Vault::VaultError => e
@@ -35,31 +35,31 @@ module SettingsReader
35
35
 
36
36
  protected
37
37
 
38
- def get_secret_with_authentication(address)
39
- get_secret_with_retries(address)
40
- rescue Vault::HTTPClientError => e # if not authenticated, let's reauthenticate and try once more
41
- raise unless e.code == 403
38
+ def get_and_retry_auth(address)
39
+ get_and_retry_connection(address)
40
+ rescue Vault::HTTPError => e # if not authenticated, let's reauthenticate and try once more
41
+ raise unless auth_error?(e)
42
42
 
43
43
  config.vault_initializer.call
44
- get_secret_with_retries(address)
44
+ get_and_retry_connection(address)
45
45
  end
46
46
 
47
- def get_secret_with_retries(address)
47
+ def get_and_retry_connection(address)
48
48
  Vault.with_retries(Vault::HTTPConnectionError, attempts: config.retrieval_retries) do
49
49
  get_secret(address)
50
50
  end
51
51
  end
52
52
 
53
- def renew_lease_with_authentication(address)
54
- renew_lease_with_retries(address)
55
- rescue Vault::HTTPClientError => e # if not authenticated, let's reauthenticate and try once more
56
- raise unless e.code == 403
53
+ def renew_and_retry_auth(address)
54
+ renew_and_retry_connection(address)
55
+ rescue Vault::HTTPError => e # if not authenticated, let's reauthenticate and try once more
56
+ raise unless auth_error?(e)
57
57
 
58
58
  config.vault_initializer.call
59
- renew_lease_with_retries(address)
59
+ renew_and_retry_connection(address)
60
60
  end
61
61
 
62
- def renew_lease_with_retries(address)
62
+ def renew_and_retry_connection(address)
63
63
  Vault.with_retries(Vault::HTTPConnectionError, attempts: config.lease_renew_retries) do
64
64
  renew_lease(address)
65
65
  end
@@ -76,6 +76,10 @@ module SettingsReader
76
76
  def wrap_secret(address, secret)
77
77
  SettingsReader::VaultResolver::Entry.new(address, secret)
78
78
  end
79
+
80
+ def auth_error?(error)
81
+ error.code == 403 || error.message =~ /token mac for token_version.*is incorrect/
82
+ end
79
83
  end
80
84
  end
81
85
  end
@@ -12,6 +12,16 @@ module SettingsReader
12
12
 
13
13
  protected
14
14
 
15
+ # Auth backend should not retry auth errors as it causing infinite recursion
16
+ def get_and_retry_auth(address)
17
+ get_and_retry_connection(address)
18
+ end
19
+
20
+ # Auth backend should not retry auth errors as it causing infinite recursion
21
+ def renew_and_retry_auth(address)
22
+ renew_and_retry_connection(address)
23
+ end
24
+
15
25
  def get_secret(address)
16
26
  return k8s_auth(address) if address.path == K8S_AUTH
17
27
 
@@ -8,8 +8,9 @@ module SettingsReader
8
8
  FAKE_RESOLVER_PATH = 'vault/authentication'.freeze
9
9
 
10
10
  def authenticate_via_k8s(role, route: nil, service_token_path: nil)
11
- params = URI.encode_www_form({ role: role, route: route, service_token_path: service_token_path }.compact)
12
- resolver.resolve("vault://auth/kubernetes/login?#{params}#client_token", FAKE_RESOLVER_PATH)
11
+ params = { role: role, route: route, service_token_path: service_token_path, no_cache: true }
12
+ url_params = URI.encode_www_form(params.compact)
13
+ resolver.resolve("vault://auth/kubernetes/login?#{url_params}#client_token", FAKE_RESOLVER_PATH)
13
14
  end
14
15
 
15
16
  private
@@ -1,5 +1,5 @@
1
1
  module SettingsReader
2
2
  module VaultResolver
3
- VERSION = '0.4.3'.freeze
3
+ VERSION = '0.4.4'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: settings_reader-vault_resolver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Volodymyr Mykhailyk
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-08 00:00:00.000000000 Z
11
+ date: 2022-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby