knife 19.0.128 → 19.0.153

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: eeae2baecd778463ca309c0b348c3c531a2ff534603b7f1d3b5668a60cf460a6
4
- data.tar.gz: 2ed971ba06ff2116df89ba4c20df43a93178eaf53bf80d74a9ddc4a400d49e59
3
+ metadata.gz: 675b2c9066c10c19fae854559b443e565cdd1e7651dd0fdbaeaee1f383f518d7
4
+ data.tar.gz: 67ae10e58e9a658119c51b6ce68e8569dd190d3f6d40d467fe4f0e5acc3704b1
5
5
  SHA512:
6
- metadata.gz: 7c323e72f2c9e1fbe0208ca8416f0ea139486c26ed986b0e81ac182ce9223635cc0d8b0f93d70eb9885e904ee830619027b0e2715690852af64413c82ac6017f
7
- data.tar.gz: 339034783d91f0b83bf0ca27f990ab1b5b5d85acf7a4d7447756a509734017392eabe8f1de18ed77bbb654c3305e5c9c06632c417821e0ccf14984291c1ad40b
6
+ metadata.gz: 1b40981f02af4ab79557a5ac6509748e8f2e7f393398b6cae819807d00bb6824495c0b22250da50d32af29953685440b9d28576253d02e7da6d864db92437080
7
+ data.tar.gz: a11c88e407a5ec99e446616d9d33ae2ae3391415167a24c5ce5bc022f3db114832ed2a4a43b9947564cdde35161fb4708291596a49df9a189998bd356fb6e42c
data/Gemfile CHANGED
@@ -23,7 +23,8 @@ gem "syslog"
23
23
  gem "ostruct"
24
24
  gem "csv"
25
25
  gem "libyajl2", ">= 2.1" # Explicitly require newer version from rubygems.org
26
- gem "mixlib-authentication", "=3.0.10" #Pinning this to a specific version to avoid breaking changes
26
+ gem "faraday", ">= 2.14.3" # Code scan remediation; transitive dep via chef-licensing/inspec-core
27
+ gem "mixlib-authentication", "=3.0.10" # Pinning this to a specific version to avoid breaking changes
27
28
 
28
29
  group :development, :test do
29
30
  gem "cheffish", ">= 14"
@@ -41,3 +42,11 @@ group :omnibus_package, :pry do
41
42
  gem "pry-byebug"
42
43
  gem "pry-stack_explorer"
43
44
  end
45
+
46
+ group :habitat do
47
+ gem "knife-ec2", "~> 2.2.0"
48
+ gem "knife-google", "~> 5.0.17"
49
+ gem "knife-windows", "~> 5.0.7"
50
+ gem "knife-vcenter", "~> 5.0", ">= 5.1.1"
51
+ gem "knife-azure", "~> 5.0"
52
+ end
data/knife.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
21
21
  s.add_dependency "mixlib-cli", ">= 2.1.1", "< 3.0"
22
22
  s.add_dependency "mixlib-archive", ">= 0.4", "< 2.0"
23
23
  s.add_dependency "ffi", ">= 1.15", "< 1.18.0"
24
- s.add_dependency "ffi-yajl", ">= 2.2", "< 4.0"
24
+ s.add_dependency "ffi-yajl", ">= 2.2", "< 3.0"
25
25
  s.add_dependency "net-ssh", ">= 5.1", "< 8"
26
26
  s.add_dependency "net-ssh-multi", "~> 1.2", ">= 1.2.1"
27
27
  s.add_dependency "bcrypt_pbkdf", "~> 1.1" # ed25519 ssh key support
@@ -42,7 +42,7 @@ class Chef
42
42
 
43
43
  all_cookbooks = Chef::CookbookVersion.list
44
44
  cookbooks_names = all_cookbooks.keys.grep(regex)
