chef 17.10.95 → 18.0.169

Sign up to get free protection for your applications and to get access to all the features.
Files changed (313) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +16 -8
  3. data/README.md +7 -7
  4. data/Rakefile +3 -22
  5. data/{chef-universal-mingw32.gemspec → chef-universal-mingw-ucrt.gemspec} +8 -7
  6. data/chef.gemspec +14 -7
  7. data/lib/chef/api_client_v1.rb +9 -1
  8. data/lib/chef/application/exit_code.rb +3 -3
  9. data/lib/chef/client.rb +169 -17
  10. data/lib/chef/compliance/input.rb +1 -1
  11. data/lib/chef/compliance/profile.rb +1 -1
  12. data/lib/chef/compliance/profile_collection.rb +0 -1
  13. data/lib/chef/compliance/waiver.rb +1 -1
  14. data/lib/chef/cookbook/syntax_check.rb +2 -2
  15. data/lib/chef/dsl/reader_helpers.rb +1 -1
  16. data/lib/chef/dsl/rest_resource.rb +77 -0
  17. data/lib/chef/event_dispatch/base.rb +3 -0
  18. data/lib/chef/exceptions.rb +8 -0
  19. data/lib/chef/http/authenticator.rb +170 -3
  20. data/lib/chef/http/ssl_policies.rb +3 -3
  21. data/lib/chef/mixin/checksum.rb +0 -6
  22. data/lib/chef/mixin/powershell_exec.rb +5 -28
  23. data/lib/chef/node/mixin/immutablize_array.rb +1 -0
  24. data/lib/chef/property.rb +5 -3
  25. data/lib/chef/provider/file.rb +2 -2
  26. data/lib/chef/provider/group/windows.rb +1 -1
  27. data/lib/chef/provider/http_request.rb +11 -9
  28. data/lib/chef/provider/mount/linux.rb +5 -0
  29. data/lib/chef/provider/mount/mount.rb +8 -0
  30. data/lib/chef/provider/mount/windows.rb +1 -1
  31. data/lib/chef/provider/package/chocolatey.rb +1 -18
  32. data/lib/chef/provider/package/rubygems.rb +1 -1
  33. data/lib/chef/provider/package/windows/msi.rb +2 -2
  34. data/lib/chef/provider/package/windows/registry_uninstall_entry.rb +1 -1
  35. data/lib/chef/provider/package/windows.rb +1 -1
  36. data/lib/chef/provider/package/zypper/version.rb +60 -0
  37. data/lib/chef/provider/package/zypper.rb +47 -3
  38. data/lib/chef/provider/service/windows.rb +1 -1
  39. data/lib/chef/provider/user/aix.rb +5 -0
  40. data/lib/chef/provider/user/linux.rb +29 -0
  41. data/lib/chef/provider/user/mac.rb +1 -1
  42. data/lib/chef/provider/user.rb +46 -14
  43. data/lib/chef/provider.rb +1 -1
  44. data/lib/chef/recipe.rb +1 -1
  45. data/lib/chef/resource/_rest_resource.rb +389 -0
  46. data/lib/chef/resource/alternatives.rb +0 -1
  47. data/lib/chef/resource/apt_package.rb +0 -1
  48. data/lib/chef/resource/apt_preference.rb +0 -1
  49. data/lib/chef/resource/apt_repository.rb +0 -1
  50. data/lib/chef/resource/apt_update.rb +0 -1
  51. data/lib/chef/resource/archive_file.rb +0 -1
  52. data/lib/chef/resource/bash.rb +0 -1
  53. data/lib/chef/resource/batch.rb +0 -1
  54. data/lib/chef/resource/bff_package.rb +0 -1
  55. data/lib/chef/resource/breakpoint.rb +0 -1
  56. data/lib/chef/resource/build_essential.rb +0 -1
  57. data/lib/chef/resource/cab_package.rb +0 -1
  58. data/lib/chef/resource/chef_client_config.rb +12 -14
  59. data/lib/chef/resource/chef_client_cron.rb +1 -2
  60. data/lib/chef/resource/chef_client_launchd.rb +2 -2
  61. data/lib/chef/resource/chef_client_scheduled_task.rb +3 -3
  62. data/lib/chef/resource/chef_client_systemd_timer.rb +0 -1
  63. data/lib/chef/resource/chef_client_trusted_certificate.rb +0 -1
  64. data/lib/chef/resource/chef_gem.rb +0 -1
  65. data/lib/chef/resource/chef_handler.rb +0 -1
  66. data/lib/chef/resource/chef_sleep.rb +1 -3
  67. data/lib/chef/resource/chef_vault_secret.rb +0 -1
  68. data/lib/chef/resource/chocolatey_config.rb +0 -1
  69. data/lib/chef/resource/chocolatey_feature.rb +0 -1
  70. data/lib/chef/resource/chocolatey_package.rb +0 -1
  71. data/lib/chef/resource/chocolatey_source.rb +0 -1
  72. data/lib/chef/resource/cookbook_file.rb +0 -1
  73. data/lib/chef/resource/cron/_cron_shared.rb +0 -1
  74. data/lib/chef/resource/cron/cron.rb +0 -1
  75. data/lib/chef/resource/cron/cron_d.rb +15 -1
  76. data/lib/chef/resource/cron_access.rb +0 -1
  77. data/lib/chef/resource/csh.rb +0 -1
  78. data/lib/chef/resource/directory.rb +0 -1
  79. data/lib/chef/resource/dmg_package.rb +0 -1
  80. data/lib/chef/resource/dnf_package.rb +0 -1
  81. data/lib/chef/resource/dpkg_package.rb +0 -1
  82. data/lib/chef/resource/dsc_resource.rb +0 -1
  83. data/lib/chef/resource/dsc_script.rb +0 -1
  84. data/lib/chef/resource/execute.rb +0 -1
  85. data/lib/chef/resource/file.rb +0 -1
  86. data/lib/chef/resource/freebsd_package.rb +0 -1
  87. data/lib/chef/resource/gem_package.rb +0 -1
  88. data/lib/chef/resource/group.rb +25 -2
  89. data/lib/chef/resource/habitat/habitat_package.rb +0 -1
  90. data/lib/chef/resource/habitat/habitat_sup.rb +6 -7
  91. data/lib/chef/resource/habitat/habitat_sup_windows.rb +1 -1
  92. data/lib/chef/resource/habitat_config.rb +0 -1
  93. data/lib/chef/resource/habitat_install.rb +0 -1
  94. data/lib/chef/resource/habitat_service.rb +0 -1
  95. data/lib/chef/resource/habitat_user_toml.rb +0 -1
  96. data/lib/chef/resource/homebrew_cask.rb +0 -1
  97. data/lib/chef/resource/homebrew_package.rb +0 -1
  98. data/lib/chef/resource/homebrew_tap.rb +0 -1
  99. data/lib/chef/resource/homebrew_update.rb +0 -2
  100. data/lib/chef/resource/hostname.rb +0 -1
  101. data/lib/chef/resource/http_request.rb +0 -1
  102. data/lib/chef/resource/ifconfig.rb +0 -1
  103. data/lib/chef/resource/inspec_input.rb +0 -1
  104. data/lib/chef/resource/inspec_waiver.rb +0 -1
  105. data/lib/chef/resource/inspec_waiver_file_entry.rb +2 -3
  106. data/lib/chef/resource/ips_package.rb +0 -1
  107. data/lib/chef/resource/kernel_module.rb +0 -1
  108. data/lib/chef/resource/ksh.rb +0 -1
  109. data/lib/chef/resource/launchd.rb +0 -1
  110. data/lib/chef/resource/link.rb +0 -1
  111. data/lib/chef/resource/locale.rb +2 -6
  112. data/lib/chef/resource/log.rb +0 -1
  113. data/lib/chef/resource/lwrp_base.rb +0 -4
  114. data/lib/chef/resource/macos_userdefaults.rb +5 -10
  115. data/lib/chef/resource/macosx_service.rb +0 -1
  116. data/lib/chef/resource/macports_package.rb +0 -1
  117. data/lib/chef/resource/mdadm.rb +0 -1
  118. data/lib/chef/resource/mount.rb +0 -1
  119. data/lib/chef/resource/msu_package.rb +0 -1
  120. data/lib/chef/resource/notify_group.rb +0 -2
  121. data/lib/chef/resource/ohai.rb +0 -1
  122. data/lib/chef/resource/ohai_hint.rb +0 -1
  123. data/lib/chef/resource/openbsd_package.rb +0 -1
  124. data/lib/chef/resource/openssl_dhparam.rb +0 -2
  125. data/lib/chef/resource/openssl_ec_private_key.rb +0 -2
  126. data/lib/chef/resource/openssl_ec_public_key.rb +0 -2
  127. data/lib/chef/resource/openssl_rsa_private_key.rb +0 -2
  128. data/lib/chef/resource/openssl_rsa_public_key.rb +0 -2
  129. data/lib/chef/resource/openssl_x509_certificate.rb +0 -2
  130. data/lib/chef/resource/openssl_x509_crl.rb +0 -2
  131. data/lib/chef/resource/openssl_x509_request.rb +0 -2
  132. data/lib/chef/resource/osx_profile.rb +0 -1
  133. data/lib/chef/resource/package.rb +0 -1
  134. data/lib/chef/resource/pacman_package.rb +0 -1
  135. data/lib/chef/resource/paludis_package.rb +0 -1
  136. data/lib/chef/resource/perl.rb +0 -1
  137. data/lib/chef/resource/plist.rb +7 -3
  138. data/lib/chef/resource/portage_package.rb +0 -1
  139. data/lib/chef/resource/powershell_package.rb +0 -1
  140. data/lib/chef/resource/powershell_package_source.rb +0 -1
  141. data/lib/chef/resource/powershell_script.rb +0 -1
  142. data/lib/chef/resource/python.rb +0 -1
  143. data/lib/chef/resource/reboot.rb +0 -1
  144. data/lib/chef/resource/registry_key.rb +0 -1
  145. data/lib/chef/resource/remote_directory.rb +0 -1
  146. data/lib/chef/resource/remote_file.rb +0 -1
  147. data/lib/chef/resource/rhsm_errata.rb +0 -1
  148. data/lib/chef/resource/rhsm_errata_level.rb +0 -1
  149. data/lib/chef/resource/rhsm_register.rb +0 -3
  150. data/lib/chef/resource/rhsm_repo.rb +0 -1
  151. data/lib/chef/resource/rhsm_subscription.rb +0 -1
  152. data/lib/chef/resource/route.rb +0 -1
  153. data/lib/chef/resource/rpm_package.rb +0 -1
  154. data/lib/chef/resource/ruby.rb +0 -1
  155. data/lib/chef/resource/ruby_block.rb +0 -1
  156. data/lib/chef/resource/scm/_scm.rb +0 -2
  157. data/lib/chef/resource/scm/git.rb +0 -2
  158. data/lib/chef/resource/scm/subversion.rb +0 -2
  159. data/lib/chef/resource/script.rb +0 -1
  160. data/lib/chef/resource/selinux/common_helpers.rb +47 -0
  161. data/lib/chef/resource/selinux/selinux_debian.erb +18 -0
  162. data/lib/chef/resource/selinux/selinux_default.erb +15 -0
  163. data/lib/chef/resource/selinux_boolean.rb +101 -0
  164. data/lib/chef/resource/selinux_fcontext.rb +160 -0
  165. data/lib/chef/resource/selinux_install.rb +107 -0
  166. data/lib/chef/resource/selinux_module.rb +143 -0
  167. data/lib/chef/resource/selinux_permissive.rb +64 -0
  168. data/lib/chef/resource/selinux_port.rb +118 -0
  169. data/lib/chef/resource/selinux_state.rb +166 -0
  170. data/lib/chef/resource/service.rb +0 -1
  171. data/lib/chef/resource/smartos_package.rb +0 -1
  172. data/lib/chef/resource/snap_package.rb +0 -1
  173. data/lib/chef/resource/solaris_package.rb +0 -1
  174. data/lib/chef/resource/ssh_known_hosts_entry.rb +0 -1
  175. data/lib/chef/resource/sudo.rb +0 -1
  176. data/lib/chef/resource/support/client.erb +2 -2
  177. data/lib/chef/resource/swap_file.rb +0 -1
  178. data/lib/chef/resource/sysctl.rb +1 -2
  179. data/lib/chef/resource/systemd_unit.rb +0 -1
  180. data/lib/chef/resource/template.rb +0 -1
  181. data/lib/chef/resource/timezone.rb +0 -1
  182. data/lib/chef/resource/user/aix_user.rb +0 -1
  183. data/lib/chef/resource/user/linux_user.rb +0 -1
  184. data/lib/chef/resource/user/mac_user.rb +0 -1
  185. data/lib/chef/resource/user/pw_user.rb +0 -1
  186. data/lib/chef/resource/user/solaris_user.rb +0 -1
  187. data/lib/chef/resource/user/windows_user.rb +0 -1
  188. data/lib/chef/resource/user.rb +10 -1
  189. data/lib/chef/resource/user_ulimit.rb +0 -1
  190. data/lib/chef/resource/whyrun_safe_ruby_block.rb +0 -1
  191. data/lib/chef/resource/windows_ad_join.rb +0 -2
  192. data/lib/chef/resource/windows_audit_policy.rb +0 -2
  193. data/lib/chef/resource/windows_auto_run.rb +0 -1
  194. data/lib/chef/resource/windows_defender.rb +0 -1
  195. data/lib/chef/resource/windows_defender_exclusion.rb +0 -1
  196. data/lib/chef/resource/windows_dfs_folder.rb +0 -1
  197. data/lib/chef/resource/windows_dfs_namespace.rb +0 -1
  198. data/lib/chef/resource/windows_dfs_server.rb +0 -1
  199. data/lib/chef/resource/windows_dns_record.rb +0 -1
  200. data/lib/chef/resource/windows_dns_zone.rb +0 -1
  201. data/lib/chef/resource/windows_env.rb +0 -1
  202. data/lib/chef/resource/windows_feature.rb +0 -1
  203. data/lib/chef/resource/windows_feature_dism.rb +0 -1
  204. data/lib/chef/resource/windows_feature_powershell.rb +0 -1
  205. data/lib/chef/resource/windows_firewall_profile.rb +0 -2
  206. data/lib/chef/resource/windows_firewall_rule.rb +0 -1
  207. data/lib/chef/resource/windows_font.rb +2 -3
  208. data/lib/chef/resource/windows_package.rb +0 -1
  209. data/lib/chef/resource/windows_pagefile.rb +0 -2
  210. data/lib/chef/resource/windows_path.rb +0 -1
  211. data/lib/chef/resource/windows_printer.rb +0 -1
  212. data/lib/chef/resource/windows_printer_port.rb +0 -1
  213. data/lib/chef/resource/windows_script.rb +0 -2
  214. data/lib/chef/resource/windows_security_policy.rb +0 -1
  215. data/lib/chef/resource/windows_service.rb +0 -1
  216. data/lib/chef/resource/windows_share.rb +0 -1
  217. data/lib/chef/resource/windows_shortcut.rb +1 -2
  218. data/lib/chef/resource/windows_task.rb +0 -1
  219. data/lib/chef/resource/windows_uac.rb +0 -1
  220. data/lib/chef/resource/windows_update_settings.rb +0 -1
  221. data/lib/chef/resource/windows_user_privilege.rb +0 -1
  222. data/lib/chef/resource/windows_workgroup.rb +0 -1
  223. data/lib/chef/resource/yum_package.rb +0 -1
  224. data/lib/chef/resource/yum_repository.rb +0 -1
  225. data/lib/chef/resource/zypper_package.rb +0 -1
  226. data/lib/chef/resource/zypper_repository.rb +0 -1
  227. data/lib/chef/resource.rb +12 -5
  228. data/lib/chef/resources.rb +7 -0
  229. data/lib/chef/run_context.rb +3 -3
  230. data/lib/chef/secret_fetcher/azure_key_vault.rb +3 -3
  231. data/lib/chef/version.rb +1 -1
  232. data/lib/chef/win32/handle.rb +6 -7
  233. data/lib/chef/win32/registry.rb +7 -3
  234. data/spec/data/rubygems.org/sexp_processor-info +2 -1
  235. data/spec/data/trusted_certs/example.crt +20 -29
  236. data/spec/data/trusted_certs/example_no_cn.crt +34 -30
  237. data/spec/data/trusted_certs/opscode.pem +54 -33
  238. data/spec/functional/resource/chocolatey_package_spec.rb +20 -32
  239. data/spec/functional/resource/dsc_script_spec.rb +1 -1
  240. data/spec/functional/resource/group_spec.rb +10 -6
  241. data/spec/functional/resource/link_spec.rb +8 -8
  242. data/spec/functional/resource/macos_userdefaults_spec.rb +4 -4
  243. data/spec/functional/resource/plist_spec.rb +25 -0
  244. data/spec/functional/resource/user/linux_user_spec.rb +127 -0
  245. data/spec/functional/resource/windows_certificate_spec.rb +1 -26
  246. data/spec/functional/resource/windows_font_spec.rb +12 -9
  247. data/spec/functional/resource/yum_package_spec.rb +1 -1
  248. data/spec/functional/resource/zypper_package_spec.rb +12 -0
  249. data/spec/functional/shell_spec.rb +1 -2
  250. data/spec/functional/version_spec.rb +1 -1
  251. data/spec/integration/client/client_spec.rb +82 -3
  252. data/spec/integration/client/exit_code_spec.rb +1 -1
  253. data/spec/integration/client/ipv6_spec.rb +1 -1
  254. data/spec/integration/compliance/compliance_spec.rb +1 -1
  255. data/spec/integration/recipes/accumulator_spec.rb +1 -1
  256. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +1 -1
  257. data/spec/integration/recipes/lwrp_spec.rb +1 -1
  258. data/spec/integration/recipes/notifies_spec.rb +1 -1
  259. data/spec/integration/recipes/notifying_block_spec.rb +1 -1
  260. data/spec/integration/recipes/remote_directory.rb +1 -1
  261. data/spec/integration/recipes/unified_mode_spec.rb +1 -1
  262. data/spec/integration/recipes/use_partial_spec.rb +2 -1
  263. data/spec/integration/solo/solo_spec.rb +2 -2
  264. data/spec/spec_helper.rb +1 -0
  265. data/spec/support/platform_helpers.rb +4 -0
  266. data/spec/support/ruby_installer.rb +1 -1
  267. data/spec/support/shared/functional/windows_script.rb +2 -2
  268. data/spec/unit/application/client_spec.rb +0 -10
  269. data/spec/unit/client_spec.rb +57 -8
  270. data/spec/unit/compliance/reporter/chef_server_automate_spec.rb +1 -1
  271. data/spec/unit/cookbook/syntax_check_spec.rb +3 -0
  272. data/spec/unit/http/authenticator_spec.rb +68 -0
  273. data/spec/unit/mixin/checksum_spec.rb +0 -28
  274. data/spec/unit/mixin/powershell_exec_spec.rb +5 -5
  275. data/spec/unit/platform/query_helpers_spec.rb +2 -17
  276. data/spec/unit/provider/http_request_spec.rb +60 -72
  277. data/spec/unit/provider/mount/linux_spec.rb +10 -0
  278. data/spec/unit/provider/package/chocolatey_spec.rb +3 -19
  279. data/spec/unit/provider/package/rubygems_spec.rb +1 -1
  280. data/spec/unit/provider/package/zypper_spec.rb +32 -0
  281. data/spec/unit/provider/user/linux_spec.rb +51 -11
  282. data/spec/unit/provider/user_spec.rb +24 -6
  283. data/spec/unit/resource/archive_file_spec.rb +1 -1
  284. data/spec/unit/resource/chef_client_cron_spec.rb +5 -0
  285. data/spec/unit/resource/chef_client_launchd_spec.rb +5 -0
  286. data/spec/unit/resource/chef_client_scheduled_task_spec.rb +5 -0
  287. data/spec/unit/resource/chef_client_systemd_timer_spec.rb +1 -1
  288. data/spec/unit/resource/cron_d_spec.rb +37 -1
  289. data/spec/unit/resource/macos_user_defaults_spec.rb +4 -4
  290. data/spec/unit/resource/rest_resource_spec.rb +381 -0
  291. data/spec/unit/resource/selinux_boolean_spec.rb +92 -0
  292. data/spec/unit/resource/selinux_fcontext_spec.rb +65 -0
  293. data/spec/unit/resource/selinux_install_spec.rb +60 -0
  294. data/spec/unit/resource/selinux_module_spec.rb +55 -0
  295. data/spec/unit/resource/selinux_permissive_spec.rb +39 -0
  296. data/spec/unit/resource/selinux_port_spec.rb +42 -0
  297. data/spec/unit/resource/selinux_state_spec.rb +46 -0
  298. data/spec/unit/resource/sysctl_spec.rb +2 -2
  299. data/spec/unit/resource/user/linux_user_spec.rb +42 -0
  300. data/spec/unit/resource_spec.rb +0 -1
  301. data/spec/unit/util/dsc/local_configuration_manager_spec.rb +1 -1
  302. data/tasks/rspec.rb +1 -1
  303. metadata +102 -30
  304. /data/spec/functional/assets/chocolatey_feed/{test-A.1.0.0.nupkg → test-A.1.0.nupkg} +0 -0
  305. /data/spec/functional/assets/chocolatey_feed/{test-A.1.5.0.nupkg → test-A.1.5.nupkg} +0 -0
  306. /data/spec/functional/assets/chocolatey_feed/{test-A.2.0.0.nupkg → test-A.2.0.nupkg} +0 -0
  307. /data/spec/functional/assets/chocolatey_feed/{test-B.1.0.0.nupkg → test-B.1.0.nupkg} +0 -0
  308. /data/spec/functional/assets/yumrepo/repodata/{01a3b-filelists.sqlite.bz2 → 4632d67cb92636e7575d911c24f0e04d3505a944e97c483abe0c3e73a7c62d33-filelists.sqlite.bz2} +0 -0
  309. /data/spec/functional/assets/yumrepo/repodata/{6bf96-other.xml.gz → 74599b793e54d877323837d2d81a1c3c594c44e4335f9528234bb490f7b9b439-other.xml.gz} +0 -0
  310. /data/spec/functional/assets/yumrepo/repodata/{5dc1e-primary.sqlite.bz2 → a845d418f919d2115ab95a56b2c76f6825ad0d0bede49181a55c04f58995d057-primary.sqlite.bz2} +0 -0
  311. /data/spec/functional/assets/yumrepo/repodata/{7c365-other.sqlite.bz2 → af9b7cf9ef23bd7b43068d74a460f3b5d06753d638e58e4a0c9edc35bfb9cdc4-other.sqlite.bz2} +0 -0
  312. /data/spec/functional/assets/yumrepo/repodata/{401dc-filelists.xml.gz → bdb4f5f1492a3b9532f22c43110a81500dd744f23da0aec5c33b2a41317c737d-filelists.xml.gz} +0 -0
  313. /data/spec/functional/assets/yumrepo/repodata/{dabe2-primary.xml.gz → c10d1d34ce99e02f12ec96ef68360543ab1bb7c3cb81a4a2bf78df7d8597e9df-primary.xml.gz} +0 -0
