chef 17.10.163 → 18.7.10

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.
Files changed (400) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +25 -21
  3. data/README.md +7 -7
  4. data/Rakefile +3 -22
  5. data/{chef-universal-mingw32.gemspec → chef-universal-mingw-ucrt.gemspec} +7 -6
  6. data/chef.gemspec +33 -27
  7. data/lib/chef/api_client_v1.rb +9 -1
  8. data/lib/chef/application/base.rb +20 -2
  9. data/lib/chef/application/exit_code.rb +3 -3
  10. data/lib/chef/chef_fs/file_pattern.rb +1 -1
  11. data/lib/chef/chef_fs/file_system.rb +21 -7
  12. data/lib/chef/chef_fs/path_utils.rb +7 -9
  13. data/lib/chef/client.rb +186 -2
  14. data/lib/chef/compliance/default_attributes.rb +2 -2
  15. data/lib/chef/compliance/input.rb +1 -1
  16. data/lib/chef/compliance/profile.rb +1 -1
  17. data/lib/chef/compliance/profile_collection.rb +0 -1
  18. data/lib/chef/compliance/runner.rb +6 -1
  19. data/lib/chef/compliance/waiver.rb +1 -1
  20. data/lib/chef/cookbook/chefignore.rb +4 -1
  21. data/lib/chef/cookbook/cookbook_version_loader.rb +1 -1
  22. data/lib/chef/cookbook/metadata.rb +1 -1
  23. data/lib/chef/cookbook/remote_file_vendor.rb +1 -3
  24. data/lib/chef/cookbook/synchronizer.rb +21 -3
  25. data/lib/chef/cookbook/syntax_check.rb +2 -2
  26. data/lib/chef/cookbook_manifest.rb +2 -2
  27. data/lib/chef/cookbook_version.rb +1 -1
  28. data/lib/chef/data_collector.rb +14 -0
  29. data/lib/chef/delayed_evaluator.rb +4 -0
  30. data/lib/chef/dsl/reader_helpers.rb +1 -1
  31. data/lib/chef/dsl/rest_resource.rb +77 -0
  32. data/lib/chef/event_dispatch/base.rb +3 -0
  33. data/lib/chef/event_dispatch/dispatcher.rb +0 -1
  34. data/lib/chef/exceptions.rb +9 -1
  35. data/lib/chef/file_access_control/windows.rb +4 -1
  36. data/lib/chef/file_cache.rb +17 -2
  37. data/lib/chef/formatters/doc.rb +1 -1
  38. data/lib/chef/guard_interpreter/resource_guard_interpreter.rb +2 -0
  39. data/lib/chef/http/authenticator.rb +253 -3
  40. data/lib/chef/http/ssl_policies.rb +2 -2
  41. data/lib/chef/mixin/{homebrew_user.rb → homebrew.rb} +13 -16
  42. data/lib/chef/mixin/openssl_helper.rb +1 -16
  43. data/lib/chef/mixin/powershell_exec.rb +5 -28
  44. data/lib/chef/monkey_patches/net-http.rb +127 -0
  45. data/lib/chef/node/attribute.rb +3 -11
  46. data/lib/chef/node/attribute_collections.rb +10 -1
  47. data/lib/chef/node/immutable_collections.rb +17 -6
  48. data/lib/chef/node/mixin/immutablize_array.rb +1 -0
  49. data/lib/chef/node/mixin/state_tracking.rb +7 -4
  50. data/lib/chef/node/mixin/state_tracking_array.rb +41 -0
  51. data/lib/chef/node.rb +23 -1
  52. data/lib/chef/platform/query_helpers.rb +4 -2
  53. data/lib/chef/policy_builder/policyfile.rb +8 -0
  54. data/lib/chef/property.rb +13 -6
  55. data/lib/chef/provider/group/windows.rb +1 -1
  56. data/lib/chef/provider/http_request.rb +11 -9
  57. data/lib/chef/provider/launchd.rb +2 -1
  58. data/lib/chef/provider/mount/linux.rb +6 -1
  59. data/lib/chef/provider/mount/mount.rb +13 -5
  60. data/lib/chef/provider/mount/windows.rb +1 -1
  61. data/lib/chef/provider/package/apt.rb +11 -2
  62. data/lib/chef/provider/package/chocolatey.rb +260 -22
  63. data/lib/chef/provider/package/dnf/dnf_helper.py +7 -0
  64. data/lib/chef/provider/package/homebrew.rb +6 -9
  65. data/lib/chef/provider/package/powershell.rb +1 -0
  66. data/lib/chef/provider/package/rubygems.rb +5 -1
  67. data/lib/chef/provider/package/snap.rb +3 -2
  68. data/lib/chef/provider/package/windows/msi.rb +2 -2
  69. data/lib/chef/provider/package/windows/registry_uninstall_entry.rb +1 -1
  70. data/lib/chef/provider/package/yum/yum_helper.py +3 -3
  71. data/lib/chef/provider/package/zypper/version.rb +60 -0
  72. data/lib/chef/provider/package/zypper.rb +47 -3
  73. data/lib/chef/provider/powershell_script.rb +96 -6
  74. data/lib/chef/provider/registry_key.rb +2 -0
  75. data/lib/chef/provider/remote_file/http.rb +1 -1
  76. data/lib/chef/provider/service/systemd.rb +23 -8
  77. data/lib/chef/provider/service/windows.rb +1 -1
  78. data/lib/chef/provider/service.rb +14 -0
  79. data/lib/chef/provider/user/aix.rb +5 -0
  80. data/lib/chef/provider/user/linux.rb +29 -0
  81. data/lib/chef/provider/user/mac.rb +1 -1
  82. data/lib/chef/provider/user/windows.rb +5 -0
  83. data/lib/chef/provider/user.rb +45 -9
  84. data/lib/chef/provider/yum_repository.rb +13 -1
  85. data/lib/chef/provider.rb +1 -1
  86. data/lib/chef/recipe.rb +4 -12
  87. data/lib/chef/resource/_rest_resource.rb +389 -0
  88. data/lib/chef/resource/alternatives.rb +0 -1
  89. data/lib/chef/resource/apt_package.rb +21 -1
  90. data/lib/chef/resource/apt_preference.rb +0 -1
  91. data/lib/chef/resource/apt_repository.rb +138 -18
  92. data/lib/chef/resource/apt_update.rb +0 -1
  93. data/lib/chef/resource/archive_file.rb +0 -1
  94. data/lib/chef/resource/bash.rb +13 -1
  95. data/lib/chef/resource/batch.rb +0 -1
  96. data/lib/chef/resource/bff_package.rb +0 -1
  97. data/lib/chef/resource/breakpoint.rb +0 -1
  98. data/lib/chef/resource/build_essential.rb +0 -1
  99. data/lib/chef/resource/cab_package.rb +0 -1
  100. data/lib/chef/resource/chef_client_config.rb +12 -14
  101. data/lib/chef/resource/chef_client_cron.rb +1 -2
  102. data/lib/chef/resource/chef_client_launchd.rb +2 -2
  103. data/lib/chef/resource/chef_client_scheduled_task.rb +3 -3
  104. data/lib/chef/resource/chef_client_systemd_timer.rb +5 -1
  105. data/lib/chef/resource/chef_client_trusted_certificate.rb +0 -1
  106. data/lib/chef/resource/chef_gem.rb +1 -2
  107. data/lib/chef/resource/chef_handler.rb +0 -1
  108. data/lib/chef/resource/chef_sleep.rb +1 -3
  109. data/lib/chef/resource/chef_vault_secret.rb +0 -1
  110. data/lib/chef/resource/chocolatey_config.rb +0 -1
  111. data/lib/chef/resource/chocolatey_feature.rb +0 -1
  112. data/lib/chef/resource/chocolatey_installer.rb +207 -0
  113. data/lib/chef/resource/chocolatey_package.rb +8 -1
  114. data/lib/chef/resource/chocolatey_source.rb +0 -1
  115. data/lib/chef/resource/cookbook_file.rb +0 -1
  116. data/lib/chef/resource/cron/_cron_shared.rb +0 -1
  117. data/lib/chef/resource/cron/cron.rb +0 -1
  118. data/lib/chef/resource/cron/cron_d.rb +15 -1
  119. data/lib/chef/resource/cron_access.rb +0 -1
  120. data/lib/chef/resource/csh.rb +0 -1
  121. data/lib/chef/resource/directory.rb +0 -1
  122. data/lib/chef/resource/dmg_package.rb +2 -1
  123. data/lib/chef/resource/dnf_package.rb +0 -1
  124. data/lib/chef/resource/dpkg_package.rb +0 -1
  125. data/lib/chef/resource/dsc_resource.rb +0 -1
  126. data/lib/chef/resource/dsc_script.rb +1 -2
  127. data/lib/chef/resource/execute.rb +8 -7
  128. data/lib/chef/resource/file.rb +0 -1
  129. data/lib/chef/resource/freebsd_package.rb +2 -1
  130. data/lib/chef/resource/gem_package.rb +2 -1
  131. data/lib/chef/resource/group.rb +25 -2
  132. data/lib/chef/resource/habitat/habitat_package.rb +0 -1
  133. data/lib/chef/resource/habitat/habitat_sup.rb +6 -7
  134. data/lib/chef/resource/habitat/habitat_sup_windows.rb +1 -1
  135. data/lib/chef/resource/habitat_config.rb +0 -1
  136. data/lib/chef/resource/habitat_install.rb +2 -2
  137. data/lib/chef/resource/habitat_service.rb +0 -1
  138. data/lib/chef/resource/habitat_user_toml.rb +0 -1
  139. data/lib/chef/resource/homebrew_cask.rb +21 -33
  140. data/lib/chef/resource/homebrew_package.rb +3 -2
  141. data/lib/chef/resource/homebrew_tap.rb +32 -18
  142. data/lib/chef/resource/homebrew_update.rb +4 -6
  143. data/lib/chef/resource/hostname.rb +0 -1
  144. data/lib/chef/resource/http_request.rb +0 -1
  145. data/lib/chef/resource/ifconfig.rb +0 -1
  146. data/lib/chef/resource/inspec_input.rb +0 -1
  147. data/lib/chef/resource/inspec_waiver.rb +0 -1
  148. data/lib/chef/resource/inspec_waiver_file_entry.rb +2 -3
  149. data/lib/chef/resource/ips_package.rb +0 -1
  150. data/lib/chef/resource/kernel_module.rb +0 -1
  151. data/lib/chef/resource/ksh.rb +0 -1
  152. data/lib/chef/resource/launchd.rb +9 -3
  153. data/lib/chef/resource/link.rb +0 -1
  154. data/lib/chef/resource/locale.rb +0 -1
  155. data/lib/chef/resource/log.rb +0 -1
  156. data/lib/chef/resource/lwrp_base.rb +0 -4
  157. data/lib/chef/resource/macos_pkg.rb +111 -0
  158. data/lib/chef/resource/macos_userdefaults.rb +3 -4
  159. data/lib/chef/resource/macosx_service.rb +0 -1
  160. data/lib/chef/resource/macports_package.rb +2 -1
  161. data/lib/chef/resource/mdadm.rb +0 -1
  162. data/lib/chef/resource/mount.rb +0 -1
  163. data/lib/chef/resource/msu_package.rb +0 -1
  164. data/lib/chef/resource/notify_group.rb +0 -2
  165. data/lib/chef/resource/ohai.rb +0 -1
  166. data/lib/chef/resource/ohai_hint.rb +0 -1
  167. data/lib/chef/resource/openbsd_package.rb +2 -1
  168. data/lib/chef/resource/openssl_dhparam.rb +0 -2
  169. data/lib/chef/resource/openssl_ec_private_key.rb +0 -2
  170. data/lib/chef/resource/openssl_ec_public_key.rb +0 -2
  171. data/lib/chef/resource/openssl_rsa_private_key.rb +0 -2
  172. data/lib/chef/resource/openssl_rsa_public_key.rb +0 -2
  173. data/lib/chef/resource/openssl_x509_certificate.rb +0 -2
  174. data/lib/chef/resource/openssl_x509_crl.rb +0 -2
  175. data/lib/chef/resource/openssl_x509_request.rb +0 -2
  176. data/lib/chef/resource/osx_profile.rb +0 -1
  177. data/lib/chef/resource/package.rb +0 -1
  178. data/lib/chef/resource/pacman_package.rb +2 -1
  179. data/lib/chef/resource/paludis_package.rb +0 -1
  180. data/lib/chef/resource/perl.rb +0 -1
  181. data/lib/chef/resource/plist.rb +7 -3
  182. data/lib/chef/resource/portage_package.rb +2 -1
  183. data/lib/chef/resource/powershell_package.rb +4 -1
  184. data/lib/chef/resource/powershell_package_source.rb +0 -1
  185. data/lib/chef/resource/powershell_script.rb +5 -2
  186. data/lib/chef/resource/python.rb +0 -1
  187. data/lib/chef/resource/reboot.rb +0 -1
  188. data/lib/chef/resource/registry_key.rb +6 -1
  189. data/lib/chef/resource/remote_directory.rb +0 -1
  190. data/lib/chef/resource/remote_file.rb +0 -1
  191. data/lib/chef/resource/rhsm_errata.rb +0 -1
  192. data/lib/chef/resource/rhsm_errata_level.rb +0 -1
  193. data/lib/chef/resource/rhsm_register.rb +2 -4
  194. data/lib/chef/resource/rhsm_repo.rb +0 -1
  195. data/lib/chef/resource/rhsm_subscription.rb +0 -1
  196. data/lib/chef/resource/route.rb +0 -1
  197. data/lib/chef/resource/rpm_package.rb +2 -1
  198. data/lib/chef/resource/ruby.rb +0 -1
  199. data/lib/chef/resource/ruby_block.rb +0 -1
  200. data/lib/chef/resource/scm/_scm.rb +0 -2
  201. data/lib/chef/resource/scm/git.rb +0 -2
  202. data/lib/chef/resource/scm/subversion.rb +0 -2
  203. data/lib/chef/resource/script.rb +0 -1
  204. data/lib/chef/resource/selinux/common_helpers.rb +47 -0
  205. data/lib/chef/resource/selinux/selinux_debian.erb +18 -0
  206. data/lib/chef/resource/selinux/selinux_default.erb +15 -0
  207. data/lib/chef/resource/selinux_boolean.rb +101 -0
  208. data/lib/chef/resource/selinux_fcontext.rb +160 -0
  209. data/lib/chef/resource/selinux_install.rb +107 -0
  210. data/lib/chef/resource/selinux_login.rb +129 -0
  211. data/lib/chef/resource/selinux_module.rb +143 -0
  212. data/lib/chef/resource/selinux_permissive.rb +64 -0
  213. data/lib/chef/resource/selinux_port.rb +118 -0
  214. data/lib/chef/resource/selinux_state.rb +166 -0
  215. data/lib/chef/resource/selinux_user.rb +137 -0
  216. data/lib/chef/resource/service.rb +4 -2
  217. data/lib/chef/resource/smartos_package.rb +2 -1
  218. data/lib/chef/resource/snap_package.rb +25 -1
  219. data/lib/chef/resource/solaris_package.rb +2 -1
  220. data/lib/chef/resource/ssh_known_hosts_entry.rb +0 -1
  221. data/lib/chef/resource/sudo.rb +37 -3
  222. data/lib/chef/resource/support/client.erb +2 -2
  223. data/lib/chef/resource/support/ulimit.erb +40 -0
  224. data/lib/chef/resource/swap_file.rb +0 -1
  225. data/lib/chef/resource/sysctl.rb +2 -2
  226. data/lib/chef/resource/systemd_unit.rb +0 -1
  227. data/lib/chef/resource/template.rb +0 -1
  228. data/lib/chef/resource/timezone.rb +0 -1
  229. data/lib/chef/resource/user/aix_user.rb +0 -1
  230. data/lib/chef/resource/user/linux_user.rb +0 -1
  231. data/lib/chef/resource/user/mac_user.rb +0 -1
  232. data/lib/chef/resource/user/pw_user.rb +0 -1
  233. data/lib/chef/resource/user/solaris_user.rb +0 -1
  234. data/lib/chef/resource/user/windows_user.rb +0 -1
  235. data/lib/chef/resource/user.rb +10 -1
  236. data/lib/chef/resource/user_ulimit.rb +38 -1
  237. data/lib/chef/resource/whyrun_safe_ruby_block.rb +0 -1
  238. data/lib/chef/resource/windows_ad_join.rb +0 -2
  239. data/lib/chef/resource/windows_audit_policy.rb +0 -2
  240. data/lib/chef/resource/windows_auto_run.rb +0 -1
  241. data/lib/chef/resource/windows_certificate.rb +1 -1
  242. data/lib/chef/resource/windows_defender.rb +0 -1
  243. data/lib/chef/resource/windows_defender_exclusion.rb +0 -1
  244. data/lib/chef/resource/windows_dfs_folder.rb +0 -1
  245. data/lib/chef/resource/windows_dfs_namespace.rb +0 -1
  246. data/lib/chef/resource/windows_dfs_server.rb +0 -1
  247. data/lib/chef/resource/windows_dns_record.rb +0 -1
  248. data/lib/chef/resource/windows_dns_zone.rb +0 -1
  249. data/lib/chef/resource/windows_env.rb +0 -1
  250. data/lib/chef/resource/windows_feature.rb +0 -1
  251. data/lib/chef/resource/windows_feature_dism.rb +0 -1
  252. data/lib/chef/resource/windows_feature_powershell.rb +0 -1
  253. data/lib/chef/resource/windows_firewall_profile.rb +0 -2
  254. data/lib/chef/resource/windows_firewall_rule.rb +0 -1
  255. data/lib/chef/resource/windows_font.rb +2 -3
  256. data/lib/chef/resource/windows_package.rb +3 -4
  257. data/lib/chef/resource/windows_pagefile.rb +0 -2
  258. data/lib/chef/resource/windows_path.rb +0 -1
  259. data/lib/chef/resource/windows_printer.rb +0 -1
  260. data/lib/chef/resource/windows_printer_port.rb +0 -1
  261. data/lib/chef/resource/windows_script.rb +0 -2
  262. data/lib/chef/resource/windows_security_policy.rb +2 -3
  263. data/lib/chef/resource/windows_service.rb +0 -1
  264. data/lib/chef/resource/windows_share.rb +0 -1
  265. data/lib/chef/resource/windows_shortcut.rb +1 -2
  266. data/lib/chef/resource/windows_task.rb +0 -1
  267. data/lib/chef/resource/windows_uac.rb +0 -1
  268. data/lib/chef/resource/windows_update_settings.rb +0 -1
  269. data/lib/chef/resource/windows_user_privilege.rb +14 -11
  270. data/lib/chef/resource/windows_workgroup.rb +0 -1
  271. data/lib/chef/resource/yum_package.rb +2 -1
  272. data/lib/chef/resource/yum_repository.rb +4 -1
  273. data/lib/chef/resource/zypper_package.rb +2 -1
  274. data/lib/chef/resource/zypper_repository.rb +0 -1
  275. data/lib/chef/resource.rb +23 -5
  276. data/lib/chef/resource_inspector.rb +25 -7
  277. data/lib/chef/resource_reporter.rb +4 -0
  278. data/lib/chef/resources.rb +11 -0
  279. data/lib/chef/run_context.rb +3 -3
  280. data/lib/chef/secret_fetcher/azure_key_vault.rb +1 -1
  281. data/lib/chef/util/powershell/ps_credential.rb +10 -0
  282. data/lib/chef/version.rb +1 -1
  283. data/lib/chef/win32/handle.rb +6 -7
  284. data/lib/chef/win32/registry.rb +12 -4
  285. data/lib/chef/win32/security.rb +16 -1
  286. data/spec/data/rubygems.org/sexp_processor-info +2 -1
  287. data/spec/data/trusted_certs/intermediate.pem +38 -27
  288. data/spec/functional/resource/cookbook_file_spec.rb +1 -1
  289. data/spec/functional/resource/dsc_script_spec.rb +1 -1
  290. data/spec/functional/resource/execute_spec.rb +1 -1
  291. data/spec/functional/resource/group_spec.rb +26 -42
  292. data/spec/functional/resource/link_spec.rb +8 -8
  293. data/spec/functional/resource/plist_spec.rb +25 -0
  294. data/spec/functional/resource/registry_spec.rb +233 -609
  295. data/spec/functional/resource/remote_file_spec.rb +1 -1
  296. data/spec/functional/resource/user/linux_user_spec.rb +127 -0
  297. data/spec/functional/resource/windows_certificate_spec.rb +1 -1
  298. data/spec/functional/resource/windows_font_spec.rb +12 -9
  299. data/spec/functional/resource/yum_package_spec.rb +1 -1
  300. data/spec/functional/resource/zypper_package_spec.rb +12 -0
  301. data/spec/functional/shell_spec.rb +1 -2
  302. data/spec/functional/version_spec.rb +1 -1
  303. data/spec/functional/win32/registry_spec.rb +0 -3
  304. data/spec/integration/client/client_spec.rb +88 -3
  305. data/spec/integration/client/exit_code_spec.rb +1 -1
  306. data/spec/integration/client/fips_spec.rb +5 -5
  307. data/spec/integration/client/ipv6_spec.rb +1 -1
  308. data/spec/integration/client/open_ssl_spec.rb +3 -3
  309. data/spec/integration/compliance/compliance_spec.rb +1 -1
  310. data/spec/integration/recipes/accumulator_spec.rb +1 -1
  311. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +1 -1
  312. data/spec/integration/recipes/lwrp_spec.rb +1 -1
  313. data/spec/integration/recipes/notifies_spec.rb +1 -1
  314. data/spec/integration/recipes/notifying_block_spec.rb +1 -1
  315. data/spec/integration/recipes/remote_directory.rb +1 -1
  316. data/spec/integration/recipes/unified_mode_spec.rb +1 -1
  317. data/spec/integration/recipes/use_partial_spec.rb +2 -1
  318. data/spec/integration/solo/solo_spec.rb +2 -2
  319. data/spec/spec_helper.rb +7 -4
  320. data/spec/support/chef_helpers.rb +2 -2
  321. data/spec/support/platform_helpers.rb +28 -7
  322. data/spec/support/ruby_installer.rb +1 -1
  323. data/spec/support/shared/functional/file_resource.rb +3 -3
  324. data/spec/support/shared/functional/windows_script.rb +2 -2
  325. data/spec/tiny_server.rb +5 -2
  326. data/spec/unit/application/client_spec.rb +0 -10
  327. data/spec/unit/chef_fs/file_system_spec.rb +2 -0
  328. data/spec/unit/client_spec.rb +80 -4
  329. data/spec/unit/compliance/runner_spec.rb +8 -0
  330. data/spec/unit/cookbook/syntax_check_spec.rb +3 -0
  331. data/spec/unit/data_collector_spec.rb +106 -2
  332. data/spec/unit/delayed_evaluator_spec.rb +35 -0
  333. data/spec/unit/file_cache_spec.rb +64 -0
  334. data/spec/unit/http/authenticator_spec.rb +121 -0
  335. data/spec/unit/mixin/homebrew_spec.rb +118 -0
  336. data/spec/unit/mixin/openssl_helper_spec.rb +5 -0
  337. data/spec/unit/mixin/powershell_exec_spec.rb +5 -5
  338. data/spec/unit/node/vivid_mash_spec.rb +42 -0
  339. data/spec/unit/node_spec.rb +6 -0
  340. data/spec/unit/platform/query_helpers_spec.rb +2 -17
  341. data/spec/unit/property/validation_spec.rb +30 -0
  342. data/spec/unit/provider/apt_repository_spec.rb +48 -12
  343. data/spec/unit/provider/cron_spec.rb +2 -0
  344. data/spec/unit/provider/http_request_spec.rb +60 -72
  345. data/spec/unit/provider/launchd_spec.rb +2 -2
  346. data/spec/unit/provider/mount/aix_spec.rb +2 -2
  347. data/spec/unit/provider/mount/linux_spec.rb +15 -4
  348. data/spec/unit/provider/mount/mount_spec.rb +8 -8
  349. data/spec/unit/provider/package/apt_spec.rb +18 -13
  350. data/spec/unit/provider/package/chocolatey_spec.rb +41 -9
  351. data/spec/unit/provider/package/homebrew_spec.rb +4 -1
  352. data/spec/unit/provider/package/rpm_spec.rb +2 -2
  353. data/spec/unit/provider/package/rubygems_spec.rb +1 -1
  354. data/spec/unit/provider/package/windows_spec.rb +5 -5
  355. data/spec/unit/provider/package/zypper_spec.rb +32 -0
  356. data/spec/unit/provider/powershell_script_spec.rb +100 -4
  357. data/spec/unit/provider/registry_key_spec.rb +17 -17
  358. data/spec/unit/provider/remote_file/http_spec.rb +4 -4
  359. data/spec/unit/provider/service/systemd_service_spec.rb +1 -0
  360. data/spec/unit/provider/user/linux_spec.rb +51 -1
  361. data/spec/unit/provider/user/windows_spec.rb +1 -0
  362. data/spec/unit/provider/user_spec.rb +24 -6
  363. data/spec/unit/resource/apt_repository_spec.rb +5 -0
  364. data/spec/unit/resource/archive_file_spec.rb +1 -1
  365. data/spec/unit/resource/chef_client_cron_spec.rb +5 -0
  366. data/spec/unit/resource/chef_client_launchd_spec.rb +5 -0
  367. data/spec/unit/resource/chef_client_scheduled_task_spec.rb +5 -0
  368. data/spec/unit/resource/chef_client_systemd_timer_spec.rb +1 -1
  369. data/spec/unit/resource/chocolatey_installer_spec.rb +151 -0
  370. data/spec/unit/resource/cron_d_spec.rb +37 -1
  371. data/spec/unit/resource/macos_pkg_spec.rb +38 -0
  372. data/spec/unit/resource/powershell_script_spec.rb +2 -2
  373. data/spec/unit/resource/rest_resource_spec.rb +381 -0
  374. data/spec/unit/resource/selinux_boolean_spec.rb +92 -0
  375. data/spec/unit/resource/selinux_fcontext_spec.rb +65 -0
  376. data/spec/unit/resource/selinux_install_spec.rb +60 -0
  377. data/spec/unit/resource/selinux_login_spec.rb +73 -0
  378. data/spec/unit/resource/selinux_module_spec.rb +55 -0
  379. data/spec/unit/resource/selinux_permissive_spec.rb +39 -0
  380. data/spec/unit/resource/selinux_port_spec.rb +42 -0
  381. data/spec/unit/resource/selinux_state_spec.rb +46 -0
  382. data/spec/unit/resource/selinux_user_spec.rb +92 -0
  383. data/spec/unit/resource/sysctl_spec.rb +2 -2
  384. data/spec/unit/resource/user/linux_user_spec.rb +42 -0
  385. data/spec/unit/resource/yum_repository_spec.rb +4 -0
  386. data/spec/unit/resource_inspector_spec.rb +36 -0
  387. data/spec/unit/resource_reporter_spec.rb +57 -3
  388. data/spec/unit/resource_spec.rb +94 -2
  389. data/spec/unit/util/dsc/local_configuration_manager_spec.rb +1 -1
  390. data/spec/unit/util/powershell/ps_credential_spec.rb +6 -0
  391. data/tasks/rspec.rb +1 -1
  392. metadata +126 -44
  393. data/lib/chef/powershell.rb +0 -81
  394. data/spec/unit/mixin/homebrew_user_spec.rb +0 -119
  395. /data/spec/functional/assets/yumrepo/repodata/{01a3b-filelists.sqlite.bz2 → 4632d67cb92636e7575d911c24f0e04d3505a944e97c483abe0c3e73a7c62d33-filelists.sqlite.bz2} +0 -0
  396. /data/spec/functional/assets/yumrepo/repodata/{6bf96-other.xml.gz → 74599b793e54d877323837d2d81a1c3c594c44e4335f9528234bb490f7b9b439-other.xml.gz} +0 -0
  397. /data/spec/functional/assets/yumrepo/repodata/{5dc1e-primary.sqlite.bz2 → a845d418f919d2115ab95a56b2c76f6825ad0d0bede49181a55c04f58995d057-primary.sqlite.bz2} +0 -0
  398. /data/spec/functional/assets/yumrepo/repodata/{7c365-other.sqlite.bz2 → af9b7cf9ef23bd7b43068d74a460f3b5d06753d638e58e4a0c9edc35bfb9cdc4-other.sqlite.bz2} +0 -0
  399. /data/spec/functional/assets/yumrepo/repodata/{401dc-filelists.xml.gz → bdb4f5f1492a3b9532f22c43110a81500dd744f23da0aec5c33b2a41317c737d-filelists.xml.gz} +0 -0
  400. /data/spec/functional/assets/yumrepo/repodata/{dabe2-primary.xml.gz → c10d1d34ce99e02f12ec96ef68360543ab1bb7c3cb81a4a2bf78df7d8597e9df-primary.xml.gz} +0 -0
