kettle-family 1.3.40 → 1.3.41

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: c098ede3aba44cf7502174188e54bdef47ca178395c21ae55255c34f7a5d06f2
4
- data.tar.gz: 9c8e473a1f5dd87b428d3be04402d930d20977ed4bf18fadbb81a39d65024b0d
3
+ metadata.gz: c447f402b39dce0119480390f5387a010ce81d6f3a317181bfa60b23a2558a8b
4
+ data.tar.gz: 1fe9cbe8c6bafefeb2056be1327b15f9911d3ba44abd70d71802fd985be1e3cb
5
5
  SHA512:
6
- metadata.gz: abed8faf333eed49004c382fa053a08d9c1acc2a24249427aa829f8a67f1adcc7d7e3c18cc10cac4f88f4fb049a4969439724e8cbc83b1fe2a39ba7c5df6b3c5
7
- data.tar.gz: 2afa7e58df348b02a5c5386d7ce43a550891483ed1b1c654b465ae968d840bbfa0b4c14b66e4d114025c7a5575b0c481f768e74ba5f8d6920b2c1f9e5d496f40
6
+ metadata.gz: d7934dce11df54417a7e8d3aeda4c1a76125b27af6f3d2f8d23b1b386c2229f50e3740404f7fd208be8392f7f443cf4e0a47286d9d2345fac25b1fba4b1cf0ca
7
+ data.tar.gz: 7893ecc55408679881af1dc077669aedda8e2b021261fc7babc24cf62520708ee044c9965da834054e9b2bafc03432814f0aa56d54da7102c5d798a5be7c377d
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -30,6 +30,26 @@ Please file a bug if you notice a violation of semantic versioning.
30
30
 
31
31
  ### Security
32
32
 
