kubeclient 4.9.1 → 4.10.0

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.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/actions.yml +43 -0
  3. data/CHANGELOG.md +65 -0
  4. data/README.md +6 -0
  5. data/kubeclient.gemspec +7 -3
  6. data/lib/kubeclient/common.rb +31 -19
  7. data/lib/kubeclient/config.rb +22 -10
  8. data/lib/kubeclient/version.rb +1 -1
  9. data/lib/kubeclient/watch_stream.rb +1 -0
  10. metadata +40 -218
  11. data/.travis.yml +0 -29
  12. data/test/cassettes/kubernetes_guestbook.yml +0 -879
  13. data/test/config/allinone.kubeconfig +0 -20
  14. data/test/config/execauth.kubeconfig +0 -62
  15. data/test/config/external-ca.pem +0 -18
  16. data/test/config/external-cert.pem +0 -19
  17. data/test/config/external-key.rsa +0 -27
  18. data/test/config/external.kubeconfig +0 -20
  19. data/test/config/gcpauth.kubeconfig +0 -22
  20. data/test/config/gcpcmdauth.kubeconfig +0 -26
  21. data/test/config/nouser.kubeconfig +0 -16
  22. data/test/config/oidcauth.kubeconfig +0 -25
  23. data/test/config/timestamps.kubeconfig +0 -25
  24. data/test/config/userauth.kubeconfig +0 -28
  25. data/test/json/bindings_list.json +0 -10
  26. data/test/json/component_status.json +0 -17
  27. data/test/json/component_status_list.json +0 -52
  28. data/test/json/config.istio.io_api_resource_list.json +0 -679
  29. data/test/json/config_map_list.json +0 -9
  30. data/test/json/core_api_resource_list.json +0 -181
  31. data/test/json/core_api_resource_list_without_kind.json +0 -129
  32. data/test/json/core_oapi_resource_list_without_kind.json +0 -197
  33. data/test/json/created_endpoint.json +0 -28
  34. data/test/json/created_namespace.json +0 -20
  35. data/test/json/created_secret.json +0 -16
  36. data/test/json/created_security_context_constraint.json +0 -65
  37. data/test/json/created_service.json +0 -31
  38. data/test/json/empty_pod_list.json +0 -9
  39. data/test/json/endpoint_list.json +0 -48
  40. data/test/json/entity_list.json +0 -56
  41. data/test/json/event_list.json +0 -35
  42. data/test/json/extensions_v1beta1_api_resource_list.json +0 -217
  43. data/test/json/limit_range.json +0 -23
  44. data/test/json/limit_range_list.json +0 -31
  45. data/test/json/namespace.json +0 -13
  46. data/test/json/namespace_exception.json +0 -8
  47. data/test/json/namespace_list.json +0 -32
  48. data/test/json/node.json +0 -29
  49. data/test/json/node_list.json +0 -37
  50. data/test/json/node_notice.json +0 -160
  51. data/test/json/persistent_volume.json +0 -37
  52. data/test/json/persistent_volume_claim.json +0 -32
  53. data/test/json/persistent_volume_claim_list.json +0 -40
  54. data/test/json/persistent_volume_claims_nil_items.json +0 -8
  55. data/test/json/persistent_volume_list.json +0 -45
  56. data/test/json/pod.json +0 -92
  57. data/test/json/pod_list.json +0 -79
  58. data/test/json/pod_template_list.json +0 -9
  59. data/test/json/pods_1.json +0 -265
  60. data/test/json/pods_2.json +0 -102
  61. data/test/json/pods_410.json +0 -9
  62. data/test/json/processed_template.json +0 -27
  63. data/test/json/replication_controller.json +0 -57
  64. data/test/json/replication_controller_list.json +0 -66
  65. data/test/json/resource_quota.json +0 -46
  66. data/test/json/resource_quota_list.json +0 -54
  67. data/test/json/secret_list.json +0 -44
  68. data/test/json/security.openshift.io_api_resource_list.json +0 -69
  69. data/test/json/security_context_constraint_list.json +0 -375
  70. data/test/json/service.json +0 -33
  71. data/test/json/service_account.json +0 -25
  72. data/test/json/service_account_list.json +0 -82
  73. data/test/json/service_illegal_json_404.json +0 -1
  74. data/test/json/service_json_patch.json +0 -26
  75. data/test/json/service_list.json +0 -97
  76. data/test/json/service_merge_patch.json +0 -26
  77. data/test/json/service_patch.json +0 -25
  78. data/test/json/service_update.json +0 -22
  79. data/test/json/template.json +0 -27
  80. data/test/json/template.openshift.io_api_resource_list.json +0 -75
  81. data/test/json/template_list.json +0 -35
  82. data/test/json/versions_list.json +0 -6
  83. data/test/json/watch_stream.json +0 -3
  84. data/test/test_common.rb +0 -95
  85. data/test/test_common_url_handling.rb +0 -160
  86. data/test/test_component_status.rb +0 -29
  87. data/test/test_config.rb +0 -222
  88. data/test/test_endpoint.rb +0 -54
  89. data/test/test_exec_credentials.rb +0 -225
  90. data/test/test_gcp_command_credentials.rb +0 -27
  91. data/test/test_google_application_default_credentials.rb +0 -15
  92. data/test/test_guestbook_go.rb +0 -235
  93. data/test/test_helper.rb +0 -18
  94. data/test/test_kubeclient.rb +0 -881
  95. data/test/test_limit_range.rb +0 -25
  96. data/test/test_missing_methods.rb +0 -80
  97. data/test/test_namespace.rb +0 -59
  98. data/test/test_node.rb +0 -70
  99. data/test/test_oidc_auth_provider.rb +0 -103
  100. data/test/test_persistent_volume.rb +0 -29
  101. data/test/test_persistent_volume_claim.rb +0 -28
  102. data/test/test_pod.rb +0 -81
  103. data/test/test_pod_log.rb +0 -157
  104. data/test/test_process_template.rb +0 -80
  105. data/test/test_replication_controller.rb +0 -47
  106. data/test/test_resource_list_without_kind.rb +0 -78
  107. data/test/test_resource_quota.rb +0 -23
  108. data/test/test_secret.rb +0 -62
  109. data/test/test_security_context_constraint.rb +0 -62
  110. data/test/test_service.rb +0 -357
  111. data/test/test_service_account.rb +0 -26
  112. data/test/test_watch.rb +0 -195
  113. data/test/txt/pod_log.txt +0 -6
  114. data/test/valid_token_file +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1ea191875dc5c9e99d49152f6615caa50478bc8604a4de9c6fdda0d46da75ea5