@@ -16,16 +16,19 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
+ require "chef/mixin/powershell_exec"
19
20
  require_relative "auth_credentials"
20
21
  require_relative "../exceptions"
22
+ require_relative "../win32/registry"
21
23
  autoload :OpenSSL, "openssl"
22
24
 
23
25
  class Chef
24
26
  class HTTP
25
27
  class Authenticator
26
-
27
28
  DEFAULT_SERVER_API_VERSION = "2".freeze
28
29
 
30
+ extend Chef::Mixin::PowershellExec
31
+
29
32
  attr_reader :signing_key_filename
30
33
  attr_reader :raw_key
31
34
  attr_reader :attr_names
@@ -83,13 +86,78 @@ class Chef
83
86
  @auth_credentials.client_name
84
87
  end
85
88
 
89
+ def detect_certificate_key(client_name)
90
+ self.class.detect_certificate_key(client_name)
91
+ end
92
+
93
+ def check_certstore_for_key(client_name)
94
+ self.class.check_certstore_for_key(client_name)
95
+ end
96
+
97
+ def retrieve_certificate_key(client_name)
98
+ self.class.retrieve_certificate_key(client_name)
99
+ end
100
+
101
+ def get_cert_password
102
+ self.class.get_cert_password
103
+ end
104
+
105
+ def encrypt_pfx_pass_with_vector
106
+ self.class.encrypt_pfx_pass_with_vector
107
+ end
108
+
109
+ def decrypt_pfx_pass_with_vector
110
+ self.class.decrypt_pfx_pass_with_vector
111
+ end
112
+
113
+ # Detects if a private key exists in a certificate repository like Keychain (macOS) or Certificate Store (Windows)
114
+ #
115
+ # @param client_name - we're using the node name to store and retrieve any keys
116
+ # Returns true if a key is found, false if not. False will trigger a registration event which will lead to a certificate based key being created
117
+ #
118
+ def self.detect_certificate_key(client_name)
119
+ if ChefUtils.windows?
120
+ check_certstore_for_key(client_name)
121
+ else # generic return for Mac and LInux clients
122
+ false
123
+ end
124
+ end
125
+
126
+ def self.get_cert_user
127
+ Chef::Config[:auth_key_registry_type] == "user" ? "CurrentUser" : "LocalMachine"
128
+ end
129
+
130
+ def self.get_registry_user
131
+ Chef::Config[:auth_key_registry_type] == "user" ? "HKEY_CURRENT_USER" : "HKEY_LOCAL_MACHINE"
132
+ end
133
+
134
+ def self.check_certstore_for_key(client_name)
135
+ store = get_cert_user
136
+ powershell_code = <<~CODE
137
+ $cert = Get-ChildItem -path cert:\\#{store}\\My -Recurse -Force | Where-Object { $_.Subject -Match "chef-#{client_name}" } -ErrorAction Stop
138
+ if (($cert.HasPrivateKey -eq $true) -and ($cert.PrivateKey.Key.ExportPolicy -ne "NonExportable")) {
139
+ return $true
140
+ }
141
+ else{
142
+ return $false
143
+ }
144
+ CODE
145
+ powershell_exec!(powershell_code).result
146
+ end
147
+
86
148
  def load_signing_key(key_file, raw_key = nil)
