chef 17.0.242-universal-mingw32 → 17.4.25-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (254) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -14
  3. data/Rakefile +2 -2
  4. data/chef.gemspec +10 -20
  5. data/lib/chef/action_collection.rb +6 -26
  6. data/lib/chef/application/base.rb +15 -0
  7. data/lib/chef/application.rb +4 -2
  8. data/lib/chef/chef_fs/file_pattern.rb +2 -2
  9. data/lib/chef/client.rb +7 -1
  10. data/lib/chef/compliance/default_attributes.rb +5 -3
  11. data/lib/chef/compliance/reporter/automate.rb +1 -1
  12. data/lib/chef/compliance/runner.rb +17 -3
  13. data/lib/chef/cookbook/cookbook_version_loader.rb +3 -3
  14. data/lib/chef/cookbook/gem_installer.rb +5 -1
  15. data/lib/chef/cookbook_version.rb +26 -4
  16. data/lib/chef/data_collector/run_end_message.rb +1 -1
  17. data/lib/chef/data_collector.rb +0 -1
  18. data/lib/chef/deprecated.rb +14 -4
  19. data/lib/chef/dsl/declare_resource.rb +5 -10
  20. data/lib/chef/dsl/render_helpers.rb +44 -0
  21. data/lib/chef/dsl/secret.rb +64 -0
  22. data/lib/chef/dsl/toml.rb +116 -0
  23. data/lib/chef/dsl/universal.rb +5 -0
  24. data/lib/chef/dsl.rb +1 -0
  25. data/lib/chef/event_dispatch/base.rb +2 -1
  26. data/lib/chef/exceptions.rb +23 -0
  27. data/lib/chef/formatters/doc.rb +2 -1
  28. data/lib/chef/formatters/error_mapper.rb +2 -2
  29. data/lib/chef/handler/slow_report.rb +66 -0
  30. data/lib/chef/handler.rb +46 -8
  31. data/lib/chef/json_compat.rb +1 -1
  32. data/lib/chef/node.rb +21 -20
  33. data/lib/chef/policy_builder/policyfile.rb +88 -45
  34. data/lib/chef/provider/directory.rb +6 -6
  35. data/lib/chef/provider/execute.rb +1 -1
  36. data/lib/chef/provider/file.rb +2 -2
  37. data/lib/chef/provider/group/dscl.rb +1 -1
  38. data/lib/chef/provider/launchd.rb +6 -6
  39. data/lib/chef/provider/link.rb +1 -1
  40. data/lib/chef/provider/lwrp_base.rb +1 -1
  41. data/lib/chef/provider/package/dnf/dnf_helper.py +11 -10
  42. data/lib/chef/provider/package/dnf/python_helper.rb +9 -8
  43. data/lib/chef/provider/package/habitat.rb +168 -0
  44. data/lib/chef/provider/package/powershell.rb +5 -0
  45. data/lib/chef/provider/package/yum/python_helper.rb +15 -10
  46. data/lib/chef/provider/package/yum/yum_helper.py +46 -62
  47. data/lib/chef/provider/package/yum.rb +1 -4
  48. data/lib/chef/provider/registry_key.rb +1 -1
  49. data/lib/chef/provider/service/systemd.rb +1 -1
  50. data/lib/chef/provider/subversion.rb +4 -4
  51. data/lib/chef/provider/support/yum_repo.erb +1 -1
  52. data/lib/chef/provider/support/zypper_repo.erb +4 -2
  53. data/lib/chef/provider/systemd_unit.rb +18 -17
  54. data/lib/chef/provider/template/content.rb +1 -1
  55. data/lib/chef/provider/user/mac.rb +3 -3
  56. data/lib/chef/provider/windows_script.rb +1 -1
  57. data/lib/chef/provider/yum_repository.rb +27 -43
  58. data/lib/chef/provider/zypper_repository.rb +30 -34
  59. data/lib/chef/provider.rb +26 -1
  60. data/lib/chef/provider_resolver.rb +8 -2
  61. data/lib/chef/providers.rb +1 -0
  62. data/lib/chef/resource/alternatives.rb +5 -5
  63. data/lib/chef/resource/apt_preference.rb +2 -2
  64. data/lib/chef/resource/apt_repository.rb +2 -2
  65. data/lib/chef/resource/apt_update.rb +4 -4
  66. data/lib/chef/resource/build_essential.rb +1 -1
  67. data/lib/chef/resource/chef_client_config.rb +10 -5
  68. data/lib/chef/resource/chef_client_cron.rb +3 -3
  69. data/lib/chef/resource/chef_client_launchd.rb +3 -3
  70. data/lib/chef/resource/chef_client_scheduled_task.rb +15 -15
  71. data/lib/chef/resource/chef_client_systemd_timer.rb +3 -3
  72. data/lib/chef/resource/chef_client_trusted_certificate.rb +2 -2
  73. data/lib/chef/resource/chef_handler.rb +2 -2
  74. data/lib/chef/resource/chef_sleep.rb +1 -1
  75. data/lib/chef/resource/chef_vault_secret.rb +2 -2
  76. data/lib/chef/resource/chocolatey_feature.rb +2 -2
  77. data/lib/chef/resource/chocolatey_source.rb +1 -1
  78. data/lib/chef/resource/cron/cron_d.rb +4 -6
  79. data/lib/chef/resource/cron_access.rb +1 -1
  80. data/lib/chef/resource/dmg_package.rb +1 -1
  81. data/lib/chef/resource/dsc_resource.rb +1 -1
  82. data/lib/chef/resource/execute.rb +5 -5
  83. data/lib/chef/resource/gem_package.rb +2 -1
  84. data/lib/chef/resource/group.rb +4 -4
  85. data/lib/chef/resource/habitat/_habitat_shared.rb +28 -0
  86. data/lib/chef/resource/habitat/habitat_package.rb +129 -0
  87. data/lib/chef/resource/habitat/habitat_sup.rb +329 -0
  88. data/lib/chef/resource/habitat/habitat_sup_systemd.rb +67 -0
  89. data/lib/chef/resource/habitat/habitat_sup_windows.rb +90 -0
  90. data/lib/chef/resource/habitat_config.rb +107 -0
  91. data/lib/chef/resource/habitat_install.rb +247 -0
  92. data/lib/chef/resource/habitat_service.rb +451 -0
  93. data/lib/chef/resource/habitat_user_toml.rb +92 -0
  94. data/lib/chef/resource/homebrew_cask.rb +18 -7
  95. data/lib/chef/resource/homebrew_package.rb +1 -1
  96. data/lib/chef/resource/homebrew_tap.rb +4 -3
  97. data/lib/chef/resource/homebrew_update.rb +2 -2
  98. data/lib/chef/resource/hostname.rb +49 -7
  99. data/lib/chef/resource/inspec_waiver_file_entry.rb +156 -0
  100. data/lib/chef/resource/kernel_module.rb +6 -6
  101. data/lib/chef/resource/launchd.rb +3 -3
  102. data/lib/chef/resource/locale.rb +1 -1
  103. data/lib/chef/resource/lwrp_base.rb +18 -3
  104. data/lib/chef/resource/macos_userdefaults.rb +2 -2
  105. data/lib/chef/resource/ohai_hint.rb +2 -6
  106. data/lib/chef/resource/openbsd_package.rb +17 -0
  107. data/lib/chef/resource/openssl_dhparam.rb +1 -2
  108. data/lib/chef/resource/openssl_ec_private_key.rb +1 -3
  109. data/lib/chef/resource/openssl_ec_public_key.rb +1 -3
  110. data/lib/chef/resource/openssl_rsa_private_key.rb +1 -3
  111. data/lib/chef/resource/openssl_rsa_public_key.rb +1 -3
  112. data/lib/chef/resource/openssl_x509_certificate.rb +1 -4
  113. data/lib/chef/resource/openssl_x509_crl.rb +1 -3
  114. data/lib/chef/resource/openssl_x509_request.rb +1 -3
  115. data/lib/chef/resource/osx_profile.rb +3 -3
  116. data/lib/chef/resource/plist.rb +1 -1
  117. data/lib/chef/resource/powershell_package_source.rb +2 -4
  118. data/lib/chef/resource/reboot.rb +38 -9
  119. data/lib/chef/resource/remote_directory.rb +2 -2
  120. data/lib/chef/resource/remote_file.rb +3 -3
  121. data/lib/chef/resource/rhsm_errata.rb +0 -2
  122. data/lib/chef/resource/rhsm_errata_level.rb +1 -5
  123. data/lib/chef/resource/rhsm_repo.rb +15 -0
  124. data/lib/chef/resource/rhsm_subscription.rb +5 -5
  125. data/lib/chef/resource/ruby_block.rb +100 -0
  126. data/lib/chef/resource/scm/subversion.rb +1 -1
  127. data/lib/chef/resource/ssh_known_hosts_entry.rb +4 -7
  128. data/lib/chef/resource/sudo.rb +2 -6
  129. data/lib/chef/resource/support/HabService.dll.config.erb +19 -0
  130. data/lib/chef/resource/support/client.erb +8 -1
  131. data/lib/chef/resource/support/sup.toml.erb +179 -0
  132. data/lib/chef/resource/swap_file.rb +2 -6
  133. data/lib/chef/resource/sysctl.rb +2 -2
  134. data/lib/chef/resource/systemd_unit.rb +3 -3
  135. data/lib/chef/resource/timezone.rb +1 -1
  136. data/lib/chef/resource/user_ulimit.rb +2 -2
  137. data/lib/chef/resource/windows_ad_join.rb +2 -2
  138. data/lib/chef/resource/windows_audit_policy.rb +2 -2
  139. data/lib/chef/resource/windows_auto_run.rb +2 -2
  140. data/lib/chef/resource/windows_certificate.rb +1 -1
  141. data/lib/chef/resource/windows_defender.rb +163 -0
  142. data/lib/chef/resource/windows_defender_exclusion.rb +125 -0
  143. data/lib/chef/resource/windows_dfs_folder.rb +2 -2
  144. data/lib/chef/resource/windows_dfs_namespace.rb +2 -2
  145. data/lib/chef/resource/windows_dns_record.rb +2 -2
  146. data/lib/chef/resource/windows_dns_zone.rb +2 -2
  147. data/lib/chef/resource/windows_env.rb +1 -1
  148. data/lib/chef/resource/windows_feature.rb +3 -3
  149. data/lib/chef/resource/windows_feature_dism.rb +3 -5
  150. data/lib/chef/resource/windows_feature_powershell.rb +3 -3
  151. data/lib/chef/resource/windows_firewall_profile.rb +2 -2
  152. data/lib/chef/resource/windows_firewall_rule.rb +20 -6
  153. data/lib/chef/resource/windows_font.rb +2 -2
  154. data/lib/chef/resource/windows_pagefile.rb +104 -65
  155. data/lib/chef/resource/windows_path.rb +4 -4
  156. data/lib/chef/resource/windows_printer.rb +80 -61
  157. data/lib/chef/resource/windows_printer_port.rb +48 -65
  158. data/lib/chef/resource/windows_security_policy.rb +7 -4
  159. data/lib/chef/resource/windows_share.rb +2 -2
  160. data/lib/chef/resource/windows_shortcut.rb +1 -1
  161. data/lib/chef/resource/windows_task.rb +2 -2
  162. data/lib/chef/resource/windows_uac.rb +3 -5
  163. data/lib/chef/resource/windows_update_settings.rb +259 -0
  164. data/lib/chef/resource/windows_user_privilege.rb +2 -2
  165. data/lib/chef/resource/windows_workgroup.rb +2 -2
  166. data/lib/chef/resource/yum_package.rb +11 -15
  167. data/lib/chef/resource/zypper_package.rb +4 -4
  168. data/lib/chef/resource/zypper_repository.rb +28 -8
  169. data/lib/chef/resource.rb +20 -25
  170. data/lib/chef/resource_builder.rb +8 -2
  171. data/lib/chef/resource_inspector.rb +6 -2
  172. data/lib/chef/resource_reporter.rb +0 -1
  173. data/lib/chef/resources.rb +13 -1
  174. data/lib/chef/run_lock.rb +1 -1
  175. data/lib/chef/runner.rb +1 -1
  176. data/lib/chef/secret_fetcher/aws_secrets_manager.rb +65 -0
  177. data/lib/chef/secret_fetcher/azure_key_vault.rb +78 -0
  178. data/lib/chef/secret_fetcher/base.rb +76 -0
  179. data/lib/chef/secret_fetcher/example.rb +46 -0
  180. data/lib/chef/secret_fetcher.rb +55 -0
  181. data/lib/chef/shell/ext.rb +3 -3
  182. data/lib/chef/version.rb +1 -1
  183. data/lib/chef/win32/api.rb +9 -2
  184. data/spec/data/knife-home/.chef/plugins/knife/example_home_subcommand.rb +0 -0
  185. data/spec/data/knife-site-subcommands/plugins/knife/example_subcommand.rb +0 -0
  186. data/spec/data/knife_subcommand/test_explicit_category.rb +7 -0
  187. data/spec/data/knife_subcommand/test_name_mapping.rb +4 -0
  188. data/spec/data/knife_subcommand/test_yourself.rb +21 -0
  189. data/spec/functional/mixin/from_file_spec.rb +1 -1
  190. data/spec/functional/resource/dnf_package_spec.rb +857 -537
  191. data/spec/functional/resource/group_spec.rb +1 -1
  192. data/spec/functional/resource/link_spec.rb +1 -1
  193. data/spec/functional/resource/remote_file_spec.rb +1 -1
  194. data/spec/functional/resource/windows_env_spec.rb +2 -2
  195. data/spec/functional/resource/windows_hostname_spec.rb +91 -0
  196. data/spec/functional/resource/windows_pagefile_spec.rb +98 -0
  197. data/spec/functional/resource/yum_package_spec.rb +495 -428
  198. data/spec/integration/client/client_spec.rb +0 -20
  199. data/spec/integration/compliance/compliance_spec.rb +1 -0
  200. data/spec/integration/recipes/recipe_dsl_spec.rb +1 -1
  201. data/spec/integration/recipes/resource_action_spec.rb +6 -6
  202. data/spec/integration/recipes/unified_mode_spec.rb +70 -0
  203. data/spec/spec_helper.rb +3 -0
  204. data/spec/support/chef_helpers.rb +1 -1
  205. data/spec/support/shared/functional/execute_resource.rb +1 -1
  206. data/spec/support/shared/functional/knife.rb +37 -0
  207. data/spec/support/shared/integration/knife_support.rb +192 -0
  208. data/spec/support/shared/unit/knife_shared.rb +39 -0
  209. data/spec/support/shared/unit/provider/file.rb +3 -9
  210. data/spec/unit/chef_fs/file_system/repository/directory_spec.rb +1 -1
  211. data/spec/unit/compliance/runner_spec.rb +46 -2
  212. data/spec/unit/cookbook_version_spec.rb +52 -0
  213. data/spec/unit/data_collector_spec.rb +47 -1
  214. data/spec/unit/dsl/render_helpers_spec.rb +102 -0
  215. data/spec/unit/dsl/secret_spec.rb +71 -0
  216. data/spec/unit/handler_spec.rb +8 -2
  217. data/spec/unit/policy_builder/dynamic_spec.rb +0 -5
  218. data/spec/unit/policy_builder/policyfile_spec.rb +144 -56
  219. data/spec/unit/provider/apt_update_spec.rb +3 -1
  220. data/spec/unit/provider/link_spec.rb +1 -1
  221. data/spec/unit/provider/mount/aix_spec.rb +1 -1
  222. data/spec/unit/provider/package/dnf/python_helper_spec.rb +1 -0
  223. data/spec/unit/provider/package/powershell_spec.rb +74 -12
  224. data/spec/unit/provider/package/yum/python_helper_spec.rb +1 -0
  225. data/spec/unit/provider/service/systemd_service_spec.rb +2 -2
  226. data/spec/unit/provider/systemd_unit_spec.rb +2 -2
  227. data/spec/unit/provider/zypper_repository_spec.rb +3 -10
  228. data/spec/unit/provider_spec.rb +23 -0
  229. data/spec/unit/resource/homebrew_cask_spec.rb +29 -11
  230. data/spec/unit/resource/inspec_waiver_file_entry_spec.rb +80 -0
  231. data/spec/unit/resource/rhsm_subscription_spec.rb +50 -3
  232. data/spec/unit/resource/systemd_unit_spec.rb +1 -1
  233. data/spec/unit/resource/windows_defender_exclusion_spec.rb +62 -0
  234. data/spec/unit/resource/windows_defender_spec.rb +71 -0
  235. data/spec/unit/resource/windows_firewall_rule_spec.rb +12 -7
  236. data/spec/unit/resource/windows_pagefile_spec.rb +4 -9
  237. data/spec/unit/resource/windows_update_settings_spec.rb +64 -0
  238. data/spec/unit/resource/zypper_repository_spec.rb +1 -1
  239. data/spec/unit/resource_spec.rb +19 -8
  240. data/spec/unit/secret_fetcher/aws_secrets_manager_spec.rb +70 -0
  241. data/spec/unit/secret_fetcher/azure_key_vault_spec.rb +70 -0
  242. data/spec/unit/secret_fetcher_spec.rb +82 -0
  243. data/tasks/rspec.rb +4 -9
  244. metadata +65 -161
  245. data/lib/chef/provider/package/yum/simplejson/LICENSE.txt +0 -79
  246. data/lib/chef/provider/package/yum/simplejson/__init__.py +0 -318
  247. data/lib/chef/provider/package/yum/simplejson/__init__.pyc +0 -0
  248. data/lib/chef/provider/package/yum/simplejson/decoder.py +0 -354
  249. data/lib/chef/provider/package/yum/simplejson/decoder.pyc +0 -0
  250. data/lib/chef/provider/package/yum/simplejson/encoder.py +0 -440
  251. data/lib/chef/provider/package/yum/simplejson/encoder.pyc +0 -0
  252. data/lib/chef/provider/package/yum/simplejson/scanner.py +0 -65
  253. data/lib/chef/provider/package/yum/simplejson/scanner.pyc +0 -0
  254. data/lib/chef/provider/package/yum/simplejson/tool.py +0 -37
