chef 17.4.25-universal-mingw32 → 17.6.18-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -2
  3. data/chef.gemspec +2 -0
  4. data/lib/chef/application/base.rb +11 -1
  5. data/lib/chef/client.rb +1 -2
  6. data/lib/chef/compliance/input.rb +115 -0
  7. data/lib/chef/compliance/input_collection.rb +139 -0
  8. data/lib/chef/compliance/profile.rb +122 -0
  9. data/lib/chef/compliance/profile_collection.rb +109 -0
  10. data/lib/chef/compliance/reporter/automate.rb +1 -1
  11. data/lib/chef/compliance/runner.rb +48 -6
  12. data/lib/chef/compliance/waiver.rb +115 -0
  13. data/lib/chef/compliance/waiver_collection.rb +143 -0
  14. data/lib/chef/dsl/compliance.rb +38 -0
  15. data/lib/chef/dsl/reader_helpers.rb +51 -0
  16. data/lib/chef/dsl/recipe.rb +4 -2
  17. data/lib/chef/dsl/secret.rb +2 -4
  18. data/lib/chef/dsl/universal.rb +2 -0
  19. data/lib/chef/event_dispatch/base.rb +44 -2
  20. data/lib/chef/formatters/doc.rb +60 -13
  21. data/lib/chef/formatters/minimal.rb +6 -5
  22. data/lib/chef/http/basic_client.rb +15 -7
  23. data/lib/chef/http.rb +12 -8
  24. data/lib/chef/provider/file.rb +2 -0
  25. data/lib/chef/provider/link.rb +2 -2
  26. data/lib/chef/provider/registry_key.rb +3 -2
  27. data/lib/chef/provider/remote_file/http.rb +1 -1
  28. data/lib/chef/provider/template.rb +1 -1
  29. data/lib/chef/resource/archive_file.rb +17 -14
  30. data/lib/chef/resource/chef_client_scheduled_task.rb +45 -2
  31. data/lib/chef/resource/chocolatey_config.rb +13 -13
  32. data/lib/chef/resource/execute.rb +2 -2
  33. data/lib/chef/resource/file/verification/json.rb +50 -0
  34. data/lib/chef/resource/file/verification/yaml.rb +52 -0
  35. data/lib/chef/resource/inspec_input.rb +127 -0
  36. data/lib/chef/resource/inspec_waiver.rb +184 -0
  37. data/lib/chef/resource/mount.rb +1 -1
  38. data/lib/chef/resource/openssl_x509_certificate.rb +1 -1
  39. data/lib/chef/resource/powershell_package_source.rb +234 -70
  40. data/lib/chef/resource/registry_key.rb +36 -48
  41. data/lib/chef/resource/remote_file.rb +98 -2
  42. data/lib/chef/resource/timezone.rb +2 -2
  43. data/lib/chef/resource/user_ulimit.rb +1 -0
  44. data/lib/chef/resource/windows_printer.rb +1 -1
  45. data/lib/chef/resource/windows_uac.rb +3 -1
  46. data/lib/chef/resource/windows_user_privilege.rb +1 -1
  47. data/lib/chef/resource.rb +1 -1
  48. data/lib/chef/resources.rb +2 -0
  49. data/lib/chef/run_context/cookbook_compiler.rb +112 -28
  50. data/lib/chef/run_context.rb +31 -1
  51. data/lib/chef/secret_fetcher/akeyless_vault.rb +57 -0
  52. data/lib/chef/secret_fetcher/aws_secrets_manager.rb +1 -1
  53. data/lib/chef/secret_fetcher/azure_key_vault.rb +1 -1
  54. data/lib/chef/secret_fetcher/base.rb +1 -1
  55. data/lib/chef/secret_fetcher/hashi_vault.rb +100 -0
  56. data/lib/chef/secret_fetcher.rb +8 -2
  57. data/lib/chef/version.rb +1 -1
  58. data/lib/chef/win32/version.rb +2 -1
  59. data/spec/data/archive_file/test_archive.tar.gz +0 -0
  60. data/spec/functional/resource/archive_file_spec.rb +87 -0
  61. data/spec/functional/resource/group_spec.rb +5 -1
  62. data/spec/functional/resource/link_spec.rb +8 -0
  63. data/spec/functional/resource/powershell_package_source_spec.rb +5 -6
  64. data/spec/integration/compliance/compliance_spec.rb +60 -0
  65. data/spec/spec_helper.rb +3 -0
  66. data/spec/support/platform_helpers.rb +4 -0
  67. data/spec/support/ruby_installer.rb +51 -0
  68. data/spec/unit/compliance/input_spec.rb +104 -0
  69. data/spec/unit/compliance/profile_spec.rb +120 -0
  70. data/spec/unit/compliance/waiver_spec.rb +104 -0
  71. data/spec/unit/formatters/doc_spec.rb +1 -1
  72. data/spec/unit/http/basic_client_spec.rb +30 -0
  73. data/spec/unit/http_spec.rb +8 -2
  74. data/spec/unit/provider/link_spec.rb +13 -7
  75. data/spec/unit/provider/remote_file/http_spec.rb +10 -0
  76. data/spec/unit/provider/template_spec.rb +2 -2
  77. data/spec/unit/resource/archive_file_spec.rb +414 -3
  78. data/spec/unit/resource/chef_client_scheduled_task_spec.rb +69 -0
  79. data/spec/unit/resource/file/verification/json_spec.rb +72 -0
  80. data/spec/unit/resource/file/verification/yaml_spec.rb +67 -0
  81. data/spec/unit/resource/inspec_input_spec.rb +300 -0
  82. data/spec/unit/resource/inspec_waiver_spec.rb +312 -0
  83. data/spec/unit/resource/mount_spec.rb +10 -0
  84. data/spec/unit/resource/powershell_package_source_spec.rb +63 -62
  85. data/spec/unit/resource/user_ulimit_spec.rb +14 -1
  86. data/spec/unit/secret_fetcher/akeyless_vault_spec.rb +37 -0
  87. data/spec/unit/secret_fetcher/hashi_vault_spec.rb +80 -0
  88. data/tasks/rspec.rb +2 -1
  89. metadata +60 -6