87
- if !!key_file
149
+ results = retrieve_certificate_key(Chef::Config[:node_name])
150
+
151
+ if !!results
152
+ @raw_key = results
153
+ elsif key_file == nil? && raw_key == nil?
154
+ puts "\nNo key detected\n"
155
+ elsif !!key_file
88
156
  @raw_key = IO.read(key_file).strip
89
157
  elsif !!raw_key
90
158
  @raw_key = raw_key.strip
91
159
  else
92
- return nil
160
+ return
93
161
  end
94
162
  # Pass in '' as the passphrase to avoid OpenSSL prompting on the TTY if
95
163
  # given an encrypted key. This also helps if using a single file for
@@ -104,6 +172,188 @@ class Chef
104
172
  raise Chef::Exceptions::InvalidPrivateKey, msg
105
173
  end
106
174
 
175
+ def self.get_cert_password
176
+ store = get_registry_user
177
+ @win32registry = Chef::Win32::Registry.new
178
+ path = "#{store}\\Software\\Progress\\Authentication"
179
+ # does the registry key even exist?
180
+ # password_blob should be an array of hashes
181
+ password_blob = @win32registry.get_values(path)
182
+ if password_blob.nil? || password_blob.empty?
183
+ raise Chef::Exceptions::Win32RegKeyMissing
184
+ end
185
+
186
+ # Did someone have just the password stored in the registry?
187
+ raw_data = password_blob.map { |x| x[:data] }
188
+ vector = raw_data[2]
189
+ if !!vector
190
+ decrypted_password = decrypt_pfx_pass_with_vector(password_blob)
191
+ else
192
+ decrypted_password = decrypt_pfx_pass_with_password(password_blob)
193
+ if !!decrypted_password
194
+ migrate_pass_to_use_vector(decrypted_password)
195
+ else
196
+ Chef::Log.error("Failed to retrieve certificate password")
197
+ end
198
+ end
199
+ decrypted_password
200
+ rescue Chef::Exceptions::Win32RegKeyMissing
201
+ # if we don't have a password, log that and generate one
202
+ store = get_registry_user
203
+ new_path = "#{store}\\Software\\Progress\\Authentication"
204
+ unless @win32registry.key_exists?(new_path)
205
+ @win32registry.create_key(new_path, true)
206
+ end
207
+ create_and_store_new_password
208
+ end
209
+
210
+ def self.encrypt_pfx_pass_with_vector(password)
211
+ powershell_code = <<~CODE
212
+ $AES = [System.Security.Cryptography.Aes]::Create()
213
+ $key_temp = [System.Convert]::ToBase64String($AES.Key)
214
+ $iv_temp = [System.Convert]::ToBase64String($AES.IV)
215
+ $encryptor = $AES.CreateEncryptor()
216
+ [System.Byte[]]$Bytes = [System.Text.Encoding]::Unicode.GetBytes("#{password}")
217
+ $EncryptedBytes = $encryptor.TransformFinalBlock($Bytes,0,$Bytes.Length)
218
+ $EncryptedBase64String = [System.Convert]::ToBase64String($EncryptedBytes)
219
+ # create array of encrypted pass, key, iv
220
+ $password_blob = @($EncryptedBase64String, $key_temp, $iv_temp)
221
+ return $password_blob
222
+ CODE
223
+ powershell_exec!(powershell_code).result
224
+ end
225
+
226
+ def self.decrypt_pfx_pass_with_vector(password_blob)
227
+ raw_data = password_blob.map { |x| x[:data] }
228
+ password = raw_data[0]
229
+ key = raw_data[1]
230
+ vector = raw_data[2]
231
+
232
+ powershell_code = <<~CODE
233
+ $KeyBytes = [System.Convert]::FromBase64String("#{key}")
234
+ $IVBytes = [System.Convert]::FromBase64String("#{vector}")
235
+ $aes = [System.Security.Cryptography.Aes]::Create()
236
+ $aes.Key = $KeyBytes
237
+ $aes.IV = $IVBytes
238
+ $EncryptedBytes = [System.Convert]::FromBase64String("#{password}")
239
+ $Decryptor = $aes.CreateDecryptor()
240
+ $DecryptedBytes = $Decryptor.TransformFinalBlock($EncryptedBytes,0,$EncryptedBytes.Length)
241
+ $DecryptedString = [System.Text.Encoding]::Unicode.GetString($DecryptedBytes)
242
+ return $DecryptedString
243
+ CODE
244
+ results = powershell_exec!(powershell_code).result
245
+ end
246
+
247
+ def self.decrypt_pfx_pass_with_password(password_blob)
248
+ password = ""
249
+ password_blob.each do |secret|
250
+ if secret[:name] == "PfxPass"
251
+ password = secret[:data]
252
+ else
253
+ Chef::Log.error("Failed to retrieve a password for the private key")
254
+ end
255
+ end
256
+ powershell_code = <<~CODE
257
+ $secure_string = "#{password}" | ConvertTo-SecureString
258
+ $string = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR((($secure_string))))
259
+ return $string
260
+ CODE
261
+ powershell_exec!(powershell_code).result
262
+ end
263
+
264
+ def self.migrate_pass_to_use_vector(password)
265
+ store = get_cert_user
266
+ corrected_store = (store == "CurrentUser" ? "HKCU" : "HKLM")
267
+ powershell_code = <<~CODE
268
+ Remove-ItemProperty -Path "#{corrected_store}:\\Software\\Progress\\Authentication" -Name "PfXPass"
269
+ CODE
270
+ powershell_exec!(powershell_code)
271
+ create_and_store_new_password(password)
272
+ end
273
+
274
+ # This method name is a bit of a misnomer. We call it to legit create a new password using the vector format.
275
+ # But we also call it with a password that needs to be migrated to use the vector format too.
276
+ def self.create_and_store_new_password(password = nil)
277
+ @win32registry = Chef::Win32::Registry.new
278
+ store = get_registry_user
279
+ path = "#{store}\\Software\\Progress\\Authentication"
280
+ if password.nil?
281
+ require "securerandom" unless defined?(SecureRandom)
282
+ size = 14
283
+ password = SecureRandom.alphanumeric(size)
284
+ end
285
+ encrypted_blob = encrypt_pfx_pass_with_vector(password)
286
+ encrypted_password = encrypted_blob[0]
287
+ key = encrypted_blob[1]
288
+ vector = encrypted_blob[2]
289
+ values = [
290
+ { name: "PfxPass", type: :string, data: encrypted_password },
291
+ { name: "PfxKey", type: :string, data: key },
292
+ { name: "PfxIV", type: :string, data: vector },
293
+ ]
294
+ values.each do |i|
295
+ @win32registry.set_value(path, i)
296
+ end
297
+ password
298
+ end
299
+
300
+ def self.retrieve_certificate_key(client_name)
301
+ if ChefUtils.windows?
302
+ require "openssl" unless defined?(OpenSSL)
303
+ password = get_cert_password
304
+ return false unless password
305
+
306
+ if !!check_certstore_for_key(client_name)
307
+ ps_blob = powershell_exec!(get_the_key_ps(client_name, password)).result
308
+ file_path = ps_blob["PSPath"].split("::")[1]
309
+ pkcs = OpenSSL::PKCS12.new(File.binread(file_path), password)
310
+
311
+ # We check the pfx we just extracted the private key from
312
+ # if that cert is expiring in 7 days or less we generate a new pfx/p12 object
313
+ # then we post the new public key from that to the client endpoint on
314
+ # chef server.
315
+ File.delete(file_path)
316
+ key_expiring = is_certificate_expiring?(pkcs)
317
+ if key_expiring
318
+ powershell_exec!(delete_old_key_ps(client_name))
319
+ ::Chef::Client.update_key_and_register(Chef::Config[:client_name], pkcs)
320
+ end
321
+
322
+ return pkcs.key.private_to_pem
323
+ end
324
+ end
325
+
326
+ false
327
+ end
328
+
329
+ def self.is_certificate_expiring?(pkcs)
330
+ today = Date.parse(Time.now.utc.iso8601)
331
+ future = Date.parse(pkcs.certificate.not_after.iso8601)
332
+ future.mjd - today.mjd <= 7
333
+ end
334
+
335
+ def self.get_the_key_ps(client_name, password)
336
+ store = get_cert_user
337
+ powershell_code = <<~CODE
338
+ Try {
339
+ $my_pwd = ConvertTo-SecureString -String "#{password}" -Force -AsPlainText;
340
+ $cert = Get-ChildItem -path cert:\\#{store}\\My -Recurse | Where-Object { $_.Subject -match "chef-#{client_name}$" } -ErrorAction Stop;
341
+ $tempfile = [System.IO.Path]::GetTempPath() + "export_pfx.pfx";
342
+ Export-PfxCertificate -Cert $cert -Password $my_pwd -FilePath $tempfile;
343
+ }
344
+ Catch {
345
+ return $false
346
+ }
347
+ CODE
348
+ end
349
+
350
+ def self.delete_old_key_ps(client_name)
351
+ store = get_cert_user
352
+ powershell_code = <<~CODE
353
+ Get-ChildItem -path cert:\\#{store}\\My -Recurse | Where-Object { $_.Subject -match "chef-#{client_name}$" } | Remove-Item -ErrorAction Stop;
354
+ CODE
355
+ end
356
+
107
357
  def authentication_headers(method, url, json_body = nil, headers = nil)
