chef 18.9.4 → 18.11.11

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 (205) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +16 -12
  3. data/README.md +0 -1
  4. data/Rakefile +21 -5
  5. data/chef-universal-mingw-ucrt.gemspec +4 -2
  6. data/chef.gemspec +17 -14
  7. data/lib/chef/application/apply.rb +1 -1
  8. data/lib/chef/application/base.rb +4 -4
  9. data/lib/chef/application/exit_code.rb +1 -1
  10. data/lib/chef/chef_fs/command_line.rb +4 -4
  11. data/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb +1 -1
  12. data/lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb +2 -3
  13. data/lib/chef/client.rb +2 -3
  14. data/lib/chef/compliance/fetcher/chef_server.rb +1 -1
  15. data/lib/chef/compliance/reporter/cli.rb +2 -2
  16. data/lib/chef/compliance/runner.rb +19 -1
  17. data/lib/chef/dsl/chef_vault.rb +1 -1
  18. data/lib/chef/dsl/rest_resource.rb +223 -16
  19. data/lib/chef/encrypted_data_bag_item/decryptor.rb +1 -5
  20. data/lib/chef/environment.rb +1 -1
  21. data/lib/chef/exceptions.rb +1 -1
  22. data/lib/chef/file_cache.rb +1 -5
  23. data/lib/chef/formatters/error_description.rb +8 -1
  24. data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +1 -1
  25. data/lib/chef/formatters/error_inspectors/cookbook_resolve_error_inspector.rb +1 -1
  26. data/lib/chef/formatters/error_inspectors/cookbook_sync_error_inspector.rb +1 -1
  27. data/lib/chef/group.rb +1 -1
  28. data/lib/chef/handler/slow_report.rb +1 -1
  29. data/lib/chef/http/authenticator.rb +25 -12
  30. data/lib/chef/mixin/api_version_request_handling.rb +1 -1
  31. data/lib/chef/mixin/powershell_type_coercions.rb +2 -2
  32. data/lib/chef/mixin/securable.rb +2 -2
  33. data/lib/chef/mixin/template.rb +25 -3
  34. data/lib/chef/mixin/versioned_api.rb +1 -1
  35. data/lib/chef/monkey_patches/net-http.rb +8 -8
  36. data/lib/chef/monkey_patches/reline-windows.rb +116 -0
  37. data/lib/chef/property.rb +1 -1
  38. data/lib/chef/provider/cron.rb +1 -1
  39. data/lib/chef/provider/directory.rb +11 -0
  40. data/lib/chef/provider/dsc_resource.rb +2 -2
  41. data/lib/chef/provider/file/content.rb +3 -2
  42. data/lib/chef/provider/file.rb +1 -1
  43. data/lib/chef/provider/git.rb +1 -1
  44. data/lib/chef/provider/ifconfig/debian.rb +1 -1
  45. data/lib/chef/provider/ifconfig/redhat.rb +1 -1
  46. data/lib/chef/provider/mount/linux.rb +1 -1
  47. data/lib/chef/provider/mount/windows.rb +4 -4
  48. data/lib/chef/provider/package/chocolatey.rb +78 -19
  49. data/lib/chef/provider/package/dnf/dnf_helper.py +355 -65
  50. data/lib/chef/provider/package/dnf/python_helper.rb +7 -4
  51. data/lib/chef/provider/package/dnf.rb +25 -6
  52. data/lib/chef/provider/package/homebrew.rb +3 -3
  53. data/lib/chef/provider/package/rubygems.rb +25 -2
  54. data/lib/chef/provider/package/snap.rb +1 -1
  55. data/lib/chef/provider/package/windows/exe.rb +1 -1
  56. data/lib/chef/provider/package/windows/msi.rb +1 -1
  57. data/lib/chef/provider/package/yum/rpm_utils.rb +2 -2
  58. data/lib/chef/provider/package/yum.rb +1 -1
  59. data/lib/chef/provider/powershell_script.rb +84 -84
  60. data/lib/chef/provider/service/debian.rb +2 -4
  61. data/lib/chef/provider/user/dscl.rb +1 -1
  62. data/lib/chef/provider/user/mac.rb +1 -1
  63. data/lib/chef/provider/windows_script.rb +1 -1
  64. data/lib/chef/resource/_rest_resource.rb +9 -7
  65. data/lib/chef/resource/alternatives.rb +41 -41
  66. data/lib/chef/resource/apt_package.rb +31 -31
  67. data/lib/chef/resource/apt_preference.rb +22 -22
  68. data/lib/chef/resource/apt_repository.rb +2 -2
  69. data/lib/chef/resource/archive_file.rb +52 -18
  70. data/lib/chef/resource/bash.rb +129 -129
  71. data/lib/chef/resource/bff_package.rb +15 -15
  72. data/lib/chef/resource/breakpoint.rb +44 -44
  73. data/lib/chef/resource/cab_package.rb +22 -22
  74. data/lib/chef/resource/chef_client_config.rb +251 -89
  75. data/lib/chef/resource/chef_client_cron.rb +18 -18
  76. data/lib/chef/resource/chef_client_launchd.rb +1 -1
  77. data/lib/chef/resource/chef_client_scheduled_task.rb +31 -31
  78. data/lib/chef/resource/chef_client_systemd_timer.rb +16 -16
  79. data/lib/chef/resource/chef_client_trusted_certificate.rb +28 -28
  80. data/lib/chef/resource/chef_handler.rb +107 -107
  81. data/lib/chef/resource/chef_vault_secret.rb +1 -1
  82. data/lib/chef/resource/chocolatey_config.rb +14 -14
  83. data/lib/chef/resource/chocolatey_feature.rb +1 -1
  84. data/lib/chef/resource/chocolatey_installer.rb +60 -42
  85. data/lib/chef/resource/chocolatey_package.rb +1 -1
  86. data/lib/chef/resource/chocolatey_source.rb +15 -15
  87. data/lib/chef/resource/cron/_cron_shared.rb +0 -2
  88. data/lib/chef/resource/cron/cron.rb +70 -70
  89. data/lib/chef/resource/csh.rb +5 -5
  90. data/lib/chef/resource/directory.rb +6 -6
  91. data/lib/chef/resource/dpkg_package.rb +3 -3
  92. data/lib/chef/resource/group.rb +28 -28
  93. data/lib/chef/resource/habitat/habitat_package.rb +80 -80
  94. data/lib/chef/resource/habitat/habitat_sup.rb +93 -95
  95. data/lib/chef/resource/habitat/habitat_sup_systemd.rb +10 -10
  96. data/lib/chef/resource/habitat/habitat_sup_windows.rb +3 -3
  97. data/lib/chef/resource/habitat_config.rb +13 -13
  98. data/lib/chef/resource/habitat_install.rb +17 -17
  99. data/lib/chef/resource/habitat_service.rb +1 -1
  100. data/lib/chef/resource/habitat_user_toml.rb +12 -12
  101. data/lib/chef/resource/helpers/cron_validations.rb +2 -2
  102. data/lib/chef/resource/homebrew_cask.rb +1 -1
  103. data/lib/chef/resource/homebrew_package.rb +20 -20
  104. data/lib/chef/resource/homebrew_tap.rb +1 -1
  105. data/lib/chef/resource/hostname.rb +2 -2
  106. data/lib/chef/resource/http_request.rb +2 -2
  107. data/lib/chef/resource/ifconfig.rb +34 -34
  108. data/lib/chef/resource/inspec_input.rb +37 -37
  109. data/lib/chef/resource/inspec_waiver.rb +63 -63
  110. data/lib/chef/resource/inspec_waiver_file_entry.rb +25 -25
  111. data/lib/chef/resource/ksh.rb +5 -5
  112. data/lib/chef/resource/launchd.rb +2 -2
  113. data/lib/chef/resource/link.rb +8 -8
  114. data/lib/chef/resource/locale.rb +6 -6
  115. data/lib/chef/resource/log.rb +4 -4
  116. data/lib/chef/resource/mdadm.rb +36 -36
  117. data/lib/chef/resource/mount.rb +3 -3
  118. data/lib/chef/resource/msu_package.rb +1 -1
  119. data/lib/chef/resource/ohai.rb +32 -32
  120. data/lib/chef/resource/ohai_hint.rb +24 -24
  121. data/lib/chef/resource/openssl_ec_private_key.rb +2 -2
  122. data/lib/chef/resource/openssl_ec_public_key.rb +2 -2
  123. data/lib/chef/resource/openssl_rsa_private_key.rb +1 -1
  124. data/lib/chef/resource/openssl_rsa_public_key.rb +2 -2
  125. data/lib/chef/resource/openssl_x509_certificate.rb +1 -1
  126. data/lib/chef/resource/openssl_x509_crl.rb +15 -15
  127. data/lib/chef/resource/openssl_x509_request.rb +2 -2
  128. data/lib/chef/resource/osx_profile.rb +54 -54
  129. data/lib/chef/resource/package.rb +6 -6
  130. data/lib/chef/resource/perl.rb +5 -5
  131. data/lib/chef/resource/plist.rb +4 -4
  132. data/lib/chef/resource/powershell_package_source.rb +12 -12
  133. data/lib/chef/resource/python.rb +4 -4
  134. data/lib/chef/resource/reboot.rb +5 -5
  135. data/lib/chef/resource/registry_key.rb +81 -81
  136. data/lib/chef/resource/remote_file.rb +72 -72
  137. data/lib/chef/resource/resource_notification.rb +4 -4
  138. data/lib/chef/resource/rhsm_errata_level.rb +1 -1
  139. data/lib/chef/resource/rhsm_register.rb +2 -2
  140. data/lib/chef/resource/scm/git.rb +79 -79
  141. data/lib/chef/resource/scm/subversion.rb +9 -9
  142. data/lib/chef/resource/script.rb +3 -3
  143. data/lib/chef/resource/selinux_boolean.rb +12 -12
  144. data/lib/chef/resource/selinux_fcontext.rb +21 -21
  145. data/lib/chef/resource/selinux_install.rb +18 -18
  146. data/lib/chef/resource/selinux_login.rb +11 -11
  147. data/lib/chef/resource/selinux_module.rb +16 -16
  148. data/lib/chef/resource/selinux_permissive.rb +9 -9
  149. data/lib/chef/resource/selinux_port.rb +16 -16
  150. data/lib/chef/resource/selinux_state.rb +28 -28
  151. data/lib/chef/resource/selinux_user.rb +14 -14
  152. data/lib/chef/resource/service.rb +5 -5
  153. data/lib/chef/resource/snap_package.rb +16 -16
  154. data/lib/chef/resource/ssh_known_hosts_entry.rb +10 -10
  155. data/lib/chef/resource/sudo.rb +68 -68
  156. data/lib/chef/resource/swap_file.rb +12 -12
  157. data/lib/chef/resource/sysctl.rb +42 -42
  158. data/lib/chef/resource/systemd_unit.rb +38 -38
  159. data/lib/chef/resource/timezone.rb +16 -16
  160. data/lib/chef/resource/user/mac_user.rb +3 -3
  161. data/lib/chef/resource/user.rb +6 -6
  162. data/lib/chef/resource/user_ulimit.rb +22 -22
  163. data/lib/chef/resource/windows_ad_join.rb +25 -25
  164. data/lib/chef/resource/windows_audit_policy.rb +34 -34
  165. data/lib/chef/resource/windows_auto_run.rb +8 -8
  166. data/lib/chef/resource/windows_certificate.rb +20 -20
  167. data/lib/chef/resource/windows_defender.rb +22 -22
  168. data/lib/chef/resource/windows_defender_exclusion.rb +17 -17
  169. data/lib/chef/resource/windows_env.rb +6 -6
  170. data/lib/chef/resource/windows_feature.rb +42 -42
  171. data/lib/chef/resource/windows_feature_dism.rb +8 -8
  172. data/lib/chef/resource/windows_feature_powershell.rb +20 -20
  173. data/lib/chef/resource/windows_firewall_profile.rb +28 -28
  174. data/lib/chef/resource/windows_firewall_rule.rb +47 -47
  175. data/lib/chef/resource/windows_font.rb +7 -7
  176. data/lib/chef/resource/windows_package.rb +59 -59
  177. data/lib/chef/resource/windows_pagefile.rb +29 -29
  178. data/lib/chef/resource/windows_path.rb +12 -12
  179. data/lib/chef/resource/windows_printer.rb +28 -28
  180. data/lib/chef/resource/windows_printer_port.rb +21 -21
  181. data/lib/chef/resource/windows_security_policy.rb +23 -23
  182. data/lib/chef/resource/windows_service.rb +108 -108
  183. data/lib/chef/resource/windows_share.rb +19 -19
  184. data/lib/chef/resource/windows_shortcut.rb +7 -7
  185. data/lib/chef/resource/windows_task.rb +105 -105
  186. data/lib/chef/resource/windows_uac.rb +14 -14
  187. data/lib/chef/resource/windows_update_settings.rb +27 -27
  188. data/lib/chef/resource/windows_user_privilege.rb +59 -59
  189. data/lib/chef/resource/windows_workgroup.rb +12 -12
  190. data/lib/chef/resource/yum_package.rb +1 -1
  191. data/lib/chef/resource/yum_repository.rb +36 -36
  192. data/lib/chef/resource.rb +1 -1
  193. data/lib/chef/resource_collection/resource_set.rb +2 -3
  194. data/lib/chef/resource_inspector.rb +1 -2
  195. data/lib/chef/run_context.rb +2 -2
  196. data/lib/chef/runner.rb +1 -1
  197. data/lib/chef/secret_fetcher/akeyless_vault.rb +0 -1
  198. data/lib/chef/secret_fetcher/hashi_vault.rb +0 -1
  199. data/lib/chef/shell/ext.rb +20 -20
  200. data/lib/chef/shell/shell_session.rb +1 -1
  201. data/lib/chef/shell.rb +7 -0
  202. data/lib/chef/version.rb +1 -1
  203. data/lib/chef/version_constraint.rb +1 -1
  204. data/lib/chef/win32/file/version_info.rb +1 -1
  205. metadata +63 -38