@@ -36,16 +36,18 @@ class Chef
36
36
  attr_reader :url
37
37
  attr_reader :ssl_policy
38
38
  attr_reader :keepalives
39
+ attr_reader :nethttp_opts
39
40
 
40
41
  # Instantiate a BasicClient.
41
42
  # === Arguments:
42
43
  # url:: An URI for the remote server.
43
44
  # === Options:
44
45
  # ssl_policy:: The SSL Policy to use, defaults to DefaultSSLPolicy
45
- def initialize(url, opts = {})
46
+ def initialize(url, ssl_policy: DefaultSSLPolicy, keepalives: false, nethttp_opts: {})
46
47
  @url = url
47
- @ssl_policy = opts[:ssl_policy] || DefaultSSLPolicy
48
- @keepalives = opts[:keepalives] || false
48
+ @ssl_policy = ssl_policy
49
+ @keepalives = keepalives
50
+ @nethttp_opts = ChefUtils::Mash.new(nethttp_opts)
49
51
  end
50
52
 
51
53
  def http_client
@@ -118,8 +120,14 @@ class Chef
118
120
  configure_ssl(http_client)
119
121
  end
120
122
 
121
- http_client.read_timeout = config[:rest_timeout]
122
- http_client.open_timeout = config[:rest_timeout]
123
+ opts = nethttp_opts.dup
124
+ opts["read_timeout"] ||= config[:rest_timeout]
125
+ opts["open_timeout"] ||= config[:rest_timeout]
126
+
127
+ opts.each do |key, value|
128
+ http_client.send(:"#{key}=", value)
129
+ end
130
+
123
131
  if keepalives
124
132
  http_client.start
125
133
  else
@@ -142,11 +150,11 @@ class Chef
142
150
  end
143
151
 
144
152
  def http_proxy_user(proxy_uri)
145
- proxy_uri.user || Chef::Config["#{proxy_uri.scheme}_proxy_user"]
153
+ proxy_uri.user || config["#{proxy_uri.scheme}_proxy_user"]
146
154
  end
