chef 14.11.21 → 14.12.3

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: 6f798de1b307dfa70ca1ce581c1a2d47848e045fb0b8ffd2560bee57617e5360
4
- data.tar.gz: 0e3deab54bb4e0876692ccb8b693fa81c524c1f367d12b8687cda83527a334c0
3
+ metadata.gz: c48c84f4c9683a3913e28858cd0e9d07aef8c3c04d4ccde07208c1ce63e87cb7
4
+ data.tar.gz: c0d67ba3df47d13b9cc636cc248c99e40e42153a84c171a14d5f146ba47fbcde
5
5
  SHA512:
6
- metadata.gz: c0ab56ed0fd49314cd2fb22bb9f3fda2765ba137e971aa865670059d5a0c674e9cdb61b8347f0776bf1115172b285c53394a898efa5840ec0728b9fb9e906fa9
7
- data.tar.gz: ed3ac08a4ff1204800ce95f1480dd2545e0a51114d09c7c83b779392a4673dddb0799e5b16a6a269d74b85bf051b78974f0e7d6a234e7c584958407ffacd4047
6
+ metadata.gz: '031997455ace5bfe53d929e08648a6c2a1faadcd7082d27cd2ba5c6b6114bfeeb664f45ac20fba8fa0b2e41f446632960ab269a65169f6aeb41ed2601970dc1f'
7
+ data.tar.gz: 2e5a32afd33b95d1d8091317937de26c51571e7d489eaac40c163ac0bdd5310873007e196bf9fd164e12e908ed34888d44575d028d384e91a3160f18f45a8ca0
data/Gemfile CHANGED
@@ -58,10 +58,6 @@ group(:development, :test) do
58
58
  gem "chefstyle", "=0.11.2"
59
59
  end
60
60
 
61
- group(:travis) do
62
- gem "travis"
63
- end
64
-
65
61
  instance_eval(ENV["GEMFILE_MOD"]) if ENV["GEMFILE_MOD"]
66
62
 
67
63
  # If you want to load debugging tools into the bundle exec sandbox,
@@ -5,18 +5,17 @@ gemspec.platform = Gem::Platform.new(%w{universal mingw32})
5
5
  gemspec.add_dependency "win32-api", "~> 1.5.3"
6
6
  gemspec.add_dependency "win32-dir", "~> 0.5.0"
7
7
  gemspec.add_dependency "win32-event", "~> 0.6.1"
8
- # TODO: Relax this pin and make the necessary updaets. The issue originally
8
+ # TODO: Relax this pin and make the necessary updates. The issue originally
9
9
  # leading to this pin has been fixed in 0.6.5.
10
10
  gemspec.add_dependency "win32-eventlog", "0.6.3"
11
11
  gemspec.add_dependency "win32-mmap", "~> 0.4.1"
12
12
  gemspec.add_dependency "win32-mutex", "~> 0.4.2"
13
13
  gemspec.add_dependency "win32-process", "~> 0.8.2"
14
- gemspec.add_dependency "win32-service", "~> 1.0"
15
- gemspec.add_dependency "windows-api", "~> 0.4.4"
14
+ gemspec.add_dependency "win32-service", ">= 1.0", "< 3.0"
16
15
  gemspec.add_dependency "wmi-lite", "~> 1.0"
17
16
  gemspec.add_dependency "win32-taskscheduler", "~> 2.0"
18
17
  gemspec.add_dependency "iso8601", "~> 0.12.1"
19
- gemspec.add_dependency "win32-certstore", "~> 0.2.4"
18
+ gemspec.add_dependency "win32-certstore", "~> 0.3"
20
19
  gemspec.extensions << "ext/win32-eventlog/Rakefile"
21
20
  gemspec.files += Dir.glob("{distro,ext}/**/*")
22
21
 
@@ -17,10 +17,10 @@ Gem::Specification.new do |s|
17
17
 
18
18
  s.add_dependency "chef-config", "= #{Chef::VERSION}"