4
- data.tar.gz: 84214e5b1f2f3116aeb646828e0a5cf6456173493abf1fb384fe6132a723271d
3
+ metadata.gz: 68296079e6db48ae555a4ca1f53c39b4c6349f3aebb426f443f884c984b904a1
4
+ data.tar.gz: 1524dfc158d01ac299c732f54dcf5e757cbd112eb07f3358ba798c3c8b09977d
5
5
  SHA512:
6
- metadata.gz: 549974ed0fbec82aa99df19db4829af4da21eec3ab037037c9a6880ab2b7f0bbf9a854ee9e1713a9eedccf6e7fafbc593301a8e67b745e54d88f9da158f6b596
7
- data.tar.gz: 2f44720eca3c585e69c562b218f6e17c1ed0fb13dd5e26177fef6fa3ec610a6c0b1f056102ac3d3e3d9cf21801fe13d8560c509423838304cac0a40b66eedae8
6
+ metadata.gz: 0aa6e0f5d6934ef4de10a71a1388f53323ab235ca4b3c1a560b99a483fba3603c51cf463a5211554ab2d97d1dfce6a5623ce65898c0f188c231476b320180bc3
7
+ data.tar.gz: a6319a5a38d228db8b0ed08eb356d7539858cb0660ec2dba376177a3c02568b19ea42d5799feef04b5d86dc4284673c978d6cdaf82b286f3642ae33a0449eba0
@@ -0,0 +1,43 @@
1
+ name: CI
2
+ on:
3
+ push:
4
+ branches:
5
+ - '**'
6
+ tags:
7
+ - '**'
8
+ pull_request:
9
+ branches:
10
+ - '**'
11
+ jobs:
12
+ build:
13
+ continue-on-error: true
14
+ runs-on: ${{ matrix.os_and_command.os }}
15
+ strategy:
16
+ matrix:
17
+ ruby: [ '2.5', '2.6', '2.7', '3.0', '3.1', 'ruby-head', 'truffleruby-head' ]
18
+ os_and_command:
19
+ - os: macos-latest
20
+ command: 'env TESTOPTS="--verbose" bundle exec rake test'
21
+ - os: windows-latest
22
+ command: 'env TESTOPTS="--verbose" bundle exec rake test'
23
+ - os: ubuntu-latest
24
+ # Sometimes minitest starts and then just hangs printing nothing.
25
+ # Github by default kills after 6hours(!). Hopefully SIGTERM may let it print some details?
26
+ command: 'timeout --signal=TERM 3m env TESTOPTS="--verbose" test/config/update_certs_k0s.rb'
27
+ include:
28
+ # run rubocop against lowest supported ruby
29
+ - os: ubuntu-latest
30
+ ruby: '2.5'
31
+ command: 'bundle exec rake rubocop'
32
+ name: ${{ matrix.os_and_command.os }} ${{ matrix.ruby }} rake ${{ matrix.os_and_command.command }}
33
+ steps:
34
+ - uses: actions/checkout@v2
35
+ # actions/setup-ruby did not support truffle or bundler caching
36
+ - uses: ruby/setup-ruby@v1
37
+ with:
38
+ ruby-version: ${{ matrix.ruby }}
39
+ bundler-cache: false # disable running 'bundle install' and caching installed gems see https://github.com/httprb/http/issues/572
40
+ - run: bundle install
41
+ - run: ${{ matrix.os_and_command.command }}
42
+ timeout-minutes: 10
43
+
data/CHANGELOG.md CHANGED
@@ -4,6 +4,71 @@ Notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
5
5
  Kubeclient release versioning follows [SemVer](https://semver.org/).
6
6
 
7
+ ## 4.10.0 — 2022-08-29
8
+
9
+ ### Added
10
+
11
+ - When using `:bearer_token_file`, re-read the file on every request. (#566 closed #561)
12
+
13
+ Kubernetes version 1.21 graduated [BoundServiceAccountTokenVolume feature][] to beta
14
+ and enabled it by default, so standard in-cluster auth now uses short-lived tokens.
15
+
16
+ This changes allows a long-lived `Client` object to keep working when the token file gets
17
+ rotated. It's not optimized at all, if you feel the performance overhead, please report!
18
+
19
+ [BoundServiceAccountTokenVolume feature]: https://github.com/kubernetes/enhancements/issues/542
20
+
21
+ ## 4.9.3 — 2022-03-23
22
+
23
+ ### Fixed
24
+
25
+ - VULNERABILITY FIX: Previously, whenever kubeconfig did not define custom CA
26
+ (normal situation for production clusters with public domain and certificate!),
27
+ `Config` was returning ssl_options[:verify_ssl] hard-coded to `VERIFY_NONE` :-(
28
+
29
+ Assuming you passed those ssl_options to Kubeclient::Client, this means that
30
+ instead of checking server's certificate against your system CA store,
31
+ it would accept ANY certificate, allowing easy man-in-the middle attacks.
32
+
33
+ This is especially dangerous with user/password or token credentials
34
+ because MITM attacker could simply steal those credentials to the cluster
35
+ and do anything you could do on the cluster.
36
+
37
+ This was broken IN ALL RELEASES MADE BEFORE 2022, ever since
38
+ [`Kubeclient::Config` was created](https://github.com/ManageIQ/kubeclient/pull/127/files#diff-32e70f2f6781a9e9c7b83ae5e7eaf5ffd068a05649077fa38f6789e72f3de837R41-R48).
39
+
40
+ [#554](https://github.com/ManageIQ/kubeclient/issues/554).
41
+
42
+ - Bug fix: kubeconfig `insecure-skip-tls-verify` field was ignored.
43
+ When kubeconfig did define custom CA, `Config` was returning hard-coded `VERIFY_PEER`.
44
+
45
+ Now we honor it, return `VERIFY_NONE` iff kubeconfig has explicit
46
+ `insecure-skip-tls-verify: true`, otherwise `VERIFY_PEER`.
47
+
48
+ [#555](https://github.com/ManageIQ/kubeclient/issues/555).
49
+
50
+ - `Config`: fixed parsing of `certificate-authority` file containing concatenation of
51
+ several certificates. Previously, server's cert was checked against only first CA cert,
52
+ resulting in possible "certificate verify failed" errors.
53
+
54
+ An important use case is a chain of root & intermediate cert(s) - necessary when cluster's CA
55
+ itself is signed by another custom CA.
56
+ But also helps when you simply concatenate independent certs. (#461, #552)
57
+
58
+ - Still broken (#460): inline `certificate-authority-data` is still parsed using `add_cert`
59
+ method that handles only one cert.
60
+
61
+ These don't affect code that supplies `Client` parameters directly,
62
+ only code that uses `Config`.
63
+
64
+ ## 4.9.2 — 2021-05-30
65
+
66
+ ### Added
67
+ - Ruby 3.0 compatibility (#500, #505).
68
+
69
+ ### Removed
70
+ - Reduce .gem size by dropping test/ directory, it's useless at run time (#502).
71
+
7
72
  ## 4.9.1 — 2020-08-31
8
73
  ### Fixed
9
74
  - Now should work with apiserver deployed not at root of domain but a sub-path,
data/README.md CHANGED
@@ -9,6 +9,12 @@ The client supports GET, POST, PUT, DELETE on all the entities available in kube
9
9
  The client currently supports Kubernetes REST api version v1.
10
10
  To learn more about groups and versions in kubernetes refer to [k8s docs](https://kubernetes.io/docs/api/)
11
11
 
12
+ ## VULNERABILITY❗
13
+
14
+ If you use `Kubeclient::Config`, all gem versions released before 2022 could return incorrect `ssl_options[:verify_ssl]`,
15
+ endangering your connection and cluster credentials.
16
+ See https://github.com/ManageIQ/kubeclient/issues/554 for details and which versions got a fix.
17
+
12
18
  ## Installation
13
19
 
14
20
  Add this line to your application's Gemfile:
data/kubeclient.gemspec CHANGED
@@ -14,15 +14,16 @@ Gem::Specification.new do |spec|
14
14
  spec.homepage = 'https://github.com/abonas/kubeclient'
15
15
  spec.license = 'MIT'
16
16
 
17
- spec.files = `git ls-files -z`.split("\x0")
17
+ git_files = `git ls-files -z`.split("\x0")
18
+ spec.files = git_files.grep_v(%r{^(test|spec|features)/})
18
19
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.test_files = []
20
21
  spec.require_paths = ['lib']
21
22
  spec.required_ruby_version = '>= 2.2.0'
22
23
 
23
24
  spec.add_development_dependency 'bundler', '>= 1.6'
24
25
  spec.add_development_dependency 'rake', '~> 12.0'
25
- spec.add_development_dependency 'minitest'
26
+ spec.add_development_dependency 'minitest', '~> 5.15.0'
26
27
  spec.add_development_dependency 'minitest-rg'
27
28
  spec.add_development_dependency 'webmock', '~> 3.0'
28
29
  spec.add_development_dependency 'vcr'
@@ -30,6 +31,9 @@ Gem::Specification.new do |spec|
30
31
  spec.add_development_dependency 'googleauth', '~> 0.5.1'
31
32
  spec.add_development_dependency('mocha', '~> 1.5')
32
33
  spec.add_development_dependency 'openid_connect', '~> 1.1'
34
+ spec.add_development_dependency 'net-smtp'
35
+ # needed on Windows, at least for openid_connect
36
+ spec.add_development_dependency 'tzinfo-data'
33
37
 
34
38
  spec.add_dependency 'jsonpath', '~> 1.0'
35
39
  spec.add_dependency 'rest-client', '~> 2.0'
@@ -78,7 +78,7 @@ module Kubeclient
78
78
  @api_version = version
79
79
  @headers = {}
80
80
  @ssl_options = ssl_options
81
- @auth_options = auth_options
81
+ @auth_options = auth_options.dup
82
82
  @socket_options = socket_options
83
83
  # Allow passing partial timeouts hash, without unspecified
84
84
  # @timeouts[:foo] == nil resulting in infinite timeout.
@@ -87,11 +87,18 @@ module Kubeclient
87
87
  @http_max_redirects = http_max_redirects
88
88
  @as = as
89
89
 
90
- if auth_options[:bearer_token]
91
- bearer_token(@auth_options[:bearer_token])
92
- elsif auth_options[:bearer_token_file]
90
+ @log = Logger.new(STDOUT)
91
+ @log.formatter = proc do |severity, datetime, progname, msg|
92
+ "#{datetime} [#{severity}]: #{msg}\n"
93
+ end
94
+
95
+ if auth_options[:bearer_token_file]
93
96
  validate_bearer_token_file
97
+ @log.info("Reading bearer token from #{@auth_options[:bearer_token_file]}")
94
98
  bearer_token(File.read(@auth_options[:bearer_token_file]))
99
+ elsif auth_options[:bearer_token]
100
+ bearer_token(@auth_options[:bearer_token])
101
+ @log.info("bearer_token_file path not provided. Kubeclient will not be able to refresh the token if it expires")
95
102
  end
96
103
  end
97
104
 
@@ -136,6 +143,11 @@ module Kubeclient
136
143
  @discovered = true
137
144
  end
138
145
 
146
+ def get_headers
147
+ bearer_token(File.read(@auth_options[:bearer_token_file])) if @auth_options[:bearer_token_file]
148
+ @headers
149
+ end
150
+
139
151
  def self.parse_definition(kind, name)
140
152
  # Kubernetes gives us 3 inputs:
141
153
  # kind: "ComponentStatus", "NetworkPolicy", "Endpoints"
@@ -267,8 +279,8 @@ module Kubeclient
267
279
  patch_entity(entity.resource_name, name, patch, 'merge-patch', namespace)
268
280
  end
269
281
 
270
- define_singleton_method("apply_#{entity.method_names[0]}") do |*args|
271
- apply_entity(entity.resource_name, *args)
282
+ define_singleton_method("apply_#{entity.method_names[0]}") do |resource, opts = {}|
283
+ apply_entity(entity.resource_name, resource, **opts)
272
284
  end
273
285
  end
274
286
  end
@@ -349,7 +361,7 @@ module Kubeclient
349
361
  ns_prefix = build_namespace_prefix(options[:namespace])
350
362
  response = handle_exception do
351
363
  rest_client[ns_prefix + resource_name]
352
- .get({ 'params' => params }.merge(@headers))
364
+ .get({ 'params' => params }.merge(get_headers))
353
365
  end
354
366
  format_response(options[:as] || @as, response.body, entity_type)
355
367
  end
@@ -362,7 +374,7 @@ module Kubeclient
362
374
  ns_prefix = build_namespace_prefix(namespace)
363
375
  response = handle_exception do
364
376
  rest_client[ns_prefix + resource_name + "/#{name}"]
365
- .get(@headers)
377
+ .get(get_headers)
366
378
  end
367
379
  format_response(options[:as] || @as, response.body)
368
380
  end
@@ -378,7 +390,7 @@ module Kubeclient
378
390
  rs.options.merge(
379
391
  method: :delete,
380
392
  url: rs.url,
381
- headers: { 'Content-Type' => 'application/json' }.merge(@headers),
393
+ headers: { 'Content-Type' => 'application/json' }.merge(get_headers),
382
394
  payload: payload
383
395
  )
384
396
  )
@@ -400,7 +412,7 @@ module Kubeclient
400
412
  hash[:apiVersion] = @api_group + @api_version
401
413
  response = handle_exception do
402
414
  rest_client[ns_prefix + resource_name]
403
- .post(hash.to_json, { 'Content-Type' => 'application/json' }.merge(@headers))
415
+ .post(hash.to_json, { 'Content-Type' => 'application/json' }.merge(get_headers))
404
416
  end
405
417
  format_response(@as, response.body)
406
418
  end
@@ -410,7 +422,7 @@ module Kubeclient
410
422
  ns_prefix = build_namespace_prefix(entity_config[:metadata][:namespace])
411
423
  response = handle_exception do
412
424
  rest_client[ns_prefix + resource_name + "/#{name}"]
413
- .put(entity_config.to_h.to_json, { 'Content-Type' => 'application/json' }.merge(@headers))
425
+ .put(entity_config.to_h.to_json, { 'Content-Type' => 'application/json' }.merge(get_headers))
414
426
  end
415
427
  format_response(@as, response.body)
416
428
  end
@@ -421,7 +433,7 @@ module Kubeclient
421
433
  rest_client[ns_prefix + resource_name + "/#{name}"]
422
434
  .patch(
423
435
  patch.to_json,
424
- { 'Content-Type' => "application/#{strategy}+json" }.merge(@headers)
436
+ { 'Content-Type' => "application/#{strategy}+json" }.merge(get_headers)
425
437
  )
426
438
  end
427
439
  format_response(@as, response.body)
@@ -434,7 +446,7 @@ module Kubeclient
434
446
  rest_client[ns_prefix + resource_name + "/#{name}"]
435
447
  .patch(
436
448
  resource.to_json,
437
- { 'Content-Type' => 'application/apply-patch+yaml' }.merge(@headers)
449
+ { 'Content-Type' => 'application/apply-patch+yaml' }.merge(get_headers)
438
450
  )
439
451
  end
440
452
  format_response(@as, response.body)
@@ -468,7 +480,7 @@ module Kubeclient
468
480
  ns = build_namespace_prefix(namespace)
469
481
  handle_exception do
470
482
  rest_client[ns + "pods/#{pod_name}/log"]
471
- .get({ 'params' => params }.merge(@headers))
483
+ .get({ 'params' => params }.merge(get_headers))
472
484
  end
473
485
  end
474
486
 
@@ -506,7 +518,7 @@ module Kubeclient
506
518
  ns_prefix = build_namespace_prefix(template[:metadata][:namespace])
507
519
  response = handle_exception do
508
520
  rest_client[ns_prefix + 'processedtemplates']
509
- .post(template.to_h.to_json, { 'Content-Type' => 'application/json' }.merge(@headers))
521
+ .post(template.to_h.to_json, { 'Content-Type' => 'application/json' }.merge(get_headers))
510
522
  end
511
523
  JSON.parse(response)
512
524
  end
@@ -519,7 +531,7 @@ module Kubeclient
519
531
  end
520
532
 
521
533
  def api
522
- response = handle_exception { create_rest_client.get(@headers) }
534
+ response = handle_exception { create_rest_client.get(get_headers) }
523
535
  JSON.parse(response)
524
536
  end
525
537
 
@@ -593,7 +605,7 @@ module Kubeclient
593
605
  end
594
606
 
595
607
  def fetch_entities
596
- JSON.parse(handle_exception { rest_client.get(@headers) })
608
+ JSON.parse(handle_exception { rest_client.get(get_headers) })
597
609
  end
598
610
 
599
611
  def bearer_token(bearer_token)
@@ -638,11 +650,11 @@ module Kubeclient
638
650
  options = {
639
651
  basic_auth_user: @auth_options[:username],
640
652
  basic_auth_password: @auth_options[:password],
641
- headers: @headers,
653
+ headers: get_headers,
642
654
  http_proxy_uri: @http_proxy_uri,
643
655
  http_max_redirects: http_max_redirects
644
656
  }
645
-
657
+ options[:bearer_token_file] = @auth_options[:bearer_token_file] if @auth_options[:bearer_token_file]
646
658
  if uri.scheme == 'https'
647
659
  options[:ssl] = {
648
660
  ca_file: @ssl_options[:ca_file],
@@ -30,7 +30,12 @@ module Kubeclient
30
30
 
31
31
  # Builds Config instance by parsing given file, with lookups relative to file's directory.
32
32
  def self.read(filename)
33
- parsed = YAML.safe_load(File.read(filename), [Date, Time])
33
+ parsed =
34
+ if RUBY_VERSION >= '2.6'
35
+ YAML.safe_load(File.read(filename), permitted_classes: [Date, Time])
36
+ else
37
+ YAML.safe_load(File.read(filename), [Date, Time])
38
+ end
34
39
  Config.new(parsed, File.dirname(filename))
35
40
  end
36
41
 
@@ -46,20 +51,22 @@ module Kubeclient
46
51
  user['exec_result'] = ExecCredentials.run(exec_opts)
47
52
  end
48
53
 
49
- ca_cert_data = fetch_cluster_ca_data(cluster)
50
54
  client_cert_data = fetch_user_cert_data(user)
51
55
  client_key_data = fetch_user_key_data(user)
52
56
  auth_options = fetch_user_auth_options(user)
53
57
 
54
58
  ssl_options = {}
55
59
 
56
- if !ca_cert_data.nil?
60
+ ssl_options[:verify_ssl] = if cluster['insecure-skip-tls-verify'] == true
61
+ OpenSSL::SSL::VERIFY_NONE
62
+ else
63
+ OpenSSL::SSL::VERIFY_PEER
64
+ end
65
+
66
+ if cluster_ca_data?(cluster)
57
67
  cert_store = OpenSSL::X509::Store.new
58
- cert_store.add_cert(OpenSSL::X509::Certificate.new(ca_cert_data))
59
- ssl_options[:verify_ssl] = OpenSSL::SSL::VERIFY_PEER
68
+ populate_cert_store_from_cluster_ca_data(cluster, cert_store)
60
69
  ssl_options[:cert_store] = cert_store
61
- else
62
- ssl_options[:verify_ssl] = OpenSSL::SSL::VERIFY_NONE
63
70
  end
64
71
 
65
72
  unless client_cert_data.nil?
@@ -126,11 +133,16 @@ module Kubeclient
126
133
  [cluster, user, namespace]
127
134
  end
128
135
 
129
- def fetch_cluster_ca_data(cluster)
136
+ def cluster_ca_data?(cluster)
137
+ cluster.key?('certificate-authority') || cluster.key?('certificate-authority-data')
138
+ end
139
+
140
+ def populate_cert_store_from_cluster_ca_data(cluster, cert_store)
130
141
  if cluster.key?('certificate-authority')
131
- File.read(ext_file_path(cluster['certificate-authority']))
142
+ cert_store.add_file(ext_file_path(cluster['certificate-authority']))
132
143
  elsif cluster.key?('certificate-authority-data')
133
- Base64.decode64(cluster['certificate-authority-data'])
144
+ ca_cert_data = Base64.decode64(cluster['certificate-authority-data'])
145
+ cert_store.add_cert(OpenSSL::X509::Certificate.new(ca_cert_data))
134
146
  end
135
147
  end
136
148
 
@@ -1,4 +1,4 @@
1
1
  # Kubernetes REST-API Client
2
2
  module Kubeclient
3
- VERSION = '4.9.1'.freeze
3
+ VERSION = '4.10.0'.freeze
4
4
  end
@@ -79,6 +79,7 @@ module Kubeclient
79
79
  end
80
80
 
81
81
  def build_client_options
82
+ @http_options[:headers][:Authorization] = "Bearer #{File.read(@http_options[:bearer_token_file])}" if @http_options[:bearer_token_file]
82
83
  client_options = {
83
84
  headers: @http_options[:headers],
84
85
  proxy: using_proxy