@@ -23,79 +23,129 @@ class Chef
23
23
 
24
24
  provides :chef_client_config
25
25
 
26
+ DIRECTORY_SPEC_DEFAULTS = {
27
+ config: { mode: "0750", inherits: :auto },
28
+ client_d: { mode: "0750", inherits: :auto },
29
+ logs: { mode: "0755", inherits: :auto },
30
+ cache: { mode: "0750", inherits: :auto },
31
+ backups: { mode: "0750", inherits: :auto },
32
+ }.freeze
33
+
26
34
  description "Use the **chef_client_config** resource to create a client.rb file in the #{ChefUtils::Dist::Infra::PRODUCT} configuration directory. See the [client.rb docs](https://docs.chef.io/config_rb_client/) for more details on options available in the client.rb configuration file."
27
35
  introduced "16.6"
28
36
  examples <<~DOC
29
- **Bare minimum #{ChefUtils::Dist::Infra::PRODUCT} client.rb**:
30
-
31
- The absolute minimum configuration necessary for a node to communicate with the #{ChefUtils::Dist::Server::PRODUCT} is the URL of the #{ChefUtils::Dist::Server::PRODUCT}. All other configuration options either have values at the server side (Policyfiles, Roles, Environments, etc) or have default values determined at client startup.
37
+ **Bare minimum #{ChefUtils::Dist::Infra::PRODUCT} client.rb**:
32
38
 