19
19
 
20
- s.add_dependency "mixlib-cli", "~> 1.7"
21
- s.add_dependency "mixlib-log", "~> 2.0", ">= 2.0.3"
20
+ s.add_dependency "mixlib-cli", ">= 1.7", "< 3.0"
21
+ s.add_dependency "mixlib-log", ">= 2.0.3", "< 4.0"
22
22
  s.add_dependency "mixlib-authentication", "~> 2.1"
23
- s.add_dependency "mixlib-shellout", "~> 2.4"
23
+ s.add_dependency "mixlib-shellout", ">= 2.4", "< 4.0"
24
24
  s.add_dependency "mixlib-archive", ">= 0.4", "< 2.0"
25
25
  s.add_dependency "ohai", "~> 14.0"
26
26
 
@@ -218,12 +218,12 @@ class Chef::Application::Solo < Chef::Application
218
218
  # Get this party started
219
219
  def run
220
220
  setup_signal_handlers
221
+ setup_application
221
222
  reconfigure
222
223
  for_ezra if Chef::Config[:ez]
223
224
  if !Chef::Config[:solo_legacy_mode]
224
225
  Chef::Application::Client.new.run
225
226
  else
226
- setup_application
227
227
  run_application
228
228
  end
229
229
  end
@@ -83,22 +83,7 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service
83
83
 
84
84
  def start_service
85
85
  if Win32::Service.exists?(@new_resource.service_name)
86
- # reconfiguration is idempotent, so just do it.
87
- new_config = {
88
- service_name: @new_resource.service_name,
89
- service_start_name: @new_resource.run_as_user,
90
- password: @new_resource.run_as_password,
91
- }.reject { |k, v| v.nil? || v.length == 0 }
92
-
93
- Win32::Service.configure(new_config)
94
- logger.info "#{@new_resource} configured."
95
-
96
- # LocalSystem is the default runas user, which is a special service account that should ultimately have the rights of BUILTIN\Administrators, but we wouldn't see that from get_account_right
97
- if new_config.key?(:service_start_name) && new_config[:service_start_name].casecmp("localsystem") != 0
98
- unless Chef::ReservedNames::Win32::Security.get_account_right(canonicalize_username(new_config[:service_start_name])).include?(SERVICE_RIGHT)
99
- grant_service_logon(new_config[:service_start_name])
100
- end
101
- end
86
+ configure_service_run_as_properties
102
87
 
103
88
  state = current_state
104
89
  if state == RUNNING
@@ -281,6 +266,21 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service
281
266
 
282
267
  private
283
268
 
269
+ def configure_service_run_as_properties
270
+ return unless new_resource.property_is_set?(:run_as_user)
271
+
272
+ new_config = {
273
+ service_name: new_resource.service_name,
274
+ service_start_name: new_resource.run_as_user,
275
+ password: new_resource.run_as_password,
276
+ }.reject { |k, v| v.nil? || v.length == 0 }
277
+
278
+ Win32::Service.configure(new_config)
279
+ logger.info "#{new_resource} configured."
280
+
281
+ grant_service_logon(new_resource.run_as_user) if new_resource.run_as_user.casecmp("localsystem") != 0
282
+ end
283
+
284
284
  def current_delayed_start
285
285
  if service = Win32::Service.services.find { |x| x.service_name == new_resource.service_name }
286
286
  service.delayed_start == 0 ? false : true
@@ -290,6 +290,8 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service
290
290
  end
291
291
 
292
292
  def grant_service_logon(username)
293
+ return if Chef::ReservedNames::Win32::Security.get_account_right(canonicalize_username(username)).include?(SERVICE_RIGHT)
294
+
293
295
  begin
294
296
  Chef::ReservedNames::Win32::Security.add_account_right(canonicalize_username(username), SERVICE_RIGHT)
295
297
  rescue Chef::Exceptions::Win32APIError => err
