chef 18.4.12 → 18.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (222) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/chef.gemspec +6 -6
  4. data/lib/chef/application/client.rb +12 -0
  5. data/lib/chef/client.rb +10 -16
  6. data/lib/chef/compliance/runner.rb +10 -0
  7. data/lib/chef/cookbook/chefignore.rb +4 -1
  8. data/lib/chef/cookbook/cookbook_version_loader.rb +1 -1
  9. data/lib/chef/cookbook/synchronizer.rb +7 -1
  10. data/lib/chef/cookbook_manifest.rb +2 -2
  11. data/lib/chef/file_access_control/unix.rb +9 -9
  12. data/lib/chef/file_cache.rb +17 -2
  13. data/lib/chef/file_content_management/deploy/target_io.rb +29 -0
  14. data/lib/chef/file_content_management/deploy.rb +4 -1
  15. data/lib/chef/formatters/doc.rb +1 -1
  16. data/lib/chef/mixin/file_class.rb +3 -1
  17. data/lib/chef/mixin/get_source_from_package.rb +1 -1
  18. data/lib/chef/mixin/openssl_helper.rb +1 -1
  19. data/lib/chef/node/attribute.rb +3 -11
  20. data/lib/chef/node/immutable_collections.rb +15 -8
  21. data/lib/chef/node/mixin/state_tracking.rb +6 -3
  22. data/lib/chef/policy_builder/policyfile.rb +8 -0
  23. data/lib/chef/provider/.gitkeep +0 -0
  24. data/lib/chef/provider/cookbook_file.rb +1 -1
  25. data/lib/chef/provider/cron.rb +1 -1
  26. data/lib/chef/provider/directory.rb +15 -15
  27. data/lib/chef/provider/file.rb +42 -29
  28. data/lib/chef/provider/git.rb +8 -8
  29. data/lib/chef/provider/group/aix.rb +1 -1
  30. data/lib/chef/provider/group/dscl.rb +1 -1
  31. data/lib/chef/provider/group/gpasswd.rb +2 -2
  32. data/lib/chef/provider/group/groupadd.rb +1 -1
  33. data/lib/chef/provider/group/groupmod.rb +2 -2
  34. data/lib/chef/provider/group/pw.rb +2 -2
  35. data/lib/chef/provider/group/solaris.rb +2 -2
  36. data/lib/chef/provider/group/usermod.rb +2 -2
  37. data/lib/chef/provider/group.rb +1 -1
  38. data/lib/chef/provider/http_request.rb +2 -3
  39. data/lib/chef/provider/ifconfig/aix.rb +1 -1
  40. data/lib/chef/provider/ifconfig/debian.rb +3 -3
  41. data/lib/chef/provider/ifconfig/redhat.rb +1 -1
  42. data/lib/chef/provider/ifconfig.rb +1 -1
  43. data/lib/chef/provider/link.rb +10 -10
  44. data/lib/chef/provider/mount/aix.rb +4 -4
  45. data/lib/chef/provider/mount/linux.rb +4 -4
  46. data/lib/chef/provider/mount/mount.rb +11 -11
  47. data/lib/chef/provider/package/apt.rb +2 -11
  48. data/lib/chef/provider/package/bff.rb +3 -3
  49. data/lib/chef/provider/package/chocolatey.rb +54 -24
  50. data/lib/chef/provider/package/dpkg.rb +3 -3
  51. data/lib/chef/provider/package/freebsd/base.rb +1 -1
  52. data/lib/chef/provider/package/habitat.rb +5 -3
  53. data/lib/chef/provider/package/ips.rb +2 -2
  54. data/lib/chef/provider/package/openbsd.rb +3 -2
  55. data/lib/chef/provider/package/pacman.rb +4 -4
  56. data/lib/chef/provider/package/paludis.rb +2 -2
  57. data/lib/chef/provider/package/portage.rb +1 -1
  58. data/lib/chef/provider/package/powershell.rb +1 -0
  59. data/lib/chef/provider/package/rpm.rb +2 -2
  60. data/lib/chef/provider/package/smartos.rb +2 -2
  61. data/lib/chef/provider/package/snap.rb +2 -1
  62. data/lib/chef/provider/package/snap_tm.rb +79 -0
  63. data/lib/chef/provider/package/solaris.rb +4 -4
  64. data/lib/chef/provider/package/zypper.rb +4 -5
  65. data/lib/chef/provider/package.rb +1 -1
  66. data/lib/chef/provider/remote_directory.rb +5 -5
  67. data/lib/chef/provider/remote_file/http.rb +2 -3
  68. data/lib/chef/provider/remote_file.rb +1 -1
  69. data/lib/chef/provider/route.rb +9 -9
  70. data/lib/chef/provider/service/aix.rb +1 -1
  71. data/lib/chef/provider/service/aixinit.rb +4 -4
  72. data/lib/chef/provider/service/arch.rb +6 -6
  73. data/lib/chef/provider/service/debian.rb +5 -5
  74. data/lib/chef/provider/service/freebsd.rb +7 -7
  75. data/lib/chef/provider/service/gentoo.rb +5 -5
  76. data/lib/chef/provider/service/init.rb +2 -2
  77. data/lib/chef/provider/service/insserv.rb +2 -2
  78. data/lib/chef/provider/service/invokercd.rb +1 -1
  79. data/lib/chef/provider/service/openbsd.rb +7 -7
  80. data/lib/chef/provider/service/redhat.rb +3 -3
  81. data/lib/chef/provider/service/solaris.rb +2 -2
  82. data/lib/chef/provider/service/systemd.rb +2 -2
  83. data/lib/chef/provider/service/upstart.rb +2 -2
  84. data/lib/chef/provider/service/windows.rb +0 -1
  85. data/lib/chef/provider/subversion.rb +8 -8
  86. data/lib/chef/provider/systemd_unit.rb +3 -3
  87. data/lib/chef/provider/template.rb +1 -1
  88. data/lib/chef/provider/user/aix.rb +3 -3
  89. data/lib/chef/provider/user/linux.rb +7 -2
  90. data/lib/chef/provider/user/pw.rb +3 -3
  91. data/lib/chef/provider/user/solaris.rb +7 -7
  92. data/lib/chef/provider/user.rb +7 -8
  93. data/lib/chef/provider/yum_repository.rb +1 -3
  94. data/lib/chef/provider/zypper_repository.rb +1 -1
  95. data/lib/chef/providers.rb +1 -0
  96. data/lib/chef/resource/.gitkeep +0 -0
  97. data/lib/chef/resource/alternatives.rb +2 -2
  98. data/lib/chef/resource/apt_preference.rb +1 -1
  99. data/lib/chef/resource/apt_repository.rb +7 -9
  100. data/lib/chef/resource/apt_update.rb +3 -3
  101. data/lib/chef/resource/bff_package.rb +1 -1
  102. data/lib/chef/resource/chef_client_config.rb +3 -2
  103. data/lib/chef/resource/chef_client_systemd_timer.rb +5 -0
  104. data/lib/chef/resource/chef_gem.rb +1 -1
  105. data/lib/chef/resource/chef_sleep.rb +1 -1
  106. data/lib/chef/resource/cookbook_file.rb +1 -1
  107. data/lib/chef/resource/cron/cron.rb +1 -1
  108. data/lib/chef/resource/cron/cron_d.rb +1 -1
  109. data/lib/chef/resource/cron_access.rb +1 -1
  110. data/lib/chef/resource/directory.rb +1 -1
  111. data/lib/chef/resource/dpkg_package.rb +1 -1
  112. data/lib/chef/resource/execute.rb +8 -6
  113. data/lib/chef/resource/file/verification/json.rb +1 -1
  114. data/lib/chef/resource/file/verification/systemd_unit.rb +1 -1
  115. data/lib/chef/resource/file/verification/yaml.rb +1 -1
  116. data/lib/chef/resource/file.rb +1 -1
  117. data/lib/chef/resource/freebsd_package.rb +2 -2
  118. data/lib/chef/resource/group.rb +1 -1
  119. data/lib/chef/resource/habitat/habitat_package.rb +1 -1
  120. data/lib/chef/resource/habitat/habitat_sup.rb +9 -9
  121. data/lib/chef/resource/habitat/habitat_sup_systemd.rb +2 -2
  122. data/lib/chef/resource/habitat_install.rb +5 -4
  123. data/lib/chef/resource/hostname.rb +11 -10
  124. data/lib/chef/resource/http_request.rb +1 -1
  125. data/lib/chef/resource/ifconfig.rb +1 -1
  126. data/lib/chef/resource/inspec_input.rb +3 -1
  127. data/lib/chef/resource/inspec_waiver.rb +1 -1
  128. data/lib/chef/resource/inspec_waiver_file_entry.rb +1 -1
  129. data/lib/chef/resource/ips_package.rb +2 -2
  130. data/lib/chef/resource/kernel_module.rb +2 -2
  131. data/lib/chef/resource/link.rb +1 -1
  132. data/lib/chef/resource/locale.rb +2 -2
  133. data/lib/chef/resource/mount.rb +1 -1
  134. data/lib/chef/resource/notify_group.rb +1 -1
  135. data/lib/chef/resource/ohai.rb +1 -1
  136. data/lib/chef/resource/ohai_hint.rb +1 -1
  137. data/lib/chef/resource/openbsd_package.rb +2 -2
  138. data/lib/chef/resource/package.rb +1 -1
  139. data/lib/chef/resource/pacman_package.rb +1 -1
  140. data/lib/chef/resource/paludis_package.rb +1 -1
  141. data/lib/chef/resource/portage_package.rb +1 -1
  142. data/lib/chef/resource/powershell_package.rb +4 -0
  143. data/lib/chef/resource/reboot.rb +1 -1
  144. data/lib/chef/resource/remote_directory.rb +1 -1
  145. data/lib/chef/resource/remote_file.rb +1 -1
  146. data/lib/chef/resource/rhsm_errata.rb +1 -1
  147. data/lib/chef/resource/rhsm_errata_level.rb +1 -1
  148. data/lib/chef/resource/rhsm_register.rb +1 -1
  149. data/lib/chef/resource/rhsm_repo.rb +3 -4
  150. data/lib/chef/resource/rhsm_subscription.rb +8 -9
  151. data/lib/chef/resource/route.rb +1 -1
  152. data/lib/chef/resource/rpm_package.rb +1 -1
  153. data/lib/chef/resource/scm/git.rb +1 -1
  154. data/lib/chef/resource/scm/subversion.rb +1 -1
  155. data/lib/chef/resource/selinux/common_helpers.rb +1 -1
  156. data/lib/chef/resource/selinux_boolean.rb +1 -1
  157. data/lib/chef/resource/selinux_fcontext.rb +3 -3
  158. data/lib/chef/resource/selinux_install.rb +1 -1
  159. data/lib/chef/resource/selinux_login.rb +1 -1
  160. data/lib/chef/resource/selinux_module.rb +5 -5
  161. data/lib/chef/resource/selinux_permissive.rb +2 -2
  162. data/lib/chef/resource/selinux_port.rb +2 -2
  163. data/lib/chef/resource/selinux_state.rb +2 -2
  164. data/lib/chef/resource/selinux_user.rb +1 -1
  165. data/lib/chef/resource/smartos_package.rb +2 -2
  166. data/lib/chef/resource/snap_package.rb +24 -1
  167. data/lib/chef/resource/solaris_package.rb +1 -1
  168. data/lib/chef/resource/ssh_known_hosts_entry.rb +1 -1
  169. data/lib/chef/resource/sudo.rb +5 -5
  170. data/lib/chef/resource/support/client.erb +1 -1
  171. data/lib/chef/resource/swap_file.rb +6 -6
  172. data/lib/chef/resource/sysctl.rb +6 -5
  173. data/lib/chef/resource/systemd_unit.rb +1 -1
  174. data/lib/chef/resource/template.rb +1 -1
  175. data/lib/chef/resource/timezone.rb +5 -5
  176. data/lib/chef/resource/user/aix_user.rb +2 -2
  177. data/lib/chef/resource/user/linux_user.rb +2 -2
  178. data/lib/chef/resource/user/pw_user.rb +2 -2
  179. data/lib/chef/resource/user/solaris_user.rb +2 -2
  180. data/lib/chef/resource/user_ulimit.rb +1 -1
  181. data/lib/chef/resource/yum_repository.rb +1 -1
  182. data/lib/chef/resource/zypper_package.rb +2 -2
  183. data/lib/chef/resource/zypper_repository.rb +2 -2
  184. data/lib/chef/run_lock.rb +3 -0
  185. data/lib/chef/scan_access_control.rb +6 -6
  186. data/lib/chef/target_io/dir.rb +12 -0
  187. data/lib/chef/target_io/etc.rb +16 -0
  188. data/lib/chef/target_io/file.rb +12 -0
  189. data/lib/chef/target_io/fileutils.rb +12 -0
  190. data/lib/chef/target_io/http.rb +22 -0
  191. data/lib/chef/target_io/io.rb +12 -0
  192. data/lib/chef/target_io/shadow.rb +44 -0
  193. data/lib/chef/target_io/train/dir.rb +69 -0
  194. data/lib/chef/target_io/train/etc.rb +112 -0
  195. data/lib/chef/target_io/train/file.rb +219 -0
  196. data/lib/chef/target_io/train/fileutils.rb +220 -0
  197. data/lib/chef/target_io/train/http.rb +117 -0
  198. data/lib/chef/target_io/train/io.rb +13 -0
  199. data/lib/chef/target_io/train/shadow.rb +52 -0
  200. data/lib/chef/target_io/train_compat.rb +7 -0
  201. data/lib/chef/target_io.rb +9 -0
  202. data/lib/chef/util/backup.rb +1 -1
  203. data/lib/chef/util/diff.rb +14 -1
  204. data/lib/chef/util/file_edit.rb +4 -4
  205. data/lib/chef/version.rb +1 -1
  206. data/lib/chef.rb +2 -0
  207. data/spec/functional/resource/remote_file_spec.rb +1 -1
  208. data/spec/integration/client/fips_spec.rb +11 -2
  209. data/spec/integration/client/open_ssl_spec.rb +20 -0
  210. data/spec/spec_helper.rb +3 -1
  211. data/spec/support/platform_helpers.rb +20 -7
  212. data/spec/unit/client_spec.rb +0 -16
  213. data/spec/unit/file_cache_spec.rb +64 -0
  214. data/spec/unit/mixin/openssl_helper_spec.rb +6 -1
  215. data/spec/unit/provider/apt_repository_spec.rb +1 -1
  216. data/spec/unit/provider/package/chocolatey_spec.rb +17 -12
  217. data/spec/unit/provider/package/windows_spec.rb +5 -5
  218. data/spec/unit/provider/package/zypper_spec.rb +0 -10
  219. data/spec/unit/provider/route_spec.rb +6 -4
  220. data/spec/unit/resource/rhsm_repo_spec.rb +1 -0
  221. data/spec/unit/resource/rhsm_subscription_spec.rb +2 -0
  222. metadata +29 -8