33
+ ## [1.3.41] - 2026-11-10
34
+
35
+ - TAG: [v1.3.41][1.3.41t]
36
+ - COVERAGE: 93.68% -- 7991/8530 lines in 45 files
37
+ - BRANCH COVERAGE: 77.96% -- 3222/4133 branches in 45 files
38
+ - 40.73% documented
39
+
40
+ ### Added
41
+
42
+ - Pluggable release secrets adapters: `Secrets::Registry` selects a provider by name and third parties can register their own. Built-in adapters share one `CliAdapter` engine: `1password` (`op`), `bitwarden` (aliases `bw`, `vaultwarden`), `rbw`, and a generic `command` adapter that runs one configured command per secret without a shell. An adapter that cannot supply a secret (unsupported operation, or access not approved such as a locked vault) falls back to asking at the terminal without echo. (#35, #36)
43
+
44
+ ### Changed
45
+
46
+ - The release secrets broker no longer depends on 1Password wording: adapters raise `Secrets::AuthorizationError` when access is not approved. After such a failure, requests already queued fail at once with one clear message instead of each raising its own prompt (previously one member failed per minute). The signing passphrase is read once; the RubyGems OTP is always fetched fresh. (#35, #36)
47
+ - When several release members fail at the same resume step, the report prints one merged `--only a,b,c [--start-step N]` command instead of one line per member. (#32, #34)
48
+
49
+ ### Fixed
50
+
51
+ - Parallel release waves no longer race to install Bundler into the shared gem dir: each Bundler version named by members' `BUNDLED WITH`, plus the newest stable, is installed once, serially, before the fan-out. (#33, #34)
52
+
33
53
  ## [1.3.40] - 2026-11-09
34
54
 
35
55
  - TAG: [v1.3.40][1.3.40t]
@@ -3398,7 +3418,9 @@ Please file a bug if you notice a violation of semantic versioning.
3398
3418
  - Fixed CI load failures on engines without compatible `pty` support by falling back to Open3 for interactive release commands.
3399
3419
  - Fixed Ruby 3.2 version-bump support by loading Prism lazily and wiring the Prism gem only for MRI versions that need it.
3400
3420
 
3401
- [Unreleased]: https://github.com/kettle-dev/kettle-family/compare/v1.3.40...HEAD
3421
+ [Unreleased]: https://github.com/kettle-dev/kettle-family/compare/v1.3.41...HEAD
3422
+ [1.3.41]: https://github.com/kettle-dev/kettle-family/compare/v1.3.40...v1.3.41
3423
+ [1.3.41t]: https://github.com/kettle-dev/kettle-family/releases/tag/v1.3.41
3402
3424
  [1.3.40]: https://github.com/kettle-dev/kettle-family/compare/v1.3.39...v1.3.40
3403
3425
  [1.3.40t]: https://github.com/kettle-dev/kettle-family/releases/tag/v1.3.40
3404
3426
  [1.3.39]: https://github.com/kettle-dev/kettle-family/compare/v1.3.38...v1.3.39
data/README.md CHANGED
@@ -434,6 +434,25 @@ release:
434
434
  rubygems_otp_field: one-time password
435
435
  ```
436
436
 
437
+ Other providers are pluggable adapters, selected the same way. For
438
+ Bitwarden-compatible tools (Bitwarden `bw`, Vaultwarden), unlock first with
439
+ `export BW_SESSION=$(bw unlock --raw)`:
440
+
441
+ ```yaml
442
+ release:
443
+ secrets:
444
+ provider: bitwarden # also: bw, vaultwarden, rbw, command
445
+ item: Rubygems # item that holds the TOTP
446
+ gem_signing_passphrase_field: GEM-SIGN-PASSPHRASE # custom field on that item
447
+ ```
448
+
449
+ `provider: command` runs one configured command per secret (no shell), for any
450
+ other tool: set `gem_signing_passphrase_command` and `rubygems_otp_command`.
451
+ Anything an adapter cannot supply (an unsupported secret, or access not
452
+ approved, such as a locked vault) is asked for at the terminal instead, without
453
+ echo. The OTP is always fetched fresh; the signing passphrase is read once.
454
+ Custom adapters register with `Kettle::Family::Secrets::Registry.register`.
455
+
437
456
  Use `--secrets-provider 1password` to opt in explicitly for a release run, or
438
457
  `--secrets-provider interactive` to force prompts even when the family config
439
458
  has a provider configured. Family publish runs pass `--yes` to child
@@ -1091,7 +1110,7 @@ If none of the available licenses suit your use case, please [contact us](mailto
1091
1110
  [📌gitmoji]: https://gitmoji.dev
1092
1111
  [📌gitmoji-img]: https://img.shields.io/badge/gitmoji_commits-%20%F0%9F%98%9C%20%F0%9F%98%8D-34495e.svg?style=flat-square
1093
1112
  [🧮kloc]: https://www.youtube.com/watch?v=dQw4w9WgXcQ
1094
- [🧮kloc-img]: https://img.shields.io/badge/KLOC-8.369-FFDD67.svg?style=for-the-badge&logo=YouTube&logoColor=blue
1113
+ [🧮kloc-img]: https://img.shields.io/badge/KLOC-8.530-FFDD67.svg?style=for-the-badge&logo=YouTube&logoColor=blue
1095
1114
  [🔐security]: https://github.com/kettle-dev/kettle-family/blob/main/SECURITY.md
1096
1115
  [🔐security-img]: https://img.shields.io/badge/security-policy-259D6C.svg?style=flat
1097
1116
  [📄copyright-notice-explainer]: https://opensource.stackexchange.com/questions/5778/why-do-licenses-such-as-the-mit-license-specify-a-single-year
@@ -700,7 +700,7 @@ module Kettle
700
700
  option :skip_bundle_audit, long: "--skip-bundle-audit", desc: "Skip bundle:audit/update during release rake checks"
701
701
  option :skip_remotes, long: "--skip-remotes", value: {type: String, usage: "LIST"}, desc: "Pass a comma-separated git remote skip list through to kettle-release commands"
702
702
  option :required_remotes, long: "--required-remotes", value: {type: String, usage: "LIST"}, desc: "Pass a comma-separated required git remote list through to kettle-release commands"
703
- option :secrets_provider, long: "--secrets-provider", value: {type: String, usage: "NAME"}, desc: "Release secrets provider: interactive, 1password"
703
+ option :secrets_provider, long: "--secrets-provider", value: {type: String, usage: "NAME"}, desc: "Release secrets provider: interactive, 1password, bitwarden (bw, vaultwarden), rbw, command"
704
704
  option :no_auto_floors, long: "--no-auto-floors", desc: "Do not raise family dependency floors between member releases" do
705
705
  options[:no_auto_floors] = true
706
706
  end
@@ -794,13 +794,39 @@ module Kettle
794
794
  end
795
795
 
796
796
  def release_resume_hints
797
- failed_hints = visible_results.reject(&:ok?).filter_map { |result| resume_hint_for(result) }.uniq
797
+ failed_hints = merged_release_failure_hints(visible_results.reject(&:ok?))
798
798
  pending_names = summary_pending.map { |entry| entry.fetch("member") }
799
799
  return failed_hints if pending_names.empty?
800
800
 
801
801
  [*failed_hints, release_resume_hint_for_pending(pending_names)]
802
802
  end
803
803
 
804
+ # Members within a wave run in parallel, so failures that need the same
805
+ # resume step share one command (--only a,b,c) instead of one line each.
806
+ # Results carrying a bespoke resume_command are kept verbatim.
807
+ def merged_release_failure_hints(failures)
808
+ groups = {}
809
+ order = []
810
+ failures.each do |result|
811
+ custom = result.respond_to?(:resume_command) && !result.resume_command.to_s.empty?
812
+ if custom || result.member_name.nil? || result.phase == "aggregate_github_release"
813
+ hint = release_resume_hint(result)
814
+ order << [:raw, hint] if hint && !order.include?([:raw, hint])
815
+ next
816
+ end
817
+ step = result.respond_to?(:resume_step) ? result.resume_step : nil
818
+ key = [:group, step]
819
+ order << key unless groups.key?(key)
820
+ (groups[key] ||= []) << result.member_name
821
+ end
822
+ order.map do |kind, value|
823
+ next value if kind == :raw
824
+
825
+ hint = "#{release_resume_base} --only #{groups[[kind, value]].uniq.join(",")}"
826
+ value ? "#{hint} --start-step #{value}" : hint
827
+ end
828
+ end
829
+
804
830
  def resume_hint_for(result)
805
831
  return release_resume_hint(result) if command == "release"
806
832
  return "kettle-family #{command}" if family_root_phase?(result.phase)
@@ -1,5 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "io/console"
4
+ require "json"
5
+ require "shellwords"
6
+
3
7
  begin
4
8
  require "kettle/dev"
5
9
  rescue LoadError
@@ -8,44 +12,38 @@ end
8
12
 
9
13
  module Kettle
10
14
  module Family
15
+ # Reopened (same superclass as family.rb) because this file loads first and
16
+ # defines error subclasses at load time.
17
+ class Error < StandardError; end
18
+
11
19
  module Secrets
12
- if defined?(Kettle::Dev::ReleaseSecrets)
13
- Kettle::Dev.const_set(:Error, Class.new(StandardError)) unless Kettle::Dev.const_defined?(:Error, false)
14
- Provider = Kettle::Dev::ReleaseSecrets::Provider
20
+ # Adapter contract (see Registry): an adapter is any object that responds
21
+ # to gem_signing_passphrase and rubygems_otp, returning a String, or nil
22
+ # when it has no value (the family then falls back to prompting the
23
+ # user). It may define supports?(operation) to declare gaps up front,
24
+ # authorize! for an eager preflight check, and should raise
25
+ # AuthorizationError when the user has not approved access (so queued
26
+ # requests fail fast) and Error for any other failure.
27
+ OPERATIONS = %i[gem_signing_passphrase rubygems_otp].freeze
15
28
 
16
- class OnePassword < Kettle::Dev::ReleaseSecrets::OnePassword
17
- def self.configured?(name)
18
- Kettle::Dev::ReleaseSecrets::OnePassword.configured?(name)
19
- end
29
+ class AuthorizationError < Error; end
20
30
 
21
- def authorize!
22
- with_release_secret_alert_suppressed { gem_signing_passphrase }
23
- rescue => error
24
- raise Error, error.message
25
- end
31
+ class UnsupportedOperation < Error; end
26
32
 
27
- def gem_signing_passphrase
28
- super
29
- rescue => error
30
- raise Error, error.message
31
- end
33
+ def self.supports?(provider, operation)
34
+ return provider.supports?(operation.to_sym) if provider.respond_to?(:supports?)
32
35
 
33
- def rubygems_otp
34
- with_release_secret_alert_suppressed { super }
35
- rescue => error
36
- raise Error, error.message
37
- end
36
+ true
37
+ end
38
38
 
39
- private
39
+ # The default Provider returns no secrets: every secret is prompted for.
40
+ def self.interactive?(provider)
41
+ provider.instance_of?(Provider)
42
+ end
40
43
 
41
- def with_release_secret_alert_suppressed
42
- previous = ENV.fetch("KETTLE_RELEASE_SECRET_ALERT", nil)
43
- ENV["KETTLE_RELEASE_SECRET_ALERT"] = "false"
44
- yield
45
- ensure
46
- previous.nil? ? ENV.delete("KETTLE_RELEASE_SECRET_ALERT") : ENV["KETTLE_RELEASE_SECRET_ALERT"] = previous
47
- end
48
- end
44
+ if defined?(Kettle::Dev::ReleaseSecrets)
45
+ Kettle::Dev.const_set(:Error, Class.new(StandardError)) unless Kettle::Dev.const_defined?(:Error, false)
46
+ Provider = Kettle::Dev::ReleaseSecrets::Provider
49
47
  else
50
48
  class Provider
51
49
  def authorize!
@@ -60,106 +58,376 @@ module Kettle
60
58
  nil
61
59
  end
62
60
  end
61
+ end
63
62
 
64
- class OnePassword < Provider
65
- PROVIDER_NAMES = %w[1password onepassword op].freeze
66
- DEFAULTS = {
67
- "item" => "Rubygems",
68
- "gem_signing_passphrase_field" => "GEM-SIGN-PASSPHRASE",
69
- "rubygems_otp_field" => "one-time password"
70
- }.freeze
63
+ # Asks the user at the family terminal, without echo. Used by the broker
64
+ # when an adapter cannot supply a secret. Only constructed when stdin is
65
+ # a terminal, so unattended runs are never left waiting on input.
66
+ class TerminalPrompter
67
+ LABELS = {
68
+ "gem_signing_passphrase" => "Gem signing passphrase",
69
+ "rubygems_otp" => "RubyGems MFA code"
70
+ }.freeze
71
+
72
+ def initialize(input: $stdin, output: $stderr)
73
+ @input = input
74
+ @output = output
75
+ end
71
76
 
72
- def self.configured?(name)
73
- PROVIDER_NAMES.include?(name.to_s.downcase)
74
- end
77
+ def self.for_terminal(input: $stdin, output: $stderr)
78
+ new(input: input, output: output) if input.respond_to?(:tty?) && input.tty?
79
+ end
75
80
 
76
- def initialize(config)
77
- @config = DEFAULTS.merge(config || {})
81
+ def ask(operation:, reason: nil)
82
+ @output.puts("#{reason}; enter it manually.") if reason
83
+ @output.print("#{LABELS.fetch(operation, operation)}: ")
84
+ @output.flush
85
+ value = if @input.respond_to?(:noecho)
86
+ @input.noecho(&:gets)
87
+ else
88
+ @input.gets
78
89
  end
90
+ @output.puts
91
+ value.to_s.chomp
92
+ end
93
+ end
79
94
 
80
- def gem_signing_passphrase
81
- reference = string_config("gem_signing_passphrase_reference")
82
- return read_reference(reference) unless reference.empty?
95
+ # Shared engine for adapters that shell out to a vault CLI. A subclass says
96
+ # *what* to run (argv_for), how its tool words "access not approved"
97
+ # (error_class_for) and how to name itself in messages (label); this class
98
+ # does the running, the error reporting and the supports?/authorize! plumbing.
99
+ # Every built-in (1Password, Bitwarden, rbw, generic command) goes through
100
+ # it, so each one exercises the same config and error handling.
101
+ class CliAdapter < Provider
102
+ def initialize(config)
103
+ super()
104
+ @config = config || {}
105
+ end
83
106
 
84
- item_field("gem_signing_passphrase_field")
85
- end
107
+ def supports?(operation)
108
+ !argv_for(operation.to_sym).nil?
109
+ end
86
110
 
87
- def authorize!
88
- gem_signing_passphrase
111
+ # Eager preflight: loading the signing passphrase proves access (and is
112
+ # what the workflow stores for signing). Nil when it is unsupported.
113
+ def authorize!
114
+ supports?(:gem_signing_passphrase) ? gem_signing_passphrase : nil
115
+ end
116
+
117
+ # Each call runs the CLI; there is no session to keep alive.
118
+ def keepalive_required?
119
+ false
120
+ end
121
+
122
+ def keepalive!(elapsed: nil)
123
+ true
124
+ end
125
+
126
+ def gem_signing_passphrase
127
+ fetch(:gem_signing_passphrase)
128
+ end
129
+
130
+ def rubygems_otp
131
+ fetch(:rubygems_otp)
132
+ end
133
+
134
+ private
135
+
136
+ attr_reader :config
137
+
138
+ # Array of argv, or nil when this adapter cannot supply the operation.
139
+ def argv_for(_operation)
140
+ nil
141
+ end
142
+
143
+ def purpose_for(operation)
144
+ operation.to_s.tr("_", " ")
145
+ end
146
+
147
+ def label
148
+ self.class.name.to_s.split("::").last
149
+ end
150
+
151
+ # Subclasses map their tool's "locked / not signed in / prompt dismissed"
152
+ # wording to AuthorizationError so the family can fall back to asking.
153
+ def error_class_for(_details)
154
+ Error
155
+ end
156
+
157
+ def postprocess(_operation, stdout)
158
+ stdout
159
+ end
160
+
161
+ def fetch(operation)
162
+ argv = argv_for(operation)
163
+ return nil if argv.nil?
164
+
165
+ stdout, stderr, status = Open3.capture3(*argv)
166
+ value = postprocess(operation, stdout.to_s.strip).to_s.strip
167
+ return value if status.success? && !value.empty?
168
+
169
+ details = stderr.to_s.strip
170
+ details = (status.success? ? "returned no value" : "#{argv.first} exited #{status.exitstatus}") if details.empty?
171
+ raise error_class_for(details), "#{label} #{purpose_for(operation)} lookup failed: #{details}"
172
+ rescue Errno::ENOENT
173
+ raise Error, "#{label} CLI executable `#{argv&.first}` was not found"
174
+ end
175
+
176
+ def setting(key)
177
+ config.fetch(key, "").to_s.strip
178
+ end
179
+
180
+ def required_setting(key)
181
+ value = setting(key)
182
+ raise Error, "#{label} release secrets require release.secrets.#{key}" if value.empty?
183
+
184
+ value
185
+ end
186
+
187
+ def account_args
188
+ account = setting("account")
189
+ account.empty? ? [] : ["--account", account]
190
+ end
191
+ end
192
+
193
+ # Generic adapter: one configured command per secret, no shell. Works with
194
+ # any CLI that prints the secret on stdout (pass, a script, ...). An
195
+ # operation without a configured command is unsupported, and the family
196
+ # prompts the user for it instead.
197
+ #
198
+ # release:
199
+ # secrets:
200
+ # provider: command
201
+ # gem_signing_passphrase_command: pass show rubygems/signing
202
+ # rubygems_otp_command: pass otp rubygems
203
+ class Command < CliAdapter
204
+ NAMES = %w[command cli].freeze
205
+
206
+ def self.configured?(name)
207
+ NAMES.include?(name.to_s.downcase)
208
+ end
209
+
210
+ private
211
+
212
+ def argv_for(operation)
213
+ command = setting("#{operation}_command")
214
+ command.empty? ? nil : Shellwords.split(command)
215
+ end
216
+
217
+ def label
218
+ "Command"
219
+ end
220
+ end
221
+
222
+ # 1Password CLI (`op`). Approval failures (dismissed prompt, locked or
223
+ # unreachable app) are recognised so the family can fall back to asking.
224
+ class OnePassword < CliAdapter
225
+ PROVIDER_NAMES = %w[1password onepassword op].freeze
226
+ DEFAULTS = {
227
+ "item" => "Rubygems",
228
+ "gem_signing_passphrase_field" => "GEM-SIGN-PASSPHRASE",
229
+ "rubygems_otp_field" => "one-time password"
230
+ }.freeze
231
+ AUTHORIZATION_FAILURE = /authoriz|dismissed|desktop app|connection reset|not signed in|session expired/i
232
+
233
+ def self.configured?(name)
234
+ PROVIDER_NAMES.include?(name.to_s.downcase)
235
+ end
236
+
237
+ def initialize(config)
238
+ super(DEFAULTS.merge(config || {}))
239
+ end
240
+
241
+ private
242
+
243
+ def label
244
+ "1Password"
245
+ end
246
+
247
+ def cli
248
+ setting("cli").empty? ? "op" : setting("cli")
249
+ end
250
+
251
+ def argv_for(operation)
252
+ case operation
253
+ when :gem_signing_passphrase
254
+ reference = setting("gem_signing_passphrase_reference")
255
+ return [cli, "read", reference, *account_args] unless reference.empty?
256
+
257
+ [cli, "item", "get", required_setting("item"), "--fields",
258
+ "label=#{required_setting("gem_signing_passphrase_field")}", "--reveal", *account_args]
259
+ when :rubygems_otp
260
+ reference = setting("rubygems_otp_reference")
261
+ return [cli, "read", reference, *account_args] unless reference.empty?
262
+
263
+ [cli, "item", "get", required_setting("item"), "--otp", *account_args]
89
264
  end
265
+ end
90
266
 
91
- def rubygems_otp
92
- reference = string_config("rubygems_otp_reference")
93
- return read_reference(reference) unless reference.empty?
94
-
95
- item = required_config("item")
96
- argv = ["op", "item", "get", item, "--otp"]
97
- account = string_config("account")
98
- argv.concat(["--account", account]) unless account.empty?
99
- run_op(argv, purpose: "RubyGems OTP")
267
+ def purpose_for(operation)
268
+ if operation == :gem_signing_passphrase
269
+ setting("gem_signing_passphrase_reference").empty? ? "gem signing passphrase field" : "secret reference"
270
+ else
271
+ setting("rubygems_otp_reference").empty? ? "RubyGems OTP" : "secret reference"
100
272
  end
273
+ end
274
+
275
+ def error_class_for(details)
276
+ details.match?(AUTHORIZATION_FAILURE) ? AuthorizationError : Error
277
+ end
278
+ end
101
279
 
102
- private
280
+ # Bitwarden-compatible CLIs (Bitwarden `bw`, Vaultwarden via `bw`).
281
+ # Unlock first and export the session: `export BW_SESSION=$(bw unlock --raw)`.
282
+ #
283
+ # release:
284
+ # secrets:
285
+ # provider: bitwarden
286
+ # item: Rubygems # item holding the TOTP
287
+ # gem_signing_passphrase_field: GEM-SIGN-PASSPHRASE # custom field on that item
288
+ # # or: gem_signing_passphrase_item: gem-signing (its password)
289
+ # # cli: bw
290
+ class Bitwarden < CliAdapter
291
+ NAMES = %w[bitwarden bw vaultwarden].freeze
292
+ DEFAULTS = {
293
+ "item" => "Rubygems",
294
+ "gem_signing_passphrase_field" => "GEM-SIGN-PASSPHRASE"
295
+ }.freeze
296
+ LOCKED = /locked|not logged in|session|unauthenticated|BW_SESSION/i
297
+
298
+ def self.configured?(name)
299
+ NAMES.include?(name.to_s.downcase)
300
+ end
103
301
 
104
- attr_reader :config
302
+ def initialize(config)
303
+ super(DEFAULTS.merge(config || {}))
304
+ end
105
305
 
106
- def item_field(field_key)
107
- item = required_config("item")
108
- field = required_config(field_key)
109
- argv = ["op", "item", "get", item, "--fields", "label=#{field}", "--reveal"]
110
- account = string_config("account")
111
- argv.concat(["--account", account]) unless account.empty?
112
- run_op(argv, purpose: field_key.tr("_", " "))
113
- end
306
+ private
114
307
 
115
- def read_reference(reference)
116
- argv = ["op", "read", reference]
117
- account = string_config("account")
118
- argv.concat(["--account", account]) unless account.empty?
119
- run_op(argv, purpose: "secret reference")
308
+ def label
309
+ "Bitwarden"
310
+ end
311
+
312
+ def cli
313
+ setting("cli").empty? ? "bw" : setting("cli")
314
+ end
315
+
316
+ def argv_for(operation)
317
+ item = setting("item")
318
+ case operation
319
+ when :rubygems_otp
320
+ [cli, "get", "totp", item] unless item.empty?
321
+ when :gem_signing_passphrase
322
+ password_item = setting("gem_signing_passphrase_item")
323
+ return [cli, "get", "password", password_item] unless password_item.empty?
324
+
325
+ [cli, "get", "item", item] unless item.empty? || setting("gem_signing_passphrase_field").empty?
120
326
  end
327
+ end
328
+
329
+ def postprocess(operation, stdout)
330
+ return stdout unless operation == :gem_signing_passphrase && setting("gem_signing_passphrase_item").empty?
331
+
332
+ field = setting("gem_signing_passphrase_field")
333
+ found = Array(JSON.parse(stdout)["fields"]).find { |entry| entry["name"] == field }
334
+ found ? found["value"].to_s : ""
335
+ rescue JSON::ParserError
336
+ ""
337
+ end
121
338
 
122
- def run_op(argv, purpose:)
123
- stdout, stderr, status = Open3.capture3(*argv)
124
- return stdout.to_s.strip if status.success? && !stdout.to_s.strip.empty?
339
+ def error_class_for(details)
340
+ details.match?(LOCKED) ? AuthorizationError : Error
341
+ end
342
+ end
343
+
344
+ # rbw (unofficial Bitwarden CLI with an agent).
345
+ #
346
+ # provider: rbw
347
+ # item: Rubygems
348
+ # gem_signing_passphrase_field: GEM-SIGN-PASSPHRASE
349
+ class Rbw < CliAdapter
350
+ NAMES = %w[rbw].freeze
351
+ DEFAULTS = {"item" => "Rubygems", "gem_signing_passphrase_field" => "GEM-SIGN-PASSPHRASE"}.freeze
352
+
353
+ def self.configured?(name)
354
+ NAMES.include?(name.to_s.downcase)
355
+ end
125
356
 
126
- details = stderr.to_s.strip
127
- details = "op exited #{status.exitstatus}" if details.empty?
128
- raise Error, "1Password #{purpose} lookup failed: #{details}"
129
- rescue Errno::ENOENT
130
- raise Error, "1Password CLI executable `op` was not found"
357
+ def initialize(config)
358
+ super(DEFAULTS.merge(config || {}))
359
+ end
360
+
361
+ private
362
+
363
+ def label
364
+ "rbw"
365
+ end
366
+
367
+ def argv_for(operation)
368
+ item = setting("item")
369
+ return nil if item.empty?
370
+
371
+ case operation
372
+ when :rubygems_otp
373
+ ["rbw", "code", item]
374
+ when :gem_signing_passphrase
375
+ field = setting("gem_signing_passphrase_field")
376
+ ["rbw", "get", item, "--field", field] unless field.empty?
131
377
  end
378
+ end
379
+
380
+ def error_class_for(details)
381
+ details.match?(/locked|not logged in|agent|pinentry/i) ? AuthorizationError : Error
382
+ end
383
+ end
132
384
 
133
- def required_config(key)
134
- value = string_config(key)
135
- raise Error, "1Password release secrets require release.secrets.#{key}" if value.empty?
385
+ # Adapter registry. Third parties (or future built-ins) register a
386
+ # builder that receives the release.secrets config hash:
387
+ #
388
+ # Kettle::Family::Secrets::Registry.register("bitwarden") { |config| MyAdapter.new(config) }
389
+ module Registry
390
+ BUILDERS = {}
391
+ LOCK = Mutex.new
392
+
393
+ class << self
394
+ def register(*names, &builder)
395
+ LOCK.synchronize { names.flatten.each { |name| BUILDERS[name.to_s.downcase] = builder } }
396
+ end
136
397
 
137
- value
398
+ def builder_for(name)
399
+ LOCK.synchronize { BUILDERS[name.to_s.downcase] }
138
400
  end
139
401
 
140
- def string_config(key)
141
- config.fetch(key, "").to_s
402
+ def names
403
+ LOCK.synchronize { BUILDERS.keys.sort }
142
404
  end
143
405
  end
144
406
  end
145
407
 
408
+ Registry.register("1password", "onepassword", "op") do |config|
409
+ if defined?(Kettle::Dev::ReleaseSecrets)
410
+ OnePassword.new(Kettle::Dev::ReleaseSecrets::Factory.env_config.merge(config))
411
+ else
412
+ OnePassword.new(config)
413
+ end
414
+ end
415
+ Registry.register(*Command::NAMES) { |config| Command.new(config) }
416
+ Registry.register(*Bitwarden::NAMES) { |config| Bitwarden.new(config) }
417
+ Registry.register(*Rbw::NAMES) { |config| Rbw.new(config) }
418
+
146
419
  class Factory
147
420
  def self.build(config:, override_provider: nil)
148
- if defined?(Kettle::Dev::ReleaseSecrets)
149
- secrets_config = config.release_secrets
150
- provider_name = override_provider.to_s.empty? ? secrets_config.fetch("provider", nil) : override_provider
151
- return Provider.new if provider_name.to_s.empty? || provider_name.to_s == "interactive"
152
- return OnePassword.new(Kettle::Dev::ReleaseSecrets::Factory.env_config.merge(secrets_config)) if OnePassword.configured?(provider_name)
153
-
154
- raise Error, "unsupported release secrets provider #{provider_name.inspect}"
155
- end
156
-
157
421
  secrets_config = config.release_secrets
158
422
  provider_name = override_provider.to_s.empty? ? secrets_config.fetch("provider", nil) : override_provider
159
423
  return Provider.new if provider_name.to_s.empty? || provider_name.to_s == "interactive"
160
- return OnePassword.new(secrets_config) if OnePassword.configured?(provider_name)
161
424
 
162
- raise Error, "unsupported release secrets provider #{provider_name.inspect}"
425
+ builder = Registry.builder_for(provider_name)
426
+ unless builder
427
+ raise Error, "unsupported release secrets provider #{provider_name.inspect} (available: interactive, #{Registry.names.join(", ")})"
428
+ end
429
+
430
+ builder.call(secrets_config)
163
431
  rescue => error
164
432
  if defined?(Kettle::Dev::Error) && error.is_a?(Kettle::Dev::Error)
165
433
  raise Error, error.message
@@ -19,8 +19,9 @@ module Kettle
19
19
 
20
20
  attr_reader :path
21
21
 
22
- def initialize(provider:, root:)
22
+ def initialize(provider:, root:, prompter: nil)
23
23
  @provider = provider
24
+ @prompter = prompter
24
25
  directory = File.join(root, "tmp", "kettle-family")
25
26
  basename = "secrets-#{SecureRandom.hex(8)}.sock"
26
27
  @path = File.join(directory, basename)
@@ -46,6 +47,8 @@ module Kettle
46
47
  FileUtils.mkdir_p(directory, mode: 0o700)
47
48
  @mutex = Mutex.new
48
49
  @closed = false
50
+ @cached = {}
51
+ @authorization_failure = nil
49
52
  end
50
53
 
51
54
  def start
@@ -85,12 +88,59 @@ module Kettle
85
88
  raise
86
89
  end
87
90
 
91
+ # Requests are serialized. Each failed approval prompt can take about a
92
+ # minute to time out, so without this every queued member would raise
93
+ # its own prompt in turn and fail one by one. A request that was already
94
+ # waiting when approval failed fails immediately with the same message;
95
+ # requests arriving afterwards may prompt again (the user may be back).
96
+ # The signing passphrase is static, so it is cached after one lookup.
97
+ # The OTP is a short-lived TOTP and is always fetched fresh.
98
+ def resolve(operation, requested_at:)
99
+ @mutex.synchronize do
100
+ return @cached.fetch(operation) if @cached.key?(operation)
101
+
102
+ failure = @authorization_failure
103
+ raise Error, failure.fetch(:message) if failure && requested_at <= failure.fetch(:at)
104
+
105
+ value = lookup(operation)
106
+ @cached[operation] = value if operation == "gem_signing_passphrase"
107
+ value
108
+ end
109
+ end
110
+
111
+ # Adapter first; the user is asked only where the adapter cannot help:
112
+ # it does not support the operation, returned nothing, or access was not
113
+ # approved. Without a terminal to ask on, those cases keep their
114
+ # original behavior (blank value, or the adapter's error).
115
+ def lookup(operation)
116
+ unless Secrets.supports?(provider, operation)
117
+ return prompt_user(operation, "this secrets provider does not support #{operation.tr("_", " ")}") ||
118
+ +""
119
+ end
120
+
121
+ provider.public_send(operation)
122
+ rescue AuthorizationError => error
123
+ message = "#{error.message} (approve the access prompt, then resume the release)"
124
+ typed = prompt_user(operation, error.message)
125
+ return typed if typed
126
+
127
+ @authorization_failure = {at: Process.clock_gettime(Process::CLOCK_MONOTONIC), message: message}
128
+ raise Error, message
129
+ end
130
+
131
+ def prompt_user(operation, reason)
132
+ return nil unless @prompter && !Secrets.interactive?(provider)
133
+
134
+ value = @prompter.ask(operation: operation, reason: reason)
135
+ value.to_s.empty? ? nil : value
136
+ end
137
+
88
138
  def handle(connection)
89
139
  request = JSON.parse(connection.gets.to_s)
90
140
  operation = request.fetch("operation")
91
141
  raise Error, "unsupported release secrets broker operation #{operation.inspect}" unless OPERATIONS.include?(operation)
92
142
 
93
- value = @mutex.synchronize { provider.public_send(operation) }
143
+ value = resolve(operation, requested_at: Process.clock_gettime(Process::CLOCK_MONOTONIC))
94
144
  connection.write(JSON.generate("ok" => true, "value" => value.to_s))
95
145
  connection.write("\n")
96
146
  rescue => error
@@ -5,7 +5,7 @@ module Kettle
5
5
  # Version namespace for this gem.
6
6
  module Version
7
7
  # Current gem version.
8
- VERSION = "1.3.40"
8
+ VERSION = "1.3.41"
9
9
  end
10
10
  # Current gem version exposed at the traditional constant location.
11
11
  VERSION = Version::VERSION # Traditional Constant Location
@@ -212,7 +212,7 @@ module Kettle
212
212
  def with_release_secrets_broker
213
213
  return yield unless release_secrets_broker_required?
214
214
 
215
- @release_secrets_broker = Secrets::Broker.new(provider: @secrets_provider, root: config.root).start
215
+ @release_secrets_broker = Secrets::Broker.new(provider: @secrets_provider, root: config.root, prompter: Secrets::TerminalPrompter.for_terminal).start
216
216
  yield
217
217
  ensure
218
218
  @release_secrets_broker&.close
@@ -2316,7 +2316,7 @@ module Kettle
2316
2316
  end
2317
2317
 
2318
2318
  def release_secrets_authorization_required?
2319
- @secrets_provider.is_a?(Secrets::OnePassword)
2319
+ !Secrets.interactive?(@secrets_provider)
2320
2320
  end
2321
2321
 
2322
2322
  def release_preflight_error_result(phase, message, member: nil)
@@ -2555,7 +2555,36 @@ module Kettle
2555
2555
  results
2556
2556
  end
2557
2557
 
2558
+ # Parallel members race to install Bundler into the shared gem dir: each
2559
+ # `bundle lock/update` auto-installs the version in its lockfile's
2560
+ # BUNDLED WITH, and `update --bundler=X` installs the newest stable.
2561
+ # Concurrent installs leave half-written gems (LoadError on
2562
+ # bundler/definition, rubygems_ext, ...). Install every needed version
2563
+ # once, serially, before the fan-out.
2564
+ def prewarm_bundlers_once(wave, wave_jobs)
2565
+ return if wave_jobs <= 1
2566
+
2567
+ versions = wave.flat_map { |member| bundled_with_versions(member) }
2568
+ versions << stable_bundler_version&.to_s
2569
+ versions = versions.compact.uniq - (@prewarmed_bundlers ||= [])
2570
+ versions.each do |version|
2571
+ next if system("gem", "list", "-i", "bundler", "-v", version, out: File::NULL, err: File::NULL)
2572
+
2573
+ system("gem", "install", "bundler", "-v", version, "--no-document", out: File::NULL, err: File::NULL)
2574
+ end
2575
+ @prewarmed_bundlers.concat(versions)
2576
+ end
2577
+
2578
+ def bundled_with_versions(member)
2579
+ Dir.glob(File.join(member.root, "{Gemfile,Appraisal.root.gemfile,gemfiles/*.gemfile}.lock")).filter_map do |lock|
2580
+ File.read(lock)[/^BUNDLED WITH\n\s+(\d[\w.]*)\s*$/, 1]
2581
+ end.uniq
2582
+ rescue SystemCallError
2583
+ []
2584
+ end
2585
+
2558
2586
  def run_release_wave(wave, wave_jobs: release_jobs(wave))
2587
+ prewarm_bundlers_once(wave, wave_jobs)
2559
2588
  queue = Queue.new
2560
2589
  wave.each_with_index { |member, index| queue << [index, member] }
2561
2590
  ordered_results = Array.new(wave.length)
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kettle-family
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.40
4
+ version: 1.3.41
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter H. Boling
@@ -628,10 +628,10 @@ licenses:
628
628
  - AGPL-3.0-only
629
629
  metadata:
630
630
  homepage_uri: https://structuredmerge.org
631
- source_code_uri: https://github.com/kettle-dev/kettle-family/tree/v1.3.40
632
- changelog_uri: https://github.com/kettle-dev/kettle-family/blob/v1.3.40/CHANGELOG.md
631
+ source_code_uri: https://github.com/kettle-dev/kettle-family/tree/v1.3.41
632
+ changelog_uri: https://github.com/kettle-dev/kettle-family/blob/v1.3.41/CHANGELOG.md
633
633
  bug_tracker_uri: https://github.com/kettle-dev/kettle-family/issues
634
- documentation_uri: https://www.rubydoc.info/gems/kettle-family/1.3.40
634
+ documentation_uri: https://www.rubydoc.info/gems/kettle-family/1.3.41
635
635
  funding_uri: https://github.com/sponsors/pboling
636
636
  wiki_uri: https://github.com/kettle-dev/kettle-family/wiki
637
637
  news_uri: https://www.railsbling.com/tags/kettle-family
metadata.gz.sig CHANGED
Binary file