@@ -62,22 +62,9 @@ class Chef
62
62
 
63
63
  # Extension of the certificate
64
64
  ext = ::File.extname(new_resource.source)
65
- cert_obj = fetch_cert_object(ext) # Fetch OpenSSL::X509::Certificate object
66
- thumbprint = OpenSSL::Digest::SHA1.new(cert_obj.to_der).to_s # Fetch its thumbprint
67
65
 
68
- # Need to check if return value is Boolean:true
69
- # If not then the given certificate should be added in certstore
70
- if verify_cert(thumbprint) == true
71
- Chef::Log.debug("Certificate is already present")
72
- else
73
- converge_by("Adding certificate #{new_resource.source} into Store #{new_resource.store_name}") do
74
- if ext == ".pfx"
75
- add_pfx_cert
76
- else
77
- add_cert(cert_obj)
78
- end
79
- end
80
- end
66
+ # PFX certificates contains private keys and we import them with some other aproach
67
+ import_certificates(fetch_cert_object(ext), (ext == ".pfx"))
81
68
  end
82
69
 
83
70
  # acl_add is a modify-if-exists operation : not idempotent
@@ -272,7 +259,7 @@ class Chef
272
259
  set_acl_script
273
260
  end
274
261
 
275
- # Method returns an OpenSSL::X509::Certificate object
262
+ # Method returns an OpenSSL::X509::Certificate object. Might also return multiple certificates if present in certificate path
276
263
  #
277
264
  # Based on its extension, the certificate contents are used to initialize
278
265
  # PKCS12 (PFX), PKCS7 (P7B) objects which contains OpenSSL::X509::Certificate.
@@ -295,9 +282,14 @@ class Chef
295
282
 
296
283
  case ext
297
284
  when ".pfx"
298
- OpenSSL::PKCS12.new(contents, new_resource.pfx_password).certificate
285
+ pfx = OpenSSL::PKCS12.new(contents, new_resource.pfx_password)
286
+ if pfx.ca_certs.nil?
287
+ pfx.certificate
288
+ else
289
+ [pfx.certificate] + pfx.ca_certs
290
+ end
299
291
  when ".p7b"
300
- OpenSSL::PKCS7.new(contents).certificates.first
292
+ OpenSSL::PKCS7.new(contents).certificates
301
293
  else
302
294
  OpenSSL::X509::Certificate.new(contents)
303
295
  end
@@ -308,6 +300,32 @@ class Chef
308
300
  def binary_cert?
309
301
  powershell_out!("file -b --mime-encoding #{new_resource.source}").stdout.strip == "binary"
310
302
  end
303
+
304
+ # Imports the certificate object into cert store
305
+ #
306
+ # @param cert_objs [OpenSSL::X509::Certificate] Object containing certificate's attributes
307
+ #
308
+ # @param is_pfx [Boolean] true if we want to import a PFX certificate
309
+ #
310
+ def import_certificates(cert_objs, is_pfx)
311
+ [cert_objs].flatten.each do |cert_obj|
312
+ thumbprint = OpenSSL::Digest::SHA1.new(cert_obj.to_der).to_s # Fetch its thumbprint
313
+
314
+ # Need to check if return value is Boolean:true
315
+ # If not then the given certificate should be added in certstore
316
+ if verify_cert(thumbprint) == true
317
+ Chef::Log.debug("Certificate is already present")
318
+ else
319
+ converge_by("Adding certificate #{new_resource.source} into Store #{new_resource.store_name}") do
320
+ if is_pfx
321
+ add_pfx_cert
322
+ else
323
+ add_cert(cert_obj)
324
+ end
325
+ end
326
+ end
327
+ end
328
+ end
311
329
  end
312
330
  end
313
331
  end
@@ -23,7 +23,7 @@ require "chef/version_string"
23
23
 
24
24
  class Chef
25
25
  CHEF_ROOT = File.expand_path("../..", __FILE__)