@@ -561,5 +561,13 @@ class Chef
561
561
  super "before subscription from #{notification.resource} resource cannot be setup to #{notification.notifying_resource} resource, which has already fired while in unified mode"
562
562
  end
563
563
  end
564
+
565
+ class RestError < RuntimeError; end
566
+
567
+ class RestTargetError < RestError; end
568
+
569
+ class RestTimeout < RestError; end
570
+
571
+ class RestOperationFailed < RestError; end
564
572
  end
565
573
  end
@@ -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,69 @@ 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
106
+ self.class.encrypt_pfx_pass
107
+ end
108
+
109
+ def decrypt_pfx_pass
110
+ self.class.decrypt_pfx_pass
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.check_certstore_for_key(client_name)
127
+ powershell_code = <<~CODE
128
+ $cert = Get-ChildItem -path cert:\\LocalMachine\\My -Recurse -Force | Where-Object { $_.Subject -Match "chef-#{client_name}" } -ErrorAction Stop
129
+ if (($cert.HasPrivateKey -eq $true) -and ($cert.PrivateKey.Key.ExportPolicy -ne "NonExportable")) {
130
+ return $true
131
+ }
132
+ else{
133
+ return $false
134
+ }
135
+ CODE
136
+ powershell_exec!(powershell_code).result
137
+ end
138
+
86
139
  def load_signing_key(key_file, raw_key = nil)