45
- cookbooks_to_delete = cookbooks_names.inject({}) { |hash, name| hash[name] = all_cookbooks[name]; hash }
45
+ cookbooks_to_delete = cookbooks_names.to_h { |name| [name, all_cookbooks[name]] }
46
46
  ui.msg "All versions of the following cookbooks will be deleted:"
47
47
  ui.msg ""
48
48
  ui.msg ui.list(cookbooks_to_delete.keys.sort, :columns_down)
@@ -64,9 +64,8 @@ class Chef
64
64
  def all_nodes
65
65
  node_uris_by_name = Chef::Node.list
66
66
 
67
- node_uris_by_name.keys.inject({}) do |nodes_by_name, name|
68
- nodes_by_name[name] = Chef::Node.new.tap { |n| n.name(name) }
69
- nodes_by_name
67
+ node_uris_by_name.keys.to_h do |name|
68
+ [name, Chef::Node.new.tap { |n| n.name(name) }]
70
69
  end
71
70
  end
72
71
 
@@ -342,6 +342,14 @@ class Chef
342
342
  command.sub(/^sudo/, "sudo -p 'knife sudo password: '")
343
343
  end
344
344
 
345
+ # Classic sudo prints the -p prompt verbatim. sudo-rs, the default sudo on
346
+ # Ubuntu 25.10 and later, wraps it as "[sudo: <prompt>] Password:".
347
+ SUDO_PASSWORD_PROMPT = /^(\[sudo: )?knife sudo password: /
348
+
349
+ def sudo_password_prompt?(data)
350
+ SUDO_PASSWORD_PROMPT.match?(data)
351
+ end
352
+
345
353
  def print_data(host, data)
346
354
  @buffers ||= {}
347
355
  if (leftover = @buffers[host])
@@ -389,9 +397,12 @@ class Chef
389
397
  raise ArgumentError, "Cannot execute #{command}" unless success
390
398
 
391
399
  ch.on_data do |ichannel, data|
392
- print_data(ichannel.connection[:prefix], data)
393
- if /^knife sudo password: /.match?(data)
394
- print_data(ichannel.connection[:prefix], "\n")
400
+ host = ichannel.connection[:prefix]
401
+ print_data(host, data)
402
+ # Match the unterminated line print_data has buffered rather than
403
+ # this chunk alone: Net::SSH may deliver the prompt in pieces.
404
+ if sudo_password_prompt?(@buffers[host].to_s)
405
+ print_data(host, "\n")
395
406
  ichannel.send_data("#{get_password}\n")
396
407
  end
397
408
  end
@@ -64,11 +64,12 @@ class Chef
64
64
  cr["items"].each do |cookbook|
65
65
  cookbook_collection[cookbook["cookbook_name"]] = cookbook["cookbook"]
66
66
  end
67
- new_start = start + items
68
- if new_start < cr["total"]
69
- get_cookbook_list(items, new_start, cookbook_collection)
70
- else
67
+ new_start = start + cr["items"].length
68
+ # Guard against infinite loop: stop pagination if no items are returned or no progress can be made
69
+ if cr["items"].empty? || new_start >= cr["total"]
71
70
  cookbook_collection
71
+ else
72
+ get_cookbook_list(items, new_start, cookbook_collection)
72
73
  end
73
74
  end
74
75
  end
@@ -78,7 +78,7 @@ class Chef
78
78
  end
79
79
 
80
80
  def disassociate_user(orgs, username)
81
- orgs.each { |org| org.dissociate_user(username) }
81
+ orgs.each { |org| org.dissociate_user(username) }
82
82
  end
83
83
 
84
84
  def org_memberships(username)
@@ -17,6 +17,6 @@
17
17
  class Chef
18
18
  class Knife
19
19
  KNIFE_ROOT = File.expand_path("../..", __dir__)
20
- VERSION = "19.0.128".freeze
20
+ VERSION = "19.0.153".freeze
21
21
  end
22
22
  end
data/lib/chef/knife.rb CHANGED
@@ -541,9 +541,9 @@ class Chef
541
541
  ui.info "Check your knife configuration and network settings"
542
542
  when NameError, NoMethodError
543
543
  ui.error "knife encountered an unexpected error"
544
- ui.info "This may be a bug in the '#{self.class.common_name}' knife command or plugin"
545
- ui.info "Please collect the output of this command with the `-VVV` option before filing a bug report."
546
- ui.info "Exception: #{e.class.name}: #{e.message}"
544
+ ui.info "This may be a bug in the '#{self.class.common_name}' knife command or plugin"
545
+ ui.info "Please collect the output of this command with the `-VVV` option before filing a bug report."
546
+ ui.info "Exception: #{e.class.name}: #{e.message}"
547
547
  when Chef::Exceptions::PrivateKeyMissing
548
548
  ui.error "Your private key could not be loaded from #{api_key}"
549
549
  ui.info "Check your configuration file and ensure that your private key is readable"
@@ -23,6 +23,14 @@ describe Chef::Knife::Core::WindowsBootstrapContext do
23
23
  let(:chef_config) { Chef::Config.save } # "dup" to a hash
24
24
  let(:bootstrap_context) { Chef::Knife::Core::WindowsBootstrapContext.new(config, nil, chef_config, nil) }
25
25
 
26
+ before do
27
+ # Stub path methods to return consistent values across all platforms.
28
+ # On actual Windows (e.g. windows-2025 CI), these methods may resolve
29
+ # to a different drive letter based on the gem installation path.
30
+ allow(ChefConfig::Config).to receive(:etc_chef_dir).with(windows: true).and_return("C:\\chef")
31
+ allow(ChefConfig::Config).to receive(:c_opscode_dir).and_return("C:\\opscode\\chef")
32
+ end
33
+
26
34
  describe "fips" do
27
35
  context "when fips is set" do
28
36
  before do
@@ -282,6 +282,74 @@ describe Chef::Knife::Ssh do
282
282
  end
283
283
  end
284
284
 
285
+ describe "#sudo_password_prompt?" do
286
+ it "recognises the prompt classic sudo prints" do
287
+ expect(@knife.sudo_password_prompt?("knife sudo password: ")).to be true
288
+ end
289
+
290
+ it "recognises the prompt sudo-rs prints" do
291
+ expect(@knife.sudo_password_prompt?("[sudo: knife sudo password: ] Password: ")).to be true
292
+ end
293
+
294
+ it "ignores other output" do
295
+ expect(@knife.sudo_password_prompt?("some command output\n")).to be false
296
+ end
297
+ end
298
+
299
+ describe "#ssh_command answering the sudo password prompt" do
300
+ let(:connection) { { prefix: "foo" } }
301
+ let(:execution_channel) { double(:execution_channel, connection: connection, on_extended_data: nil) }
302
+ let(:session_channel) { double(:session_channel, request_pty: nil) }
303
+ let(:session) { double(:session, loop: nil, close: nil) }
304
+
305
+ before do
306
+ @knife.instance_variable_set(:@longest, connection[:prefix].length)
307
+ allow(@knife.ui).to receive(:msg)
308
+ allow(@knife).to receive(:prompt_for_password).and_return("s3cret")
309
+
310
+ expect(execution_channel)
311
+ .to receive(:on_request)
312
+ .and_yield(nil, double(:data_stream, read_long: 0))
313
+
314
+ expect(session_channel)
315
+ .to receive(:exec)
316
+ .with("sudo -p 'knife sudo password: ' chef-client")
317
+ .and_yield(execution_channel, true)
318
+
319
+ expect(session)
320
+ .to receive(:open_channel)
321
+ .and_yield(session_channel)
322
+ end
323
+
324
+ # Delivers each chunk to the channel's on_data handler in turn, as Net::SSH
325
+ # does when the remote output arrives in several packets.
326
+ def run_with_output(*chunks)
327
+ on_data = expect(execution_channel).to receive(:on_data)
328
+ chunks.each { |chunk| on_data.and_yield(execution_channel, chunk.dup) }
329
+ @knife.ssh_command("sudo chef-client", session)
330
+ end
331
+
332
+ it "sends the password once when the prompt arrives in one chunk" do
333
+ expect(execution_channel).to receive(:send_data).with("s3cret\n").once
334
+ run_with_output("knife sudo password: ")
335
+ end
336
+
337
+ it "sends the password once when the prompt follows other output in the same chunk" do
338
+ expect(execution_channel).to receive(:send_data).with("s3cret\n").once
339
+ run_with_output("Starting Chef Infra Client\nknife sudo password: ")
340
+ end
341
+
342
+ it "sends the password once when the sudo-rs prompt is split across chunks" do
343
+ expect(execution_channel).to receive(:send_data).with("s3cret\n").once
344
+ run_with_output("[sudo: knife sudo pass", "word: ] Password: ")
345
+ end
346
+
347
+ it "does not send the password for ordinary output" do
348
+ expect(execution_channel).not_to receive(:send_data)
349
+ run_with_output("Starting Chef Infra Client\n", "Resolving cookbooks for run list")
350
+ end
351
+ end
352
+
285
353
  describe "#ssh_command" do
286
354
  let(:execution_channel) { double(:execution_channel, on_data: nil, on_extended_data: nil) }
287
355
  let(:session_channel) { double(:session_channel, request_pty: nil) }
@@ -67,4 +67,199 @@ describe Chef::Knife::SupermarketList do
67
67
  end
68
68
  end
69
69
  end
70
+
71
+ describe "pagination" do
72
+ let(:first_page_data) {
73
+ [
74
+ { "cookbook_name" => "cookbook1", "cookbook_maintainer" => "user1", "cookbook_description" => "Test 1", "cookbook" => "https://supermarket.chef.io/api/v1/cookbooks/cookbook1" },
75
+ { "cookbook_name" => "cookbook2", "cookbook_maintainer" => "user2", "cookbook_description" => "Test 2", "cookbook" => "https://supermarket.chef.io/api/v1/cookbooks/cookbook2" },
76
+ ]
77
+ }
78
+
79
+ let(:second_page_data) {
80
+ [
81
+ { "cookbook_name" => "cookbook3", "cookbook_maintainer" => "user3", "cookbook_description" => "Test 3", "cookbook" => "https://supermarket.chef.io/api/v1/cookbooks/cookbook3" },
82
+ { "cookbook_name" => "cookbook4", "cookbook_maintainer" => "user4", "cookbook_description" => "Test 4", "cookbook" => "https://supermarket.chef.io/api/v1/cookbooks/cookbook4" },
83
+ ]
84
+ }
85
+
86
+ let(:third_page_data) {
87
+ [
88
+ { "cookbook_name" => "cookbook5", "cookbook_maintainer" => "user5", "cookbook_description" => "Test 5", "cookbook" => "https://supermarket.chef.io/api/v1/cookbooks/cookbook5" },
89
+ ]
90
+ }
91
+
92
+ before do
93
+ allow(knife.ui).to receive(:stdout).and_return(stdout)
94
+ allow(knife).to receive(:noauth_rest).and_return(noauth_rest)
95
+ knife.configure_chef
96
+ end
97
+
98
+ it "should handle pagination with multiple pages correctly" do
99
+ # First page: 2 items, total is 5
100
+ first_response = {
101
+ "start" => 0,
102
+ "total" => 5,
103
+ "items" => first_page_data,
104
+ }
105
+
106
+ # Second page: 2 items, total is 5
107
+ second_response = {
108
+ "start" => 2,
109
+ "total" => 5,
110
+ "items" => second_page_data,
111
+ }
112
+
113
+ # Third page: 1 item, total is 5 (last page)
114
+ third_response = {
115
+ "start" => 4,
116
+ "total" => 5,
117
+ "items" => third_page_data,
118
+ }
119
+
120
+ # Verify that the API is called with correct parameters for each page
121
+ expect(noauth_rest).to receive(:get)
122
+ .with("https://supermarket.chef.io/api/v1/cookbooks?items=9999999&start=0")
123
+ .and_return(first_response)
124
+ expect(noauth_rest).to receive(:get)
125
+ .with("https://supermarket.chef.io/api/v1/cookbooks?items=9999999&start=2")
126
+ .and_return(second_response)
127
+ expect(noauth_rest).to receive(:get)
128
+ .with("https://supermarket.chef.io/api/v1/cookbooks?items=9999999&start=4")
129
+ .and_return(third_response)
130
+
131
+ result = knife.get_cookbook_list
132
+ expect(result.keys).to eq(%w{cookbook1 cookbook2 cookbook3 cookbook4 cookbook5})
133
+ end
134
+
135
+ it "should calculate next_start correctly based on cr[\"items\"].length" do
136
+ # When items returned is less than the items parameter, next_start should be based on actual items returned
137
+ first_response = {
138
+ "start" => 0,
139
+ "total" => 3,
140
+ "items" => first_page_data, # 2 items returned
141
+ }
142
+
143
+ second_response = {
144
+ "start" => 2,
145
+ "total" => 3,
146
+ "items" => [third_page_data[0]], # 1 item in second page (last page)
147
+ }
148
+
149
+ expect(noauth_rest).to receive(:get)
150
+ .with("https://supermarket.chef.io/api/v1/cookbooks?items=9999999&start=0")
151
+ .and_return(first_response)
152
+ expect(noauth_rest).to receive(:get)
153
+ .with("https://supermarket.chef.io/api/v1/cookbooks?items=9999999&start=2")
154
+ .and_return(second_response)
155
+
156
+ result = knife.get_cookbook_list
157
+ expect(result.length).to eq(3)
158
+ expect(result.keys).to eq(%w{cookbook1 cookbook2 cookbook5})
159
+ end
160
+
161
+ it "should respect sort_by parameter across pages" do
162
+ knife.config[:sort_by] = "recently_updated"
163
+
164
+ first_response = {
165
+ "start" => 0,
166
+ "total" => 4,
167
+ "items" => first_page_data,
168
+ }
169
+
170
+ second_response = {
171
+ "start" => 2,
172
+ "total" => 4,
173
+ "items" => second_page_data[0..1], # Last 2 items
174
+ }
175
+
176
+ expect(noauth_rest).to receive(:get)
177
+ .with("https://supermarket.chef.io/api/v1/cookbooks?items=9999999&start=0&order=recently_updated")
178
+ .and_return(first_response)
179
+ expect(noauth_rest).to receive(:get)
180
+ .with("https://supermarket.chef.io/api/v1/cookbooks?items=9999999&start=2&order=recently_updated")
181
+ .and_return(second_response)
182
+
183
+ result = knife.get_cookbook_list
184
+ expect(result.length).to eq(4)
185
+ end
186
+
187
+ it "should respect owned_by parameter across pages" do
188
+ knife.config[:owned_by] = "testuser"
189
+
190
+ first_response = {
191
+ "start" => 0,
192
+ "total" => 2,
193
+ "items" => first_page_data,
194
+ }
195
+
196
+ expect(noauth_rest).to receive(:get)
197
+ .with("https://supermarket.chef.io/api/v1/cookbooks?items=9999999&start=0&user=testuser")
198
+ .and_return(first_response)
199
+
200
+ result = knife.get_cookbook_list
201
+ expect(result.length).to eq(2)
202
+ end
203
+
204
+ it "should handle single page result (no pagination needed)" do
205
+ single_response = {
206
+ "start" => 0,
207
+ "total" => 2,
208
+ "items" => first_page_data,
209
+ }
210
+
211
+ expect(noauth_rest).to receive(:get)
212
+ .with("https://supermarket.chef.io/api/v1/cookbooks?items=9999999&start=0")
213
+ .and_return(single_response)
214
+
215
+ result = knife.get_cookbook_list
216
+ expect(result.length).to eq(2)
217
+ end
218
+
219
+ it "should handle empty result" do
220
+ empty_response = {
221
+ "start" => 0,
222
+ "total" => 0,
223
+ "items" => [],
224
+ }
225
+
226
+ expect(noauth_rest).to receive(:get)
227
+ .with("https://supermarket.chef.io/api/v1/cookbooks?items=9999999&start=0")
228
+ .and_return(empty_response)
229
+
230
+ result = knife.get_cookbook_list
231
+ expect(result).to eq({})
232
+ end
233
+
234
+ it "should handle empty page in pagination (regression test for infinite loop)" do
235
+ # This regression test ensures pagination stops when an empty page is returned,
236
+ # preventing infinite recursion if the API returns empty items but total > start
237
+ first_response = {
238
+ "start" => 0,
239
+ "total" => 4,
240
+ "items" => first_page_data, # 2 items
241
+ }
242
+
243
+ # Second page returns empty items but total still indicates more results
244
+ # This should NOT cause infinite recursion
245
+ second_response = {
246
+ "start" => 2,
247
+ "total" => 4,
248
+ "items" => [], # Empty array - the edge case
249
+ }
250
+
251
+ expect(noauth_rest).to receive(:get)
252
+ .with("https://supermarket.chef.io/api/v1/cookbooks?items=9999999&start=0")
253
+ .and_return(first_response)
254
+ expect(noauth_rest).to receive(:get)
255
+ .with("https://supermarket.chef.io/api/v1/cookbooks?items=9999999&start=2")
256
+ .and_return(second_response)
257
+ # Should only call the API twice, not infinitely
258
+
259
+ result = knife.get_cookbook_list
260
+ # Should return only the items from the first page
261
+ expect(result.keys).to eq(%w{cookbook1 cookbook2})
262
+ expect(result.length).to eq(2)
263
+ end
264
+ end
70
265
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife
3
3
  version: !ruby/object:Gem::Version
4
- version: 19.0.128
4
+ version: 19.0.153
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Jacob
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-06-17 00:00:00.000000000 Z
11
+ date: 2026-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: train-core
@@ -133,7 +133,7 @@ dependencies:
133
133
  version: '2.2'
134
134
  - - "<"
135
135
  - !ruby/object:Gem::Version
136
- version: '4.0'
136
+ version: '3.0'
137
137
  type: :runtime
138
138
  prerelease: false
139
139
  version_requirements: !ruby/object:Gem::Requirement
@@ -143,7 +143,7 @@ dependencies:
143
143
  version: '2.2'
144
144
  - - "<"
145
145
  - !ruby/object:Gem::Version
146
- version: '4.0'
146
+ version: '3.0'
147
147
  - !ruby/object:Gem::Dependency
148
148
  name: net-ssh
149
149
  requirement: !ruby/object:Gem::Requirement
@@ -1144,7 +1144,7 @@ metadata:
1144
1144
  homepage_uri: https://www.chef.io
1145
1145
  mailing_list_uri: https://discourse.chef.io/
1146
1146
  source_code_uri: https://github.com/chef/knife/
1147
- post_install_message:
1147
+ post_install_message:
1148
1148
  rdoc_options: []
1149
1149
  require_paths:
1150
1150
  - lib
@@ -1160,7 +1160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1160
1160
  version: '0'
1161
1161
  requirements: []
1162
1162
  rubygems_version: 3.3.27
1163
- signing_key:
1163
+ signing_key:
1164
1164
  specification_version: 4
1165
1165
  summary: The knife CLI for Chef Infra.
1166
1166
  test_files: []