26
- VERSION = Chef::VersionString.new("14.11.21")
26
+ VERSION = Chef::VersionString.new("14.12.3")
27
27
  end
28
28
 
29
29
  #
@@ -74,11 +74,11 @@ describe Chef::Resource::DscScript, :windows_powershell_dsc_only do
74
74
  let(:env_value2) { "value2" }
75
75
  let(:dsc_test_run_context) do
76
76
  node = Chef::Node.new
77
+ node.consume_external_attrs(OHAI_SYSTEM.data, {}) # node[:languages][:powershell][:version]
77
78
  node.automatic["os"] = "windows"
78
79
  node.automatic["platform"] = "windows"
79
80
  node.automatic["platform_version"] = "6.1"
80
81
  node.automatic["kernel"][:machine] = :x86_64 # Only 64-bit architecture is supported
81
- node.automatic[:languages][:powershell][:version] = "4.0"
82
82
  empty_events = Chef::EventDispatch::Dispatcher.new
83
83
  Chef::RunContext.new(node, {}, empty_events)
84
84
  end
@@ -292,14 +292,27 @@ describe Chef::Resource::Group, :requires_root_or_running_windows do
292
292
  end
293
293
  end
294
294
 
295
- let(:group_name) { "group#{SecureRandom.random_number(9999)}" }
295
+ let(:number) do
296
+ # Loop until we pick a gid that is not in use.
297
+ loop do
298
+ begin
299
+ gid = rand(2000..9999) # avoid low group numbers
300
+ return nil if Etc.getgrgid(gid).nil? # returns nil on windows
301
+ rescue ArgumentError # group does not exist
302
+ return gid
303
+ end
304
+ end
305
+ end
306
+
307
+ let(:group_name) { "grp#{number}" } # group name should be 8 characters or less for Solaris, and possibly others
308
+ # https://community.aegirproject.org/developing/architecture/unix-group-limitations/index.html#Group_name_length_limits
296
309
  let(:included_members) { [] }
297
310
  let(:excluded_members) { [] }
298
311
  let(:group_resource) do
299
312
  group = Chef::Resource::Group.new(group_name, run_context)
300
313
  group.members(included_members)
301
314
  group.excluded_members(excluded_members)
302
- group.gid(30000) unless ohai[:platform_family] == "mac_os_x"
315
+ group.gid(number) unless ohai[:platform_family] == "mac_os_x"
303
316
  group
304
317
  end
305
318
 
@@ -62,11 +62,14 @@ describe Chef::Resource::WindowsCertificate, :windows_only, :appveyor_only do
62
62
  let(:cer_path) { File.join(certificate_path, "test.cer") }
63
63
  let(:base64_path) { File.join(certificate_path, "base64_test.cer") }
64
64
  let(:pem_path) { File.join(certificate_path, "test.pem") }
65
+ let(:p7b_path) { File.join(certificate_path, "test.p7b") }
65
66
  let(:pfx_path) { File.join(certificate_path, "test.pfx") }
66
67
  let(:out_path) { File.join(certificate_path, "testout.pem") }
67
68
  let(:tests_thumbprint) { "3180B3E3217862600BD7B2D28067B03D41576A4F" }
68
69
  let(:other_cer_path) { File.join(certificate_path, "othertest.cer") }
69
70
  let(:others_thumbprint) { "AD393859B2D2D4161D224F16CBD3D16555753A20" }
71
+ let(:p7b_thumbprint) { "50954A52DDFA2043F36EA9026FDD95EC252048D0" }
72
+ let(:p7b_nested_thumbprint) { "4A3333FC4E1274995AF5A95810881C86F2DF7FBD" }
70
73
 
71
74
  before do
72
75
  opts = { store_name: store }
@@ -205,6 +208,23 @@ describe Chef::Resource::WindowsCertificate, :windows_only, :appveyor_only do
205
208
  end
206
209
  end
207
210
 