147
155
 
148
156
  def http_proxy_pass(proxy_uri)
149
- proxy_uri.password || Chef::Config["#{proxy_uri.scheme}_proxy_pass"]
157
+ proxy_uri.password || config["#{proxy_uri.scheme}_proxy_pass"]
150
158
  end
151
159
 
152
160
  def configure_ssl(http_client)
data/lib/chef/http.rb CHANGED
@@ -82,6 +82,9 @@ class Chef
82
82
  # [Boolean] if we're doing keepalives or not
83
83
  attr_reader :keepalives
84
84
 
85
+ # @returns [Hash] options for Net::HTTP to be sent to setters on the object
86
+ attr_reader :nethttp_opts
87
+
85
88
  # Create a HTTP client object. The supplied +url+ is used as the base for
86
89
  # all subsequent requests. For example, when initialized with a base url
87
90
  # http://localhost:4000, a call to +get+ with 'nodes' will make an
@@ -94,6 +97,7 @@ class Chef
94
97
  @redirect_limit = 10
95
98
  @keepalives = options[:keepalives] || false
96
99
  @options = options
100
+ @nethttp_opts = options[:nethttp] || {}
97
101
 
98
102
  @middlewares = []
99
103
  self.class.middlewares.each do |middleware_class|
@@ -311,7 +315,7 @@ class Chef
311
315
 
312
316
  SocketlessChefZeroClient.new(base_url)
313
317
  else
314
- BasicClient.new(base_url, ssl_policy: ssl_policy, keepalives: keepalives)
318
+ BasicClient.new(base_url, ssl_policy: ssl_policy, keepalives: keepalives, nethttp_opts: nethttp_opts)
315
319
  end
316
320
  end
317
321
 
@@ -423,7 +427,7 @@ class Chef
423
427
  if response.is_a?(Net::HTTPServerError) && !Chef::Config.local_mode
424
428
  if http_retry_count - http_attempts >= 0
425
429
  sleep_time = 1 + (2**http_attempts) + rand(2**http_attempts)
426
- Chef::Log.error("Server returned error #{response.code} for #{url}, retrying #{http_attempts}/#{http_retry_count} in #{sleep_time}s")
430
+ Chef::Log.warn("Server returned error #{response.code} for #{url}, retrying #{http_attempts}/#{http_retry_count} in #{sleep_time}s") # Updated from error to warn
427
431
  sleep(sleep_time)
428
432
  redo
429
433
  end
@@ -432,7 +436,7 @@ class Chef
432
436
  end
433
437
  rescue SocketError, Errno::ETIMEDOUT, Errno::ECONNRESET => e
434
438
  if http_retry_count - http_attempts >= 0
435
- Chef::Log.error("Error connecting to #{url}, retry #{http_attempts}/#{http_retry_count}")
439
+ Chef::Log.warn("Error connecting to #{url}, retry #{http_attempts}/#{http_retry_count}") # Updated from error to warn
436
440
  sleep(http_retry_delay)
437
441
  retry
438
442
  end
@@ -440,21 +444,21 @@ class Chef
440
444
  raise e
441
445
  rescue Errno::ECONNREFUSED
442
446
  if http_retry_count - http_attempts >= 0
443
- Chef::Log.error("Connection refused connecting to #{url}, retry #{http_attempts}/#{http_retry_count}")
447
+ Chef::Log.warn("Connection refused connecting to #{url}, retry #{http_attempts}/#{http_retry_count}") # Updated from error to warn
444
448
  sleep(http_retry_delay)
445
449
  retry
446
450
  end
447
451
  raise Errno::ECONNREFUSED, "Connection refused connecting to #{url}, giving up"
448
452
  rescue Timeout::Error
449
453
  if http_retry_count - http_attempts >= 0
450
- Chef::Log.error("Timeout connecting to #{url}, retry #{http_attempts}/#{http_retry_count}")
454
+ Chef::Log.warn("Timeout connecting to #{url}, retry #{http_attempts}/#{http_retry_count}") # Updated from error to warn
451
455
  sleep(http_retry_delay)