33
- ```ruby
34
- chef_client_config 'Create client.rb' do
35
- chef_server_url 'https://chef.example.dmz'
36
- end
37
- ```
38
-
39
- **More complex #{ChefUtils::Dist::Infra::PRODUCT} client.rb**:
40
-
41
- ```ruby
42
- chef_client_config 'Create client.rb' do
43
- chef_server_url 'https://chef.example.dmz'
44
- log_level :info
45
- log_location :syslog
46
- http_proxy 'proxy.example.dmz'
47
- https_proxy 'proxy.example.dmz'
48
- no_proxy %w(internal.example.dmz)
49
- end
50
- ```
51
-
52
- **Adding additional config content to the client.rb**:
53
-
54
- This resource aims to provide common configuration options. Some configuration options are missing and some users may want to use arbitrary Ruby code within their configuration. For this we offer an `additional_config` property that can be used to add any configuration or code to the bottom of the `client.rb` file. Also keep in mind that within the configuration directory is a `client.d` directory where you can put additional `.rb` files containing configuration options. These can be created using `file` or `template` resources within your cookbooks as necessary.
55
-
56
- ```ruby
57
- chef_client_config 'Create client.rb' do
58
- chef_server_url 'https://chef.example.dmz'
59
- additional_config <<~CONFIG
60
- # Extra config code to safely load a gem into the client run.
61
- # Since the config is Ruby you can run any Ruby code you want via the client.rb.
62
- # It's a great way to break things, so be careful
63
- begin
64
- require 'aws-sdk'
65
- rescue LoadError
66
- Chef::Log.warn "Failed to load aws-sdk."
67
- end
68
- CONFIG
69
- end
70
- ```
39
+ The absolute minimum configuration necessary for a node to communicate with the #{ChefUtils::Dist::Server::PRODUCT} is the URL of the #{ChefUtils::Dist::Server::PRODUCT}. All other configuration options either have values at the server side (Policyfiles, Roles, Environments, etc) or have default values determined at client startup.
71
40
 