87
- if !!key_file
140
+ results = retrieve_certificate_key(Chef::Config[:node_name])
141
+
142
+ if !!results
143
+ @raw_key = results
144
+ elsif key_file == nil? && raw_key == nil?
145
+ puts "\nNo key detected\n"
146
+ elsif !!key_file
88
147
  @raw_key = IO.read(key_file).strip
89
148
  elsif !!raw_key
90
149
  @raw_key = raw_key.strip
91
150
  else
92
- return nil
151
+ return
93
152
  end
94
153
  # Pass in '' as the passphrase to avoid OpenSSL prompting on the TTY if
95
154
  # given an encrypted key. This also helps if using a single file for
@@ -104,6 +163,114 @@ class Chef
104
163
  raise Chef::Exceptions::InvalidPrivateKey, msg
105
164
  end
106
165
 
166
+ def self.get_cert_password
167
+ @win32registry = Chef::Win32::Registry.new
168
+ path = "HKEY_LOCAL_MACHINE\\Software\\Progress\\Authentication"
169
+ # does the registry key even exist?
170
+ present = @win32registry.get_values(path)
171
+ if present.nil? || present.empty?
172
+ raise Chef::Exceptions::Win32RegKeyMissing
173
+ end
174
+
175
+ present.each do |secret|
176
+ if secret[:name] == "PfxPass"
177
+ password = decrypt_pfx_pass(secret[:data])
178
+ return password
179
+ end
180
+ end
181
+
182
+ raise Chef::Exceptions::Win32RegKeyMissing
183
+
184
+ rescue Chef::Exceptions::Win32RegKeyMissing
185
+ # if we don't have a password, log that and generate one
186
+ Chef::Log.warn "Authentication Hive and values not present in registry, creating them now"
187
+ new_path = "HKEY_LOCAL_MACHINE\\Software\\Progress\\Authentication"
188
+ unless @win32registry.key_exists?(new_path)
189
+ @win32registry.create_key(new_path, true)
190
+ end
191
+ require "securerandom" unless defined?(SecureRandom)
192
+ size = 14
193
+ password = SecureRandom.alphanumeric(size)
194
+ encrypted_pass = encrypt_pfx_pass(password)
195
+ values = { name: "PfxPass", type: :string, data: encrypted_pass }
196
+ @win32registry.set_value(new_path, values)
197
+ password
198
+ end
199
+
200
+ def self.encrypt_pfx_pass(password)
201
+ powershell_code = <<~CODE
202
+ $encrypted_string = ConvertTo-SecureString "#{password}" -AsPlainText -Force
203
+ $secure_string = ConvertFrom-SecureString $encrypted_string
204
+ return $secure_string
205
+ CODE
206
+ powershell_exec!(powershell_code).result
207
+ end
208
+
209
+ def self.decrypt_pfx_pass(password)
210
+ powershell_code = <<~CODE
211
+ $secure_string = "#{password}" | ConvertTo-SecureString
212
+ $string = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR((($secure_string))))
213
+ return $string
214
+ CODE
215
+ powershell_exec!(powershell_code).result
216
+ end
217
+
218
+ def self.retrieve_certificate_key(client_name)
219
+ require "openssl" unless defined?(OpenSSL)
220
+
221
+ if ChefUtils.windows?
222
+ password = get_cert_password
223
+ return false unless password
224
+
225
+ if check_certstore_for_key(client_name)
226
+ ps_blob = powershell_exec!(get_the_key_ps(client_name, password)).result
227
+ file_path = ps_blob["PSPath"].split("::")[1]
228
+ pkcs = OpenSSL::PKCS12.new(File.binread(file_path), password)
229
+
230
+ # We check the pfx we just extracted the private key from
231
+ # if that cert is expiring in 7 days or less we generate a new pfx/p12 object
232
+ # then we post the new public key from that to the client endpoint on
233
+ # chef server.
234
+ File.delete(file_path)
235
+ key_expiring = is_certificate_expiring?(pkcs)
236
+ if key_expiring
237
+ powershell_exec!(delete_old_key_ps(client_name))
238
+ ::Chef::Client.update_key_and_register(Chef::Config[:client_name], pkcs)
239
+ end
240
+
241
+ return pkcs.key.private_to_pem
242
+ end
243
+ end
244
+
245
+ false
246
+ end
247
+
248
+ def self.is_certificate_expiring?(pkcs)
249
+ today = Date.parse(Time.now.utc.iso8601)
250
+ future = Date.parse(pkcs.certificate.not_after.iso8601)
251
+ future.mjd - today.mjd <= 7
252
+ end
253
+
254
+ def self.get_the_key_ps(client_name, password)
255
+ powershell_code = <<~CODE
256
+ Try {
257
+ $my_pwd = ConvertTo-SecureString -String "#{password}" -Force -AsPlainText;
258
+ $cert = Get-ChildItem -path cert:\\LocalMachine\\My -Recurse | Where-Object { $_.Subject -match "chef-#{client_name}$" } -ErrorAction Stop;
259
+ $tempfile = [System.IO.Path]::GetTempPath() + "export_pfx.pfx";
260
+ Export-PfxCertificate -Cert $cert -Password $my_pwd -FilePath $tempfile;
261
+ }
262
+ Catch {
263
+ return $false
264
+ }
265
+ CODE
266
+ end
267
+
268
+ def self.delete_old_key_ps(client_name)
269
+ powershell_code = <<~CODE
270
+ Get-ChildItem -path cert:\\LocalMachine\\My -Recurse | Where-Object { $_.Subject -match "chef-#{client_name}$" } | Remove-Item -ErrorAction Stop;
271
+ CODE
272
+ end
273
+
107
274
  def authentication_headers(method, url, json_body = nil, headers = nil)