211
+ context "Adds P7B" do
212
+ before do
213
+ win_certificate.source = p7b_path
214
+ win_certificate.run_action(:create)
215
+ end
216
+ it "Imports certificate into store" do
217
+ expect(no_of_certificates).not_to eq(0)
218
+ end
219
+ it "Idempotent: Does not converge while adding again" do
220
+ win_certificate.run_action(:create)
221
+ expect(win_certificate).not_to be_updated_by_last_action
222
+ end
223
+ it "Nested certificates are also imported" do
224
+ expect(no_of_certificates).to eq(2)
225
+ end
226
+ end
227
+
208
228
  context "Adds PFX" do
209
229
  context "With valid password" do
210
230
  before do
@@ -289,6 +309,61 @@ describe Chef::Resource::WindowsCertificate, :windows_only, :appveyor_only do
289
309
  end
290
310
  end
291
311
  end
312
+
313
+ context "When multiple certificates are present" do
314
+ before do
315
+ win_certificate.source = p7b_path
316
+ win_certificate.run_action(:create)
317
+ end
318
+
319
+ context "With main certificate's thumbprint" do
320
+ before do
321
+ win_certificate.source = p7b_thumbprint
322
+ win_certificate.run_action(:verify)
323
+ end
324
+ it "Initial check if certificate is present" do
325
+ expect(no_of_certificates).to eq(2)
326
+ end
327
+ it "Displays correct message" do
328
+ expect(stdout.string.strip).to eq("Certificate is valid")
329
+ end
330
+ it "Does not converge while verifying" do
331
+ expect(win_certificate).not_to be_updated_by_last_action
332
+ end
333
+ end
334
+
335
+ context "With nested certificate's thumbprint" do
336
+ before do
337
+ win_certificate.source = p7b_nested_thumbprint
338
+ win_certificate.run_action(:verify)
339
+ end
340
+ it "Initial check if certificate is present" do
341
+ expect(no_of_certificates).to eq(2)
342
+ end
343
+ it "Displays correct message" do
344
+ expect(stdout.string.strip).to eq("Certificate is valid")
345
+ end
346
+ it "Does not converge while verifying" do
347
+ expect(win_certificate).not_to be_updated_by_last_action
348
+ end
349
+ end
350
+
351
+ context "For an invalid thumbprint" do
352
+ before do
353
+ win_certificate.source = others_thumbprint
354
+ win_certificate.run_action(:verify)
355
+ end
356
+ it "Initial check if certificate is present" do
357
+ expect(no_of_certificates).to eq(2)
358
+ end
359
+ it "Displays correct message" do
360
+ expect(stdout.string.strip).to eq("Certificate not found")
361
+ end
362
+ it "Does not converge while verifying" do
363
+ expect(win_certificate).not_to be_updated_by_last_action
364
+ end
365
+ end
366
+ end
292
367
  end
293
368
 
294
369
  describe "action: fetch" do
@@ -96,6 +96,7 @@ describe Chef::Provider::Service::Windows, "load_current_resource", :windows_onl
96
96
  Win32::Service::DEMAND_START = 0x00000003
97
97
  Win32::Service::DISABLED = 0x00000004
98
98
 
99
+ allow(Win32::Service).to receive(:start).with(any_args).and_return(Win32::Service)
99
100
  allow(Win32::Service).to receive(:status).with(new_resource.service_name).and_return(
100
101
  double("StatusStruct", current_state: "running"))
101
102
  allow(Win32::Service).to receive(:config_info).with(new_resource.service_name)
@@ -505,6 +506,31 @@ describe Chef::Provider::Service::Windows, "load_current_resource", :windows_onl
505
506
  double("StatusStruct", current_state: "running"))
506
507
  end
507
508
 