@@ -1,6 +1,7 @@
1
1
  #
2
2
  # Author:: Doug Ireton <doug@1strategy.com>
3
3
  # Copyright:: 2012-2018, Nordstrom, Inc.
4
+ # Copyright:: Chef Software, Inc.
4
5
  #
5
6
  # Licensed under the Apache License, Version 2.0 (the "License");
6
7
  # you may not use this file except in compliance with the License.
@@ -68,14 +69,17 @@ class Chef
68
69
  }
69
70
 
70
71
  property :port_name, String,
71
- description: "The port name."
72
+ description: "The port name.",
73
+ default: lazy { |x| "IP_#{x.ipv4_address}" },
74
+ default_description: "The resource block name or the ipv4_address prepended with IP_."
72
75
 
73
76
  property :port_number, Integer,
74
- description: "The port number.",
77
+ description: "The TCP port number.",
75
78
  default: 9100
76
79
 
77
80
  property :port_description, String,
78
- description: "The description of the port."
81
+ desired_state: false,
82
+ deprecated: true
79
83
 
80
84
  property :snmp_enabled, [TrueClass, FalseClass],
81
85
  description: "Determines if SNMP is enabled on the port.",
@@ -86,79 +90,58 @@ class Chef
86
90
  validation_message: "port_protocol must be either 1 for RAW or 2 for LPR!",
