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.
- checksums.yaml +4 -4
- data/Gemfile +4 -14
- data/Rakefile +2 -2
- data/chef.gemspec +10 -20
- data/lib/chef/action_collection.rb +6 -26
- data/lib/chef/application/base.rb +15 -0
- data/lib/chef/application.rb +4 -2
- data/lib/chef/chef_fs/file_pattern.rb +2 -2
- data/lib/chef/client.rb +7 -1
- data/lib/chef/compliance/default_attributes.rb +5 -3
- data/lib/chef/compliance/reporter/automate.rb +1 -1
- data/lib/chef/compliance/runner.rb +17 -3
- data/lib/chef/cookbook/cookbook_version_loader.rb +3 -3
- data/lib/chef/cookbook/gem_installer.rb +5 -1
- data/lib/chef/cookbook_version.rb +26 -4
- data/lib/chef/data_collector/run_end_message.rb +1 -1
- data/lib/chef/data_collector.rb +0 -1
- data/lib/chef/deprecated.rb +14 -4
- data/lib/chef/dsl/declare_resource.rb +5 -10
- data/lib/chef/dsl/render_helpers.rb +44 -0
- data/lib/chef/dsl/secret.rb +64 -0
- data/lib/chef/dsl/toml.rb +116 -0
- data/lib/chef/dsl/universal.rb +5 -0
- data/lib/chef/dsl.rb +1 -0
- data/lib/chef/event_dispatch/base.rb +2 -1
- data/lib/chef/exceptions.rb +23 -0
- data/lib/chef/formatters/doc.rb +2 -1
- data/lib/chef/formatters/error_mapper.rb +2 -2
- data/lib/chef/handler/slow_report.rb +66 -0
- data/lib/chef/handler.rb +46 -8
- data/lib/chef/json_compat.rb +1 -1
- data/lib/chef/node.rb +21 -20
- data/lib/chef/policy_builder/policyfile.rb +88 -45
- data/lib/chef/provider/directory.rb +6 -6
- data/lib/chef/provider/execute.rb +1 -1
- data/lib/chef/provider/file.rb +2 -2
- data/lib/chef/provider/group/dscl.rb +1 -1
- data/lib/chef/provider/launchd.rb +6 -6
- data/lib/chef/provider/link.rb +1 -1
- data/lib/chef/provider/lwrp_base.rb +1 -1
- data/lib/chef/provider/package/dnf/dnf_helper.py +11 -10
- data/lib/chef/provider/package/dnf/python_helper.rb +9 -8
- data/lib/chef/provider/package/habitat.rb +168 -0
- data/lib/chef/provider/package/powershell.rb +5 -0
- data/lib/chef/provider/package/yum/python_helper.rb +15 -10
- data/lib/chef/provider/package/yum/yum_helper.py +46 -62
- data/lib/chef/provider/package/yum.rb +1 -4
- data/lib/chef/provider/registry_key.rb +1 -1
- data/lib/chef/provider/service/systemd.rb +1 -1
- data/lib/chef/provider/subversion.rb +4 -4
- data/lib/chef/provider/support/yum_repo.erb +1 -1
- data/lib/chef/provider/support/zypper_repo.erb +4 -2
- data/lib/chef/provider/systemd_unit.rb +18 -17
- data/lib/chef/provider/template/content.rb +1 -1
- data/lib/chef/provider/user/mac.rb +3 -3
- data/lib/chef/provider/windows_script.rb +1 -1
- data/lib/chef/provider/yum_repository.rb +27 -43
- data/lib/chef/provider/zypper_repository.rb +30 -34
- data/lib/chef/provider.rb +26 -1
- data/lib/chef/provider_resolver.rb +8 -2
- data/lib/chef/providers.rb +1 -0
- data/lib/chef/resource/alternatives.rb +5 -5
- data/lib/chef/resource/apt_preference.rb +2 -2
- data/lib/chef/resource/apt_repository.rb +2 -2
- data/lib/chef/resource/apt_update.rb +4 -4
- data/lib/chef/resource/build_essential.rb +1 -1
- data/lib/chef/resource/chef_client_config.rb +10 -5
- data/lib/chef/resource/chef_client_cron.rb +3 -3
- data/lib/chef/resource/chef_client_launchd.rb +3 -3
- data/lib/chef/resource/chef_client_scheduled_task.rb +15 -15
- data/lib/chef/resource/chef_client_systemd_timer.rb +3 -3
- data/lib/chef/resource/chef_client_trusted_certificate.rb +2 -2
- data/lib/chef/resource/chef_handler.rb +2 -2
- data/lib/chef/resource/chef_sleep.rb +1 -1
- data/lib/chef/resource/chef_vault_secret.rb +2 -2
- data/lib/chef/resource/chocolatey_feature.rb +2 -2
- data/lib/chef/resource/chocolatey_source.rb +1 -1
- data/lib/chef/resource/cron/cron_d.rb +4 -6
- data/lib/chef/resource/cron_access.rb +1 -1
- data/lib/chef/resource/dmg_package.rb +1 -1
- data/lib/chef/resource/dsc_resource.rb +1 -1
- data/lib/chef/resource/execute.rb +5 -5
- data/lib/chef/resource/gem_package.rb +2 -1
- data/lib/chef/resource/group.rb +4 -4
- data/lib/chef/resource/habitat/_habitat_shared.rb +28 -0
- data/lib/chef/resource/habitat/habitat_package.rb +129 -0
- data/lib/chef/resource/habitat/habitat_sup.rb +329 -0
- data/lib/chef/resource/habitat/habitat_sup_systemd.rb +67 -0
- data/lib/chef/resource/habitat/habitat_sup_windows.rb +90 -0
- data/lib/chef/resource/habitat_config.rb +107 -0
- data/lib/chef/resource/habitat_install.rb +247 -0
- data/lib/chef/resource/habitat_service.rb +451 -0
- data/lib/chef/resource/habitat_user_toml.rb +92 -0
- data/lib/chef/resource/homebrew_cask.rb +18 -7
- data/lib/chef/resource/homebrew_package.rb +1 -1
- data/lib/chef/resource/homebrew_tap.rb +4 -3
- data/lib/chef/resource/homebrew_update.rb +2 -2
- data/lib/chef/resource/hostname.rb +49 -7
- data/lib/chef/resource/inspec_waiver_file_entry.rb +156 -0
- data/lib/chef/resource/kernel_module.rb +6 -6
- data/lib/chef/resource/launchd.rb +3 -3
- data/lib/chef/resource/locale.rb +1 -1
- data/lib/chef/resource/lwrp_base.rb +18 -3
- data/lib/chef/resource/macos_userdefaults.rb +2 -2
- data/lib/chef/resource/ohai_hint.rb +2 -6
- data/lib/chef/resource/openbsd_package.rb +17 -0
- data/lib/chef/resource/openssl_dhparam.rb +1 -2
- data/lib/chef/resource/openssl_ec_private_key.rb +1 -3
- data/lib/chef/resource/openssl_ec_public_key.rb +1 -3
- data/lib/chef/resource/openssl_rsa_private_key.rb +1 -3
- data/lib/chef/resource/openssl_rsa_public_key.rb +1 -3
- data/lib/chef/resource/openssl_x509_certificate.rb +1 -4
- data/lib/chef/resource/openssl_x509_crl.rb +1 -3
- data/lib/chef/resource/openssl_x509_request.rb +1 -3
- data/lib/chef/resource/osx_profile.rb +3 -3
- data/lib/chef/resource/plist.rb +1 -1
- data/lib/chef/resource/powershell_package_source.rb +2 -4
- data/lib/chef/resource/reboot.rb +38 -9
- data/lib/chef/resource/remote_directory.rb +2 -2
- data/lib/chef/resource/remote_file.rb +3 -3
- data/lib/chef/resource/rhsm_errata.rb +0 -2
- data/lib/chef/resource/rhsm_errata_level.rb +1 -5
- data/lib/chef/resource/rhsm_repo.rb +15 -0
- data/lib/chef/resource/rhsm_subscription.rb +5 -5
- data/lib/chef/resource/ruby_block.rb +100 -0
- data/lib/chef/resource/scm/subversion.rb +1 -1
- data/lib/chef/resource/ssh_known_hosts_entry.rb +4 -7
- data/lib/chef/resource/sudo.rb +2 -6
- data/lib/chef/resource/support/HabService.dll.config.erb +19 -0
- data/lib/chef/resource/support/client.erb +8 -1
- data/lib/chef/resource/support/sup.toml.erb +179 -0
- data/lib/chef/resource/swap_file.rb +2 -6
- data/lib/chef/resource/sysctl.rb +2 -2
- data/lib/chef/resource/systemd_unit.rb +3 -3
- data/lib/chef/resource/timezone.rb +1 -1
- data/lib/chef/resource/user_ulimit.rb +2 -2
- data/lib/chef/resource/windows_ad_join.rb +2 -2
- data/lib/chef/resource/windows_audit_policy.rb +2 -2
- data/lib/chef/resource/windows_auto_run.rb +2 -2
- data/lib/chef/resource/windows_certificate.rb +1 -1
- data/lib/chef/resource/windows_defender.rb +163 -0
- data/lib/chef/resource/windows_defender_exclusion.rb +125 -0
- data/lib/chef/resource/windows_dfs_folder.rb +2 -2
- data/lib/chef/resource/windows_dfs_namespace.rb +2 -2
- data/lib/chef/resource/windows_dns_record.rb +2 -2
- data/lib/chef/resource/windows_dns_zone.rb +2 -2
- data/lib/chef/resource/windows_env.rb +1 -1
- data/lib/chef/resource/windows_feature.rb +3 -3
- data/lib/chef/resource/windows_feature_dism.rb +3 -5
- data/lib/chef/resource/windows_feature_powershell.rb +3 -3
- data/lib/chef/resource/windows_firewall_profile.rb +2 -2
- data/lib/chef/resource/windows_firewall_rule.rb +20 -6
- data/lib/chef/resource/windows_font.rb +2 -2
- data/lib/chef/resource/windows_pagefile.rb +104 -65
- data/lib/chef/resource/windows_path.rb +4 -4
- data/lib/chef/resource/windows_printer.rb +80 -61
- data/lib/chef/resource/windows_printer_port.rb +48 -65
- data/lib/chef/resource/windows_security_policy.rb +7 -4
- data/lib/chef/resource/windows_share.rb +2 -2
- data/lib/chef/resource/windows_shortcut.rb +1 -1
- data/lib/chef/resource/windows_task.rb +2 -2
- data/lib/chef/resource/windows_uac.rb +3 -5
- data/lib/chef/resource/windows_update_settings.rb +259 -0
- data/lib/chef/resource/windows_user_privilege.rb +2 -2
- data/lib/chef/resource/windows_workgroup.rb +2 -2
- data/lib/chef/resource/yum_package.rb +11 -15
- data/lib/chef/resource/zypper_package.rb +4 -4
- data/lib/chef/resource/zypper_repository.rb +28 -8
- data/lib/chef/resource.rb +20 -25
- data/lib/chef/resource_builder.rb +8 -2
- data/lib/chef/resource_inspector.rb +6 -2
- data/lib/chef/resource_reporter.rb +0 -1
- data/lib/chef/resources.rb +13 -1
- data/lib/chef/run_lock.rb +1 -1
- data/lib/chef/runner.rb +1 -1
- data/lib/chef/secret_fetcher/aws_secrets_manager.rb +65 -0
- data/lib/chef/secret_fetcher/azure_key_vault.rb +78 -0
- data/lib/chef/secret_fetcher/base.rb +76 -0
- data/lib/chef/secret_fetcher/example.rb +46 -0
- data/lib/chef/secret_fetcher.rb +55 -0
- data/lib/chef/shell/ext.rb +3 -3
- data/lib/chef/version.rb +1 -1
- data/lib/chef/win32/api.rb +9 -2
- data/spec/data/knife-home/.chef/plugins/knife/example_home_subcommand.rb +0 -0
- data/spec/data/knife-site-subcommands/plugins/knife/example_subcommand.rb +0 -0
- data/spec/data/knife_subcommand/test_explicit_category.rb +7 -0
- data/spec/data/knife_subcommand/test_name_mapping.rb +4 -0
- data/spec/data/knife_subcommand/test_yourself.rb +21 -0
- data/spec/functional/mixin/from_file_spec.rb +1 -1
- data/spec/functional/resource/dnf_package_spec.rb +857 -537
- data/spec/functional/resource/group_spec.rb +1 -1
- data/spec/functional/resource/link_spec.rb +1 -1
- data/spec/functional/resource/remote_file_spec.rb +1 -1
- data/spec/functional/resource/windows_env_spec.rb +2 -2
- data/spec/functional/resource/windows_hostname_spec.rb +91 -0
- data/spec/functional/resource/windows_pagefile_spec.rb +98 -0
- data/spec/functional/resource/yum_package_spec.rb +495 -428
- data/spec/integration/client/client_spec.rb +0 -20
- data/spec/integration/compliance/compliance_spec.rb +1 -0
- data/spec/integration/recipes/recipe_dsl_spec.rb +1 -1
- data/spec/integration/recipes/resource_action_spec.rb +6 -6
- data/spec/integration/recipes/unified_mode_spec.rb +70 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/support/chef_helpers.rb +1 -1
- data/spec/support/shared/functional/execute_resource.rb +1 -1
- data/spec/support/shared/functional/knife.rb +37 -0
- data/spec/support/shared/integration/knife_support.rb +192 -0
- data/spec/support/shared/unit/knife_shared.rb +39 -0
- data/spec/support/shared/unit/provider/file.rb +3 -9
- data/spec/unit/chef_fs/file_system/repository/directory_spec.rb +1 -1
- data/spec/unit/compliance/runner_spec.rb +46 -2
- data/spec/unit/cookbook_version_spec.rb +52 -0
- data/spec/unit/data_collector_spec.rb +47 -1
- data/spec/unit/dsl/render_helpers_spec.rb +102 -0
- data/spec/unit/dsl/secret_spec.rb +71 -0
- data/spec/unit/handler_spec.rb +8 -2
- data/spec/unit/policy_builder/dynamic_spec.rb +0 -5
- data/spec/unit/policy_builder/policyfile_spec.rb +144 -56
- data/spec/unit/provider/apt_update_spec.rb +3 -1
- data/spec/unit/provider/link_spec.rb +1 -1
- data/spec/unit/provider/mount/aix_spec.rb +1 -1
- data/spec/unit/provider/package/dnf/python_helper_spec.rb +1 -0
- data/spec/unit/provider/package/powershell_spec.rb +74 -12
- data/spec/unit/provider/package/yum/python_helper_spec.rb +1 -0
- data/spec/unit/provider/service/systemd_service_spec.rb +2 -2
- data/spec/unit/provider/systemd_unit_spec.rb +2 -2
- data/spec/unit/provider/zypper_repository_spec.rb +3 -10
- data/spec/unit/provider_spec.rb +23 -0
- data/spec/unit/resource/homebrew_cask_spec.rb +29 -11
- data/spec/unit/resource/inspec_waiver_file_entry_spec.rb +80 -0
- data/spec/unit/resource/rhsm_subscription_spec.rb +50 -3
- data/spec/unit/resource/systemd_unit_spec.rb +1 -1
- data/spec/unit/resource/windows_defender_exclusion_spec.rb +62 -0
- data/spec/unit/resource/windows_defender_spec.rb +71 -0
- data/spec/unit/resource/windows_firewall_rule_spec.rb +12 -7
- data/spec/unit/resource/windows_pagefile_spec.rb +4 -9
- data/spec/unit/resource/windows_update_settings_spec.rb +64 -0
- data/spec/unit/resource/zypper_repository_spec.rb +1 -1
- data/spec/unit/resource_spec.rb +19 -8
- data/spec/unit/secret_fetcher/aws_secrets_manager_spec.rb +70 -0
- data/spec/unit/secret_fetcher/azure_key_vault_spec.rb +70 -0
- data/spec/unit/secret_fetcher_spec.rb +82 -0
- data/tasks/rspec.rb +4 -9
- metadata +65 -161
- data/lib/chef/provider/package/yum/simplejson/LICENSE.txt +0 -79
- data/lib/chef/provider/package/yum/simplejson/__init__.py +0 -318
- data/lib/chef/provider/package/yum/simplejson/__init__.pyc +0 -0
- data/lib/chef/provider/package/yum/simplejson/decoder.py +0 -354
- data/lib/chef/provider/package/yum/simplejson/decoder.pyc +0 -0
- data/lib/chef/provider/package/yum/simplejson/encoder.py +0 -440
- data/lib/chef/provider/package/yum/simplejson/encoder.pyc +0 -0
- data/lib/chef/provider/package/yum/simplejson/scanner.py +0 -65
- data/lib/chef/provider/package/yum/simplejson/scanner.pyc +0 -0
- data/lib/chef/provider/package/yum/simplejson/tool.py +0 -37
@@ -0,0 +1,163 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Chef Software, Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require_relative "../resource"
|
18
|
+
|
19
|
+
class Chef
|
20
|
+
class Resource
|
21
|
+
class WindowsDefender < Chef::Resource
|
22
|
+
unified_mode true
|
23
|
+
provides :windows_defender
|
24
|
+
|
25
|
+
description "Use the **windows_defender** resource to enable or disable the Microsoft Windows Defender service."
|
26
|
+
introduced "17.3"
|
27
|
+
examples <<~DOC
|
28
|
+
**Configure Windows Defender AV settings**:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
windows_defender 'Configure Defender' do
|
32
|
+
realtime_protection true
|
33
|
+
intrusion_protection_system true
|
34
|
+
lock_ui true
|
35
|
+
scan_archives true
|
36
|
+
scan_scripts true
|
37
|
+
scan_email true
|
38
|
+
scan_removable_drives true
|
39
|
+
scan_network_files false
|
40
|
+
scan_mapped_drives false
|
41
|
+
action :enable
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
**Disable Windows Defender AV**:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
windows_defender 'Disable Defender' do
|
49
|
+
action :disable
|
50
|
+
end
|
51
|
+
```
|
52
|
+
DOC
|
53
|
+
|
54
|
+
# DisableIOAVProtection
|
55
|
+
property :realtime_protection, [true, false],
|
56
|
+
default: true,
|
57
|
+
description: "Enable realtime scanning of downloaded files and attachments."
|
58
|
+
|
59
|
+
# DisableIntrusionPreventionSystem
|
60
|
+
property :intrusion_protection_system, [true, false],
|
61
|
+
default: true,
|
62
|
+
description: "Enable network protection against exploitation of known vulnerabilities."
|
63
|
+
|
64
|
+
# UILockdown
|
65
|
+
property :lock_ui, [true, false],
|
66
|
+
description: "Lock the UI to prevent users from changing Windows Defender settings.",
|
67
|
+
default: false
|
68
|
+
|
69
|
+
# DisableArchiveScanning
|
70
|
+
property :scan_archives, [true, false],
|
71
|
+
default: true,
|
72
|
+
description: "Scan file archives such as .zip or .gz archives."
|
73
|
+
|
74
|
+
# DisableScriptScanning
|
75
|
+
property :scan_scripts, [true, false],
|
76
|
+
default: false,
|
77
|
+
description: "Scan scripts in malware scans."
|
78
|
+
|
79
|
+
# DisableEmailScanning
|
80
|
+
property :scan_email, [true, false],
|
81
|
+
default: false,
|
82
|
+
description: "Scan e-mails for malware."
|
83
|
+
|
84
|
+
# DisableRemovableDriveScanning
|
85
|
+
property :scan_removable_drives, [true, false],
|
86
|
+
default: false,
|
87
|
+
description: "Scan content of removable drives."
|
88
|
+
|
89
|
+
# DisableScanningNetworkFiles
|
90
|
+
property :scan_network_files, [true, false],
|
91
|
+
default: false,
|
92
|
+
description: "Scan files on a network."
|
93
|
+
|
94
|
+
# DisableScanningMappedNetworkDrivesForFullScan
|
95
|
+
property :scan_mapped_drives, [true, false],
|
96
|
+
default: true,
|
97
|
+
description: "Scan files on mapped network drives."
|
98
|
+
|
99
|
+
load_current_value do
|
100
|
+
values = powershell_exec!("Get-MPpreference").result
|
101
|
+
|
102
|
+
lock_ui values["UILockdown"]
|
103
|
+
realtime_protection !values["DisableIOAVProtection"]
|
104
|
+
intrusion_protection_system !values["DisableIntrusionPreventionSystem"]
|
105
|
+
scan_archives !values["DisableArchiveScanning"]
|
106
|
+
scan_scripts !values["DisableScriptScanning"]
|
107
|
+
scan_email !values["DisableEmailScanning"]
|
108
|
+
scan_removable_drives !values["DisableRemovableDriveScanning"]
|
109
|
+
scan_network_files !values["DisableScanningNetworkFiles"]
|
110
|
+
scan_mapped_drives !values["DisableScanningMappedNetworkDrivesForFullScan"]
|
111
|
+
end
|
112
|
+
|
113
|
+
action :enable, description: "Enable and configure Windows Defender." do
|
114
|
+
windows_service "Windows Defender" do
|
115
|
+
service_name "WinDefend"
|
116
|
+
action %i{start enable}
|
117
|
+
startup_type :automatic
|
118
|
+
end
|
119
|
+
|
120
|
+
converge_if_changed do
|
121
|
+
powershell_exec!(set_mppreference_cmd)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
action :disable, description: "Disable Windows Defender." do
|
126
|
+
windows_service "Windows Defender" do
|
127
|
+
service_name "WinDefend"
|
128
|
+
action %i{disable stop}
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
action_class do
|
133
|
+
require "chef/mixin/powershell_type_coercions"
|
134
|
+
include Chef::Mixin::PowershellTypeCoercions
|
135
|
+
|
136
|
+
PROPERTY_TO_PS_MAP = {
|
137
|
+
realtime_protection: "DisableIOAVProtection",
|
138
|
+
intrusion_protection_system: "DisableIntrusionPreventionSystem",
|
139
|
+
scan_archives: "DisableArchiveScanning",
|
140
|
+
scan_scripts: "DisableScriptScanning",
|
141
|
+
scan_email: "DisableEmailScanning",
|
142
|
+
scan_removable_drives: "DisableRemovableDriveScanning",
|
143
|
+
scan_network_files: "DisableScanningNetworkFiles",
|
144
|
+
scan_mapped_drives: "DisableScanningMappedNetworkDrivesForFullScan",
|
145
|
+
}.freeze
|
146
|
+
|
147
|
+
def set_mppreference_cmd
|
148
|
+
cmd = "Set-MpPreference -Force"
|
149
|
+
cmd << " -UILockdown #{type_coercion(new_resource.lock_ui)}"
|
150
|
+
|
151
|
+
# the values are the opposite in Set-MpPreference and our properties so we have to iterate
|
152
|
+
# over the list and negate the provided values so it makes sense with the cmdlet flag's expected value
|
153
|
+
PROPERTY_TO_PS_MAP.each do |prop, flag|
|
154
|
+
next if new_resource.send(prop).nil? || current_resource.send(prop) == new_resource.send(prop)
|
155
|
+
|
156
|
+
cmd << " -#{flag} #{type_coercion(!new_resource.send(prop))}"
|
157
|
+
end
|
158
|
+
cmd
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Chef Software, Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require_relative "../resource"
|
18
|
+
|
19
|
+
class Chef
|
20
|
+
class Resource
|
21
|
+
class WindowsDefenderExclusion < Chef::Resource
|
22
|
+
|
23
|
+
provides :windows_defender_exclusion
|
24
|
+
|
25
|
+
description "Use the **windows_defender_exclusion** resource to exclude paths, processes, or file types from Windows Defender realtime protection scanning."
|
26
|
+
introduced "17.3"
|
27
|
+
examples <<~DOC
|
28
|
+
**Add excluded items to Windows Defender scans**:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
windows_defender_exclusion 'Add to things to be excluded from scanning' do
|
32
|
+
paths 'c:\\foo\\bar, d:\\bar\\baz'
|
33
|
+
extensions 'png, foo, ppt, doc'
|
34
|
+
process_paths 'c:\\windows\\system32'
|
35
|
+
action :add
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
**Remove excluded items from Windows Defender scans**:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
windows_defender_exclusion 'Remove things from the list to be excluded' do
|
43
|
+
process_paths 'c:\\windows\\system32'
|
44
|
+
action :remove
|
45
|
+
end
|
46
|
+
```
|
47
|
+
DOC
|
48
|
+
unified_mode true
|
49
|
+
|
50
|
+
property :paths, [String, Array], default: [],
|
51
|
+
coerce: proc { |x| to_consistent_path_array(x) },
|
52
|
+
description: "File or directory paths to exclude from scanning."
|
53
|
+
|
54
|
+
property :extensions, [String, Array], default: [],
|
55
|
+
coerce: proc { |x| to_consistent_path_array(x) },
|
56
|
+
description: "File extensions to exclude from scanning."
|
57
|
+
|
58
|
+
property :process_paths, [String, Array], default: [],
|
59
|
+
coerce: proc { |x| to_consistent_path_array(x) },
|
60
|
+
description: "Paths to executables to exclude from scanning."
|
61
|
+
|
62
|
+
def to_consistent_path_array(x)
|
63
|
+
fixed = x.dup || []
|
64
|
+
fixed = fixed.split(/\s*,\s*/) if fixed.is_a?(String)
|
65
|
+
fixed.map!(&:downcase)
|
66
|
+
fixed.map! { |v| v.gsub(%r{/}, "\\") }
|
67
|
+
fixed
|
68
|
+
end
|
69
|
+
|
70
|
+
load_current_value do |new_resource|
|
71
|
+
Chef::Log.debug("Running 'Get-MpPreference | Select-Object ExclusionExtension,ExclusionPath,ExclusionProcess' to get Windows Defender State")
|
72
|
+
|
73
|
+
values = powershell_exec!("Get-MPpreference | Select-Object ExclusionExtension,ExclusionPath,ExclusionProcess").result
|
74
|
+
|
75
|
+
values.transform_values! { |x| Array(x) }
|
76
|
+
|
77
|
+
paths new_resource.paths & values["ExclusionPath"]
|
78
|
+
extensions new_resource.extensions & values["ExclusionExtension"]
|
79
|
+
process_paths new_resource.process_paths & values["ExclusionProcess"]
|
80
|
+
end
|
81
|
+
|
82
|
+
action :add, description: "Add an exclusion to Windows Defender." do
|
83
|
+
converge_if_changed do
|
84
|
+
powershell_exec!(add_cmd)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
action :remove, description: "Remove an exclusion to Windows Defender." do
|
89
|
+
converge_if_changed do
|
90
|
+
powershell_exec!(remove_cmd)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
action_class do
|
95
|
+
MAPPING = {
|
96
|
+
paths: "ExclusionPath",
|
97
|
+
extensions: "ExclusionExtension",
|
98
|
+
process_paths: "ExclusionProcess",
|
99
|
+
}.freeze
|
100
|
+
|
101
|
+
def add_cmd
|
102
|
+
cmd = "Add-MpPreference -Force"
|
103
|
+
|
104
|
+
MAPPING.each do |prop, flag|
|
105
|
+
to_add = new_resource.send(prop) - current_resource.send(prop)
|
106
|
+
cmd << " -#{flag} #{to_add.join(",")}" unless to_add.empty?
|
107
|
+
end
|
108
|
+
|
109
|
+
cmd
|
110
|
+
end
|
111
|
+
|
112
|
+
def remove_cmd
|
113
|
+
cmd = "Remove-MpPreference -Force"
|
114
|
+
|
115
|
+
MAPPING.each do |prop, flag|
|
116
|
+
to_add = new_resource.send(prop) & current_resource.send(prop)
|
117
|
+
cmd << " -#{flag} #{to_add.join(",")}" unless to_add.empty?
|
118
|
+
end
|
119
|
+
|
120
|
+
cmd
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -42,7 +42,7 @@ class Chef
|
|
42
42
|
property :description, String,
|
43
43
|
description: "Description for the share."
|
44
44
|
|
45
|
-
action :create, description: "Creates the folder in dfs namespace" do
|
45
|
+
action :create, description: "Creates the folder in dfs namespace." do
|
46
46
|
raise "target_path is required for install" unless property_is_set?(:target_path)
|
47
47
|
raise "description is required for install" unless property_is_set?(:description)
|
48
48
|
|
@@ -60,7 +60,7 @@ class Chef
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
action :delete, description: "Deletes the folder in the dfs namespace" do
|
63
|
+
action :delete, description: "Deletes the folder in the dfs namespace." do
|
64
64
|
powershell_script "Delete DFS Namespace" do
|
65
65
|
code <<-EOH
|
66
66
|
Remove-DfsnFolder -Path '\\\\#{ENV["COMPUTERNAME"]}\\#{new_resource.namespace_name}\\#{new_resource.folder_path}' -Force
|
@@ -52,7 +52,7 @@ class Chef
|
|
52
52
|
description: "The root from which to create the DFS tree. Defaults to C:\\DFSRoots.",
|
53
53
|
default: 'C:\\DFSRoots'
|
54
54
|
|
55
|
-
action :create, description: "Creates the dfs namespace on the server" do
|
55
|
+
action :create, description: "Creates the dfs namespace on the server." do
|
56
56
|
directory file_path do
|
57
57
|
action :create
|
58
58
|
recursive true
|
@@ -82,7 +82,7 @@ class Chef
|
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
-
action :delete, description: "Deletes a DFS Namespace including the directory on disk" do
|
85
|
+
action :delete, description: "Deletes a DFS Namespace including the directory on disk." do
|
86
86
|
powershell_script "Delete DFS Namespace" do
|
87
87
|
code <<-EOH
|
88
88
|
Remove-DfsnRoot -Path '\\\\#{ENV["COMPUTERNAME"]}\\#{new_resource.namespace_name}' -Force
|
@@ -49,7 +49,7 @@ class Chef
|
|
49
49
|
default: "localhost",
|
50
50
|
introduced: "16.3"
|
51
51
|
|
52
|
-
action :create, description: "Creates and updates the DNS entry" do
|
52
|
+
action :create, description: "Creates and updates the DNS entry." do
|
53
53
|
windows_feature "RSAT-DNS-Server" do
|
54
54
|
not_if new_resource.dns_server.casecmp?("localhost")
|
55
55
|
end
|
@@ -59,7 +59,7 @@ class Chef
|
|
59
59
|
run_dsc_resource "Present"
|
60
60
|
end
|
61
61
|
|
62
|
-
action :delete, description: "Deletes a DNS entry" do
|
62
|
+
action :delete, description: "Deletes a DNS entry." do
|
63
63
|
windows_feature "RSAT-DNS-Server" do
|
64
64
|
not_if new_resource.dns_server.casecmp?("localhost")
|
65
65
|
end
|
@@ -40,13 +40,13 @@ class Chef
|
|
40
40
|
description: "The type of DNS server, Domain or Standalone.",
|
41
41
|
default: "Domain", equal_to: %w{Domain Standalone}
|
42
42
|
|
43
|
-
action :create, description: "Creates and updates a DNS Zone" do
|
43
|
+
action :create, description: "Creates and updates a DNS Zone." do
|
44
44
|
powershell_package "xDnsServer"
|
45
45
|
|
46
46
|
run_dsc_resource "Present"
|
47
47
|
end
|
48
48
|
|
49
|
-
action :delete, description: "Deletes a DNS Zone" do
|
49
|
+
action :delete, description: "Deletes a DNS Zone." do
|
50
50
|
powershell_package "xDnsServer"
|
51
51
|
|
52
52
|
run_dsc_resource "Absent"
|
@@ -186,7 +186,7 @@ class Chef
|
|
186
186
|
if environment_variables && environment_variables.length > 0
|
187
187
|
environment_variables.each do |env|
|
188
188
|
@env_obj = env.wmi_ole_object
|
189
|
-
return @env_obj if @env_obj.username.split(
|
189
|
+
return @env_obj if @env_obj.username.split("\\").last.casecmp(new_resource.user) == 0
|
190
190
|
end
|
191
191
|
end
|
192
192
|
@env_obj = nil
|
@@ -108,15 +108,15 @@ class Chef
|
|
108
108
|
default: 600,
|
109
109
|
desired_state: false
|
110
110
|
|
111
|
-
action :install, description: "Install a Windows role
|
111
|
+
action :install, description: "Install a Windows role or feature." do
|
112
112
|
run_default_subresource :install
|
113
113
|
end
|
114
114
|
|
115
|
-
action :remove, description: "Remove a Windows role
|
115
|
+
action :remove, description: "Remove a Windows role or feature." do
|
116
116
|
run_default_subresource :remove
|
117
117
|
end
|
118
118
|
|
119
|
-
action :delete, description: "Remove a Windows role
|
119
|
+
action :delete, description: "Remove a Windows role or feature from the image." do
|
120
120
|
run_default_subresource :delete
|
121
121
|
end
|
122
122
|
|
@@ -65,9 +65,7 @@ class Chef
|
|
65
65
|
x.map(&:downcase)
|
66
66
|
end
|
67
67
|
|
68
|
-
action :install do
|
69
|
-
description "Install a Windows role/feature using DISM"
|
70
|
-
|
68
|
+
action :install, description: "Install a Windows role/feature using DISM." do
|
71
69
|
reload_cached_dism_data unless node["dism_features_cache"]
|
72
70
|
fail_if_unavailable # fail if the features don't exist
|
73
71
|
|
@@ -91,7 +89,7 @@ class Chef
|
|
91
89
|
end
|
92
90
|
end
|
93
91
|
|
94
|
-
action :remove, description: "Remove a Windows role
|
92
|
+
action :remove, description: "Remove a Windows role or feature using DISM." do
|
95
93
|
reload_cached_dism_data unless node["dism_features_cache"]
|
96
94
|
|
97
95
|
logger.trace("Windows features needing removal: #{features_to_remove.empty? ? "none" : features_to_remove.join(",")}")
|
@@ -106,7 +104,7 @@ class Chef
|
|
106
104
|
end
|
107
105
|
end
|
108
106
|
|
109
|
-
action :delete, description: "Remove a Windows role
|
107
|
+
action :delete, description: "Remove a Windows role or feature from the image using DISM." do
|
110
108
|
reload_cached_dism_data unless node["dism_features_cache"]
|
111
109
|
|
112
110
|
fail_if_unavailable # fail if the features don't exist
|
@@ -87,7 +87,7 @@ class Chef
|
|
87
87
|
x.map(&:downcase)
|
88
88
|
end
|
89
89
|
|
90
|
-
action :install, description: "Install a Windows role
|
90
|
+
action :install, description: "Install a Windows role or feature using PowerShell." do
|
91
91
|
reload_cached_powershell_data unless node["powershell_features_cache"]
|
92
92
|
fail_if_unavailable # fail if the features don't exist
|
93
93
|
fail_if_removed # fail if the features are in removed state
|
@@ -108,7 +108,7 @@ class Chef
|
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
111
|
-
action :remove, description: "Remove a Windows role
|
111
|
+
action :remove, description: "Remove a Windows role or feature using PowerShell." do
|
112
112
|
reload_cached_powershell_data unless node["powershell_features_cache"]
|
113
113
|
|
114
114
|
Chef::Log.debug("Windows features needing removal: #{features_to_remove.empty? ? "none" : features_to_remove.join(",")}")
|
@@ -123,7 +123,7 @@ class Chef
|
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
|
-
action :delete, description: "Delete a Windows role
|
126
|
+
action :delete, description: "Delete a Windows role or feature from the image using PowerShell." do
|
127
127
|
reload_cached_powershell_data unless node["powershell_features_cache"]
|
128
128
|
|
129
129
|
fail_if_unavailable # fail if the features don't exist
|