kubesealr 0.1.0 → 0.1.4

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
  SHA256:
3
- metadata.gz: 35b04586dd5c804bf697478a11e919da402c87519cdb22bc940c9060b0b07792
4
- data.tar.gz: cfba159bc9ce48fbe5add4a7640bfb3edfa1f66a79617855e22784e5fa60aaf9
3
+ metadata.gz: fbb5b323fccfd16bf9def64effd750701802ac652cbb1103041d4a1add260700
4
+ data.tar.gz: 0f5703b58200f864f4b67540eb7c459b5f5bf0740734ddcec87bfb19890af21b
5
5
  SHA512:
6
- metadata.gz: 5b199eef47106927b95b724393e1d4bd9bf003bdad5c13b3251b58e600c3afcac53d9824d2c2e922ef8dc1b0ac848acbd7404f8600a7b5f5769b65c49802a9bf
7
- data.tar.gz: 41a52d3229fda407fa074cffae4b8b1af562182142d54c664bce35ae52493f5693d6343d638644bbb729b3f36fd931dbd89c4cdfbae4eed8c1c7a98107034ad9
6
+ metadata.gz: e8b38ebdda58c849a445e2f545e1302f654d90eaf958d9c695567ca0b7b0f1c60e20afedc81d324541e947273191a2d7db3fc6bd45e3e342a5f470da48c9cc95
7
+ data.tar.gz: e3eb7c1c043d254884289f277925e8f14f3ade87378792597c7d679d2cb391f4c56233b14c652397a99f4ccff4390dfc424b22678e535c2d88d30411a3da0c12
data/.gitignore CHANGED
@@ -6,6 +6,7 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ /vendor/
9
10
 
10
11
  # rspec failure tracking
11
12
  .rspec_status
data/Gemfile CHANGED
@@ -7,8 +7,7 @@ gemspec
7
7
 
8
8
  # override dep resolution to fix Ruby 3.0 support
9
9
  # (libs dependent on this lib must do this on their own)
10
- gem 'k8s-ruby', github: 'tsutsu/k8s-ruby', branch: 'fork-master'
11
- gem 'recursive-open-struct', github: 'tsutsu/recursive-open-struct', branch: 'fix-ruby3-support'
10
+ # gem 'k8s-ruby', github: 'tsutsu/k8s-ruby', branch: 'fork-master'
12
11
 
13
12
  # development dependencies
14
13
  gem 'rake', '~> 13.0'
data/Gemfile.lock CHANGED
@@ -1,70 +1,55 @@
1
- GIT
2
- remote: https://github.com/tsutsu/k8s-ruby.git
3
- revision: 177ba953169f32b6b40b85eedae85659825381b5
4
- branch: fork-master
5
- specs:
6
- k8s-ruby (0.10.5)
7
- dry-struct (~> 1.3.0)
8
- dry-types (~> 1.4.0)
9
- excon (~> 0.78)
10
- hashdiff (~> 1.0.1)
11
- jsonpath (~> 1.1.0)
12
- recursive-open-struct (~> 1.1.3)
13
- yajl-ruby (~> 1.4.1)
14
- yaml-safe_load_stream2 (~> 0.1)
15
-
16
- GIT
17
- remote: https://github.com/tsutsu/recursive-open-struct.git
18
- revision: 1467ac3107582ab32de016fa320c1e204b10a1af
19
- branch: fix-ruby3-support
20
- specs:
21
- recursive-open-struct (1.1.3)
22
-
23
1
  PATH
24
2
  remote: .
25
3
  specs:
26
- kubesealr (0.1.0)
27
- k8s-ruby
4
+ kubesealr (0.1.4)
5
+ k8s-ruby2 (~> 0.10.7)
28
6
  openssl-oaep
29
7
 
30
8
  GEM
31
9
  remote: https://rubygems.org/
32
10
  specs:
33
- concurrent-ruby (1.1.7)
11
+ concurrent-ruby (1.1.9)
34
12
  diff-lcs (1.4.4)
35
- dry-configurable (0.12.0)
13
+ dry-configurable (0.13.0)
36
14
  concurrent-ruby (~> 1.0)
37
- dry-core (~> 0.5, >= 0.5.0)
38
- dry-container (0.7.2)
15
+ dry-core (~> 0.6)
16
+ dry-container (0.9.0)
39
17
  concurrent-ruby (~> 1.0)