108
275
  request_params = {
109
276
  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
@@ -132,7 +132,7 @@ class Chef
132
132
  def add_trusted_cert(cert)
133
133
  http_client.cert_store.add_cert(cert)
134
134
  rescue OpenSSL::X509::StoreError => e
135
- raise e unless e.message == "cert already in hash table"
135
+ raise e unless e.message =~ /cert already in hash table/
136
136
  end
137
137
 
138
138
  end
@@ -31,12 +31,6 @@ class Chef
31
31
 
32
32
  checksum.slice(0, 6)
33
33
  end
34
-
35
- def checksum_match?(ref_checksum, diff_checksum)
36
- return false if ref_checksum.nil? || diff_checksum.nil?
37
-
38
- ref_checksum.casecmp?(diff_checksum)
39
- end
40
34
  end
41
35
  end
42
36
  end
@@ -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
@@ -73,6 +73,7 @@ class Chef
73
73
  include?
74
74
  index
75
75
  inject
76
+ intersect?
76
77
  intersection
77
78
  join
78
79
  last
data/lib/chef/property.rb CHANGED
@@ -113,9 +113,11 @@ class Chef
113
113
  # and the transformed value returned as output. Lazy values will *not*
114
114
  # be passed to this method until after they are evaluated. Called in the
115
115
  # context of the resource (meaning you can access other properties).
116
- # @option options [Boolean] :required `true` if this property
117
- # must be present; `false` otherwise. This is checked after the resource
118
- # is fully initialized.
116
+ # @option options [Boolean, Array<Symbol>] :required `true` if this property
117
+ # must be present for *all* actions; `false` otherwise. Alternatively
118
+ # you may specify a list of actions the property is required for, when
119
+ # the property is only required for a subset of actions. This is checked
120
+ # after the resource is fully initialized.
119
121
  # @option options [String] :deprecated If set, this property is deprecated and
120
122
  # will create a deprecation warning.
121
123
  #
@@ -336,7 +336,7 @@ class Chef
336
336
  end
337
337
 
338
338
  def do_validate_content
339
- if new_resource.checksum && tempfile && !checksum_match?(new_resource.checksum, tempfile_checksum)
339
+ if new_resource.checksum && tempfile && ( new_resource.checksum != tempfile_checksum )
340
340
  raise Chef::Exceptions::ChecksumMismatch.new(short_cksum(new_resource.checksum), short_cksum(tempfile_checksum))
341
341
  end
342
342
 
@@ -450,7 +450,7 @@ class Chef
450
450
 
451
451
  def contents_changed?
452
452
  logger.trace "calculating checksum of #{tempfile.path} to compare with #{current_resource.checksum}"
453
- !checksum_match?(tempfile_checksum, current_resource.checksum)
453
+ tempfile_checksum != current_resource.checksum
454
454
  end
455
455
 
456
456
  def tempfile
@@ -17,7 +17,7 @@
17
17
  #
18
18
 
19
19
  require_relative "../user"
20
- if RUBY_PLATFORM.match?(/mswin|mingw32|windows/)
20
+ if RUBY_PLATFORM.match?(/mswin|mingw|windows/)
21
21
  require_relative "../../util/windows/net_group"
22
22
  end
23
23
 
@@ -25,18 +25,20 @@ class Chef
25
25
 
26
26
  provides :http_request
27
27
 
28
- attr_accessor :http
28
+ attr_writer :http
29
29
 
30
- def load_current_resource
31
- @http = Chef::HTTP::Simple.new(new_resource.url)
30
+ def http
31
+ @http ||= Chef::HTTP::Simple.new(new_resource.url)
32
32
  end
33
33
 
34
+ def load_current_resource; end
35
+
34
36
  # Send a HEAD request to new_resource.url
35
37
  action :head do
36
38
  message = check_message(new_resource.message)
37
39
  # CHEF-4762: we expect a nil return value from Chef::HTTP for a "200 Success" response
38
40
  # and false for a "304 Not Modified" response
39
- modified = @http.head(
41
+ modified = http.head(
40
42
  (new_resource.url).to_s,
41
43
  new_resource.headers
42
44
  )
@@ -53,7 +55,7 @@ class Chef
53
55
  converge_by("#{new_resource} GET to #{new_resource.url}") do
54
56
 
55
57
  message = check_message(new_resource.message)
56
- body = @http.get(
58
+ body = http.get(
57
59
  (new_resource.url).to_s,
58
60
  new_resource.headers
59
61
  )
@@ -66,7 +68,7 @@ class Chef
66
68
  action :patch do
67
69
  converge_by("#{new_resource} PATCH to #{new_resource.url}") do
68
70
  message = check_message(new_resource.message)
69
- body = @http.patch(
71
+ body = http.patch(
70
72
  (new_resource.url).to_s,
71
73
  message,
72
74
  new_resource.headers
@@ -80,7 +82,7 @@ class Chef
80
82
  action :put do
81
83
  converge_by("#{new_resource} PUT to #{new_resource.url}") do
82
84
  message = check_message(new_resource.message)
83
- body = @http.put(
85
+ body = http.put(
84
86
  (new_resource.url).to_s,
85
87
  message,
86
88
  new_resource.headers
@@ -94,7 +96,7 @@ class Chef
94
96
  action :post do
95
97
  converge_by("#{new_resource} POST to #{new_resource.url}") do
96
98
  message = check_message(new_resource.message)
97
- body = @http.post(
99
+ body = http.post(
98
100
  (new_resource.url).to_s,
99
101
  message,
100
102
  new_resource.headers
@@ -107,7 +109,7 @@ class Chef
107
109
  # Send a DELETE request to new_resource.url
108
110
  action :delete do
109
111
  converge_by("#{new_resource} DELETE to #{new_resource.url}") do
110
- body = @http.delete(
112
+ body = http.delete(
111
113
  (new_resource.url).to_s,
112
114
  new_resource.headers
113
115
  )
@@ -71,6 +71,11 @@ class Chef
71
71
  when /\A#{Regexp.escape(real_mount_point)}\s+#{device_mount_regex}\[/
72
72
  mounted = true
73
73
  logger.trace("Network device #{device_logstring} mounted as #{real_mount_point}")
74
+ # Permalink for network device mounted with a space in device name https://rubular.com/r/CK5zWWms96CRES
75
+ # See the comment in "device_with_space_escape" for an explanation what's going here.
76
+ when /\A#{Regexp.escape(real_mount_point)}\s+#{device_with_space_escape}\s/
77
+ mounted = true
78
+ logger.trace("Network device #{device_logstring} mounted as #{real_mount_point}")
74
79
  end
75
80
  end
76
81
  @current_resource.mounted(mounted)
@@ -217,6 +217,14 @@ class Chef
217
217
  end
218
218
  end
219
219
 
220
+ def device_with_space_escape
221
+ # For CIFS (and perhaps other remote network mounts) when a space is in the "device name"
222
+ # It will appear with the space substituted with a special character. However, when mounting,
223
+ # The mount needs to be done with an actual space. This function provides the device name with
224
+ # The special character to determine if the device is mounted.
225
+ device_mount_regex.gsub(" ", "\\x20")
226
+ end
227
+
220
228
  def device_mount_regex
221
229
  if network_device?
222
230
  # ignore trailing slash
@@ -17,7 +17,7 @@
17
17
  #
18
18
 
19
19
  require_relative "../mount"
20
- if RUBY_PLATFORM.match?(/mswin|mingw32|windows/)
20
+ if RUBY_PLATFORM.match?(/mswin|mingw|windows/)
21
21
  require_relative "../../util/windows/net_use"
22
22
  require_relative "../../util/windows/volume"
23
23
  end
@@ -130,21 +130,6 @@ class Chef
130
130
  # install from, but like the rubygem provider's sources which are more like repos.
131
131
  def check_resource_semantics!; end
132
132
 
133
- def self.get_choco_version
134
- @get_choco_version ||= powershell_exec!("choco --version").result
135
- end
136
-
137
- # Choco V2 uses 'Search' for remote repositories and 'List' for local packages
138
- def self.query_command
139
- return "list" if get_choco_version.match?(/^1/)
140
-
141
- "search"
142
- end
143
-
144
- def query_command
145
- self.class.query_command
146
- end
147
-
148
133
  private
149
134
 
150
135
  def version_compare(v1, v2)
@@ -240,7 +225,7 @@ class Chef
240
225
  package_name_array.each do |pkg|
241
226
  available_versions =
242
227
  begin
243
- cmd = [ query_command, "-r", pkg ]
228
+ cmd = [ "list", "-r", pkg ]
244
229
  cmd += common_options
245
230
  cmd.push( new_resource.list_options ) if new_resource.list_options
246
231
 
@@ -257,8 +242,6 @@ class Chef
257
242
  # Installed packages in chocolatey as a Hash of names mapped to versions
258
243
  # (names are downcased for case-insensitive matching)
259
244
  #
260
- # Beginning with Choco 2.0, "list" returns local packages only while "search" returns packages from external package sources
261
- #
262
245
  # @return [Hash] name-to-version mapping of installed packages
263
246
  def installed_packages
264
247
  @installed_packages ||= Hash[*parse_list_output("list", "-l", "-r").flatten]
@@ -92,7 +92,7 @@ class Chef
92
92
  #
93
93
  def installed_versions(gem_dep)
94
94
  rubygems_version = Gem::Version.new(Gem::VERSION)
95
- if rubygems_version >= Gem::Version.new("2.7")
95
+ if rubygems_version >= Gem::Version.new("3.1")
96
96
  # In newer Rubygems, bundler is now a "default gem" which means
97
97
  # even with AlternateGemEnvironment when you try to get the
98
98
  # installed versions, you get the one from Chef's Ruby's default
@@ -18,7 +18,7 @@
18
18
 
19
19
  # TODO: Allow new_resource.source to be a Product Code as a GUID for uninstall / network install
20
20
 
21
- require_relative "../../../win32/api/installer" if RUBY_PLATFORM.match?(/mswin|mingw32|windows/)
21
+ require_relative "../../../win32/api/installer" if RUBY_PLATFORM.match?(/mswin|mingw|windows/)
22
22
  require_relative "../../../mixin/shell_out"
23
23
 
24
24
  class Chef
@@ -26,7 +26,7 @@ class Chef
26
26
  class Package
27
27
  class Windows
28
28
  class MSI
29
- include Chef::ReservedNames::Win32::API::Installer if RUBY_PLATFORM.match?(/mswin|mingw32|windows/)
29
+ include Chef::ReservedNames::Win32::API::Installer if RUBY_PLATFORM.match?(/mswin|mingw|windows/)
30
30
  include Chef::Mixin::ShellOut
31
31
 
32
32
  def initialize(resource, uninstall_entries)
@@ -18,7 +18,7 @@
18
18
  #
19
19
 
20
20
  module Win32
21
- autoload :Registry, File.expand_path("../../../monkey_patches/win32/registry", __dir__) if RUBY_PLATFORM.match?(/mswin|mingw32|windows/)
21
+ autoload :Registry, File.expand_path("../../../monkey_patches/win32/registry", __dir__) if RUBY_PLATFORM.match?(/mswin|mingw|windows/)
22
22
  end
23
23
 
24
24
  class Chef
@@ -38,7 +38,7 @@ class Chef
38
38
  def define_resource_requirements
39
39
  if new_resource.checksum
40
40
  requirements.assert(:install) do |a|
41
- a.assertion { checksum_match?(new_resource.checksum, checksum(source_location)) }
41
+ a.assertion { new_resource.checksum == checksum(source_location) }
42
42
  a.failure_message Chef::Exceptions::Package, "Checksum on resource (#{short_cksum(new_resource.checksum)}) does not match checksum on content (#{short_cksum(source_location)})"
43
43
  end
44
44
  end
@@ -0,0 +1,60 @@
1
+ #
2
+ # Copyright:: Copyright (c) Chef Software Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ class Chef
19
+ class Provider
20
+ class Package
21
+ class Zypper < Chef::Provider::Package
22
+
23
+ # helper class to assist in passing around name/version/arch triples
24
+ class Version
25
+ attr_accessor :name
26
+ attr_accessor :version
27
+ attr_accessor :arch
28
+
29
+ def initialize(name, version, arch)
30
+ @name = name
31
+ @version = version
32
+ @arch = arch
33
+ end
34
+
35
+ def to_s
36
+ "#{name}-#{version}.#{arch}" unless version.nil?
37
+ end
38
+
39
+ def version_with_arch
40
+ "#{version}.#{arch}" unless version.nil?
41
+ end
42
+
43
+ def name_with_arch
44
+ "#{name}.#{arch}" unless name.nil?
45
+ end
46
+
47
+ def matches_name_and_arch?(other)
48
+ other.version == version && other.arch == arch
49
+ end
50
+
51
+ def ==(other)
52
+ name == other.name && version == other.version && arch == other.arch
53
+ end
54
+
55
+ alias eql? ==
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end