87
91
  default: 1, equal_to: [1, 2]
88
92
 
89
- PORTS_REG_KEY = 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\\'.freeze unless defined?(PORTS_REG_KEY)
90
-
91
- # @todo Set @current_resource port properties from registry
92
93
  load_current_value do |new_resource|
93
- name new_resource.name
94
- ipv4_address new_resource.ipv4_address
95
- port_name new_resource.port_name || "IP_#{new_resource.ipv4_address}"
96
- end
97
-
98
- action :create, description: "Create the printer port, if one doesn't already exist" do
99
- description "Create the new printer port if it does not already exist."
100
-
101
- if port_exists?
102
- Chef::Log.info "#{@new_resource} already exists - nothing to do."
103
- else
104
- converge_by("Create #{@new_resource}") do
105
- create_printer_port
106
- end
107
- end
108
- end
94
+ port_data = powershell_exec(%Q{Get-WmiObject -Class Win32_TCPIPPrinterPort -Filter "Name='#{new_resource.port_name}'"}).result
109
95
 
110
- action :delete, description: "Delete an existing printer port" do
111
- description "Delete an existing printer port."
112
-
113
- if port_exists?
114
- converge_by("Delete #{@new_resource}") do
115
- delete_printer_port
116
- end
96
+ if port_data.empty?
97
+ current_value_does_not_exist!
117
98
  else