72
- **Setup two report handlers in the client.rb**:
73
-
74
- ```ruby
75
- chef_client_config 'Create client.rb' do
76
- chef_server_url 'https://chef.example.dmz'
77
- report_handlers [
78
- {
79
- 'class' => 'ReportHandler1Class',
80
- 'arguments' => ["'FirstArgument'", "'SecondArgument'"],
81
- },
82
- {
83
- 'class' => 'ReportHandler2Class',
84
- 'arguments' => ["'FirstArgument'", "'SecondArgument'"],
85
- },
86
- ]
87
- end
88
- ```
41
+ ```ruby
42
+ chef_client_config 'Create client.rb' do
43
+ chef_server_url 'https://chef.example.dmz'
44
+ end
45
+ ```
46
+
47
+ **More complex #{ChefUtils::Dist::Infra::PRODUCT} client.rb**:
48
+
49
+ ```ruby
50
+ chef_client_config 'Create client.rb' do
51
+ chef_server_url 'https://chef.example.dmz'
52
+ log_level :info
53
+ log_location :syslog
54
+ http_proxy 'proxy.example.dmz'
55
+ https_proxy 'proxy.example.dmz'
56
+ no_proxy %w(internal.example.dmz)
57
+ end
58
+ ```
59
+
60
+ **Adding additional config content to the client.rb**:
61
+
62
+ This resource aims to provide common configuration options. Some configuration options are missing and some users may want to use arbitrary Ruby code within their configuration. For this we offer an `additional_config` property that can be used to add any configuration or code to the bottom of the `client.rb` file. Also keep in mind that within the configuration directory is a `client.d` directory where you can put additional `.rb` files containing configuration options. These can be created using `file` or `template` resources within your cookbooks as necessary.
63
+
64
+ ```ruby
65
+ chef_client_config 'Create client.rb' do
66
+ chef_server_url 'https://chef.example.dmz'
67
+ additional_config <<~CONFIG
68
+ # Extra config code to safely load a gem into the client run.
69
+ # Since the config is Ruby you can run any Ruby code you want via the client.rb.
70
+ # It's a great way to break things, so be careful
71
+ begin
72
+ require 'aws-sdk'
73
+ rescue LoadError
74
+ Chef::Log.warn "Failed to load aws-sdk."
75
+ end
76
+ CONFIG
77
+ end
78
+ ```
79
+
80
+ **Setup two report handlers in the client.rb**:
81
+
82
+ ```ruby
83
+ chef_client_config 'Create client.rb' do
84
+ chef_server_url 'https://chef.example.dmz'
85
+ report_handlers [
86
+ {
87
+ 'class' => 'ReportHandler1Class',
88
+ 'arguments' => ["'FirstArgument'", "'SecondArgument'"],
89
+ },
90
+ {
91
+ 'class' => 'ReportHandler2Class',
92
+ 'arguments' => ["'FirstArgument'", "'SecondArgument'"],
93
+ },
94
+ ]
95
+ end
96
+ ```
89
97
 