452
456
  retry
453
457
  end
454
458
  raise Timeout::Error, "Timeout connecting to #{url}, giving up"
455
459
  rescue OpenSSL::SSL::SSLError => e
456
460
  if (http_retry_count - http_attempts >= 0) && !e.message.include?("certificate verify failed")
457
- Chef::Log.error("SSL Error connecting to #{url}, retry #{http_attempts}/#{http_retry_count}")
461
+ Chef::Log.warn("SSL Error connecting to #{url}, retry #{http_attempts}/#{http_retry_count}") # Updated from error to warn
458
462
  sleep(http_retry_delay)
459
463
  retry
460
464
  end
@@ -468,12 +472,12 @@ class Chef
468
472
 
469
473
  # @api private
470
474
  def http_retry_delay
471
- config[:http_retry_delay]
475
+ options[:http_retry_delay] || config[:http_retry_delay]
472
476
  end
473
477
 
474
478
  # @api private
475
479
  def http_retry_count
476
- config[:http_retry_count]
480
+ options[:http_retry_count] || config[:http_retry_count]
477
481
  end
478
482
 
479
483
  # @api private
@@ -27,6 +27,8 @@ require_relative "../scan_access_control"
27
27
  require_relative "../mixin/checksum"
28
28
  require_relative "../mixin/file_class"
29
29
  require_relative "../mixin/enforce_ownership_and_permissions"
30
+ require_relative "../resource/file/verification/json"
31
+ require_relative "../resource/file/verification/yaml"
30
32
  require_relative "../util/backup"
31
33
  require_relative "../util/diff"
32
34
  require_relative "../util/selinux"
@@ -43,8 +43,8 @@ class Chef
43
43
  )
44
44
  else
45
45
  current_resource.link_type(:hard)
46
- if ::File.exists?(current_resource.target_file)
47
- if ::File.exists?(new_resource.to) &&
46
+ if ::File.exist?(current_resource.target_file)
47
+ if ::File.exist?(new_resource.to) &&
48
48
  file_class.stat(current_resource.target_file).ino ==
49
49
  file_class.stat(new_resource.to).ino
50
50
  current_resource.to(canonicalize(new_resource.to))
@@ -19,7 +19,7 @@
19
19
 
20
20
  require_relative "../config"
21
21
  require_relative "../log"
22
- require_relative "../resource/file"
22
+ require_relative "../resource/registry_key"
23
23
  require_relative "../mixin/checksum"
24
24
  require_relative "../provider"
25
25
  require "etc" unless defined?(Etc)
@@ -50,7 +50,8 @@ class Chef
50
50
  current_resource.architecture(new_resource.architecture)
51
51
  current_resource.recursive(new_resource.recursive)
52
52
  if registry.key_exists?(new_resource.key)
53
- current_resource.values(registry.get_values(new_resource.key))
53
+ current_registry_values = registry.get_values(new_resource.key) || []
54
+ current_resource.values(current_registry_values)
54
55
  end
55
56
  values_to_hash(current_resource.unscrubbed_values)
56
57
  current_resource
@@ -137,7 +137,7 @@ class Chef
137
137
  if new_resource.ssl_verify_mode
138
138
  opts[:ssl_verify_mode] = new_resource.ssl_verify_mode
139
139
  end
140
- opts
140
+ opts.merge(new_resource.http_options)
141
141
  end
142
142
 
143
143
  end
@@ -39,7 +39,7 @@ class Chef
39
39
  super
40
40
 
41
41
  requirements.assert(:create, :create_if_missing) do |a|
42
- a.assertion { ::File.exists?(content.template_location) }
42
+ a.assertion { ::File.exist?(content.template_location) }
43
43
  a.failure_message "Template source #{content.template_location} could not be found."
44
44
  a.whyrun "Template source #{content.template_location} does not exist. Assuming it would have been created."
45
45
  a.block_action!
@@ -81,6 +81,11 @@ class Chef
81
81
  description: "Should the resource overwrite the destination file contents if they already exist? If set to `:auto` the date stamp of files within the archive will be compared to those on disk and disk contents will be overwritten if they differ. This may cause unintended consequences if disk date stamps are changed between runs, which will result in the files being overwritten during each client run. Make sure to properly test any change to this property.",