@@ -20,14 +20,19 @@ class Chef
20
20
  class Provider
21
21
  class User
22
22
  class Linux < Chef::Provider::User
23
- provides :linux_user
24
- provides :user, os: "linux"
23
+ provides :linux_user, target_mode: true
24
+ provides :user, os: "linux", target_mode: true
25
25
 
26
26
  def load_current_resource
27
27
  super
28
28
  load_shadow_options
29
29
  end
30
30
 
31
+ def supports_ruby_shadow?
32
+ # For target mode, ruby-shadow is redirected to a file-based implementation
33
+ true unless ChefConfig::Config.target_mode?
34
+ end
35
+
31
36
  def compare_user
32
37
  user_changed = super
33
38
 
@@ -22,12 +22,12 @@ class Chef
22
22
  class Provider
23
23
  class User
24
24
  class Pw < Chef::Provider::User
25
- provides :pw_user
26
- provides :user, os: "freebsd"
25
+ provides :pw_user, target_mode: true
26
+ provides :user, os: "freebsd", target_mode: true
27
27
 
28
28
  def load_current_resource
29
29
  super
30
- raise Chef::Exceptions::User, "Could not find binary /usr/sbin/pw for #{new_resource}" unless ::File.exist?("/usr/sbin/pw")
30
+ raise Chef::Exceptions::User, "Could not find binary /usr/sbin/pw for #{new_resource}" unless ::TargetIO::File.exist?("/usr/sbin/pw")
31
31
  end