108
358
  request_params = {
109
359
  http_method: method,
@@ -88,10 +88,10 @@ class Chef
88
88
  certs = Dir.glob(::File.join(Chef::Util::PathHelper.escape_glob_dir(config.trusted_certs_dir), "*.{crt,pem}"))
89
89
  certs.each do |cert_file|
90
90
  cert = begin
91
- OpenSSL::X509::Certificate.new(::File.binread(cert_file))
91
+ OpenSSL::X509::Certificate.new(::File.binread(cert_file))
92
92
  rescue OpenSSL::X509::CertificateError => e
93
93
  raise Chef::Exceptions::ConfigurationError, "Error reading cert file '#{cert_file}', original error '#{e.class}: #{e.message}'"
94
- end
94
+ end
95
95
  add_trusted_cert(cert)
96
96
  end
97
97
  end
@@ -27,7 +27,7 @@ require "etc" unless defined?(Etc)
27
27
 
28
28
  class Chef
29
29
  module Mixin
30
- module HomebrewUser
30
+ module Homebrew
31
31
  include Chef::Mixin::ShellOut
32
32
 
33
33
  ##
@@ -57,15 +57,19 @@ class Chef
57
57
  @homebrew_owner_username
58
58
  end
59
59
 
60
+ # Use homebrew_bin_path to return the path to the brew binary
61
+ # @param [String, Array(String)] brew_bin_path
62
+ # @return [String] path to the brew binary
60
63
  def homebrew_bin_path(brew_bin_path = nil)
61
64
  if brew_bin_path && ::File.exist?(brew_bin_path)
62
65
  brew_bin_path
63
66
  else
64
- [which("brew"), "/opt/homebrew/bin/brew", "/usr/local/bin/brew", "/home/linuxbrew/.linuxbrew/bin/brew"].uniq.select do |x|
65
- next if x == false
67
+ brew_path = which("brew", prepend_path: %w{/opt/homebrew/bin /usr/local/bin /home/linuxbrew/.linuxbrew/bin})
68
+ unless brew_path
69
+ raise Chef::Exceptions::CannotDetermineHomebrewPath, 'Couldn\'t find the "brew" executable anywhere on the path.'
70
+ end
66
71
 
67
- ::File.exist?(x) && ::File.executable?(x)
68
- end.first || nil
72
+ brew_path
69
73
  end
70
74
  end
71
75
 
@@ -73,18 +77,11 @@ class Chef
73
77
 
74
78
  def calculate_owner
75
79
  brew_path = homebrew_bin_path
76
- if brew_path
77
- # By default, this follows symlinks which is what we want
78
- owner = ::File.stat(brew_path).uid
79
- else
80
- raise Chef::Exceptions::CannotDetermineHomebrewOwner,
81
- 'Could not find the "brew" executable anywhere on the path.'
82
- end
83
-
84
- Chef::Log.debug "Found Homebrew owner #{Etc.getpwuid(owner).name}; executing `brew` commands as them"
85
- owner
80
+ # By default, this follows symlinks which is what we want
81
+ owner_uid = ::File.stat(brew_path).uid
82
+ Chef::Log.debug "Found Homebrew owner #{Etc.getpwuid(owner_uid).name}; executing `brew` commands as them"
83
+ owner_uid
86
84
  end
87
-
88
85
  end
89
86
  end
90
87
  end
@@ -170,22 +170,7 @@ class Chef
170
170
  key_content = ::File.exist?(priv_key) ? File.read(priv_key) : priv_key
171
171
  key = ::OpenSSL::PKey::EC.new key_content, priv_key_password
172
172
 
173
- if windows? || macos? || aix?
174
- # Get curve type (prime256v1...)
175
- group = ::OpenSSL::PKey::EC::Group.new(key.group.curve_name)
176
- # Get Generator point & public point (priv * generator)
177
- generator = group.generator
178
- pub_point = generator.mul(key.private_key)
179
- key.public_key = pub_point
180
-
181
- # Public Key in pem
182
- public_key = ::OpenSSL::PKey::EC.new
183
- public_key.group = group
184
- public_key.public_key = pub_point
185
- public_key.to_pem
186
- else
187
- key.public_to_pem
188
- end
173
+ key.public_to_pem
189
174
  end
190
175
 
191
176
  # generate a pem file given a cipher, key, an optional key_password
@@ -15,9 +15,6 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
- require_relative "../powershell"
19
- require_relative "../pwsh"
20
-
21
18
  # The powershell_exec mixin provides in-process access to the PowerShell engine.
22
19
  #
23
20
  # powershell_exec is initialized with a string that should be set to the script
@@ -94,35 +91,15 @@ require_relative "../pwsh"
94
91
  # - It is not possible to impersonate another user running powershell, the
95
92
  # credentials of the user running Chef Client are used.
96
93
  #
94
+ if ChefUtils.windows?
95
+ require "chef-powershell"
96
+ end
97
97
 
98
98
  class Chef
99
99
  module Mixin
100
100
  module PowershellExec
101
- # Run a command under PowerShell via a managed (.NET) API.
102
- #
103
- # Requires: .NET Framework 4.0 or higher on the target machine.
104
- #
105
- # @param script [String] script to run
106
- # @param interpreter [Symbol] the interpreter type, `:powershell` or `:pwsh`
107
- # @param timeout [Integer, nil] timeout in seconds.
108
- # @return [Chef::PowerShell] output
109
- def powershell_exec(script, interpreter = :powershell, timeout: -1)
110
- case interpreter
111
- when :powershell
112
- Chef::PowerShell.new(script, timeout: timeout)
113
- when :pwsh
114
- Chef::Pwsh.new(script, timeout: timeout)
115
- else
116
- raise ArgumentError, "Expected interpreter of :powershell or :pwsh"
117
- end
118
- end
119
-
120
- # The same as the #powershell_exec method except this will raise
121
- # Chef::PowerShell::CommandFailed if the command fails
122
- def powershell_exec!(script, interpreter = :powershell, **options)
123
- cmd = powershell_exec(script, interpreter, **options)
124
- cmd.error!
125
- cmd
101
+ if ChefUtils.windows?
102
+ include ChefPowerShell::ChefPowerShellModule::PowerShellExec
126
103
  end
127
104
  end
128
105
  end
@@ -0,0 +1,127 @@
1
+ if RUBY_VERSION.split(".")[0..1].join(".") == "3.1"
2
+ require "net/http" unless defined?(Net::HTTP)
3
+ # This is monkey-patch for ruby 3.1.x
4
+ # Due to change https://github.com/ruby/net-http/pull/10, when making net/http requests to a url which supports only IPv6 and not IPv4,
5
+ # ruby waits for IPv4 request to timeout first, then makes IPv6 request. This increased response time.
6
+ # NOTE 1: This is already reverted https://github.com/ruby/ruby/commit/f88bff770578583a708093f4a0d8b1483a1d2039 but under ruby 3.2.2
7
+ # NOTE 2: We are patching action `connect` from here https://github.com/ruby/ruby/blob/f88bff770578583a708093f4a0d8b1483a1d2039/lib/net/http.rb#L1000
8
+
9
+ module Net
10
+ class HTTP
11
+ def connect
12
+ if use_ssl?
13
+ # reference early to load OpenSSL before connecting,
14
+ # as OpenSSL may take time to load.
15
+ @ssl_context = OpenSSL::SSL::SSLContext.new
16
+ end
17
+
18
+ if proxy?
19
+ conn_addr = proxy_address
20
+ conn_port = proxy_port
21
+ else
22
+ conn_addr = conn_address
23
+ conn_port = port
24
+ end
25
+
26
+ Chef::Log.debug("opening connection to #{conn_addr}:#{conn_port}...")
27
+ s = Timeout.timeout(@open_timeout, Net::OpenTimeout) {
28
+ begin
29
+ TCPSocket.open(conn_addr, conn_port, @local_host, @local_port)
30
+ rescue => e
31
+ raise e, "Failed to open TCP connection to " +
32
+ "#{conn_addr}:#{conn_port} (#{e.message})"
33
+ end
34
+ }
35
+ s.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
36
+ Chef::Log.debug("opened")
37
+ if use_ssl?
38
+ if proxy?
39
+ plain_sock = BufferedIO.new(s, read_timeout: @read_timeout,
40
+ write_timeout: @write_timeout,
41
+ continue_timeout: @continue_timeout,
42
+ debug_output: @debug_output)
43
+ buf = "CONNECT #{conn_address}:#{@port} HTTP/#{HTTPVersion}\r\n"
44
+ buf << "Host: #{@address}:#{@port}\r\n"
45
+ if proxy_user
46
+ credential = ["#{proxy_user}:#{proxy_pass}"].pack("m0")
47
+ buf << "Proxy-Authorization: Basic #{credential}\r\n"
48
+ end
49
+ buf << "\r\n"
50
+ plain_sock.write(buf)
51
+ HTTPResponse.read_new(plain_sock).value
52
+ # assuming nothing left in buffers after successful CONNECT response
53
+ end
54
+
55
+ ssl_parameters = {}
56
+ iv_list = instance_variables
57
+ SSL_IVNAMES.each_with_index do |ivname, i|
58
+ if iv_list.include?(ivname)
59
+ value = instance_variable_get(ivname)
60
+ unless value.nil?
61
+ ssl_parameters[SSL_ATTRIBUTES[i]] = value
62
+ end
63
+ end
64
+ end
65
+ @ssl_context.set_params(ssl_parameters)
66
+ unless @ssl_context.session_cache_mode.nil? # a dummy method on JRuby
67
+ @ssl_context.session_cache_mode =
68
+ OpenSSL::SSL::SSLContext::SESSION_CACHE_CLIENT |
69
+ OpenSSL::SSL::SSLContext::SESSION_CACHE_NO_INTERNAL_STORE
70
+ end
71
+ if @ssl_context.respond_to?(:session_new_cb) # not implemented under JRuby
72
+ @ssl_context.session_new_cb = proc { |sock, sess| @ssl_session = sess }
73
+ end
74
+
75
+ # Still do the post_connection_check below even if connecting
76
+ # to IP address
77
+ verify_hostname = @ssl_context.verify_hostname
78
+
79
+ # requiring 'resolv' near the top of the file causes registry.rb monkey patch to fail
80
+ # Windows 2012 R2 somehow fails to have Resolv defined unless we require it manually
81
+ require "resolv" unless defined?(Resolv)
82
+
83
+ # Server Name Indication (SNI) RFC 3546/6066
84
+ case @address
85
+ when ::Resolv::IPv4::Regex, ::Resolv::IPv6::Regex
86
+ # don't set SNI, as IP addresses in SNI is not valid
87
+ # per RFC 6066, section 3.
88
+
89
+ # Avoid openssl warning
90
+ @ssl_context.verify_hostname = false
91
+ else
92
+ ssl_host_address = @address
93
+ end
94
+
95
+ Chef::Log.debug("starting SSL for #{conn_addr}:#{conn_port}...")
96
+ s = OpenSSL::SSL::SSLSocket.new(s, @ssl_context)
97
+ s.sync_close = true
98
+ s.hostname = ssl_host_address if s.respond_to?(:hostname=) && ssl_host_address
99
+
100
+ if @ssl_session &&
101
+ (Process.clock_gettime(Process::CLOCK_REALTIME) < @ssl_session.time.to_f + @ssl_session.timeout)
102
+ s.session = @ssl_session
103
+ end
104
+ ssl_socket_connect(s, @open_timeout)
105
+ if (@ssl_context.verify_mode != OpenSSL::SSL::VERIFY_NONE) && verify_hostname
106
+ s.post_connection_check(@address)
107
+ end
108
+ Chef::Log.debug("SSL established, protocol: #{s.ssl_version}, cipher: #{s.cipher[0]}")
109
+ end
110
+ @socket = BufferedIO.new(s, read_timeout: @read_timeout,
111
+ write_timeout: @write_timeout,
112
+ continue_timeout: @continue_timeout,
113
+ debug_output: @debug_output)
114
+ @last_communicated = nil
115
+ on_connect
116
+ rescue => exception
117
+ if s
118
+ Chef::Log.debug("Conn close because of connect error #{exception}")
119
+ s.close
120
+ end
121
+ raise
122
+ end
123
+ end
124
+ end
125
+ else
126
+ warn "Not applying net/http monkey patch needed for ruby 3.1"
127
+ end
@@ -570,7 +570,7 @@ class Chef
570
570
  ]