82
82
  default: false
83
83
 
84
+ property :strip_components, Integer,
85
+ description: "Remove the specified number of leading path elements. Pathnames with fewer elements will be silently skipped. This behaves similarly to tar's --strip-components command line argument.",
86
+ introduced: "17.5",
87
+ default: 0
88
+
84
89
  # backwards compatibility for the legacy cookbook names
85
90
  alias_method :extract_options, :options
86
91
  alias_method :extract_to, :destination
@@ -117,7 +122,7 @@ class Chef
117
122
 
118
123
  if new_resource.owner || new_resource.group
119
124
  converge_by("set owner of files extracted in #{new_resource.destination} to #{new_resource.owner}:#{new_resource.group}") do
120
- archive = Archive::Reader.open_filename(new_resource.path)
125
+ archive = Archive::Reader.open_filename(new_resource.path, nil, strip_components: new_resource.strip_components)
121
126
  archive.each_entry do |e|
122
127
  FileUtils.chown(new_resource.owner, new_resource.group, "#{new_resource.destination}/#{e.pathname}")
123
128
  end
@@ -160,18 +165,16 @@ class Chef
160
165
  # @return [Boolean]
161
166
  def archive_differs_from_disk?(src, dest)
162
167
  modified = false
163
- Dir.chdir(dest) do
164
- archive = Archive::Reader.open_filename(src)
165
- Chef::Log.trace("Beginning the comparison of file mtime between contents of #{src} and #{dest}")
166
- archive.each_entry do |e|
167
- pathname = ::File.expand_path(e.pathname)
168
- if ::File.exist?(pathname)
169
- Chef::Log.trace("#{pathname} mtime is #{::File.mtime(pathname)} and archive is #{e.mtime}")
170
- modified = true unless ::File.mtime(pathname) == e.mtime
171
- else
172
- Chef::Log.trace("#{pathname} doesn't exist on disk, but exists in the archive")
173
- modified = true
174
- end
168
+ archive = Archive::Reader.open_filename(src, nil, strip_components: new_resource.strip_components)
169
+ Chef::Log.trace("Beginning the comparison of file mtime between contents of #{src} and #{dest}")
170
+ archive.each_entry do |e|
171
+ pathname = ::File.expand_path(e.pathname, dest)
172
+ if ::File.exist?(pathname)
173
+ Chef::Log.trace("#{pathname} mtime is #{::File.mtime(pathname)} and archive is #{e.mtime}")
174
+ modified = true unless ::File.mtime(pathname) == e.mtime
175
+ else
176
+ Chef::Log.trace("#{pathname} doesn't exist on disk, but exists in the archive")
177
+ modified = true
175
178
  end
176
179
  end
177
180
  modified
@@ -189,7 +192,7 @@ class Chef
189
192
  flags = [options].flatten.map { |option| extract_option_map[option] }.compact.reduce(:|)
190
193
 
191
194
  Dir.chdir(dest) do
192
- archive = Archive::Reader.open_filename(src)
195
+ archive = Archive::Reader.open_filename(src, nil, strip_components: new_resource.strip_components)
193
196
 
194
197
  archive.each_entry do |e|
195
198
  archive.extract(e, flags.to_i)
@@ -58,6 +58,14 @@ class Chef
58
58
  daemon_options ['-n audit_only']
59
59
  end