118
- Chef::Log.info "#{@current_resource} doesn't exist - can't delete."
99
+ ipv4_address port_data["HostAddress"]
100
+ port_name port_data["Name"]
101
+ snmp_enabled port_data["SNMPEnabled"]
102
+ port_protocol port_data["Protocol"]
103
+ port_number port_data["PortNumber"]
119
104
  end
120
105
  end
121
106
 
122
- action_class do
123
- private
124
-
125
- def port_exists?
126
- name = new_resource.port_name || "IP_#{new_resource.ipv4_address}"
127
- port_reg_key = PORTS_REG_KEY + name
128
-
129
- logger.trace "Checking to see if this reg key exists: '#{port_reg_key}'"
130
- registry_key_exists?(port_reg_key)
131
- end
132
-
133
- def create_printer_port
134
- port_name = new_resource.port_name || "IP_#{new_resource.ipv4_address}"
135
-
136
- # create the printer port using PowerShell
137
- declare_resource(:powershell_script, "Creating printer port #{new_resource.port_name}") do
138
- code <<-EOH
139
-
140
- Set-WmiInstance -class Win32_TCPIPPrinterPort `
141
- -EnableAllPrivileges `
142
- -Argument @{ HostAddress = "#{new_resource.ipv4_address}";
143
- Name = "#{port_name}";
144
- Description = "#{new_resource.port_description}";
145
- PortNumber = "#{new_resource.port_number}";
146
- Protocol = "#{new_resource.port_protocol}";
147
- SNMPEnabled = "$#{new_resource.snmp_enabled}";
148
- }
107
+ action :create, description: "Create or update the printer port." do
108
+ converge_if_changed do
109
+ if current_resource
110
+ # update the printer port using PowerShell
111
+ powershell_exec! <<-EOH
112
+ Get-WmiObject Win32_TCPIPPrinterPort -EnableAllPrivileges -filter "Name='#{new_resource.port_name}'" |
113
+ ForEach-Object{
114
+ $_.HostAddress='#{new_resource.ipv4_address}'
115
+ $_.PortNumber='#{new_resource.port_number}'
116
+ $_.Protocol='#{new_resource.port_protocol}'
117
+ $_.SNMPEnabled='$#{new_resource.snmp_enabled}'
118
+ $_.Put()
119
+ }
120
+ EOH
121
+ else
122
+ # create the printer port using PowerShell
123
+ powershell_exec! <<-EOH
124
+ Set-WmiInstance -class Win32_TCPIPPrinterPort `
125
+ -EnableAllPrivileges `
126
+ -Argument @{ HostAddress = "#{new_resource.ipv4_address}";
127
+ Name = "#{new_resource.port_name}";
128
+ PortNumber = "#{new_resource.port_number}";
129
+ Protocol = "#{new_resource.port_protocol}";
130
+ SNMPEnabled = "$#{new_resource.snmp_enabled}";
131
+ }
149
132
  EOH