40
- dry-configurable (~> 0.1, >= 0.1.3)
41
- dry-core (0.5.0)
18
+ dry-configurable (~> 0.13, >= 0.13.0)
19
+ dry-core (0.7.1)
42
20
  concurrent-ruby (~> 1.0)
43
- dry-equalizer (0.3.0)
44
- dry-inflector (0.2.0)
45
- dry-logic (1.1.0)
21
+ dry-inflector (0.2.1)
22
+ dry-logic (1.2.0)
46
23
  concurrent-ruby (~> 1.0)
47
24
  dry-core (~> 0.5, >= 0.5)
48
- dry-struct (1.3.0)
49
- dry-core (~> 0.4, >= 0.4.4)
50
- dry-equalizer (~> 0.3)
51
- dry-types (~> 1.3)
25
+ dry-struct (1.4.0)
26
+ dry-core (~> 0.5, >= 0.5)
27
+ dry-types (~> 1.5)
52
28
  ice_nine (~> 0.11)
53
- dry-types (1.4.0)
29
+ dry-types (1.5.1)
54
30
  concurrent-ruby (~> 1.0)
55
31
  dry-container (~> 0.3)
56
- dry-core (~> 0.4, >= 0.4.4)
57
- dry-equalizer (~> 0.3)
32
+ dry-core (~> 0.5, >= 0.5)
58
33
  dry-inflector (~> 0.1, >= 0.1.2)
59
34
  dry-logic (~> 1.0, >= 1.0.2)
60
- excon (0.78.1)
35
+ excon (0.88.0)
61
36
  hashdiff (1.0.1)
62
37
  ice_nine (0.11.2)
63
38
  jsonpath (1.1.0)
64
39
  multi_json
40
+ k8s-ruby2 (0.10.7)
41
+ dry-struct (~> 1.4.0)
42
+ dry-types (~> 1.5.0)
43
+ excon (~> 0.78)
44
+ hashdiff (~> 1.0.1)
45
+ jsonpath (~> 1.1.0)
46
+ recursive-open-struct (~> 1.1.3)
47
+ yajl-ruby (~> 1.4.1)
48
+ yaml-safe_load_stream2 (~> 0.1.1)
65
49
  multi_json (1.15.0)
66
50
  openssl-oaep (0.1.0)
67
- rake (13.0.3)
51
+ rake (13.0.6)
52
+ recursive-open-struct (1.1.3)
68
53
  rspec (3.10.0)
69
54
  rspec-core (~> 3.10.0)
70
55
  rspec-expectations (~> 3.10.0)
@@ -74,22 +59,20 @@ GEM
74
59
  rspec-expectations (3.10.1)
75
60
  diff-lcs (>= 1.2.0, < 2.0)
76
61
  rspec-support (~> 3.10.0)
77
- rspec-mocks (3.10.1)
62
+ rspec-mocks (3.10.2)
78
63
  diff-lcs (>= 1.2.0, < 2.0)
79
64
  rspec-support (~> 3.10.0)
80
- rspec-support (3.10.1)
65
+ rspec-support (3.10.2)
81
66
  yajl-ruby (1.4.1)
82
67
  yaml-safe_load_stream2 (0.1.1)
83
68
 
84
69
  PLATFORMS
85
- x86_64-darwin-20
70
+ ruby
86
71
 
87
72
  DEPENDENCIES
88
- k8s-ruby!
89
73
  kubesealr!
90
74
  rake (~> 13.0)
91
- recursive-open-struct!
92
75
  rspec (~> 3.0)
93
76
 
94
77
  BUNDLED WITH
95
- 2.2.5
78
+ 2.2.30
data/kubesealr.gemspec CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
  EOF
18
18
  spec.homepage = "https://github.com/tsutsu/kubesealr"
19
19
  spec.license = "MIT"
20
- spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
20
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
21
21
 
22
22
  spec.metadata["homepage_uri"] = spec.homepage
23
23
  spec.metadata["source_code_uri"] = spec.homepage
@@ -31,6 +31,6 @@ Gem::Specification.new do |spec|
31
31
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
32
  spec.require_paths = ["lib"]
33
33
 
34
- spec.add_runtime_dependency 'k8s-ruby'
34
+ spec.add_runtime_dependency 'k8s-ruby2', '~> 0.10.7'
35
35
  spec.add_runtime_dependency 'openssl-oaep'
36
36
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Kubeseal
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.4"
5
5
  end
data/lib/kubeseal.rb CHANGED
@@ -10,11 +10,12 @@ require 'kubeseal/version'
10
10
 
11
11
  class Kubeseal