571
571
 
572
572
  ret = components.inject(NIL) do |merged, component|
573
- hash_only_merge!(merged, component)
573
+ component == NIL ? merged : hash_only_merge!(merged, component)
574
574
  end
575
575
  ret == NIL ? nil : ret
576
576
  end
@@ -584,7 +584,7 @@ class Chef
584
584
  def merge_defaults(path)
585
585
  DEFAULT_COMPONENTS.inject(NIL) do |merged, component_ivar|
586
586
  component_value = apply_path(instance_variable_get(component_ivar), path)
587
- deep_merge!(merged, component_value)
587
+ component_value == NIL ? merged : deep_merge!(merged, component_value)
588
588
  end
589
589
  end
590
590
 
@@ -597,7 +597,7 @@ class Chef
597
597
  def merge_overrides(path)
598
598
  OVERRIDE_COMPONENTS.inject(NIL) do |merged, component_ivar|
599
599
  component_value = apply_path(instance_variable_get(component_ivar), path)
600
- deep_merge!(merged, component_value)
600
+ component_value == NIL ? merged : deep_merge!(merged, component_value)
601
601
  end
602
602
  end
603
603
 
@@ -628,10 +628,6 @@ class Chef
628
628
  elsif merge_onto.is_a?(Array) && merge_with.is_a?(Array)