32
32
 
33
33
  def create_user
@@ -24,8 +24,8 @@ class Chef
24
24
  class Provider
25
25
  class User
26
26
  class Solaris < Chef::Provider::User
27
- provides :solaris_user
28
- provides :user, os: %w{openindiana illumos omnios solaris2 smartos}
27
+ provides :solaris_user, target_mode: true
28
+ provides :user, os: %w{openindiana illumos omnios solaris2 smartos}, target_mode: true
29
29
 
30
30
  PASSWORD_FILE = "/etc/shadow".freeze
31
31
 
@@ -46,7 +46,7 @@ class Chef
46
46
  end
47
47
 
48
48
  def check_lock
49
- user = IO.read(PASSWORD_FILE).match(/^#{Regexp.escape(new_resource.username)}:([^:]*):/)
49
+ user = TargetIO::IO.read(PASSWORD_FILE).match(/^#{Regexp.escape(new_resource.username)}:([^:]*):/)
50
50
 
51
51
  # If we're in whyrun mode, and the user is not created, we assume it will be
52
52
  return false if whyrun_mode? && user.nil?
@@ -122,7 +122,7 @@ class Chef
122
122
  # a pipe to passwd(1) or evaluating modern ruby-shadow. See https://github.com/chef/chef/pull/721
123
123
  def write_shadow_file
124
124
  buffer = Tempfile.new("shadow", "/etc")
125
- ::File.open(PASSWORD_FILE) do |shadow_file|
125
+ ::TargetIO::File.open(PASSWORD_FILE) do |shadow_file|
126
126
  shadow_file.each do |entry|
127
127
  user = entry.split(":").first
128
128
  if user == new_resource.username
@@ -140,10 +140,10 @@ class Chef
140
140
  uid = s.uid
141
141
  gid = s.gid
142
142
 
143
- FileUtils.chown uid, gid, buffer.path
144
- FileUtils.chmod mode, buffer.path
143
+ TargetIO::FileUtils.chown uid, gid, buffer.path
144
+ TargetIO::FileUtils.chmod mode, buffer.path
145
145
 
146
- FileUtils.mv buffer.path, PASSWORD_FILE
146
+ TargetIO::FileUtils.mv buffer.path, PASSWORD_FILE
147
147
  end
148
148
 
149
149
  def updated_password(entry)
@@ -36,7 +36,7 @@ class Chef
36
36
 
37
37
  def convert_group_name
38
38
  if new_resource.gid.is_a?(String) && new_resource.gid.to_i == 0
39
- new_resource.gid(Etc.getgrnam(new_resource.gid).gid)
39
+ new_resource.gid(TargetIO::Etc.getgrnam(new_resource.gid).gid)
40
40
  end
41
41
  rescue ArgumentError
42
42
  @group_name_resolved = false
@@ -47,7 +47,7 @@ class Chef
47
47
  current_resource.username(new_resource.username)
48
48
 
49
49
  begin
50
- user_info = Etc.getpwnam(new_resource.username)
50
+ user_info = TargetIO::Etc.getpwnam(new_resource.username)
51
51
  rescue ArgumentError
52
52
  @user_exists = false
53
53
  logger.trace("#{new_resource} user does not exist")
@@ -68,10 +68,13 @@ class Chef
68
68
 
69
69
  begin
70
70
  require "shadow"
71
+
72
+ # Cannot use this library remotely
73
+ @shadow_lib_ok = false if ChefConfig::Config.target_mode?
71
74
  rescue LoadError
72
75
  @shadow_lib_ok = false
73
76
  else
74
- @shadow_info = Shadow::Passwd.getspnam(new_resource.username)
77
+ @shadow_info = TargetIO::Shadow::Passwd.getspnam(new_resource.username)
75
78
  # This conditional remains in place until we can sort out whether we need it.
76
79
  # Currently removing it causes tests to fail, but that /seems/ to be mocking/setup issues.
77
80
  # Some notes for context:
@@ -153,11 +156,7 @@ class Chef
153
156
  new_val = new_resource.send(user_attrib)
154
157
  cur_val = current_resource.send(user_attrib)
155
158
  if !new_val.nil? && new_val.to_s != cur_val.to_s
156
- if user_attrib.to_s == "password" && new_resource.sensitive
157
- @change_desc << "change #{user_attrib} from ******** to ********"
158
- else
159
- @change_desc << "change #{user_attrib} from #{cur_val} to #{new_val}"
160
- end
159
+ @change_desc << "change #{user_attrib} from #{cur_val} to #{new_val}"
161
160
  end
162
161
  end
163
162
 
@@ -25,9 +25,7 @@ class Chef
25
25
  class YumRepository < Chef::Provider
26
26
  extend Chef::Mixin::Which
27
27
 
28
- provides :yum_repository do
29
- which "yum"
30
- end
28
+ provides(:yum_repository, target_mode: true) { which "yum" }
31
29
 
32
30
  def load_current_resource; end
33
31
 
@@ -25,7 +25,7 @@ require "chef-utils/dist" unless defined?(ChefUtils::Dist)
25
25
  class Chef
26
26
  class Provider
27
27
  class ZypperRepository < Chef::Provider
28
- provides :zypper_repository, platform_family: "suse"
28
+ provides :zypper_repository, platform_family: "suse", target_mode: true
29
29
 
30
30
  def load_current_resource; end
31
31
 
@@ -74,6 +74,7 @@ require_relative "provider/package/cab"
74
74
  require_relative "provider/package/powershell"
75
75
  require_relative "provider/package/msu"
76
76
  require_relative "provider/package/snap"
77
+ require_relative "provider/package/snap_tm"
77
78
  require_relative "provider/package/habitat"
78
79
 
79
80
  require_relative "provider/service/arch"
File without changes
@@ -23,7 +23,7 @@ class Chef
23
23
  class Resource
24
24
  class Alternatives < Chef::Resource
25
25
 
26
- provides(:alternatives) { true }
26
+ provides(:alternatives, target_mode: true) { true }
27
27
 
28
28
  description "Use the **alternatives** resource to configure command alternatives in Linux using the alternatives or update-alternatives packages."
29
29
  introduced "16.0"
@@ -113,7 +113,7 @@ class Chef
113
113
 
114
114
  requirements.assert(:install, :set, :remove) do |a|
115
115
  a.assertion do
116
- ::File.exist?(new_resource.path)
116
+ ::TargetIO::File.exist?(new_resource.path)
117
117
  end
118
118
 
119
119
  a.whyrun("Assuming file #{new_resource.path} already exists or was created already")
@@ -22,7 +22,7 @@ class Chef
22
22
  class Resource
23
23
  class AptPreference < Chef::Resource
24
24
 
25
- provides(:apt_preference) { true }
25
+ provides(:apt_preference, target_mode: true) { true }
26
26
 
27
27
  description "Use the **apt_preference** resource to create APT [preference files](https://wiki.debian.org/AptPreferences). Preference files are used to control which package versions and sources are prioritized during installation."
28
28
  introduced "13.3"
@@ -17,7 +17,6 @@
17
17
  #
18
18
 
19
19
  require_relative "../resource"
20
- require_relative "../http/simple"
21
20
  require "tmpdir" unless defined?(Dir.mktmpdir)
22
21
  module Addressable
23
22
  autoload :URI, "addressable/uri"
@@ -27,7 +26,7 @@ class Chef
27
26
  class Resource
28
27
  class AptRepository < Chef::Resource
29
28
 
30
- provides(:apt_repository) { true }
29
+ provides(:apt_repository, target_mode: true) { true }
31
30
 
32
31
  description "Use the **apt_repository** resource to specify additional APT repositories. Adding a new repository will update the APT package cache immediately."
33
32
  introduced "12.9"
@@ -99,7 +98,6 @@ class Chef
99
98
  ```
100
99
 
101
100
  **Add repository that needs custom options**:
102
-
103
101
  ```ruby
104
102
  apt_repository 'corretto' do
105
103
  uri 'https://apt.corretto.aws'
@@ -173,7 +171,7 @@ class Chef
173
171
  default: true, desired_state: false
174
172
 
175
173
  property :options, [String, Array],
176
- description: "Additional options to set for the repository.",
174
+ description: "Additional options to set for the repository",
177
175
  default: [], coerce: proc { |x| Array(x) }
178
176
 
179
177
  default_action :add
@@ -289,8 +287,8 @@ class Chef
289
287
  def install_key_from_uri(key)
290
288
  key_name = key.gsub(/[^0-9A-Za-z\-]/, "_")
291
289
  cached_keyfile = ::File.join(Chef::Config[:file_cache_path], key_name)
292
- tmp_dir = Dir.mktmpdir(".gpg")
293
- at_exit { FileUtils.remove_entry(tmp_dir) }
290
+ tmp_dir = TargetIO::Dir.mktmpdir(".gpg")
291
+ at_exit { TargetIO::FileUtils.remove_entry(tmp_dir) }
294
292
 
295
293
  declare_resource(key_type(key), cached_keyfile) do
296
294
  source key
@@ -360,7 +358,7 @@ class Chef
360
358
  # @return [void]
361
359
  def install_ppa_key(owner, repo)
362
360
  url = "https://launchpad.net/api/1.0/~#{owner}/+archive/#{repo}"
363
- key_id = Chef::HTTP::Simple.new(url).get("signing_key_fingerprint").delete('"')
361
+ key_id = TargetIO::HTTP.new(url).get("signing_key_fingerprint").delete('"')
364
362
  install_key_from_keyserver(key_id, "keyserver.ubuntu.com")
365
363
  rescue Net::HTTPClientException => e
366
364
  raise "Could not access Launchpad ppa API: #{e.message}"
@@ -434,7 +432,7 @@ class Chef
434
432
  # @return [void]
435
433
  def cleanup_legacy_file!
436
434
  legacy_path = "/etc/apt/sources.list.d/#{new_resource.name}.list"
437
- if new_resource.name != new_resource.repo_name && ::File.exist?(legacy_path)
435
+ if new_resource.name != new_resource.repo_name && ::TargetIO::File.exist?(legacy_path)
438
436
  converge_by "Cleaning up legacy #{legacy_path} repo file" do
439
437
  file legacy_path do
440
438
  action :delete
@@ -500,7 +498,7 @@ class Chef
500
498
  return unless debian?
501
499
 
502
500
  cleanup_legacy_file!
503
- if ::File.exist?("/etc/apt/sources.list.d/#{new_resource.repo_name}.list")
501
+ if ::TargetIO::File.exist?("/etc/apt/sources.list.d/#{new_resource.repo_name}.list")
504
502
  converge_by "Removing #{new_resource.repo_name} repository from /etc/apt/sources.list.d/" do
505
503
  apt_update new_resource.name do
506
504
  ignore_failure true
@@ -23,7 +23,7 @@ class Chef
23
23
  class Resource
24
24
  class AptUpdate < Chef::Resource
25
25
 
26
- provides(:apt_update) { true }
26
+ provides(:apt_update, target_mode: true) { true }
27
27
 
28
28
  description "Use the **apt_update** resource to manage APT repository updates on Debian and Ubuntu platforms."
29
29
  introduced "12.7"
@@ -62,8 +62,8 @@ class Chef
62
62
  #
63
63
  # @return [Boolean]
64
64
  def apt_up_to_date?
65
- ::File.exist?("#{STAMP_DIR}/update-success-stamp") &&
66
- ::File.mtime("#{STAMP_DIR}/update-success-stamp") > Time.now - new_resource.frequency
65
+ ::TargetIO::File.exist?("#{STAMP_DIR}/update-success-stamp") &&
66
+ ::TargetIO::File.mtime("#{STAMP_DIR}/update-success-stamp") > Time.now - new_resource.frequency
67
67
  end
68
68
 
69
69
  def do_update
@@ -23,7 +23,7 @@ class Chef
23
23
  class Resource
24
24
  class BffPackage < Chef::Resource::Package
25
25
 
26
- provides :bff_package
26
+ provides :bff_package, target_mode: true
27
27
 
28
28
  description "Use the **bff_package** resource to manage packages for the AIX platform using the installp utility. When a package is installed from a local file, it must be added to the node using the **remote_file** or **cookbook_file** resources."
29
29
  introduced "12.0"
@@ -21,7 +21,7 @@ class Chef
21
21
  class Resource
22
22
  class ChefClientConfig < Chef::Resource
23
23
 
24
- provides :chef_client_config
24
+ provides :chef_client_config, target_mode: true
25
25
 
26
26
  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
27
  introduced "16.6"
@@ -198,7 +198,8 @@ class Chef
198
198
  introduced: "17.3"
199
199
 
200
200
  property :minimal_ohai, [true, false],
201
- description: "Run a minimal set of Ohai plugins providing data necessary for the execution of #{ChefUtils::Dist::Infra::PRODUCT}'s built-in resources. Setting this to true will skip many large and time consuming data sets such as `cloud` or `packages`. Setting this this to true may break cookbooks that assume all Ohai data will be present."
201
+ description: "Run a minimal set of Ohai plugins providing data necessary for the execution of #{ChefUtils::Dist::Infra::PRODUCT}'s built-in resources. Setting this to true will skip many large and time consuming data sets such as `cloud` or `packages`. Setting this to true may break cookbooks that assume all Ohai data will be present.",
202
+ default: false
202
203
 
203
204
  property :start_handlers, Array,
204
205
  description: %q(An array of hashes that contain a report handler class and the arguments to pass to that class on initialization. The hash should include `class` and `argument` keys where `class` is a String and `argument` is an array of quoted String values. For example: `[{'class' => 'MyHandler', %w('"argument1"', '"argument2"')}]`),
@@ -103,6 +103,10 @@ class Chef
103
103
  coerce: proc { |x| Integer(x) },
104
104
  callbacks: { "should be a positive Integer" => proc { |v| v > 0 } }
105
105
 
106
+ property :service_umask, [Integer, String],
107
+ description: "Fix umask for hardened systems that have a changed default umask. This changes the chef-client umask so any files or folders are created with new umask. Recommend setting to stand install default of 0022.",
108
+ introduced: "18.5"
109
+
106
110
  action :add, description: "Add a systemd timer that runs #{ChefUtils::Dist::Infra::PRODUCT}." do
107
111
  systemd_unit "#{new_resource.job_name}.service" do
108
112
  content service_content
@@ -175,6 +179,7 @@ class Chef
175
179
  "Install" => { "WantedBy" => "multi-user.target" },
176
180
  }
177
181
 
182
+ unit["Service"]["UMask"] = new_resource.service_umask if new_resource.service_umask
178
183
  unit["Service"]["ConditionACPower"] = "true" unless new_resource.run_on_battery
179
184
  unit["Service"]["CPUQuota"] = "#{new_resource.cpu_quota}%" if new_resource.cpu_quota
180
185
  unit["Service"]["Environment"] = new_resource.environment.collect { |k, v| "\"#{k}=#{v}\"" } unless new_resource.environment.empty?
@@ -62,7 +62,7 @@ class Chef
62
62
  end
63
63
  ```
64
64
 
65
- **Install MySQL gem into #{ChefUtils::Dist::Infra::PRODUCT}***
65
+ **Install MySQL gem into #{ChefUtils::Dist::Infra::PRODUCT}**
66
66
  ```ruby
67
67
  apt_update
68
68
 
@@ -20,7 +20,7 @@ require "chef-utils/dist" unless defined?(ChefUtils::Dist)
20
20
  class Chef
21
21
  class Resource
22
22
  class ChefSleep < Chef::Resource
23
- provides :chef_sleep
23
+ provides :chef_sleep, target_mode: true
24
24
 
25
25
  description "Use the **chef_sleep** resource to pause (sleep) for a number of seconds during a #{ChefUtils::Dist::Infra::PRODUCT} run. Only use this resource when a command or service exits successfully but is not ready for the next step in a recipe."
26
26
  introduced "15.5"
@@ -28,7 +28,7 @@ class Chef
28
28
  class CookbookFile < Chef::Resource::File
29
29
  include Chef::Mixin::Securable
30
30
 
31
- provides :cookbook_file
31
+ provides :cookbook_file, target_mode: true
32
32
 
33
33
  description "Use the **cookbook_file** resource to transfer files from a sub-directory of COOKBOOK_NAME/files/ to a specified path located on a host that is running the #{ChefUtils::Dist::Infra::PRODUCT}. The file is selected according to file specificity, which allows different source files to be used based on the hostname, host platform (operating system, distro, or as appropriate), or platform version. Files that are located in the COOKBOOK_NAME/files/default sub-directory may be used on any platform.\n\nDuring a #{ChefUtils::Dist::Infra::PRODUCT} run, the checksum for each local file is calculated and then compared against the checksum for the same file as it currently exists in the cookbook on the #{ChefUtils::Dist::Server::PRODUCT}. A file is not transferred when the checksums match. Only files that require an update are transferred from the #{ChefUtils::Dist::Server::PRODUCT} to a node."
34
34
 
@@ -28,7 +28,7 @@ class Chef
28
28
 
29
29
  use "cron_shared"
30
30
 
31
- provides :cron
31
+ provides :cron, target_mode: true
32
32
 
33
33
  description "Use the **cron** resource to manage cron entries for time-based job scheduling. Properties for a schedule will default to * if not provided. The cron resource requires access to a crontab program, typically cron. Warning: The cron resource should only be used to modify an entry in a crontab file. The `cron_d` resource directly manages `cron.d` files. This resource ships in #{ChefUtils::Dist::Infra::PRODUCT} 14.4 or later and can also be found in the [cron](https://github.com/chef-cookbooks/cron) cookbook) for previous #{ChefUtils::Dist::Infra::PRODUCT} releases."
34
34
 
@@ -26,7 +26,7 @@ class Chef
26
26
 
27
27
  use "cron_shared"
28
28
 
29
- provides :cron_d
29
+ provides :cron_d, target_mode: true
30
30
 
31
31
  introduced "14.4"
32
32
  description "Use the **cron_d** resource to manage cron job files in the `/etc/cron.d` directory. Warning: #{ChefUtils::Dist::Infra::PRODUCT} also ships with the **cron** resource for managing the monolithic `/etc/crontab` file on platforms that lack cron.d support. See the [cron resource](/resources/cron/) for information on using that resource."
@@ -23,7 +23,7 @@ require_relative "../resource"
23
23
  class Chef
24
24
  class Resource
25
25
  class CronAccess < Chef::Resource
26
- provides :cron_access
26
+ provides :cron_access, target_mode: true
27
27
  provides(:cron_manage) # legacy name @todo in Chef 15 we should { true } this so it wins over the cookbook
28
28
 
29
29
  introduced "14.4"
@@ -25,7 +25,7 @@ class Chef
25
25
  class Resource
26
26
  class Directory < Chef::Resource
27
27
 
28
- provides :directory
28
+ provides :directory, target_mode: true
29
29
 
30
30
  description "Use the **directory** resource to manage a directory, which is a hierarchy"\
31
31
  " of folders that comprises all of the information stored on a computer."\
@@ -22,7 +22,7 @@ class Chef
22
22
  class Resource
23
23
  class DpkgPackage < Chef::Resource::Package
24
24
 
25
- provides :dpkg_package
25
+ provides :dpkg_package, target_mode: true
26
26
 
27
27
  description "Use the **dpkg_package** resource to manage packages for the dpkg platform. When a package is installed from a local file, it must be added to the node using the **remote_file** or **cookbook_file** resources."
28
28
 
@@ -442,14 +442,14 @@ class Chef
442
442
  NetworkService have this right when running as a service. This is necessary
443
443
  even if the user is an Administrator.
444
444
 
445
- This right can be added and checked in a recipe using this example:
445
+ This right can be added and checked in a recipe using this example (will not take effect in the same Chef run):
446
446
 
447
447
  ```ruby
448
- # Add 'SeAssignPrimaryTokenPrivilege' for the user
449
- Chef::ReservedNames::Win32::Security.add_account_right('<user>', 'SeAssignPrimaryTokenPrivilege')
450
-
451
- # Check if the user has 'SeAssignPrimaryTokenPrivilege' rights
452
- Chef::ReservedNames::Win32::Security.get_account_right('<user>').include?('SeAssignPrimaryTokenPrivilege')
448
+ windows_user_privilege 'add assign token privilege' do
449
+ principal '<user>'
450
+ privilege 'SeAssignPrimaryTokenPrivilege'
451
+ action :add
452
+ end
453
453
  ```
454
454
 
455
455
  The following example shows how to run `mkdir test_dir` from a Chef Infra Client
@@ -492,9 +492,11 @@ class Chef
492
492
 
493
493
  **Run a command with an external input file**:
494
494
 
495
+ ```ruby
495
496
  execute 'md5sum' do
496
497
  input File.read(__FILE__)
497
498
  end
499
+ ```
498
500
  EXAMPLES
499
501
 
500
502
  # The ResourceGuardInterpreter wraps a resource's guards in another resource. That inner resource
@@ -37,7 +37,7 @@ class Chef
37
37
  provides :json
38
38
 
39
39
  def verify(path, opts = {})
40
- Chef::JSONCompat.parse(IO.read(path))
40
+ Chef::JSONCompat.parse(TargetIO::IO.read(path))
41
41
  true
42
42
  rescue Chef::Exceptions::JSON::ParseError => e
43
43
  Chef::Log.error("Json syntax verify failed with : #{e.message}")
@@ -49,7 +49,7 @@ class Chef
49
49
 
50
50
  Dir.mktmpdir("chef-systemd-unit") do |dir|
51
51
  temp = "#{dir}/#{::File.basename(@parent_resource.path)}"
52
- ::FileUtils.cp(path, temp)
52
+ ::TargetIO::FileUtils.cp(path, temp)
53
53
  verify_command(temp, opts)
54
54
  end
55
55
  end
@@ -39,7 +39,7 @@ class Chef
39
39
  provides :yaml
40
40
 
41
41
  def verify(path, opts = {})
42
- Psych.parse_file(path)
42
+ Psych.parse(TargetIO::IO.read(path))
43
43
  true
44
44
  rescue Psych::SyntaxError => e
45
45
  Chef::Log.error("Yaml syntax verify failed with : #{e.message}")
@@ -29,7 +29,7 @@ class Chef
29
29
  class File < Chef::Resource
30
30
  include Chef::Mixin::Securable
31
31
 
32
- provides :file
32
+ provides :file, target_mode: true
33
33
 
34
34
  description "Use the **file** resource to manage files directly on a node. Note: Use the **cookbook_file** resource to copy a file from a cookbook's `/files` directory. Use the **template** resource to create a file based on a template in a cookbook's `/templates` directory. And use the **remote_file** resource to transfer a file to a node from a remote location."
35
35
 
@@ -25,8 +25,8 @@ require_relative "../provider/package/freebsd/pkgng"
25
25
  class Chef
26
26
  class Resource
27
27
  class FreebsdPackage < Chef::Resource::Package
28
- provides :freebsd_package
29
- provides :package, platform: "freebsd"
28
+ provides :freebsd_package, target_mode: true
29
+ provides :package, platform: "freebsd", target_mode: true
30
30
 
31
31
  description "Use the **freebsd_package** resource to manage packages for the FreeBSD platform."
32
32
 
@@ -48,7 +48,7 @@ class Chef
48
48
  ```
49
49
  EXAMPLES
50
50
 
51
- provides :group
51
+ provides :group, target_mode: true
52
52
 
53
53
  allowed_actions :create, :remove, :modify, :manage
54
54
  default_action :create
@@ -22,7 +22,7 @@ class Chef
22
22
  class Resource
23
23
  class HabitatPackage < Chef::Resource::Package
24
24
 
25
- provides :habitat_package
25
+ provides :habitat_package, target_mode: true
26
26
  use "habitat_shared"
27
27
  description "Use the **habitat_package** to install or remove Chef Habitat packages from Habitat Builder."
28
28
  introduced "17.3"
@@ -21,7 +21,7 @@ class Chef
21
21
  class Resource
22
22
  class HabitatSup < Chef::Resource
23
23
 
24
- provides :habitat_sup do |_node|
24
+ provides(:habitat_sup, target_mode: true) do |_node|
25
25
  false
26
26
  end
27
27
 
@@ -186,10 +186,10 @@ class Chef
186
186
  habitat_install new_resource.name do
187
187
  license new_resource.license
188
188
  hab_version new_resource.sup_version if new_resource.sup_version
189
- not_if { ::File.exist?("/bin/hab") }
190
- not_if { ::File.exist?("/usr/bin/hab") }
191
- not_if { ::File.exist?("c:/habitat/hab.exe") }
192
- not_if { ::File.exist?("c:/ProgramData/Habitat/hab.exe") }
189
+ not_if { ::TargetIO::File.exist?("/bin/hab") }
190
+ not_if { ::TargetIO::File.exist?("/usr/bin/hab") }
191
+ not_if { ::TargetIO::File.exist?("c:/habitat/hab.exe") }
192
+ not_if { ::TargetIO::File.exist?("c:/ProgramData/Habitat/hab.exe") }
193
193
  end
194
194
 
195
195
  habitat_package "core/hab-sup" do
@@ -205,7 +205,7 @@ class Chef
205
205
  if windows?
206
206
  directory "C:/hab/sup/default/config" do
207
207
  recursive true
208
- only_if { ::Dir.exist?("C:/hab") }
208
+ only_if { ::TargetIO::Dir.exist?("C:/hab") }
209
209
  only_if { use_toml_config }
210
210
  action :create
211
211
  end
@@ -235,14 +235,14 @@ class Chef
235
235
  keep_latest_packages: new_resource.keep_latest
236
236
  )
237
237
  only_if { use_toml_config }
238
- only_if { ::Dir.exist?("C:/hab/sup/default/config") }
238
+ only_if { ::TargetIO::Dir.exist?("C:/hab/sup/default/config") }
239
239
  end
240
240
  else
241
241
  directory "/hab/sup/default/config" do
242
242
  mode "0755"
243
243
  recursive true
244
244
  only_if { use_toml_config }
245
- only_if { ::Dir.exist?("/hab") }
245
+ only_if { ::TargetIO::Dir.exist?("/hab") }
246
246
  action :create
247
247
  end
248
248
 
@@ -271,7 +271,7 @@ class Chef
271
271
  keep_latest_packages: new_resource.keep_latest
272
272
  )
273
273
  only_if { use_toml_config }
274
- only_if { ::Dir.exist?("/hab/sup/default/config") }
274
+ only_if { ::TargetIO::Dir.exist?("/hab/sup/default/config") }
275
275
  end
276
276
  end
277
277
  end
@@ -20,8 +20,8 @@ require_relative "habitat_sup"
20
20
  class Chef
21
21
  class Resource
22
22
  class HabitatSupSystemd < HabitatSup
23
- provides :habitat_sup, os: "linux"
24
- provides :habitat_sup_systemd
23
+ provides :habitat_sup, os: "linux", target_mode: true
24
+ provides :habitat_sup_systemd, target_mode: true
25
25
 
26
26
  action :run do
27
27
  super()
@@ -19,7 +19,7 @@ require_relative "../resource"
19
19
  class Chef
20
20
  class Resource
21
21
  class HabitatInstall < Chef::Resource
22
- provides :habitat_install
22
+ provides :habitat_install, target_mode: true
23
23
 
24
24
  description "Use the **habitat_install** resource to install Chef Habitat."
25
25
  introduced "17.3"
@@ -70,7 +70,7 @@ class Chef
70
70
  description: "Specify the version of `Habitat` you would like to install."
71
71
 
72
72
  action :install, description: "Installs Habitat. Does nothing if the `hab` binary is found in the default location for the system (`/bin/hab` on Linux, `/usr/local/bin/hab` on macOS, `C:/habitat/hab.exe` on Windows)" do
73
- if ::File.exist?(hab_path)
73
+ if ::TargetIO::File.exist?(hab_path)
74
74
  cmd = shell_out!([hab_path, "--version"].flatten.compact.join(" "))
75
75
  version = %r{hab (\d*\.\d*\.\d[^\/]*)}.match(cmd.stdout)[1]
76
76
  return if version == new_resource.hab_version
@@ -94,7 +94,7 @@ class Chef
94
94
  path habfile
95
95
  destination "#{Chef::Config[:file_cache_path]}/habitat"
96
96
  action :extract
97
- not_if { ::Dir.exist?("c:\\habitat") }
97
+ not_if { ::TargetIO::Dir.exist?("c:\\habitat") }
98
98
  end
99
99
 
100
100
  directory "c:\\habitat" do
@@ -127,6 +127,7 @@ class Chef
127
127
  remote_file ::File.join(Chef::Config[:file_cache_path], "hab-install.sh") do
128
128
  source new_resource.install_url
129
129
  sensitive true
130
+ mode 0755
130
131
  end
131
132
 
132
133
  execute "installing with hab-install.sh" do
@@ -235,7 +236,7 @@ class Chef
235
236
  end
236
237
 
237
238
  def hab_command
238
- cmd = "bash #{Chef::Config[:file_cache_path]}/hab-install.sh"
239
+ cmd = "#{Chef::Config[:file_cache_path]}/hab-install.sh"
239
240
  cmd << " -v #{new_resource.hab_version} " if new_resource.hab_version
240
241
  cmd << " -t x86_64-linux-kernel2" if node["kernel"]["release"].to_i < 3
241
242
  cmd