150
133
  end
151
- end
152
134
 
153
- def delete_printer_port
154
- port_name = new_resource.port_name || "IP_#{new_resource.ipv4_address}"
135
+ end
136
+ end
155
137
 
156
- declare_resource(:powershell_script, "Deleting printer port: #{new_resource.port_name}") do
157
- code <<-EOH
158
- $port = Get-WMIObject -class Win32_TCPIPPrinterPort -EnableAllPrivileges -Filter "name = '#{port_name}'"
159
- $port.Delete()
160
- EOH
138
+ action :delete, description: "Delete an existing printer port." do
139
+ if current_resource
140
+ converge_by("delete port #{new_resource.port_name}") do
141
+ powershell_exec!("Remove-PrinterPort -Name #{new_resource.port_name}")
161
142
  end
143
+ else
144
+ Chef::Log.info "#{new_resource.port_name} doesn't exist - can't delete."
162
145
  end
163
146
  end
164
147
  end
@@ -28,6 +28,7 @@ class Chef
28
28
 
29
29
  # The valid policy_names options found here
30
30
  # https://github.com/ChrisAWalker/cSecurityOptions under 'AccountSettings'
31
+ # This needs to be revisited - the list at the link above is non-exhaustive and is missing a couple of items
31
32
  policy_names = %w{LockoutDuration
32
33
  MaximumPasswordAge
33
34
  MinimumPasswordAge
@@ -36,6 +37,8 @@ class Chef
36
37
  PasswordHistorySize
37
38
  LockoutBadCount
38
39
  ResetLockoutCount
40
+ AuditPolicyChange
41
+ LockoutDuration
39
42
  RequireLogonToChangePassword
40
43
  ForceLogoffWhenHourExpire
41
44
  NewAdministratorName
@@ -87,8 +90,8 @@ class Chef
87
90
  current_state = load_security_options
88
91
 
89
92
  if new_resource.secoption == "ResetLockoutCount"
90
- if new_resource.secvalue.to_i > 30
91
- raise Chef::Exceptions::ValidationFailed, "The \"ResetLockoutCount\" value cannot be greater than 30 minutes"
93
+ if new_resource.secvalue.to_i > current_state["LockoutDuration"].to_i
94
+ raise Chef::Exceptions::ValidationFailed, "The \"ResetLockoutCount\" value cannot be greater than the value currently set for \"LockoutDuration\""
92
95
  end
93
96
  end
94
97
  if (new_resource.secoption == "ResetLockoutCount" || new_resource.secoption == "LockoutDuration") && current_state["LockoutBadCount"] == "0"
@@ -115,13 +118,13 @@ class Chef
115
118
  policy_line = "#{security_option} = \"#{security_value}\""
116
119
  file.write("[Unicode]\r\nUnicode=yes\r\n[System Access]\r\n#{policy_line}\r\n[Version]\r\nsignature=\"$CHICAGO$\"\r\nRevision=1\r\n")
117
120
  file.close
118
- file_path = file.path.tr("/", '\\')
121
+ file_path = file.path.tr("/", "\\")
119
122
  cmd = "C:\\Windows\\System32\\secedit /configure /db C:\\windows\\security\\new.sdb /cfg #{file_path} /areas SECURITYPOLICY"
120
123
  else
121
124
  policy_line = "#{security_option} = #{security_value}"
122
125
  file.write("[Unicode]\r\nUnicode=yes\r\n[System Access]\r\n#{policy_line}\r\n[Version]\r\nsignature=\"$CHICAGO$\"\r\nRevision=1\r\n")
123
126
  file.close
124
- file_path = file.path.tr("/", '\\')
127
+ file_path = file.path.tr("/", "\\")
125
128
  cmd = "C:\\Windows\\System32\\secedit /configure /db C:\\windows\\security\\new.sdb /cfg #{file_path} /areas SECURITYPOLICY"
126
129
  end
127
130
  shell_out!(cmd)
@@ -192,7 +192,7 @@ class Chef
192
192
  name
193
193
  end
194
194
 
195
- action :create, description: "Create or modify a Windows share" do
195
+ action :create, description: "Create or modify a Windows share." do
196
196
  # we do this here instead of requiring the property because :delete doesn't need path set
197
197
  raise "No path property set" unless new_resource.path
198
198
 
@@ -216,7 +216,7 @@ class Chef
216
216
  end
217
217
  end
218
218
 
219
- action :delete, description: "Delete an existing Windows share" do
219
+ action :delete, description: "Delete an existing Windows share." do
220
220
  if current_resource.nil?
221
221
  Chef::Log.debug("#{new_resource.share_name} does not exist - nothing to do")
222
222
  else
@@ -69,7 +69,7 @@ class Chef
69
69
  iconlocation(link.IconLocation)
70
70
  end
71
71
 
72
- action :create, description: "Create or modify a Windows shortcut" do
72
+ action :create, description: "Create or modify a Windows shortcut." do
73
73
  converge_if_changed do
74
74
  converge_by "creating shortcut #{new_resource.shortcut_name}" do
75
75
  link = WIN32OLE.new("WScript.Shell").CreateShortcut(new_resource.shortcut_name)
@@ -49,7 +49,7 @@ class Chef
49
49
 
50
50
  **Create a scheduled task to run every 2 days**:
51
51
 
52
- ``` ruby
52
+ ```ruby
53
53
  windows_task 'chef-client' do
54
54
  command 'chef-client'
55
55
  run_level :highest
@@ -549,7 +549,7 @@ class Chef
549
549
  if @current_resource.exists
550
550
  task.get_task(new_resource.task_name)
551
551
  @current_resource.task = task
552
- pathed_task_name = new_resource.task_name.start_with?('\\') ? new_resource.task_name : "\\#{new_resource.task_name}"
552
+ pathed_task_name = new_resource.task_name.start_with?("\\") ? new_resource.task_name : "\\#{new_resource.task_name}"
553
553
  @current_resource.task_name(pathed_task_name)
554
554
  end
555
555
  @current_resource
@@ -29,7 +29,7 @@ class Chef
29
29
  examples <<~DOC
30
30
  **Disable UAC prompts for the admin**:
31
31
 
32
- ``` ruby
32
+ ```ruby
33
33
  windows_uac 'Disable UAC prompts for the admin' do
34
34
  enable_uac true
35
35
  prompt_on_secure_desktop false
@@ -39,7 +39,7 @@ class Chef
39
39
 
40
40
  **Disable UAC entirely**:
41
41
 
42
- ``` ruby
42
+ ```ruby
43
43
  windows_uac 'Disable UAC entirely' do
44
44
  enable_uac false
45
45
  end
@@ -72,9 +72,7 @@ class Chef
72
72
  equal_to: %i{auto_deny secure_prompt_for_creds prompt_for_creds},
73
73
  default: :prompt_for_creds
74
74
 
75
- action :configure, description: "Configures UAC by setting registry keys at `HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System`" do
76
- description 'Configures UAC by setting registry keys at \'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\''
77
-
75
+ action :configure, description: "Configures UAC by setting registry keys at `HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System`." do
78
76
  registry_key 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System' do
79
77
  values [{ name: "EnableLUA", type: :dword, data: bool_to_reg(new_resource.enable_uac) },
80
78
  { name: "ValidateAdminCodeSignatures", type: :dword, data: bool_to_reg(new_resource.require_signed_binaries) },
@@ -0,0 +1,259 @@
1
+ #
2
+ # Author:: Sölvi Páll Ásgeirsson (<solvip@gmail.com>)
3
+ # Author:: Richard Lavey (richard.lavey@calastone.com)
4
+ # Author:: Tim Smith (tsmith@chef.io)
5
+ #
6
+ # Copyright:: 2014-2017, Sölvi Páll Ásgeirsson.
7
+ # Copyright:: Copyright (c) Chef Software Inc.
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ #
21
+
22
+ require_relative "../resource"
23
+ class Chef
24
+ class Resource
25
+ class WindowsUpdateSettings < Chef::Resource
26
+ unified_mode true
27
+
28
+ provides :windows_update_settings
29
+
30
+ description "Use the **windows_update_settings** resource to manage the various Windows Update patching options."
31
+ introduced "17.3"
32
+ examples <<~DOC
33
+ **Set Windows Update settings**:
34
+
35
+ ```ruby
36
+ windows_update_settings 'Settings to Configure Windows Nodes to automatically receive updates' do
37
+ disable_os_upgrades true
38
+ elevate_non_admins true
39
+ block_windows_update_website true
40
+ automatically_install_minor_updates true
41
+ scheduled_install_day 'Friday'
42
+ scheduled_install_hour 18
43
+ update_other_ms_products true
44
+ action :enable
45
+ end
46
+ ```
47
+ DOC
48
+
49
+ # required for the alias to pass validation
50
+ allowed_actions :set, :enable
51
+
52
+ DAYS = %W{Everyday Monday Tuesday Wednesday Thursday Friday Saturday Sunday}.freeze
53
+ UPDATE_OPTIONS = {
54
+ notify: 2,
55
+ download_and_notify: 3,
56
+ download_and_schedule: 4,
57
+ local_admin_decides: 5,
58
+ }.freeze
59
+
60
+ # HKLM\Software\Policies\Microsoft\Windows\WindowsUpdate
61
+
62
+ property :disable_os_upgrades, [true, false], default: false, description: "Disable OS upgrades."
63
+ # options: 0 - let windows update update the os - false
64
+ # 1 - don't let windows update update the os - true
65
+
66
+ property :elevate_non_admins, [true, false], default: true, description: "Allow normal user accounts to temporarily be elevated to install patches."
67
+ # options: 0 - do not elevate a user to force an install - false
68
+ # 1 - do elevate the logged on user to install an update - true
69
+
70
+ property :add_to_target_wsus_group, [true, false], deprecated: "As of Chef Infra Client 17.3 the `add_to_target_wsus_group` property is no longer necessary."
71
+ # we set this registry value now automatically if the group name is set
72
+
73
+ property :target_wsus_group_name, String, description: "Add the node to a WSUS Target Group."
74
+ # options: --- a string representing the name of a target group you defined on your wsus server
75
+
76
+ property :wsus_server_url, String, description: "The URL of your WSUS server if you use one."
77
+ # options: --- a url for your internal update server in the form of https://my.updateserver.tld:4545 or whatever
78
+
79
+ property :wsus_status_server_url, String, deprecated: "As of Chef Infra Client 17.3 the `wsus_status_server_url` no longer needs to be set."
80
+ # this needs to be the same as wsus_server_url so we just set that value in both places now
81
+
82
+ # HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer
83
+
84
+ property :block_windows_update_website, [true, false], default: false, description: "Block accessing the Windows Update website."
85
+ # options: 0 - allow access to the windows update website - false
86
+ # 1 - do not allow access to the windows update website - true
87
+
88
+ # HKLM\Software\Policies\Microsoft\Windows\WindowsUpdate\AU
89
+
90
+ property :automatic_update_option, [Integer, Symbol], equal_to: UPDATE_OPTIONS.keys, coerce: proc { |x| UPDATE_OPTIONS.key(x) || x },
91
+ default: :download_and_schedule,
92
+ description: "Control what to do when updates are found. This allows you to notify, automatically download and notify to install, automatically download and schedule the install, or let the local admin decide what action to take."
93
+ # options: 2 - notify before download
94
+ # 3 - auto download and notify
95
+ # 4 - auto download and schedule - must also set day and time (below)
96
+ # 5 - allow the local admin to decide
97
+
98
+ property :automatically_install_minor_updates, [true, false], default: false, description: "Automatically install minor updates."
99
+ # options: 0 - do not automatically install minor updates - false
100
+ # 1 - of course, silently install them! - true
101
+
102
+ property :enable_detection_frequency, [true, false], default: false, description: "Used to override the OS default of how often to check for updates"
103
+ # do i want my nodes checking for updates at a time interval i chose?
104
+ # options: 0 - do not enable the option for a custom interval - false
105
+ # 1 - yeah, buddy, i want to set my own interval for checking for updates - true
106
+
107
+ property :custom_detection_frequency, Integer, default: 22, description: "If you decided to override the OS default detection frequency, specify your choice here. Valid choices are 0 - 22",
108
+ callbacks: {
109
+ "should be a valid detection frequency (0-22)" => lambda { |p|
110
+ p >= 0 && p <= 22
111
+ },
112
+ }
113
+ # a time period of between 0 and 22 hours to check for new updates
114
+ # this is a hex value - convert it from dec to hex
115
+
116
+ property :no_reboot_with_users_logged_on, [true, false], default: true, description: "Prevents the OS from rebooting while someone is on the console."
117
+ # options: 0 - user is notified of pending reboot in xx minutes - false/off
118
+ # 1 - user is notified of pending reboot but can defer - true/on
119
+
120
+ property :disable_automatic_updates, [true, false], default: false, description: "Disable Windows Update."
121
+ # options: 0 - enable automatic updates to the local system - false
122
+ # 1 - disable automatic updates - true
123
+
124
+ property :scheduled_install_day, String, equal_to: DAYS, default: DAYS.first, description: "A day of the week to tell Windows when to install updates."
125
+ # options: Everyday - install every day
126
+ # Sunday - Saturday day of the week to install, 1 == sunday
127
+
128
+ property :scheduled_install_hour, Integer, description: "If you chose a scheduled day to install, then choose an hour on that day for you installation",
129
+ callbacks: {
130
+ "should be a valid hour in a 24 hour clock" => lambda { |p|
131
+ p > 0 && p < 25
132
+ },
133
+ }
134
+ # options: --- 2-digit number representing an hour of the day, uses a 24-hour clock, 12 == noon, 24 == midnight
135
+
136
+ property :update_other_ms_products, [true, false], default: true, description: "Allows for other Microsoft products to get updates too"
137
+ # options: 0 - do not allow wu to update other apps - remove key from hive - false/off
138
+ # 1 - please update all my stuff! - true/on
139
+
140
+ # \AU\AllowMUUpdateService dword: 1
141
+
142
+ property :custom_wsus_server, [true, false], deprecated: "As of Chef Infra Client 17.3 the `custom_wsus_server` no longer needs to be setup when specifying a WSUS endpoint."
143
+ # not necessary as we set this registry value automatically if a URL is set
144
+
145
+ action :set, description: "Set Windows Update settings." do
146
+ actual_day = convert_day(new_resource.scheduled_install_day)
147
+
148
+ registry_key 'HKEY_LOCAL_MACHINE\\Software\\Policies\\Microsoft\\Windows\\WindowsUpdate' do
149
+ recursive true
150
+ values [{
151
+ name: "DisableOSUpgrade",
152
+ type: :dword,
153
+ data: new_resource.disable_os_upgrades ? 1 : 0,
154
+ },
155
+ {
156
+ name: "ElevateNonAdmins",
157
+ type: :dword,
158
+ data: new_resource.elevate_non_admins ? 1 : 0,
159
+ },
160
+ {
161
+ name: "TargetGroupEnabled",
162
+ type: :dword,
163
+ data: new_resource.target_wsus_group_name ? 1 : 0,
164
+ },
165
+ {
166
+ name: "TargetGroup",
167
+ type: :string,
168
+ data: new_resource.target_wsus_group_name,
169
+ },
170
+ {
171
+ name: "WUServer",
172
+ type: :string,
173
+ data: new_resource.wsus_server_url,
174
+ },
175
+ {
176
+ name: "WUStatusServer",
177
+ type: :string,
178
+ data: new_resource.wsus_server_url, # status server and server need to be the same. Why? Ask Microsoft
179
+ }]
180
+ action :create
181
+ end
182
+
183
+ registry_key 'HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer' do
184
+ recursive true
185
+ values [{
186
+ name: "NoWindowsUpdate",
187
+ type: :dword,
188
+ data: new_resource.block_windows_update_website ? 1 : 0,
189
+ }]
190
+ action :create
191
+ end
192
+
193
+ registry_key 'HKEY_LOCAL_MACHINE\\Software\\Policies\\Microsoft\\Windows\\WindowsUpdate\\AU' do
194
+ recursive true
195
+ values [{
196
+ name: "AUOptions",
197
+ type: :dword,
198
+ data: UPDATE_OPTIONS[new_resource.automatic_update_option],
199
+ },
200
+ {
201
+ name: "AutoInstallMinorUpdates",
202
+ type: :dword,
203
+ data: new_resource.automatically_install_minor_updates ? 1 : 0,
204
+ },
205
+ {
206
+ name: "DetectionFrequencyEnabled",
207
+ type: :dword,
208
+ data: new_resource.enable_detection_frequency ? 1 : 0,
209
+ },
210
+ {
211
+ name: "DetectionFrequency",
212
+ type: :dword,
213
+ data: new_resource.custom_detection_frequency,
214
+ },
215
+ {
216
+ name: "NoAutoRebootWithLoggedOnUsers",
217
+ type: :dword,
218
+ data: new_resource.no_reboot_with_users_logged_on ? 1 : 0,
219
+ },
220
+ {
221
+ name: "NoAutoUpdate",
222
+ type: :dword,
223
+ data: new_resource.disable_automatic_updates ? 1 : 0,
224
+ },
225
+ {
226
+ name: "ScheduledInstallDay",
227
+ type: :dword,
228
+ data: actual_day,
229
+ },
230
+ {
231
+ name: "ScheduledInstallTime",
232
+ type: :dword,
233
+ data: new_resource.scheduled_install_hour,
234
+ },
235
+ {
236
+ name: "AllowMUUpdateService",
237
+ type: :dword,
238
+ data: new_resource.update_other_ms_products ? 1 : 0,
239
+ },
240
+ {
241
+ name: "UseWUServer",
242
+ type: :dword,
243
+ data: new_resource.wsus_server_url ? 1 : 0, # if we have a URL set then want to turn on WSUS functionality
244
+ }]
245
+ action :create
246
+ end
247
+ end
248
+
249
+ action_class do
250
+ def convert_day(day)
251
+ DAYS.index(day)
252
+ end
253
+
254
+ # support the old name as well
255
+ alias_method :action_enable, :action_set
256
+ end
257
+ end
258
+ end
259
+ end