60
60
  ```
61
+
62
+ **Run #{ChefUtils::Dist::Infra::PRODUCT} with a persistent delay on every run calculated once, similar to how chef_client_cron resource works**:
63
+
64
+ ```ruby
65
+ chef_client_scheduled_task 'Run chef-client with persistent splay' do
66
+ use_consistent_splay true
67
+ end
68
+ ```
61
69
  DOC
62
70
 
63
71
  resource_name :chef_client_scheduled_task
@@ -104,6 +112,11 @@ class Chef
104
112
  description: "A random number of seconds between 0 and X to add to interval so that all #{ChefUtils::Dist::Infra::CLIENT} commands don't execute at the same time.",
105
113
  default: 300
106
114
 
115
+ property :use_consistent_splay, [true, false],
116
+ description: "Always use the same random splay amount for each node to ensure consistent frequencies between #{ChefUtils::Dist::Infra::CLIENT} execution.",
117
+ introduced: "17.5",
118
+ default: false
119
+
107
120
  property :run_on_battery, [true, false],
108
121
  description: "Run the #{ChefUtils::Dist::Infra::PRODUCT} task when the system is on batteries.",
109
122
  default: true
@@ -129,6 +142,11 @@ class Chef
129
142
  description: "An array of options to pass to the #{ChefUtils::Dist::Infra::CLIENT} command.",
130
143
  default: []
131
144
 
145
+ property :priority, Integer,
146
+ description: "Use to set Priority Levels range from 0 to 10.",
147
+ introduced: "17.5",
148
+ default: 7, callbacks: { "should be in range of 0 to 10" => proc { |v| v >= 0 && v <= 10 } }
149
+
132
150
  action :add, description: "Add a Windows Scheduled Task that runs #{ChefUtils::Dist::Infra::PRODUCT}." do
133
151
  # TODO: Replace this with a :create_if_missing action on directory when that exists
134
152
  unless Dir.exist?(new_resource.log_directory)
@@ -151,8 +169,9 @@ class Chef
151
169
  frequency_modifier new_resource.frequency_modifier if frequency_supports_frequency_modifier?
152
170
  start_time new_resource.start_time
153
171
  start_day new_resource.start_date unless new_resource.start_date.nil?
154
- random_delay new_resource.splay if frequency_supports_random_delay?
172
+ random_delay new_resource.splay if frequency_supports_random_delay? && !new_resource.use_consistent_splay
155
173
  disallow_start_if_on_batteries new_resource.splay unless new_resource.run_on_battery
174
+ priority new_resource.priority
156
175
  action %i{create enable}
157
176
  end
158
177
  end
@@ -173,7 +192,31 @@ class Chef
173
192
  # Fetch path of cmd.exe through environment variable comspec
174
193
  cmd_path = ENV["COMSPEC"]
175
194
 
176
- "#{cmd_path} /c \"#{client_cmd}\""
195
+ "#{cmd_path} /c \"#{consistent_splay_command}#{client_cmd}\""
196
+ end
197
+
198
+ #
199
+ # Generate a uniformly distributed unique number to sleep from 0 to the splay time
200
+ #
201
+ # @param [Integer] splay The number of seconds to splay
202
+ #
203
+ # @return [Integer]
204
+ #
205
+ def splay_sleep_time(splay)
206
+ seed = node["shard_seed"] || Digest::MD5.hexdigest(node.name).to_s.hex
207
+ random = Random.new(seed.to_i)
208
+ random.rand(splay)
209
+ end
210
+
211
+ #
212
+ # The consistent splay sleep time when use_consistent_splay is true.
213
+ #
214
+ # @return [NilClass,String] The prepended sleep command to run prior to executing the full command.
215
+ #
216
+ def consistent_splay_command
217
+ return unless new_resource.use_consistent_splay
218
+
219
+ "C:/windows/system32/windowspowershell/v1.0/powershell.exe Start-Sleep -s #{splay_sleep_time(new_resource.splay)} && "
177
220
  end
178
221
 
179
222
  #
@@ -24,22 +24,22 @@ class Chef
24
24
  description "Use the **chocolatey_config** resource to add or remove Chocolatey configuration keys."
25
25
  introduced "14.3"
26
26
  examples <<~DOC
27
- **Set the Chocolatey cacheLocation config**:
27
+ **Set the Chocolatey cacheLocation config**:
28
28
 
29
- ```ruby
30
- chocolatey_config 'Set cacheLocation config' do
31
- config_key 'cacheLocation'
32
- value 'C:\temp\choco'
33
- end
34
- ```
29
+ ```ruby
30
+ chocolatey_config 'Set cacheLocation config' do
31
+ config_key 'cacheLocation'
32
+ value 'C:\\temp\\choco'
33
+ end
34
+ ```
35
35
 
36
- **Unset a Chocolatey config**:
36
+ **Unset a Chocolatey config**:
37
37
 
38
- ```ruby
39
- chocolatey_config 'BogusConfig' do
40
- action :unset
41
- end
42
- ```
38
+ ```ruby
39
+ chocolatey_config 'BogusConfig' do
40
+ action :unset
41
+ end
42
+ ```
43
43
  DOC
44
44
 
45
45
  property :config_key, String, name_property: true,
@@ -549,11 +549,11 @@ class Chef
549
549
  desired_state: false
550
550
 
551
551
  property :user, [ String, Integer ],
552
- description: "The user name of the user identity with which to launch the new process. The user name may optionally be specified with a domain, i.e. `domainuser` or `user@my.dns.domain.com` via Universal Principal Name (UPN)format. It can also be specified without a domain simply as user if the domain is instead specified using the domain property. On Windows only, if this property is specified, the password property must be specified."
552
+ description: "The user name of the user identity with which to launch the new process. The user name may optionally be specified with a domain, i.e. `domain\\user` or `user@my.dns.domain.com` via Universal Principal Name (UPN)format. It can also be specified without a domain simply as user if the domain is instead specified using the domain property. On Windows only, if this property is specified, the password property must be specified."
553
553
 
554
554
  property :domain, String,
555
555
  introduced: "12.21",
556
- description: "Windows only: The domain of the user user specified by the user property. If not specified, the username and password specified by the `user` and `password` properties will be used to resolve that user against the domain in which the system running #{ChefUtils::Dist::Infra::PRODUCT} is joined, or if that system is not joined to a domain it will resolve the user as a local account on that system. An alternative way to specify the domain is to leave this property unspecified and specify the domain as part of the user property."
556
+ description: "Windows only: The domain of the user specified by the user property. If not specified, the username and password specified by the `user` and `password` properties will be used to resolve that user against the domain in which the system running #{ChefUtils::Dist::Infra::PRODUCT} is joined, or if that system is not joined to a domain it will resolve the user as a local account on that system. An alternative way to specify the domain is to leave this property unspecified and specify the domain as part of the user property."
557
557
 
558
558
  property :password, String, sensitive: true,
559
559
  introduced: "12.21",
@@ -0,0 +1,50 @@
1
+ #
2
+ # Author:: Antony Thomas (<antonydeepak@gmail.com>)
3
+ # Copyright:: Copyright (c) Facebook, Inc. and its affiliates.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ class Chef
20
+ class Resource
21
+ class File
22
+ class Verification
23
+
24
+ #
25
+ # Extends File verification to provide Json verification
26
+ #
27
+ # Example:
28
+ # file 'foo.json' do
29
+ # content '{"foo": "bar"}'
30
+ # verify :json
31
+ # end
32
+ #
33
+ #
34
+
35
+ class Json < Chef::Resource::File::Verification
36
+
37
+ provides :json
38
+
39
+ def verify(path, opts = {})
40
+ Chef::JSONCompat.parse(IO.read(path))
41
+ true
42
+ rescue Chef::Exceptions::JSON::ParseError => e
43
+ Chef::Log.error("Json syntax verify failed with : #{e.message}")
44
+ false
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,52 @@
1
+ #
2
+ # Author:: Antony Thomas (<antonydeepak@gmail.com>)
3
+ # Copyright:: Copyright (c) Chef Software Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require "psych" unless defined?(Psych)
20
+
21
+ class Chef
22
+ class Resource
23
+ class File
24
+ class Verification
25
+
26
+ #
27
+ # Extends File verification to provide a Yaml verification
28
+ #
29
+ # Example:
30
+ # file 'foo.yaml' do
31
+ # content "--- foo: 'foo-"
32
+ # verify :yaml
33
+ # end
34
+ #
35
+ #
36
+
37
+ class Yaml < Chef::Resource::File::Verification
38
+
39
+ provides :yaml
40
+
41
+ def verify(path, opts = {})
42
+ Psych.parse_file(path)
43
+ true
44
+ rescue Psych::SyntaxError => e
45
+ Chef::Log.error("Yaml syntax verify failed with : #{e.message}")
46
+ false
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,127 @@
1
+ #
2
+ # Copyright:: Copyright (c) Chef Software Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require_relative "../resource"
18
+
19
+ class Chef
20
+ class Resource
21
+ class InspecInput < Chef::Resource
22
+ provides :inspec_input
23
+ unified_mode true
24
+
25
+ description "Use the **inspec_input** resource to add an input to the Compliance Phase."
26
+ introduced "17.5"
27
+ examples <<~DOC
28
+
29
+ **Activate the default input in the openssh cookbook's compliance segment**:
30
+
31
+ ```ruby
32
+ inspec_input 'openssh' do
33
+ action :add
34
+ end
35
+ ```
36
+
37
+ **Activate all inputs in the openssh cookbook's compliance segment**:
38
+
39
+ ```ruby
40
+ inspec_input 'openssh::.*' do
41
+ action :add
42
+ end
43
+ ```
44
+
45
+ **Add an InSpec input to the Compliance Phase from a hash**:
46
+
47
+ ```ruby
48
+ inspec_input { ssh_custom_path: '/whatever2' }
49
+ ```
50
+
51
+ **Add an InSpec input to the Compliance Phase using the 'name' property to identify the input**:
52
+
53
+ ```ruby
54
+ inspec_input "setting my input" do
55
+ source( { ssh_custom_path: '/whatever2' })
56
+ end
57
+ ```
58
+
59
+ **Add an InSpec input to the Compliance Phase using a TOML, JSON, or YAML file**:
60
+
61
+ ```ruby
62
+ inspec_input "/path/to/my/input.yml"
63
+ ```
64
+
65
+ **Add an InSpec input to the Compliance Phase using a TOML, JSON, or YAML file, using the 'name' property**:
66
+
67
+ ```ruby
68
+ inspec_input "setting my input" do
69
+ source "/path/to/my/input.yml"
70
+ end
71
+ ```
72
+
73
+ Note that the **inspec_input** resource does not update and will not fire notifications (similar to the log resource). This is done to preserve the ability to use
74
+ the resource while not causing the updated resource count to be larger than zero. Since the resource does not update the state of the managed node, this behavior
75
+ is still consistent with the configuration management model. Instead, you should use events to observe configuration changes for the compliance phase. It is
76
+ possible to use the `notify_group` resource to chain notifications of the two resources, but notifications are the wrong model to use, and you should use pure ruby
77
+ conditionals instead. Compliance configuration should be independent of other resources and should only be conditional based on state/attributes, not other resources.
78
+ DOC
79
+
80
+ property :name, [ Hash, String ]
81
+
82
+ property :input, [ Hash, String ],
83
+ name_property: true
84
+
85
+ property :source, [ Hash, String ],
86
+ name_property: true
87
+
88
+ action :add, description: "Add an input to the compliance phase" do
89
+ if run_context.input_collection.valid?(new_resource.input)
90
+ include_input(new_resource.input)
91
+ else
92
+ include_input(input_hash)
93
+ end
94
+ end
95
+
96
+ action_class do
97
+ # If the source is nil and the input / name_property contains a file separator and is a string of a
98
+ # file that exists, then use that as the file (similar to the package provider automatic source property). Otherwise
99
+ # just return the source.
100
+ #
101
+ # @api private
102
+ def source
103
+ @source ||= build_source
104
+ end
105
+
106
+ def build_source
107
+ return new_resource.source unless new_resource.source.nil?
108
+ return nil unless new_resource.input.count(::File::SEPARATOR) > 0 || (::File::ALT_SEPARATOR && new_resource.input.count(::File::ALT_SEPARATOR) > 0 )
109
+ return nil unless ::File.exist?(new_resource.input)
110
+
111
+ new_resource.input
112
+ end
113
+
114
+ def input_hash
115
+ case source
116
+ when Hash
117
+ source
118
+ when String
119
+ parse_file(source)
120
+ when nil
121
+ raise Chef::Exceptions::ValidationFailed, "Could not find the input #{new_resource.input} in any cookbook segment."
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
127
+ end