12
12
  DEFAULT_KEY_FETCHER = lambda do |_|
13
- raise NotImplementedError, "no cert getter passed"
13
+ raise NotImplementedError, "no cluster key-fetcher passed"
14
14
  end
15
15
 
16
- def initialize(&cluster_sealer_key_fetcher)
17
- @cluster_sealer_key_fetcher = cluster_sealer_key_fetcher || DEFAULT_KEY_FETCHER
16
+ def initialize(key_fetcher: nil, resealer: nil)
17
+ @cluster_sealer_key_fetcher = key_fetcher || DEFAULT_KEY_FETCHER
18
+ @cluster_sealer_resealer = resealer
18
19
  end
19
20
 
20
21
  def cluster_sealer_public_key
@@ -94,7 +95,6 @@ class Kubeseal
94
95
  )
95
96
  end
96
97
 
97
- private
98
98
  def seal(plaintext, scope_label)
99
99
  cs_pubkey = self.cluster_sealer_public_key
100
100
 
@@ -126,7 +126,6 @@ class Kubeseal
126
126
  ciphertext_parts.pack('S>A*A*')
127
127
  end
128
128
 
129
- private
130
129
  def unseal(ciphertext, scope_label)
131
130
  cs_privkeys_to_try = self.cluster_sealer_private_keys.dup
132
131
 
@@ -168,6 +167,47 @@ class Kubeseal
168
167
  plaintext
169
168
  end
170
169
 
170
+ def reseal(...)
171
+ if @cluster_sealer_resealer
172
+ reseal_serverside(...)
173
+ else
174
+ reseal_clientside(...)
175
+ end
176
+ end
177
+
178
+ def reseal_clientside(ciphertext, scope_label)
179
+ plaintext = unseal(ciphertext, scope_label)
180
+ seal(plaintext, scope_label)
181
+ end
182
+
183
+ def reseal_serverside(ciphertext, scope_label)
184
+ rc_namespace, rc_name, scope =
185
+ case scope_label.split('/', 2)
186
+ in []
187
+ ["dummy", "dummy", :"cluster-wide"]
188
+ in [ns]
189
+ [ns, "dummy", :"namespace-wide"]
190
+ in [ns, name]
191
+ [ns, name, :strict]
192
+ end
193
+
194
+ rc = build_sealed_secret_rc(
195
+ rc_namespace,
196
+ rc_name,
197
+ 'Opaque',
198
+ armor({'dummy' => ciphertext}, strict: true)
199
+ )
200
+ rc = patch_with_scope(rc, scope)
201
+
202
+ resealed_rc = reseal_wrapped_serverside(rc)
203
+
204
+ Base64.decode64(resealed_rc.dig('spec', 'encryptedData', 'dummy'))
205
+ end
206
+
207
+ def reseal_wrapped_serverside(sealed_secret_rc)
208
+ YAML.load(@cluster_sealer_resealer.call(sealed_secret_rc.to_yaml))
209
+ end
210
+
171
211
  private
172
212
  def label_for(scope, rc_namespace, rc_name)
173
213
  case scope
@@ -248,8 +288,12 @@ class Kubeseal
248
288
  end
249
289
  end
250
290
 
251
- def armor(h)
252
- (h || {}).map{ |k, v| [k, Base64.encode64(v)] }.to_h
291
+ def armor(h, strict: false)
292
+ if strict
293
+ (h || {}).map{ |k, v| [k, Base64.strict_encode64(v)] }.to_h
294
+ else
295
+ (h || {}).map{ |k, v| [k, Base64.encode64(v)] }.to_h
296
+ end
253
297
  end
254
298
 
255
299
  def unarmor(h)
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kubesealr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Levi Aul
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-20 00:00:00.000000000 Z
11
+ date: 2021-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: k8s-ruby
14
+ name: k8s-ruby2
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 0.10.7
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 0.10.7
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: openssl-oaep
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -78,14 +78,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
78
78
  requirements:
79
79
  - - ">="
80
80
  - !ruby/object:Gem::Version
81
- version: 2.7.0
81
+ version: 2.6.0
82
82
  required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  requirements:
84
84
  - - ">="
85
85
  - !ruby/object:Gem::Version
86
86
  version: '0'
87
87
  requirements: []
88
- rubygems_version: 3.2.3
88
+ rubygems_version: 3.2.22
89
89
  signing_key:
90
90
  specification_version: 4
91
91
  summary: K8s sealed-secret client and KustomizeR transformer