629
629
  merge_onto |= merge_with
630
630
 
631
- # If merge_with is NIL, don't replace merge_onto
632
- elsif merge_with == NIL
633
- merge_onto
634
-
635
631
  # In all other cases, replace merge_onto with merge_with
636
632
  else
637
633
  if merge_with.is_a?(Hash)
@@ -661,10 +657,6 @@ class Chef
661
657
  end
662
658
  merge_onto
663
659
 
664
- # If merge_with is NIL, don't replace merge_onto
665
- elsif merge_with == NIL
666
- merge_onto
667
-
668
660
  # In all other cases, replace merge_onto with merge_with
669
661
  else
670
662
  if merge_with.is_a?(Hash)
@@ -18,6 +18,7 @@
18
18
 
19
19
  require_relative "common_api"
20
20
  require_relative "mixin/state_tracking"
21
+ require_relative "mixin/state_tracking_array"
21
22
  require_relative "mixin/immutablize_array"
22
23
  require_relative "mixin/immutablize_hash"
23
24
  require_relative "mixin/mashy_array"
@@ -39,11 +40,19 @@ class Chef
39
40
  MUTATOR_METHODS.each do |mutator|
40
41
  define_method(mutator) do |*args, &block|
41
42
  ret = super(*args, &block)
43
+ # TODO: use `send_reset_cache(__path__)` for all mutator methods?
42
44
  send_reset_cache
43
45
  ret
44
46
  end
45
47
  end
46
48
 
49
+ def <<(obj)
50
+ ret = super(obj)
51
+ # NOTE: Expecting __path__ to be top-level attribute only
52
+ send_reset_cache(__path__)
53
+ ret
54
+ end
55
+
47
56
  def delete(key, &block)
48
57
  send_reset_cache(__path__, key)
49
58
  super
@@ -89,7 +98,7 @@ class Chef
89
98
  key
90
99
  end
91
100
 
92
- prepend Chef::Node::Mixin::StateTracking
101
+ prepend Chef::Node::Mixin::StateTrackingArray
93
102
  end
94
103
 
95
104
  # == VividMash