509
+ context "run_as_user user is specified" do
510
+ let(:run_as_user) { provider.new_resource.class.properties[:run_as_user].default }
511
+
512
+ before do
513
+ provider.new_resource.run_as_user run_as_user
514
+ end
515
+
516
+ it "configures service run_as_user and run_as_password" do
517
+ expect(provider).to receive(:configure_service_run_as_properties).and_call_original
518
+ expect(Win32::Service).to receive(:configure)
519
+ provider.start_service
520
+ end
521
+ end
522
+
523
+ context "run_as_user user is not specified" do
524
+ before do
525
+ expect(provider.new_resource.property_is_set?(:run_as_user)).to be false
526
+ end
527
+
528
+ it "does not configure service run_as_user and run_as_password" do
529
+ expect(Win32::Service).not_to receive(:configure)
530
+ provider.start_service
531
+ end
532
+ end
533
+
508
534
  it "calls the start command if one is specified" do
509
535
  new_resource.start_command "sc start #{chef_service_name}"
510
536
  expect(provider).to receive(:shell_out!).with((new_resource.start_command).to_s).and_return("Starting custom service")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef
3
3
  version: !ruby/object:Gem::Version
4
- version: 14.11.21
4
+ version: 14.12.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Jacob
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-06 00:00:00.000000000 Z
11
+ date: 2019-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef-config
@@ -16,48 +16,54 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 14.11.21
19
+ version: 14.12.3
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: 14.11.21
26
+ version: 14.12.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mixlib-cli
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.7'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '3.0'
34
37
  type: :runtime
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
38
- - - "~>"
41
+ - - ">="
39
42
  - !ruby/object:Gem::Version
40
43
  version: '1.7'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '3.0'
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: mixlib-log
43
49
  requirement: !ruby/object:Gem::Requirement
44
50
  requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '2.0'
48
51
  - - ">="
49
52
  - !ruby/object:Gem::Version
50
53
  version: 2.0.3
54
+ - - "<"
55
+ - !ruby/object:Gem::Version
56
+ version: '4.0'
51
57
  type: :runtime
52
58
  prerelease: false
53
59
  version_requirements: !ruby/object:Gem::Requirement
54
60
  requirements:
55
- - - "~>"
56
- - !ruby/object:Gem::Version
57
- version: '2.0'
58
61
  - - ">="
59
62
  - !ruby/object:Gem::Version
60
63
  version: 2.0.3
64
+ - - "<"
65
+ - !ruby/object:Gem::Version
66
+ version: '4.0'
61
67
  - !ruby/object:Gem::Dependency
62
68
  name: mixlib-authentication
63
69
  requirement: !ruby/object:Gem::Requirement
@@ -76,16 +82,22 @@ dependencies:
76
82
  name: mixlib-shellout
77
83
  requirement: !ruby/object:Gem::Requirement
78
84
  requirements:
79
- - - "~>"
85
+ - - ">="
80
86
  - !ruby/object:Gem::Version
81
87
  version: '2.4'
88
+ - - "<"
89
+ - !ruby/object:Gem::Version
90
+ version: '4.0'
82
91
  type: :runtime
83
92
  prerelease: false
84
93
  version_requirements: !ruby/object:Gem::Requirement
85
94
  requirements:
86
- - - "~>"
95
+ - - ">="
87
96
  - !ruby/object:Gem::Version
88
97
  version: '2.4'
98
+ - - "<"
99
+ - !ruby/object:Gem::Version
100
+ version: '4.0'
89
101
  - !ruby/object:Gem::Dependency
90
102
  name: mixlib-archive
91
103
  requirement: !ruby/object:Gem::Requirement
@@ -1699,6 +1711,7 @@ files:
1699
1711
  - spec/data/windows_certificates/base64_test.cer
1700
1712
  - spec/data/windows_certificates/othertest.cer
1701
1713
  - spec/data/windows_certificates/test.cer
1714
+ - spec/data/windows_certificates/test.p7b
1702
1715
  - spec/data/windows_certificates/test.pem
1703
1716
  - spec/data/windows_certificates/test.pfx
1704
1717
  - spec/functional/application_spec.rb