90
- **Report directly to the [Chef Automate data collector endpoint](/automate/data_collection/#configure-chef-infra-client-to-use-the-data-collector-endpoint-in-chef-automate).**
98
+ **Report directly to the [Chef Automate data collector endpoint](/automate/data_collection/#configure-chef-infra-client-to-use-the-data-collector-endpoint-in-chef-automate).**
91
99
 
92
- ```ruby
93
- chef_client_config 'Create client.rb' do
94
- chef_server_url 'https://chef.example.dmz'
95
- data_collector_server_url 'https://automate.example.dmz'
96
- data_collector_token 'TEST_TOKEN_TEST'
97
- end
98
- ```
100
+ ```ruby
101
+ chef_client_config 'Create client.rb' do
102
+ chef_server_url 'https://chef.example.dmz'
103
+ data_collector_server_url 'https://automate.example.dmz'
104
+ data_collector_token 'TEST_TOKEN_TEST'
105
+ end
106
+ ```
107
+
108
+ **Set Linux directory ownership and modes**:
109
+
110
+ ```ruby
111
+ chef_client_config 'Create client.rb' do
112
+ chef_server_url 'https://chef.example.dmz'
113
+ user 'root'
114
+ group 'root'
115
+ file_cache_path '/var/chef/cache'
116
+ file_backup_path '/var/chef/backups'
117
+ log_location '/var/log/chef/client.log'
118
+ directory_specs(
119
+ config: { owner: 'root', group: 'root', mode: '0700' },
120
+ client_d: { owner: 'root', group: 'root', mode: '0700' },
121
+ logs: { owner: 'root', group: 'root', mode: '0750' },
122
+ cache: { owner: 'root', group: 'root', mode: '0750' },
123
+ backups: { owner: 'root', group: 'root', mode: '0750' }
124
+ )
125
+ end
126
+ ```
127
+
128
+ **Set Windows directory inheritance and rights**:
129
+
130
+ ```ruby
131
+ chef_client_config 'Create client.rb' do
132
+ chef_server_url 'https://chef.example.dmz'
133
+ config_directory 'C:/chef'
134
+ file_cache_path 'C:/chef/cache'
135
+ file_backup_path 'C:/chef/backups'
136
+ log_location 'C:/chef/log/client.log'
137
+ directory_specs(
138
+ config: {
139
+ owner: 'Administrators',
140
+ inherits: false,
141
+ rights: {
142
+ 'Administrators' => :full_control,
143
+ 'SYSTEM' => :full_control,
144
+ },
145
+ }
146
+ )
147
+ end
148
+ ```
99
149
  DOC
100
150
 
101
151
  # @todo policy_file or policy_group being set requires the other to be set so enforce that.
@@ -141,10 +191,10 @@ class Chef
141
191
  equal_to: %i{verify_none verify_peer},
142
192
  coerce: proc { |x| string_to_symbol(x) },
143
193
  description: <<~DESC
144
- Set the verify mode for HTTPS requests.
194
+ Set the verify mode for HTTPS requests.
145
195
 
146
- * Use :verify_none for no validation of SSL certificates.
147
- * Use :verify_peer for validation of all SSL certificates, including the #{ChefUtils::Dist::Server::PRODUCT} connections, S3 connections, and any HTTPS remote_file resource URLs used in #{ChefUtils::Dist::Infra::PRODUCT} runs. This is the recommended setting.
196
+ * Use :verify_none for no validation of SSL certificates.
197
+ * Use :verify_peer for validation of all SSL certificates, including the #{ChefUtils::Dist::Server::PRODUCT} connections, S3 connections, and any HTTPS remote_file resource URLs used in #{ChefUtils::Dist::Infra::PRODUCT} runs. This is the recommended setting.
148
198
  DESC
149
199
 
150
200
  property :formatters, Array,
@@ -174,7 +224,7 @@ class Chef
174
224
  description: "The proxy server to use for HTTPS connections."
175
225
 
176
226
  property :ftp_proxy, String,
177
- description: "The proxy server to use for FTP connections."
227
+ description: "The proxy server to use for FTP connections."
178
228
 
179
229
  property :no_proxy, [String, Array],
180
230
  description: "A comma-separated list or an array of URLs that do not need a proxy.",
@@ -254,21 +304,83 @@ class Chef
254
304
  description: "The data collector token to interact with the data collector server URL (Automate). Note: If possible, use Chef Infra Server to do all data collection reporting, as this removes the need to distribute tokens to individual nodes.",
255
305
  introduced: "17.8"
256
306
 
307
+ property :directory_specs, Hash,
308
+ description: <<~DESC,
309
+ Permission overrides for Chef-managed directories.
310
+ This must be a hash of hashes: top-level keys are directory names, values are per-directory option hashes.
311
+
312
+ Use this property like:
313
+ directory_specs(
314
+ config: { owner: "root", group: "root", mode: "0700" },
315
+ client_d: { owner: "root", group: "root", mode: "0700" },
316
+ logs: { owner: "root", group: "root", mode: "0700" },
317
+ cache: { owner: "root", group: "root", mode: "0700" },
318
+ backups: { owner: "root", group: "root", mode: "0700" }
319
+ )
320
+
321
+ Directory keys: :config, :client_d, :logs, :cache, :backups
322
+ Override keys: :owner, :group, :mode, :rights, :inherits (:rights and :inherits are Windows-only)
323
+ DESC
324
+ callbacks: {
325
+ "keys must be one of :config, :client_d, :logs, :cache, :backups" => lambda { |v|
326
+ valid_keys = %i{config client_d logs cache backups}
327
+ v.keys.all? { |k| valid_keys.include?(k) }
328
+ },
329
+ "values must be a hash with keys only from :owner, :group, :mode, :rights, :inherits" => lambda { |v|
330
+ valid_inner_keys = %i{owner group mode rights inherits}
331
+ v.values.all? { |value| value.is_a?(Hash) && value.keys.all? { |k| valid_inner_keys.include?(k) } }
332
+ },
333
+ },
334
+ default: DIRECTORY_SPEC_DEFAULTS,
335
+ coerce: proc { |v|
336
+ DIRECTORY_SPEC_DEFAULTS.merge(v) do |_key, base, override|
337
+ override.is_a?(Hash) ? base.merge(override) : override
338
+ end
339
+ }
340
+
341
+ property :client_rb_mode, String,
342
+ description: "The mode to set on the client.rb file that is written out by this resource (e.g., 0600).",
343
+ default: "0640"
344
+
257
345
  action :create, description: "Create a client.rb config file and folders for configuring #{ChefUtils::Dist::Infra::PRODUCT}." do
258
- [
259
- new_resource.config_directory,
260
- (::File.dirname(new_resource.log_location) if new_resource.log_location.is_a?(String) && !%w{STDOUT STDERR}.include?(new_resource.log_location) && !new_resource.log_location.empty?),
261
- new_resource.file_backup_path,
262
- new_resource.file_cache_path,
263
- ::File.join(new_resource.config_directory, "client.d"),
264
- (::File.dirname(new_resource.pid_file) unless new_resource.pid_file.nil?),
265
- ].compact.each do |dir_path|
266
-
267
- directory dir_path do
268
- user new_resource.user unless new_resource.user.nil?
269
- group new_resource.group unless new_resource.group.nil?
270
- mode dir_path == ::File.dirname(new_resource.log_location.to_s) ? "0755" : "0750"
271
- recursive true
346
+ # The logs directory is derived from log_location, which may be a symbol
347
+ # or a stream name (STDOUT/STDERR) rather than a file path. Only raise if
348
+ # the user customized logs specs but log_location is not a usable file path.
349
+ if new_resource.directory_specs[:logs] != DIRECTORY_SPEC_DEFAULTS[:logs] && log_directory.nil?
350
+ raise ArgumentError, "Invalid directory_specs: logs requires :logs (file path)"
351
+ end
352
+
353
+ # Build path map for each managed directory. For cache and backups, fall
354
+ # back to ChefConfig defaults when not explicitly set so that directory_specs
355
+ # overrides are applied even if the user didn't configure a custom path in client.rb.
356
+ spec_paths = {
357
+ config: new_resource.config_directory,
358
+ client_d: ::File.join(new_resource.config_directory, "client.d"),
359
+ logs: log_directory,
360
+ cache: new_resource.file_cache_path || ChefConfig::Config.file_cache_path,
361
+ backups: new_resource.file_backup_path || ChefConfig::Config.file_backup_path,
362
+ }
363
+
364
+ # Build directory specs based on user input and defaults
365
+ specs = {}
366
+ new_resource.directory_specs.each do |key, overrides|
367
+ path = spec_paths[key]
368
+ next if path.nil?
369
+
370
+ specs[key] = DirectorySpec.new(
371
+ path: path,
372
+ owner: overrides[:owner] || new_resource.user,
373
+ group: overrides[:group] || new_resource.group,
374
+ mode: overrides[:mode],
375
+ rights: overrides[:rights],
376
+ inherits: overrides[:inherits]
377
+ )
378
+ end
379
+
380
+ # Converge directories
381
+ specs.each_value do |spec|
382
+ directory spec.path do
383
+ spec.apply(self)
272
384
  end
273
385
  end
274
386
 
@@ -309,7 +421,7 @@ class Chef
309
421
  data_collector_server_url: new_resource.data_collector_server_url,
310
422
  data_collector_token: new_resource.data_collector_token
311
423
  )
312
- mode "0640"
424
+ mode new_resource.client_rb_mode
313
425
  action :create
314
426
  end
315
427
  end
@@ -329,13 +441,63 @@ class Chef
329
441
  # @return [Array] Array of handler data
330
442
  #
331
443
  def format_handler(handler_property)
332
- handler_data = []
444
+ handler_data = handler_property.map do |handler|
445
+ "#{handler["class"]}.new(#{handler["arguments"].join(",")})"
446
+ end
447
+ end
448
+
449
+ # A helper class to encapsulate directory spec data and application logic for both *nix and Windows.
450
+ # This allows us to keep the logic for how to apply permissions to directories in one place and makes it easier to test.
451
+ class DirectorySpec
452
+ attr_reader :path, :owner, :group, :mode, :rights, :inherits
453
+
454
+ def initialize(path:, owner: nil, group: nil, mode: nil, rights: nil, inherits: :auto)
455
+ @path = path
456
+ @owner = owner
457
+ @group = group
458
+ @mode = mode
459
+ @rights = rights
460
+ @inherits = inherits
461
+ end
462
+
463
+ def windows?
464
+ Chef::Platform.windows?
465
+ end
333
466
 
334
- handler_property.each do |handler|
335
- handler_data << "#{handler["class"]}.new(#{handler["arguments"].join(",")})"
467
+ def apply(resource)
468
+ resource.recursive true
469
+
470
+ if windows?
471
+ if rights && !rights.empty?
472
+ resource.inherits(inherits == :auto ? false : inherits)
473
+
474
+ rights.each do |principal, permission|
475
+ resource.rights(permission, principal)
476
+ end
477
+ else
478
+ # Ensure defaults can restore inherited ACL behavior after custom rights were applied.
479
+ resource.inherits(inherits == :auto ? true : inherits)
480
+ resource.mode(mode) if mode
481
+ end
482
+
483
+ resource.owner(owner) if owner
484
+ else
485
+ resource.owner(owner) if owner
486
+ resource.group(group) if group
487
+ resource.mode(mode) if mode
488
+ end
336
489
  end
490
+ end
491
+
492
+ # A helper method to determine the directory to apply log permissions to based on the log_location property.
493
+ # If log_location is a file path, this returns the directory containing that file.
494
+ # If log_location is not a file path (e.g., it's a symbol for syslog or win_evt, or it's STDOUT/STDERR),
495
+ # this returns nil since there is no directory to apply permissions to.
496
+ def log_directory
497
+ return unless new_resource.log_location.is_a?(String)
498
+ return if %w{STDOUT STDERR}.include?(new_resource.log_location)
337
499
 
338
- handler_data
500
+ ::File.dirname(new_resource.log_location)
339
501
  end
340
502
  end
341
503
  end
@@ -28,28 +28,28 @@ class Chef
28
28
  description "Use the **chef_client_cron** resource to setup the #{ChefUtils::Dist::Infra::PRODUCT} to run as a cron job. This resource will also create the specified log directory if it doesn't already exist."
29
29
  introduced "16.0"
30
30
  examples <<~DOC
31
- **Setup #{ChefUtils::Dist::Infra::PRODUCT} to run using the default 30 minute cadence**:
31
+ **Setup #{ChefUtils::Dist::Infra::PRODUCT} to run using the default 30 minute cadence**:
32
32
 
33
- ```ruby
34
- chef_client_cron 'Run #{ChefUtils::Dist::Infra::PRODUCT} as a cron job'
35
- ```
33
+ ```ruby
34
+ chef_client_cron 'Run #{ChefUtils::Dist::Infra::PRODUCT} as a cron job'
35
+ ```
36
36
 
37
- **Run #{ChefUtils::Dist::Infra::PRODUCT} twice a day**:
37
+ **Run #{ChefUtils::Dist::Infra::PRODUCT} twice a day**:
38
38
 
39
- ```ruby
40
- chef_client_cron 'Run #{ChefUtils::Dist::Infra::PRODUCT} every 12 hours' do
41
- minute 0
42
- hour '0,12'
43
- end
44
- ```
39
+ ```ruby
40
+ chef_client_cron 'Run #{ChefUtils::Dist::Infra::PRODUCT} every 12 hours' do
41
+ minute 0
42
+ hour '0,12'
43
+ end
44
+ ```
45
45
 
46
- **Run #{ChefUtils::Dist::Infra::PRODUCT} with extra options passed to the client**:
46
+ **Run #{ChefUtils::Dist::Infra::PRODUCT} with extra options passed to the client**:
47
47
 
48
- ```ruby
49
- chef_client_cron 'Run an override recipe' do
50
- daemon_options ['--override-runlist mycorp_base::default']
51
- end
52
- ```
48
+ ```ruby
49
+ chef_client_cron 'Run an override recipe' do
50
+ daemon_options ['--override-runlist mycorp_base::default']
51
+ end
52
+ ```
53
53
  DOC
54
54
 
55
55
  extend Chef::ResourceHelpers::CronValidations
@@ -141,7 +141,7 @@ class Chef
141
141
  description: "The process priority to run the #{ChefUtils::Dist::Infra::CLIENT} process at. A value of -20 is the highest priority and 19 is the lowest priority.",
142
142
  introduced: "16.5",
143
143
  coerce: proc { |x| Integer(x) },
144
- callbacks: { "should be an Integer between -20 and 19" => proc { |v| v >= -20 && v <= 19 } }
144
+ callbacks: { "should be an Integer between -20 and 19" => proc { |v| v.between?(-20, 19) } }
145
145
 
146
146
  action :add, description: "Add a cron job to run #{ChefUtils::Dist::Infra::PRODUCT}." do
147
147
  # TODO: Replace this with a :create_if_missing action on directory when that exists
@@ -94,7 +94,7 @@ class Chef
94
94
  property :nice, [Integer, String],
95
95
  description: "The process priority to run the #{ChefUtils::Dist::Infra::CLIENT} process at. A value of -20 is the highest priority and 19 is the lowest priority.",
96
96
  coerce: proc { |x| Integer(x) },
97
- callbacks: { "should be an Integer between -20 and 19" => proc { |v| v >= -20 && v <= 19 } }
97
+ callbacks: { "should be an Integer between -20 and 19" => proc { |v| v.between?(-20, 19) } }
98
98
 
99
99
  property :low_priority_io, [true, false],
100
100
  description: "Run the #{ChefUtils::Dist::Infra::CLIENT} process with low priority disk IO",
@@ -26,45 +26,45 @@ class Chef
26
26
  description "Use the **chef_client_scheduled_task** resource to setup the #{ChefUtils::Dist::Infra::PRODUCT} to run as a Windows scheduled task. This resource will also create the specified log directory if it doesn't already exist."
27
27
  introduced "16.0"
28
28
  examples <<~DOC
29
- **Setup #{ChefUtils::Dist::Infra::PRODUCT} to run using the default 30 minute cadence**:
29
+ **Setup #{ChefUtils::Dist::Infra::PRODUCT} to run using the default 30 minute cadence**:
30
30
 
31
- ```ruby
32
- chef_client_scheduled_task 'Run #{ChefUtils::Dist::Infra::PRODUCT} as a scheduled task'
33
- ```
31
+ ```ruby
32
+ chef_client_scheduled_task 'Run #{ChefUtils::Dist::Infra::PRODUCT} as a scheduled task'
33
+ ```
34
34
 
35
- **Run #{ChefUtils::Dist::Infra::PRODUCT} on system start**:
35
+ **Run #{ChefUtils::Dist::Infra::PRODUCT} on system start**:
36
36
 
37
- ```ruby
38
- chef_client_scheduled_task '#{ChefUtils::Dist::Infra::PRODUCT} on start' do
39
- frequency 'onstart'
40
- end
41
- ```
37
+ ```ruby
38
+ chef_client_scheduled_task '#{ChefUtils::Dist::Infra::PRODUCT} on start' do
39
+ frequency 'onstart'
40
+ end
41
+ ```
42
42
 
43
- **Run #{ChefUtils::Dist::Infra::PRODUCT} with extra options passed to the client**:
43
+ **Run #{ChefUtils::Dist::Infra::PRODUCT} with extra options passed to the client**:
44
44
 
45
- ```ruby
46
- chef_client_scheduled_task 'Run an override recipe' do
47
- daemon_options ['--override-runlist mycorp_base::default']
48
- end
49
- ```
45
+ ```ruby
46
+ chef_client_scheduled_task 'Run an override recipe' do
47
+ daemon_options ['--override-runlist mycorp_base::default']
48
+ end
49
+ ```
50
50
 
51
- **Run #{ChefUtils::Dist::Infra::PRODUCT} daily at 01:00 am, specifying a named run-list**:
51
+ **Run #{ChefUtils::Dist::Infra::PRODUCT} daily at 01:00 am, specifying a named run-list**:
52
52
 
53
- ```ruby
54
- chef_client_scheduled_task 'Run chef-client named run-list daily' do
55
- frequency 'daily'
56
- start_time '01:00'
57
- daemon_options ['-n audit_only']
58
- end
59
- ```
53
+ ```ruby
54
+ chef_client_scheduled_task 'Run chef-client named run-list daily' do
55
+ frequency 'daily'
56
+ start_time '01:00'
57
+ daemon_options ['-n audit_only']
58
+ end
59
+ ```
60
60
 
61
- **Run #{ChefUtils::Dist::Infra::PRODUCT} with a persistent delay on every run calculated once, similar to how chef_client_cron resource works**:
61
+ **Run #{ChefUtils::Dist::Infra::PRODUCT} with a persistent delay on every run calculated once, similar to how chef_client_cron resource works**:
62
62
 
63
- ```ruby
64
- chef_client_scheduled_task 'Run chef-client with persistent splay' do
65
- use_consistent_splay true
66
- end
67
- ```
63
+ ```ruby
64
+ chef_client_scheduled_task 'Run chef-client with persistent splay' do
65
+ use_consistent_splay true
66
+ end
67
+ ```
68
68
  DOC
69
69
 
70
70
  resource_name :chef_client_scheduled_task
@@ -145,7 +145,7 @@ class Chef
145
145
  property :priority, Integer,
146
146
  description: "Use to set Priority Levels range from 0 to 10.",
147
147
  introduced: "17.5",
148
- default: 7, callbacks: { "should be in range of 0 to 10" => proc { |v| v >= 0 && v <= 10 } }
148
+ default: 7, callbacks: { "should be in range of 0 to 10" => proc { |v| v.between?(0, 10) } }
149
149
 
150
150
  action :add, description: "Add a Windows Scheduled Task that runs #{ChefUtils::Dist::Infra::PRODUCT}." do
151
151
  # TODO: Replace this with a :create_if_missing action on directory when that exists
@@ -26,27 +26,27 @@ class Chef
26
26
  description "Use the **chef_client_systemd_timer** resource to setup the #{ChefUtils::Dist::Infra::PRODUCT} to run as a systemd timer."
27
27
  introduced "16.0"
28
28
  examples <<~DOC
29
- **Setup #{ChefUtils::Dist::Infra::PRODUCT} to run using the default 30 minute cadence**:
29
+ **Setup #{ChefUtils::Dist::Infra::PRODUCT} to run using the default 30 minute cadence**:
30
30
 
31
- ```ruby
32
- chef_client_systemd_timer 'Run #{ChefUtils::Dist::Infra::PRODUCT} as a systemd timer'
33
- ```
31
+ ```ruby
32
+ chef_client_systemd_timer 'Run #{ChefUtils::Dist::Infra::PRODUCT} as a systemd timer'
33
+ ```
34
34
 
35
- **Run #{ChefUtils::Dist::Infra::PRODUCT} every 1 hour**:
35
+ **Run #{ChefUtils::Dist::Infra::PRODUCT} every 1 hour**:
36
36
 
37
- ```ruby
38
- chef_client_systemd_timer 'Run #{ChefUtils::Dist::Infra::PRODUCT} every 1 hour' do
39
- interval '1hr'
40
- end
41
- ```
37
+ ```ruby
38
+ chef_client_systemd_timer 'Run #{ChefUtils::Dist::Infra::PRODUCT} every 1 hour' do
39
+ interval '1hr'
40
+ end
41
+ ```
42
42
 
43
- **Run #{ChefUtils::Dist::Infra::PRODUCT} with extra options passed to the client**:
43
+ **Run #{ChefUtils::Dist::Infra::PRODUCT} with extra options passed to the client**:
44
44
 
45
- ```ruby
46
- chef_client_systemd_timer 'Run an override recipe' do
47
- daemon_options ['--override-runlist mycorp_base::default']
48
- end
49
- ```
45
+ ```ruby
46
+ chef_client_systemd_timer 'Run an override recipe' do
47
+ daemon_options ['--override-runlist mycorp_base::default']
48
+ end
49
+ ```
50
50
  DOC
51
51
 
52
52
  property :job_name, String,
@@ -26,35 +26,35 @@ class Chef
26
26
  description "Use the **chef_client_trusted_certificate** resource to add certificates to #{ChefUtils::Dist::Infra::PRODUCT}'s trusted certificate directory. This allows the #{ChefUtils::Dist::Infra::PRODUCT} to communicate with internal encrypted resources without errors."
27
27
  introduced "16.5"
28
28
  examples <<~DOC
29
- **Trust a self signed certificate**:
29
+ **Trust a self signed certificate**:
30
30
 
31
- ```ruby
32
- chef_client_trusted_certificate 'self-signed.badssl.com' do
33
- certificate <<~CERT
34
- -----BEGIN CERTIFICATE-----
35
- MIIDeTCCAmGgAwIBAgIJAPziuikCTox4MA0GCSqGSIb3DQEBCwUAMGIxCzAJBgNV
36
- BAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlhMRYwFAYDVQQHDA1TYW4gRnJhbmNp
37
- c2NvMQ8wDQYDVQQKDAZCYWRTU0wxFTATBgNVBAMMDCouYmFkc3NsLmNvbTAeFw0x
38
- OTEwMDkyMzQxNTJaFw0yMTEwMDgyMzQxNTJaMGIxCzAJBgNVBAYTAlVTMRMwEQYD
39
- VQQIDApDYWxpZm9ybmlhMRYwFAYDVQQHDA1TYW4gRnJhbmNpc2NvMQ8wDQYDVQQK
40
- DAZCYWRTU0wxFTATBgNVBAMMDCouYmFkc3NsLmNvbTCCASIwDQYJKoZIhvcNAQEB
41
- BQADggEPADCCAQoCggEBAMIE7PiM7gTCs9hQ1XBYzJMY61yoaEmwIrX5lZ6xKyx2
42
- PmzAS2BMTOqytMAPgLaw+XLJhgL5XEFdEyt/ccRLvOmULlA3pmccYYz2QULFRtMW
43
- hyefdOsKnRFSJiFzbIRMeVXk0WvoBj1IFVKtsyjbqv9u/2CVSndrOfEk0TG23U3A
44
- xPxTuW1CrbV8/q71FdIzSOciccfCFHpsKOo3St/qbLVytH5aohbcabFXRNsKEqve
45
- ww9HdFxBIuGa+RuT5q0iBikusbpJHAwnnqP7i/dAcgCskgjZjFeEU4EFy+b+a1SY
46
- QCeFxxC7c3DvaRhBB0VVfPlkPz0sw6l865MaTIbRyoUCAwEAAaMyMDAwCQYDVR0T
47
- BAIwADAjBgNVHREEHDAaggwqLmJhZHNzbC5jb22CCmJhZHNzbC5jb20wDQYJKoZI
48
- hvcNAQELBQADggEBAGlwCdbPxflZfYOaukZGCaxYK6gpincX4Lla4Ui2WdeQxE95
49
- w7fChXvP3YkE3UYUE7mupZ0eg4ZILr/A0e7JQDsgIu/SRTUE0domCKgPZ8v99k3A
50
- vka4LpLK51jHJJK7EFgo3ca2nldd97GM0MU41xHFk8qaK1tWJkfrrfcGwDJ4GQPI
51
- iLlm6i0yHq1Qg1RypAXJy5dTlRXlCLd8ufWhhiwW0W75Va5AEnJuqpQrKwl3KQVe
52
- wGj67WWRgLfSr+4QG1mNvCZb2CkjZWmxkGPuoP40/y7Yu5OFqxP5tAjj4YixCYTW
53
- EVA0pmzIzgBg+JIe3PdRy27T0asgQW/F4TY61Yk=
54
- -----END CERTIFICATE-----
55
- CERT
56
- end
57
- ```
31
+ ```ruby
32
+ chef_client_trusted_certificate 'self-signed.badssl.com' do
33
+ certificate <<~CERT
34
+ -----BEGIN CERTIFICATE-----
35
+ MIIDeTCCAmGgAwIBAgIJAPziuikCTox4MA0GCSqGSIb3DQEBCwUAMGIxCzAJBgNV
36
+ BAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlhMRYwFAYDVQQHDA1TYW4gRnJhbmNp
37
+ c2NvMQ8wDQYDVQQKDAZCYWRTU0wxFTATBgNVBAMMDCouYmFkc3NsLmNvbTAeFw0x
38
+ OTEwMDkyMzQxNTJaFw0yMTEwMDgyMzQxNTJaMGIxCzAJBgNVBAYTAlVTMRMwEQYD
39
+ VQQIDApDYWxpZm9ybmlhMRYwFAYDVQQHDA1TYW4gRnJhbmNpc2NvMQ8wDQYDVQQK
40
+ DAZCYWRTU0wxFTATBgNVBAMMDCouYmFkc3NsLmNvbTCCASIwDQYJKoZIhvcNAQEB
41
+ BQADggEPADCCAQoCggEBAMIE7PiM7gTCs9hQ1XBYzJMY61yoaEmwIrX5lZ6xKyx2
42
+ PmzAS2BMTOqytMAPgLaw+XLJhgL5XEFdEyt/ccRLvOmULlA3pmccYYz2QULFRtMW
43
+ hyefdOsKnRFSJiFzbIRMeVXk0WvoBj1IFVKtsyjbqv9u/2CVSndrOfEk0TG23U3A
44
+ xPxTuW1CrbV8/q71FdIzSOciccfCFHpsKOo3St/qbLVytH5aohbcabFXRNsKEqve
45
+ ww9HdFxBIuGa+RuT5q0iBikusbpJHAwnnqP7i/dAcgCskgjZjFeEU4EFy+b+a1SY
46
+ QCeFxxC7c3DvaRhBB0VVfPlkPz0sw6l865MaTIbRyoUCAwEAAaMyMDAwCQYDVR0T
47
+ BAIwADAjBgNVHREEHDAaggwqLmJhZHNzbC5jb22CCmJhZHNzbC5jb20wDQYJKoZI
48
+ hvcNAQELBQADggEBAGlwCdbPxflZfYOaukZGCaxYK6gpincX4Lla4Ui2WdeQxE95
49
+ w7fChXvP3YkE3UYUE7mupZ0eg4ZILr/A0e7JQDsgIu/SRTUE0domCKgPZ8v99k3A
50
+ vka4LpLK51jHJJK7EFgo3ca2nldd97GM0MU41xHFk8qaK1tWJkfrrfcGwDJ4GQPI
51
+ iLlm6i0yHq1Qg1RypAXJy5dTlRXlCLd8ufWhhiwW0W75Va5AEnJuqpQrKwl3KQVe
52
+ wGj67WWRgLfSr+4QG1mNvCZb2CkjZWmxkGPuoP40/y7Yu5OFqxP5tAjj4YixCYTW
53
+ EVA0pmzIzgBg+JIe3PdRy27T0asgQW/F4TY61Yk=
54
+ -----END CERTIFICATE-----
55
+ CERT
56
+ end
57
+ ```
58
58
  DOC
59
59
 
60
60
  property :cert_name, String, name_property: true,