chef 17.10.163 → 18.7.10
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.
- checksums.yaml +4 -4
- data/Gemfile +25 -21
- data/README.md +7 -7
- data/Rakefile +3 -22
- data/{chef-universal-mingw32.gemspec → chef-universal-mingw-ucrt.gemspec} +7 -6
- data/chef.gemspec +33 -27
- data/lib/chef/api_client_v1.rb +9 -1
- data/lib/chef/application/base.rb +20 -2
- data/lib/chef/application/exit_code.rb +3 -3
- data/lib/chef/chef_fs/file_pattern.rb +1 -1
- data/lib/chef/chef_fs/file_system.rb +21 -7
- data/lib/chef/chef_fs/path_utils.rb +7 -9
- data/lib/chef/client.rb +186 -2
- data/lib/chef/compliance/default_attributes.rb +2 -2
- data/lib/chef/compliance/input.rb +1 -1
- data/lib/chef/compliance/profile.rb +1 -1
- data/lib/chef/compliance/profile_collection.rb +0 -1
- data/lib/chef/compliance/runner.rb +6 -1
- data/lib/chef/compliance/waiver.rb +1 -1
- data/lib/chef/cookbook/chefignore.rb +4 -1
- data/lib/chef/cookbook/cookbook_version_loader.rb +1 -1
- data/lib/chef/cookbook/metadata.rb +1 -1
- data/lib/chef/cookbook/remote_file_vendor.rb +1 -3
- data/lib/chef/cookbook/synchronizer.rb +21 -3
- data/lib/chef/cookbook/syntax_check.rb +2 -2
- data/lib/chef/cookbook_manifest.rb +2 -2
- data/lib/chef/cookbook_version.rb +1 -1
- data/lib/chef/data_collector.rb +14 -0
- data/lib/chef/delayed_evaluator.rb +4 -0
- data/lib/chef/dsl/reader_helpers.rb +1 -1
- data/lib/chef/dsl/rest_resource.rb +77 -0
- data/lib/chef/event_dispatch/base.rb +3 -0
- data/lib/chef/event_dispatch/dispatcher.rb +0 -1
- data/lib/chef/exceptions.rb +9 -1
- data/lib/chef/file_access_control/windows.rb +4 -1
- data/lib/chef/file_cache.rb +17 -2
- data/lib/chef/formatters/doc.rb +1 -1
- data/lib/chef/guard_interpreter/resource_guard_interpreter.rb +2 -0
- data/lib/chef/http/authenticator.rb +253 -3
- data/lib/chef/http/ssl_policies.rb +2 -2
- data/lib/chef/mixin/{homebrew_user.rb → homebrew.rb} +13 -16
- data/lib/chef/mixin/openssl_helper.rb +1 -16
- data/lib/chef/mixin/powershell_exec.rb +5 -28
- data/lib/chef/monkey_patches/net-http.rb +127 -0
- data/lib/chef/node/attribute.rb +3 -11
- data/lib/chef/node/attribute_collections.rb +10 -1
- data/lib/chef/node/immutable_collections.rb +17 -6
- data/lib/chef/node/mixin/immutablize_array.rb +1 -0
- data/lib/chef/node/mixin/state_tracking.rb +7 -4
- data/lib/chef/node/mixin/state_tracking_array.rb +41 -0
- data/lib/chef/node.rb +23 -1
- data/lib/chef/platform/query_helpers.rb +4 -2
- data/lib/chef/policy_builder/policyfile.rb +8 -0
- data/lib/chef/property.rb +13 -6
- data/lib/chef/provider/group/windows.rb +1 -1
- data/lib/chef/provider/http_request.rb +11 -9
- data/lib/chef/provider/launchd.rb +2 -1
- data/lib/chef/provider/mount/linux.rb +6 -1
- data/lib/chef/provider/mount/mount.rb +13 -5
- data/lib/chef/provider/mount/windows.rb +1 -1
- data/lib/chef/provider/package/apt.rb +11 -2
- data/lib/chef/provider/package/chocolatey.rb +260 -22
- data/lib/chef/provider/package/dnf/dnf_helper.py +7 -0
- data/lib/chef/provider/package/homebrew.rb +6 -9
- data/lib/chef/provider/package/powershell.rb +1 -0
- data/lib/chef/provider/package/rubygems.rb +5 -1
- data/lib/chef/provider/package/snap.rb +3 -2
- data/lib/chef/provider/package/windows/msi.rb +2 -2
- data/lib/chef/provider/package/windows/registry_uninstall_entry.rb +1 -1
- data/lib/chef/provider/package/yum/yum_helper.py +3 -3
- data/lib/chef/provider/package/zypper/version.rb +60 -0
- data/lib/chef/provider/package/zypper.rb +47 -3
- data/lib/chef/provider/powershell_script.rb +96 -6
- data/lib/chef/provider/registry_key.rb +2 -0
- data/lib/chef/provider/remote_file/http.rb +1 -1
- data/lib/chef/provider/service/systemd.rb +23 -8
- data/lib/chef/provider/service/windows.rb +1 -1
- data/lib/chef/provider/service.rb +14 -0
- data/lib/chef/provider/user/aix.rb +5 -0
- data/lib/chef/provider/user/linux.rb +29 -0
- data/lib/chef/provider/user/mac.rb +1 -1
- data/lib/chef/provider/user/windows.rb +5 -0
- data/lib/chef/provider/user.rb +45 -9
- data/lib/chef/provider/yum_repository.rb +13 -1
- data/lib/chef/provider.rb +1 -1
- data/lib/chef/recipe.rb +4 -12
- data/lib/chef/resource/_rest_resource.rb +389 -0
- data/lib/chef/resource/alternatives.rb +0 -1
- data/lib/chef/resource/apt_package.rb +21 -1
- data/lib/chef/resource/apt_preference.rb +0 -1
- data/lib/chef/resource/apt_repository.rb +138 -18
- data/lib/chef/resource/apt_update.rb +0 -1
- data/lib/chef/resource/archive_file.rb +0 -1
- data/lib/chef/resource/bash.rb +13 -1
- data/lib/chef/resource/batch.rb +0 -1
- data/lib/chef/resource/bff_package.rb +0 -1
- data/lib/chef/resource/breakpoint.rb +0 -1
- data/lib/chef/resource/build_essential.rb +0 -1
- data/lib/chef/resource/cab_package.rb +0 -1
- data/lib/chef/resource/chef_client_config.rb +12 -14
- data/lib/chef/resource/chef_client_cron.rb +1 -2
- data/lib/chef/resource/chef_client_launchd.rb +2 -2
- data/lib/chef/resource/chef_client_scheduled_task.rb +3 -3
- data/lib/chef/resource/chef_client_systemd_timer.rb +5 -1
- data/lib/chef/resource/chef_client_trusted_certificate.rb +0 -1
- data/lib/chef/resource/chef_gem.rb +1 -2
- data/lib/chef/resource/chef_handler.rb +0 -1
- data/lib/chef/resource/chef_sleep.rb +1 -3
- data/lib/chef/resource/chef_vault_secret.rb +0 -1
- data/lib/chef/resource/chocolatey_config.rb +0 -1
- data/lib/chef/resource/chocolatey_feature.rb +0 -1
- data/lib/chef/resource/chocolatey_installer.rb +207 -0
- data/lib/chef/resource/chocolatey_package.rb +8 -1
- data/lib/chef/resource/chocolatey_source.rb +0 -1
- data/lib/chef/resource/cookbook_file.rb +0 -1
- data/lib/chef/resource/cron/_cron_shared.rb +0 -1
- data/lib/chef/resource/cron/cron.rb +0 -1
- data/lib/chef/resource/cron/cron_d.rb +15 -1
- data/lib/chef/resource/cron_access.rb +0 -1
- data/lib/chef/resource/csh.rb +0 -1
- data/lib/chef/resource/directory.rb +0 -1
- data/lib/chef/resource/dmg_package.rb +2 -1
- data/lib/chef/resource/dnf_package.rb +0 -1
- data/lib/chef/resource/dpkg_package.rb +0 -1
- data/lib/chef/resource/dsc_resource.rb +0 -1
- data/lib/chef/resource/dsc_script.rb +1 -2
- data/lib/chef/resource/execute.rb +8 -7
- data/lib/chef/resource/file.rb +0 -1
- data/lib/chef/resource/freebsd_package.rb +2 -1
- data/lib/chef/resource/gem_package.rb +2 -1
- data/lib/chef/resource/group.rb +25 -2
- data/lib/chef/resource/habitat/habitat_package.rb +0 -1
- data/lib/chef/resource/habitat/habitat_sup.rb +6 -7
- data/lib/chef/resource/habitat/habitat_sup_windows.rb +1 -1
- data/lib/chef/resource/habitat_config.rb +0 -1
- data/lib/chef/resource/habitat_install.rb +2 -2
- data/lib/chef/resource/habitat_service.rb +0 -1
- data/lib/chef/resource/habitat_user_toml.rb +0 -1
- data/lib/chef/resource/homebrew_cask.rb +21 -33
- data/lib/chef/resource/homebrew_package.rb +3 -2
- data/lib/chef/resource/homebrew_tap.rb +32 -18
- data/lib/chef/resource/homebrew_update.rb +4 -6
- data/lib/chef/resource/hostname.rb +0 -1
- data/lib/chef/resource/http_request.rb +0 -1
- data/lib/chef/resource/ifconfig.rb +0 -1
- data/lib/chef/resource/inspec_input.rb +0 -1
- data/lib/chef/resource/inspec_waiver.rb +0 -1
- data/lib/chef/resource/inspec_waiver_file_entry.rb +2 -3
- data/lib/chef/resource/ips_package.rb +0 -1
- data/lib/chef/resource/kernel_module.rb +0 -1
- data/lib/chef/resource/ksh.rb +0 -1
- data/lib/chef/resource/launchd.rb +9 -3
- data/lib/chef/resource/link.rb +0 -1
- data/lib/chef/resource/locale.rb +0 -1
- data/lib/chef/resource/log.rb +0 -1
- data/lib/chef/resource/lwrp_base.rb +0 -4
- data/lib/chef/resource/macos_pkg.rb +111 -0
- data/lib/chef/resource/macos_userdefaults.rb +3 -4
- data/lib/chef/resource/macosx_service.rb +0 -1
- data/lib/chef/resource/macports_package.rb +2 -1
- data/lib/chef/resource/mdadm.rb +0 -1
- data/lib/chef/resource/mount.rb +0 -1
- data/lib/chef/resource/msu_package.rb +0 -1
- data/lib/chef/resource/notify_group.rb +0 -2
- data/lib/chef/resource/ohai.rb +0 -1
- data/lib/chef/resource/ohai_hint.rb +0 -1
- data/lib/chef/resource/openbsd_package.rb +2 -1
- data/lib/chef/resource/openssl_dhparam.rb +0 -2
- data/lib/chef/resource/openssl_ec_private_key.rb +0 -2
- data/lib/chef/resource/openssl_ec_public_key.rb +0 -2
- data/lib/chef/resource/openssl_rsa_private_key.rb +0 -2
- data/lib/chef/resource/openssl_rsa_public_key.rb +0 -2
- data/lib/chef/resource/openssl_x509_certificate.rb +0 -2
- data/lib/chef/resource/openssl_x509_crl.rb +0 -2
- data/lib/chef/resource/openssl_x509_request.rb +0 -2
- data/lib/chef/resource/osx_profile.rb +0 -1
- data/lib/chef/resource/package.rb +0 -1
- data/lib/chef/resource/pacman_package.rb +2 -1
- data/lib/chef/resource/paludis_package.rb +0 -1
- data/lib/chef/resource/perl.rb +0 -1
- data/lib/chef/resource/plist.rb +7 -3
- data/lib/chef/resource/portage_package.rb +2 -1
- data/lib/chef/resource/powershell_package.rb +4 -1
- data/lib/chef/resource/powershell_package_source.rb +0 -1
- data/lib/chef/resource/powershell_script.rb +5 -2
- data/lib/chef/resource/python.rb +0 -1
- data/lib/chef/resource/reboot.rb +0 -1
- data/lib/chef/resource/registry_key.rb +6 -1
- data/lib/chef/resource/remote_directory.rb +0 -1
- data/lib/chef/resource/remote_file.rb +0 -1
- data/lib/chef/resource/rhsm_errata.rb +0 -1
- data/lib/chef/resource/rhsm_errata_level.rb +0 -1
- data/lib/chef/resource/rhsm_register.rb +2 -4
- data/lib/chef/resource/rhsm_repo.rb +0 -1
- data/lib/chef/resource/rhsm_subscription.rb +0 -1
- data/lib/chef/resource/route.rb +0 -1
- data/lib/chef/resource/rpm_package.rb +2 -1
- data/lib/chef/resource/ruby.rb +0 -1
- data/lib/chef/resource/ruby_block.rb +0 -1
- data/lib/chef/resource/scm/_scm.rb +0 -2
- data/lib/chef/resource/scm/git.rb +0 -2
- data/lib/chef/resource/scm/subversion.rb +0 -2
- data/lib/chef/resource/script.rb +0 -1
- data/lib/chef/resource/selinux/common_helpers.rb +47 -0
- data/lib/chef/resource/selinux/selinux_debian.erb +18 -0
- data/lib/chef/resource/selinux/selinux_default.erb +15 -0
- data/lib/chef/resource/selinux_boolean.rb +101 -0
- data/lib/chef/resource/selinux_fcontext.rb +160 -0
- data/lib/chef/resource/selinux_install.rb +107 -0
- data/lib/chef/resource/selinux_login.rb +129 -0
- data/lib/chef/resource/selinux_module.rb +143 -0
- data/lib/chef/resource/selinux_permissive.rb +64 -0
- data/lib/chef/resource/selinux_port.rb +118 -0
- data/lib/chef/resource/selinux_state.rb +166 -0
- data/lib/chef/resource/selinux_user.rb +137 -0
- data/lib/chef/resource/service.rb +4 -2
- data/lib/chef/resource/smartos_package.rb +2 -1
- data/lib/chef/resource/snap_package.rb +25 -1
- data/lib/chef/resource/solaris_package.rb +2 -1
- data/lib/chef/resource/ssh_known_hosts_entry.rb +0 -1
- data/lib/chef/resource/sudo.rb +37 -3
- data/lib/chef/resource/support/client.erb +2 -2
- data/lib/chef/resource/support/ulimit.erb +40 -0
- data/lib/chef/resource/swap_file.rb +0 -1
- data/lib/chef/resource/sysctl.rb +2 -2
- data/lib/chef/resource/systemd_unit.rb +0 -1
- data/lib/chef/resource/template.rb +0 -1
- data/lib/chef/resource/timezone.rb +0 -1
- data/lib/chef/resource/user/aix_user.rb +0 -1
- data/lib/chef/resource/user/linux_user.rb +0 -1
- data/lib/chef/resource/user/mac_user.rb +0 -1
- data/lib/chef/resource/user/pw_user.rb +0 -1
- data/lib/chef/resource/user/solaris_user.rb +0 -1
- data/lib/chef/resource/user/windows_user.rb +0 -1
- data/lib/chef/resource/user.rb +10 -1
- data/lib/chef/resource/user_ulimit.rb +38 -1
- data/lib/chef/resource/whyrun_safe_ruby_block.rb +0 -1
- data/lib/chef/resource/windows_ad_join.rb +0 -2
- data/lib/chef/resource/windows_audit_policy.rb +0 -2
- data/lib/chef/resource/windows_auto_run.rb +0 -1
- data/lib/chef/resource/windows_certificate.rb +1 -1
- data/lib/chef/resource/windows_defender.rb +0 -1
- data/lib/chef/resource/windows_defender_exclusion.rb +0 -1
- data/lib/chef/resource/windows_dfs_folder.rb +0 -1
- data/lib/chef/resource/windows_dfs_namespace.rb +0 -1
- data/lib/chef/resource/windows_dfs_server.rb +0 -1
- data/lib/chef/resource/windows_dns_record.rb +0 -1
- data/lib/chef/resource/windows_dns_zone.rb +0 -1
- data/lib/chef/resource/windows_env.rb +0 -1
- data/lib/chef/resource/windows_feature.rb +0 -1
- data/lib/chef/resource/windows_feature_dism.rb +0 -1
- data/lib/chef/resource/windows_feature_powershell.rb +0 -1
- data/lib/chef/resource/windows_firewall_profile.rb +0 -2
- data/lib/chef/resource/windows_firewall_rule.rb +0 -1
- data/lib/chef/resource/windows_font.rb +2 -3
- data/lib/chef/resource/windows_package.rb +3 -4
- data/lib/chef/resource/windows_pagefile.rb +0 -2
- data/lib/chef/resource/windows_path.rb +0 -1
- data/lib/chef/resource/windows_printer.rb +0 -1
- data/lib/chef/resource/windows_printer_port.rb +0 -1
- data/lib/chef/resource/windows_script.rb +0 -2
- data/lib/chef/resource/windows_security_policy.rb +2 -3
- data/lib/chef/resource/windows_service.rb +0 -1
- data/lib/chef/resource/windows_share.rb +0 -1
- data/lib/chef/resource/windows_shortcut.rb +1 -2
- data/lib/chef/resource/windows_task.rb +0 -1
- data/lib/chef/resource/windows_uac.rb +0 -1
- data/lib/chef/resource/windows_update_settings.rb +0 -1
- data/lib/chef/resource/windows_user_privilege.rb +14 -11
- data/lib/chef/resource/windows_workgroup.rb +0 -1
- data/lib/chef/resource/yum_package.rb +2 -1
- data/lib/chef/resource/yum_repository.rb +4 -1
- data/lib/chef/resource/zypper_package.rb +2 -1
- data/lib/chef/resource/zypper_repository.rb +0 -1
- data/lib/chef/resource.rb +23 -5
- data/lib/chef/resource_inspector.rb +25 -7
- data/lib/chef/resource_reporter.rb +4 -0
- data/lib/chef/resources.rb +11 -0
- data/lib/chef/run_context.rb +3 -3
- data/lib/chef/secret_fetcher/azure_key_vault.rb +1 -1
- data/lib/chef/util/powershell/ps_credential.rb +10 -0
- data/lib/chef/version.rb +1 -1
- data/lib/chef/win32/handle.rb +6 -7
- data/lib/chef/win32/registry.rb +12 -4
- data/lib/chef/win32/security.rb +16 -1
- data/spec/data/rubygems.org/sexp_processor-info +2 -1
- data/spec/data/trusted_certs/intermediate.pem +38 -27
- data/spec/functional/resource/cookbook_file_spec.rb +1 -1
- data/spec/functional/resource/dsc_script_spec.rb +1 -1
- data/spec/functional/resource/execute_spec.rb +1 -1
- data/spec/functional/resource/group_spec.rb +26 -42
- data/spec/functional/resource/link_spec.rb +8 -8
- data/spec/functional/resource/plist_spec.rb +25 -0
- data/spec/functional/resource/registry_spec.rb +233 -609
- data/spec/functional/resource/remote_file_spec.rb +1 -1
- data/spec/functional/resource/user/linux_user_spec.rb +127 -0
- data/spec/functional/resource/windows_certificate_spec.rb +1 -1
- data/spec/functional/resource/windows_font_spec.rb +12 -9
- data/spec/functional/resource/yum_package_spec.rb +1 -1
- data/spec/functional/resource/zypper_package_spec.rb +12 -0
- data/spec/functional/shell_spec.rb +1 -2
- data/spec/functional/version_spec.rb +1 -1
- data/spec/functional/win32/registry_spec.rb +0 -3
- data/spec/integration/client/client_spec.rb +88 -3
- data/spec/integration/client/exit_code_spec.rb +1 -1
- data/spec/integration/client/fips_spec.rb +5 -5
- data/spec/integration/client/ipv6_spec.rb +1 -1
- data/spec/integration/client/open_ssl_spec.rb +3 -3
- data/spec/integration/compliance/compliance_spec.rb +1 -1
- data/spec/integration/recipes/accumulator_spec.rb +1 -1
- data/spec/integration/recipes/lwrp_inline_resources_spec.rb +1 -1
- data/spec/integration/recipes/lwrp_spec.rb +1 -1
- data/spec/integration/recipes/notifies_spec.rb +1 -1
- data/spec/integration/recipes/notifying_block_spec.rb +1 -1
- data/spec/integration/recipes/remote_directory.rb +1 -1
- data/spec/integration/recipes/unified_mode_spec.rb +1 -1
- data/spec/integration/recipes/use_partial_spec.rb +2 -1
- data/spec/integration/solo/solo_spec.rb +2 -2
- data/spec/spec_helper.rb +7 -4
- data/spec/support/chef_helpers.rb +2 -2
- data/spec/support/platform_helpers.rb +28 -7
- data/spec/support/ruby_installer.rb +1 -1
- data/spec/support/shared/functional/file_resource.rb +3 -3
- data/spec/support/shared/functional/windows_script.rb +2 -2
- data/spec/tiny_server.rb +5 -2
- data/spec/unit/application/client_spec.rb +0 -10
- data/spec/unit/chef_fs/file_system_spec.rb +2 -0
- data/spec/unit/client_spec.rb +80 -4
- data/spec/unit/compliance/runner_spec.rb +8 -0
- data/spec/unit/cookbook/syntax_check_spec.rb +3 -0
- data/spec/unit/data_collector_spec.rb +106 -2
- data/spec/unit/delayed_evaluator_spec.rb +35 -0
- data/spec/unit/file_cache_spec.rb +64 -0
- data/spec/unit/http/authenticator_spec.rb +121 -0
- data/spec/unit/mixin/homebrew_spec.rb +118 -0
- data/spec/unit/mixin/openssl_helper_spec.rb +5 -0
- data/spec/unit/mixin/powershell_exec_spec.rb +5 -5
- data/spec/unit/node/vivid_mash_spec.rb +42 -0
- data/spec/unit/node_spec.rb +6 -0
- data/spec/unit/platform/query_helpers_spec.rb +2 -17
- data/spec/unit/property/validation_spec.rb +30 -0
- data/spec/unit/provider/apt_repository_spec.rb +48 -12
- data/spec/unit/provider/cron_spec.rb +2 -0
- data/spec/unit/provider/http_request_spec.rb +60 -72
- data/spec/unit/provider/launchd_spec.rb +2 -2
- data/spec/unit/provider/mount/aix_spec.rb +2 -2
- data/spec/unit/provider/mount/linux_spec.rb +15 -4
- data/spec/unit/provider/mount/mount_spec.rb +8 -8
- data/spec/unit/provider/package/apt_spec.rb +18 -13
- data/spec/unit/provider/package/chocolatey_spec.rb +41 -9
- data/spec/unit/provider/package/homebrew_spec.rb +4 -1
- data/spec/unit/provider/package/rpm_spec.rb +2 -2
- data/spec/unit/provider/package/rubygems_spec.rb +1 -1
- data/spec/unit/provider/package/windows_spec.rb +5 -5
- data/spec/unit/provider/package/zypper_spec.rb +32 -0
- data/spec/unit/provider/powershell_script_spec.rb +100 -4
- data/spec/unit/provider/registry_key_spec.rb +17 -17
- data/spec/unit/provider/remote_file/http_spec.rb +4 -4
- data/spec/unit/provider/service/systemd_service_spec.rb +1 -0
- data/spec/unit/provider/user/linux_spec.rb +51 -1
- data/spec/unit/provider/user/windows_spec.rb +1 -0
- data/spec/unit/provider/user_spec.rb +24 -6
- data/spec/unit/resource/apt_repository_spec.rb +5 -0
- data/spec/unit/resource/archive_file_spec.rb +1 -1
- data/spec/unit/resource/chef_client_cron_spec.rb +5 -0
- data/spec/unit/resource/chef_client_launchd_spec.rb +5 -0
- data/spec/unit/resource/chef_client_scheduled_task_spec.rb +5 -0
- data/spec/unit/resource/chef_client_systemd_timer_spec.rb +1 -1
- data/spec/unit/resource/chocolatey_installer_spec.rb +151 -0
- data/spec/unit/resource/cron_d_spec.rb +37 -1
- data/spec/unit/resource/macos_pkg_spec.rb +38 -0
- data/spec/unit/resource/powershell_script_spec.rb +2 -2
- data/spec/unit/resource/rest_resource_spec.rb +381 -0
- data/spec/unit/resource/selinux_boolean_spec.rb +92 -0
- data/spec/unit/resource/selinux_fcontext_spec.rb +65 -0
- data/spec/unit/resource/selinux_install_spec.rb +60 -0
- data/spec/unit/resource/selinux_login_spec.rb +73 -0
- data/spec/unit/resource/selinux_module_spec.rb +55 -0
- data/spec/unit/resource/selinux_permissive_spec.rb +39 -0
- data/spec/unit/resource/selinux_port_spec.rb +42 -0
- data/spec/unit/resource/selinux_state_spec.rb +46 -0
- data/spec/unit/resource/selinux_user_spec.rb +92 -0
- data/spec/unit/resource/sysctl_spec.rb +2 -2
- data/spec/unit/resource/user/linux_user_spec.rb +42 -0
- data/spec/unit/resource/yum_repository_spec.rb +4 -0
- data/spec/unit/resource_inspector_spec.rb +36 -0
- data/spec/unit/resource_reporter_spec.rb +57 -3
- data/spec/unit/resource_spec.rb +94 -2
- data/spec/unit/util/dsc/local_configuration_manager_spec.rb +1 -1
- data/spec/unit/util/powershell/ps_credential_spec.rb +6 -0
- data/tasks/rspec.rb +1 -1
- metadata +126 -44
- data/lib/chef/powershell.rb +0 -81
- data/spec/unit/mixin/homebrew_user_spec.rb +0 -119
- /data/spec/functional/assets/yumrepo/repodata/{01a3b-filelists.sqlite.bz2 → 4632d67cb92636e7575d911c24f0e04d3505a944e97c483abe0c3e73a7c62d33-filelists.sqlite.bz2} +0 -0
- /data/spec/functional/assets/yumrepo/repodata/{6bf96-other.xml.gz → 74599b793e54d877323837d2d81a1c3c594c44e4335f9528234bb490f7b9b439-other.xml.gz} +0 -0
- /data/spec/functional/assets/yumrepo/repodata/{5dc1e-primary.sqlite.bz2 → a845d418f919d2115ab95a56b2c76f6825ad0d0bede49181a55c04f58995d057-primary.sqlite.bz2} +0 -0
- /data/spec/functional/assets/yumrepo/repodata/{7c365-other.sqlite.bz2 → af9b7cf9ef23bd7b43068d74a460f3b5d06753d638e58e4a0c9edc35bfb9cdc4-other.sqlite.bz2} +0 -0
- /data/spec/functional/assets/yumrepo/repodata/{401dc-filelists.xml.gz → bdb4f5f1492a3b9532f22c43110a81500dd744f23da0aec5c33b2a41317c737d-filelists.xml.gz} +0 -0
- /data/spec/functional/assets/yumrepo/repodata/{dabe2-primary.xml.gz → c10d1d34ce99e02f12ec96ef68360543ab1bb7c3cb81a4a2bf78df7d8597e9df-primary.xml.gz} +0 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
#
|
|
6
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
#
|
|
8
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
# See the License for the specific language governing permissions and
|
|
12
|
+
# limitations under the License.
|
|
13
|
+
#
|
|
14
|
+
|
|
15
|
+
require_relative "../resource"
|
|
16
|
+
require_relative "selinux/common_helpers"
|
|
17
|
+
|
|
18
|
+
class Chef
|
|
19
|
+
class Resource
|
|
20
|
+
class SelinuxFcontext < Chef::Resource
|
|
21
|
+
unified_mode true
|
|
22
|
+
|
|
23
|
+
provides :selinux_fcontext
|
|
24
|
+
|
|
25
|
+
description "Use the **selinux_fcontext** resource to set the SELinux context of files using the `semanage fcontext` command."
|
|
26
|
+
introduced "18.0"
|
|
27
|
+
examples <<~DOC
|
|
28
|
+
**Allow http servers (e.g. nginx/apache) to modify moodle files**:
|
|
29
|
+
|
|
30
|
+
```ruby
|
|
31
|
+
selinux_fcontext '/var/www/moodle(/.*)?' do
|
|
32
|
+
secontext 'httpd_sys_rw_content_t'
|
|
33
|
+
end
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
**Adapt a symbolic link**:
|
|
37
|
+
|
|
38
|
+
```ruby
|
|
39
|
+
selinux_fcontext '/var/www/symlink_to_webroot' do
|
|
40
|
+
secontext 'httpd_sys_rw_content_t'
|
|
41
|
+
file_type 'l'
|
|
42
|
+
end
|
|
43
|
+
```
|
|
44
|
+
DOC
|
|
45
|
+
|
|
46
|
+
property :file_spec, String,
|
|
47
|
+
name_property: true,
|
|
48
|
+
description: "Path to or regex matching the files or directories to label."
|
|
49
|
+
|
|
50
|
+
property :secontext, String,
|
|
51
|
+
required: %i{add modify manage},
|
|
52
|
+
description: "SELinux context to assign."
|
|
53
|
+
|
|
54
|
+
property :file_type, String,
|
|
55
|
+
default: "a",
|
|
56
|
+
equal_to: %w{a f d c b s l p},
|
|
57
|
+
description: "The type of the file being labeled."
|
|
58
|
+
|
|
59
|
+
action_class do
|
|
60
|
+
include Chef::SELinux::CommonHelpers
|
|
61
|
+
def current_file_context
|
|
62
|
+
file_hash = {
|
|
63
|
+
"a" => "all files",
|
|
64
|
+
"f" => "regular file",
|
|
65
|
+
"d" => "directory",
|
|
66
|
+
"c" => "character device",
|
|
67
|
+
"b" => "block device",
|
|
68
|
+
"s" => "socket",
|
|
69
|
+
"l" => "symbolic link",
|
|
70
|
+
"p" => "named pipe",
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
contexts = shell_out!("semanage fcontext -l").stdout.split("\n")
|
|
74
|
+
# pull out file label from user:role:type:level context string
|
|
75
|
+
contexts.grep(/^#{Regexp.escape(new_resource.file_spec)}\s+#{file_hash[new_resource.file_type]}/) do |c|
|
|
76
|
+
c.match(/.+ (?<user>.+):(?<role>.+):(?<type>.+):(?<level>.+)$/)[:type]
|
|
77
|
+
# match returns ['foo'] or [], shift converts that to 'foo' or nil
|
|
78
|
+
end.shift
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# Run restorecon to fix label
|
|
82
|
+
# https://github.com/sous-chefs/selinux_policy/pull/72#issuecomment-338718721
|
|
83
|
+
def relabel_files
|
|
84
|
+
spec = new_resource.file_spec
|
|
85
|
+
escaped = Regexp.escape spec
|
|
86
|
+
|
|
87
|
+
# find common path between regex and string
|
|
88
|
+
common = if spec == escaped
|
|
89
|
+
spec
|
|
90
|
+
else
|
|
91
|
+
index = spec.size.times { |i| break i if spec[i] != escaped[i] }
|
|
92
|
+
::File.dirname spec[0...index]
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# if path is not absolute, ignore it and search everything
|
|
96
|
+
common = "/" if common[0] != "/"
|
|
97
|
+
|
|
98
|
+
if ::File.exist? common
|
|
99
|
+
shell_out!("find #{common.shellescape} -ignore_readdir_race -regextype posix-egrep -regex #{spec.shellescape} -prune -print0 | xargs -0 restorecon -iRv")
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
action :manage, description: "Assign the file to the right context regardless of previous state." do
|
|
105
|
+
run_action(:add)
|
|
106
|
+
run_action(:modify)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
action :addormodify, description: "Assign the file context if not set. Update the file context if previously set." do
|
|
110
|
+
Chef::Log.warn("The :addormodify action for selinux_fcontext is deprecated and will be removed in a future release. Use the :manage action instead.")
|
|
111
|
+
run_action(:manage)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# Create if doesn't exist, do not touch if fcontext is already registered
|
|
115
|
+
action :add, description: "Assign the file context if not set." do
|
|
116
|
+
if selinux_disabled?
|
|
117
|
+
Chef::Log.warn("Unable to add SELinux fcontext #{new_resource.name} as SELinux is disabled")
|
|
118
|
+
return
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
unless current_file_context
|
|
122
|
+
converge_by "adding label #{new_resource.secontext} to #{new_resource.file_spec}" do
|
|
123
|
+
shell_out!("semanage fcontext -a -f #{new_resource.file_type} -t #{new_resource.secontext} '#{new_resource.file_spec}'")
|
|
124
|
+
relabel_files
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
# Only modify if fcontext exists & doesn't have the correct label already
|
|
130
|
+
action :modify, description: "Update the file context if previously set." do
|
|
131
|
+
if selinux_disabled?
|
|
132
|
+
Chef::Log.warn("Unable to modify SELinux fcontext #{new_resource.name} as SELinux is disabled")
|
|
133
|
+
return
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
if current_file_context && current_file_context != new_resource.secontext
|
|
137
|
+
converge_by "modifying label #{new_resource.secontext} to #{new_resource.file_spec}" do
|
|
138
|
+
shell_out!("semanage fcontext -m -f #{new_resource.file_type} -t #{new_resource.secontext} '#{new_resource.file_spec}'")
|
|
139
|
+
relabel_files
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# Delete if exists
|
|
145
|
+
action :delete, description: "Removes the file context if set. " do
|
|
146
|
+
if selinux_disabled?
|
|
147
|
+
Chef::Log.warn("Unable to delete SELinux fcontext #{new_resource.name} as SELinux is disabled")
|
|
148
|
+
return
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
if current_file_context
|
|
152
|
+
converge_by "deleting label for #{new_resource.file_spec}" do
|
|
153
|
+
shell_out!("semanage fcontext -d -f #{new_resource.file_type} '#{new_resource.file_spec}'")
|
|
154
|
+
relabel_files
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
end
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
#
|
|
6
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
#
|
|
8
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
# See the License for the specific language governing permissions and
|
|
12
|
+
# limitations under the License.
|
|
13
|
+
|
|
14
|
+
require_relative "../resource"
|
|
15
|
+
|
|
16
|
+
class Chef
|
|
17
|
+
class Resource
|
|
18
|
+
class SelinuxInstall < Chef::Resource
|
|
19
|
+
unified_mode true
|
|
20
|
+
|
|
21
|
+
provides :selinux_install
|
|
22
|
+
|
|
23
|
+
description "Use **selinux_install** resource to encapsulates the set of selinux packages to install in order to manage selinux. It also ensures the directory `/etc/selinux` is created."
|
|
24
|
+
introduced "18.0"
|
|
25
|
+
examples <<~DOC
|
|
26
|
+
**Default installation**:
|
|
27
|
+
|
|
28
|
+
```ruby
|
|
29
|
+
selinux_install 'example'
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**Install with custom packages**:
|
|
33
|
+
|
|
34
|
+
```ruby
|
|
35
|
+
selinux_install 'example' do
|
|
36
|
+
packages %w(policycoreutils selinux-policy selinux-policy-targeted)
|
|
37
|
+
end
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
**Uninstall**
|
|
41
|
+
```ruby
|
|
42
|
+
selinux_install 'example' do
|
|
43
|
+
action :remove
|
|
44
|
+
end
|
|
45
|
+
```
|
|
46
|
+
DOC
|
|
47
|
+
|
|
48
|
+
property :packages, [String, Array],
|
|
49
|
+
default: lazy { default_install_packages },
|
|
50
|
+
description: "SELinux packages for system."
|
|
51
|
+
|
|
52
|
+
action_class do
|
|
53
|
+
def do_package_action(action)
|
|
54
|
+
# friendly message for unsupported platforms
|
|
55
|
+
raise "The platform #{node["platform"]} is not currently supported by the `selinux_install` resource. Please file an issue at https://github.com/chef/chef/issues with details on the platform this cookbook is running on." if new_resource.packages.nil?
|
|
56
|
+
|
|
57
|
+
package "selinux" do
|
|
58
|
+
package_name new_resource.packages
|
|
59
|
+
action action
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
action :install, description: "Install required packages." do
|
|
65
|
+
do_package_action(action)
|
|
66
|
+
|
|
67
|
+
directory "/etc/selinux" do
|
|
68
|
+
owner "root"
|
|
69
|
+
group "root"
|
|
70
|
+
mode "0755"
|
|
71
|
+
action :create
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
action :upgrade, description: "Upgrade required packages." do
|
|
76
|
+
do_package_action(a)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
action :remove, description: "Remove any SELinux-related packages." do
|
|
80
|
+
do_package_action(a)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
private
|
|
84
|
+
|
|
85
|
+
#
|
|
86
|
+
# Get an array of packages to be installed based upon node platform_family
|
|
87
|
+
#
|
|
88
|
+
# @return [Array] Array of string of package names
|
|
89
|
+
def default_install_packages
|
|
90
|
+
case node["platform_family"]
|
|
91
|
+
when "rhel", "fedora", "amazon"
|
|
92
|
+
%w{make policycoreutils selinux-policy selinux-policy-targeted selinux-policy-devel libselinux-utils setools-console}
|
|
93
|
+
when "debian"
|
|
94
|
+
if node["platform"] == "ubuntu"
|
|
95
|
+
if node["platform_version"].to_f == 18.04
|
|
96
|
+
%w{make policycoreutils selinux selinux-basics selinux-policy-default selinux-policy-dev auditd setools}
|
|
97
|
+
else
|
|
98
|
+
%w{make policycoreutils selinux-basics selinux-policy-default selinux-policy-dev auditd setools}
|
|
99
|
+
end
|
|
100
|
+
else
|
|
101
|
+
%w{make policycoreutils selinux-basics selinux-policy-default selinux-policy-dev auditd setools}
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
#
|
|
6
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
#
|
|
8
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
# See the License for the specific language governing permissions and
|
|
12
|
+
# limitations under the License.
|
|
13
|
+
|
|
14
|
+
require_relative "../resource"
|
|
15
|
+
require_relative "selinux/common_helpers"
|
|
16
|
+
|
|
17
|
+
class Chef
|
|
18
|
+
class Resource
|
|
19
|
+
class SelinuxLogin < Chef::Resource
|
|
20
|
+
unified_mode true
|
|
21
|
+
|
|
22
|
+
provides :selinux_login
|
|
23
|
+
|
|
24
|
+
description "Use the **selinux_login** resource to add, update, or remove SELinux user to OS login mappings."
|
|
25
|
+
introduced "18.1"
|
|
26
|
+
examples <<~DOC
|
|
27
|
+
**Manage test OS user mapping with a range of s0 and associated SELinux user test_u**:
|
|
28
|
+
|
|
29
|
+
```ruby
|
|
30
|
+
selinux_login 'test' do
|
|
31
|
+
user 'test_u'
|
|
32
|
+
range 's0'
|
|
33
|
+
end
|
|
34
|
+
```
|
|
35
|
+
DOC
|
|
36
|
+
|
|
37
|
+
property :login, String,
|
|
38
|
+
name_property: true,
|
|
39
|
+
description: "An optional property to set the OS user login value if it differs from the resource block's name."
|
|
40
|
+
|
|
41
|
+
property :user, String,
|
|
42
|
+
description: "SELinux user to be mapped."
|
|
43
|
+
|
|
44
|
+
property :range, String,
|
|
45
|
+
description: "MLS/MCS security range for the SELinux user."
|
|
46
|
+
|
|
47
|
+
load_current_value do |new_resource|
|
|
48
|
+
logins = shell_out!("semanage login -l").stdout.split("\n")
|
|
49
|
+
|
|
50
|
+
current_login = logins.grep(/^#{Regexp.escape(new_resource.login)}\s+/) do |l|
|
|
51
|
+
l.match(/^(?<login>[^\s]+)\s+(?<user>[^\s]+)\s+(?<range>[^\s]+)/)
|
|
52
|
+
# match returns [<Match 'data'>] or [], shift converts that to <Match 'data'> or nil
|
|
53
|
+
end.shift
|
|
54
|
+
|
|
55
|
+
current_value_does_not_exist! unless current_login
|
|
56
|
+
|
|
57
|
+
# Existing resources should maintain their current configuration unless otherwise specified
|
|
58
|
+
new_resource.user ||= current_login[:user]
|
|
59
|
+
new_resource.range ||= current_login[:range]
|
|
60
|
+
|
|
61
|
+
user current_login[:user]
|
|
62
|
+
range current_login[:range]
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
action_class do
|
|
66
|
+
include Chef::SELinux::CommonHelpers
|
|
67
|
+
|
|
68
|
+
def semanage_login_args
|
|
69
|
+
# Generate arguments for semanage login -a or -m
|
|
70
|
+
args = ""
|
|
71
|
+
|
|
72
|
+
args += " -s #{new_resource.user}" if new_resource.user
|
|
73
|
+
args += " -r #{new_resource.range}" if new_resource.range
|
|
74
|
+
|
|
75
|
+
args
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
action :manage, description: "Sets the SELinux login mapping to the desired settings regardless of previous state." do
|
|
80
|
+
run_action(:add)
|
|
81
|
+
run_action(:modify)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Create if doesn't exist, do not touch if user already exists
|
|
85
|
+
action :add, description: "Creates the SELinux login mapping if not previously created." do
|
|
86
|
+
raise "The user property must be populated to create a new SELinux login" if new_resource.user.to_s.empty?
|
|
87
|
+
|
|
88
|
+
if selinux_disabled?
|
|
89
|
+
Chef::Log.warn("Unable to add SELinux login #{new_resource.login} as SELinux is disabled")
|
|
90
|
+
return
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
unless current_resource
|
|
94
|
+
converge_if_changed do
|
|
95
|
+
shell_out!("semanage login -a#{semanage_login_args} #{new_resource.login}")
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# Only modify port if it exists & doesn't have the correct context already
|
|
101
|
+
action :modify, description: "Updates the SELinux login mapping if previously created." do
|
|
102
|
+
if selinux_disabled?
|
|
103
|
+
Chef::Log.warn("Unable to modify SELinux login #{new_resource.login} as SELinux is disabled")
|
|
104
|
+
return
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
if current_resource
|
|
108
|
+
converge_if_changed do
|
|
109
|
+
shell_out!("semanage login -m#{semanage_login_args} #{new_resource.login}")
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# Delete if exists
|
|
115
|
+
action :delete, description: "Removes the SELinux login mapping if previously created." do
|
|
116
|
+
if selinux_disabled?
|
|
117
|
+
Chef::Log.warn("Unable to delete SELinux login #{new_resource.login} as SELinux is disabled")
|
|
118
|
+
return
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
if current_resource
|
|
122
|
+
converge_by "deleting SELinux login #{new_resource.login}" do
|
|
123
|
+
shell_out!("semanage login -d #{new_resource.login}")
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
#
|
|
6
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
#
|
|
8
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
# See the License for the specific language governing permissions and
|
|
12
|
+
# limitations under the License.
|
|
13
|
+
|
|
14
|
+
require_relative "../resource"
|
|
15
|
+
|
|
16
|
+
class Chef
|
|
17
|
+
class Resource
|
|
18
|
+
class SelinuxModule < Chef::Resource
|
|
19
|
+
unified_mode true
|
|
20
|
+
|
|
21
|
+
provides :selinux_module
|
|
22
|
+
|
|
23
|
+
description "Use **selinux_module** module resource to create an SELinux policy module from a cookbook file or content provided as a string."
|
|
24
|
+
introduced "18.0"
|
|
25
|
+
examples <<~DOC
|
|
26
|
+
**Creating SElinux module from .te file located at `files` directory of your cookbook.**:
|
|
27
|
+
|
|
28
|
+
```ruby
|
|
29
|
+
selinux_module 'my_policy_module' do
|
|
30
|
+
source 'my_policy_module.te'
|
|
31
|
+
action :create
|
|
32
|
+
end
|
|
33
|
+
```
|
|
34
|
+
DOC
|
|
35
|
+
|
|
36
|
+
property :module_name, String,
|
|
37
|
+
name_property: true,
|
|
38
|
+
description: "Override the module name."
|
|
39
|
+
|
|
40
|
+
property :source, String,
|
|
41
|
+
description: "Module source file name."
|
|
42
|
+
|
|
43
|
+
property :content, String,
|
|
44
|
+
description: "Module source as String."
|
|
45
|
+
|
|
46
|
+
property :cookbook, String,
|
|
47
|
+
description: "Cookbook to source from module source file from(if it is not located in the current cookbook). The default value is the current cookbook.",
|
|
48
|
+
desired_state: false
|
|
49
|
+
|
|
50
|
+
property :base_dir, String,
|
|
51
|
+
default: "/etc/selinux/local",
|
|
52
|
+
description: "Directory to create module source file in."
|
|
53
|
+
|
|
54
|
+
action_class do
|
|
55
|
+
def selinux_module_filepath(type)
|
|
56
|
+
path = ::File.join(new_resource.base_dir, "#{new_resource.module_name}")
|
|
57
|
+
path.concat(".#{type}") if type
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def list_installed_modules
|
|
61
|
+
shell_out!("semodule --list-modules").stdout.split("\n").map { |x| x.split(/\s/).first }
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
action :create, description: "Compile a module and install it." do
|
|
66
|
+
directory new_resource.base_dir
|
|
67
|
+
|
|
68
|
+
if property_is_set?(:content)
|
|
69
|
+
file selinux_module_filepath("te") do
|
|
70
|
+
content new_resource.content
|
|
71
|
+
|
|
72
|
+
mode "0600"
|
|
73
|
+
owner "root"
|
|
74
|
+
group "root"
|
|
75
|
+
|
|
76
|
+
action :create
|
|
77
|
+
|
|
78
|
+
notifies :run, "execute[Compiling SELinux modules at '#{new_resource.base_dir}']", :immediately
|
|
79
|
+
end
|
|
80
|
+
else
|
|
81
|
+
cookbook_file selinux_module_filepath("te") do
|
|
82
|
+
cookbook new_resource.cookbook
|
|
83
|
+
source new_resource.source
|
|
84
|
+
|
|
85
|
+
mode "0600"
|
|
86
|
+
owner "root"
|
|
87
|
+
group "root"
|
|
88
|
+
|
|
89
|
+
action :create
|
|
90
|
+
|
|
91
|
+
notifies :run, "execute[Compiling SELinux modules at '#{new_resource.base_dir}']", :immediately
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
execute "Compiling SELinux modules at '#{new_resource.base_dir}'" do
|
|
96
|
+
cwd new_resource.base_dir
|
|
97
|
+
command "make -C #{new_resource.base_dir} -f /usr/share/selinux/devel/Makefile"
|
|
98
|
+
timeout 120
|
|
99
|
+
user "root"
|
|
100
|
+
|
|
101
|
+
action :nothing
|
|
102
|
+
|
|
103
|
+
notifies :run, "execute[Install SELinux module '#{selinux_module_filepath("pp")}']", :immediately
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
raise "Compilation must have failed, no 'pp' file found at: '#{selinux_module_filepath("pp")}'" unless ::File.exist?(selinux_module_filepath("pp"))
|
|
107
|
+
|
|
108
|
+
execute "Install SELinux module '#{selinux_module_filepath("pp")}'" do
|
|
109
|
+
command "semodule --install '#{selinux_module_filepath("pp")}'"
|
|
110
|
+
action :nothing
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
action :delete, description: "Remove module source files from `/etc/selinux/local`." do
|
|
115
|
+
%w{fc if pp te}.each do |type|
|
|
116
|
+
next unless ::File.exist?(selinux_module_filepath(type))
|
|
117
|
+
|
|
118
|
+
file selinux_module_filepath(type) do
|
|
119
|
+
action :delete
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
action :install, description: "Install a compiled module into the system." do
|
|
125
|
+
raise "Module must be compiled before it can be installed, no 'pp' file found at: '#{selinux_module_filepath("pp")}'" unless ::File.exist?(selinux_module_filepath("pp"))
|
|
126
|
+
|
|
127
|
+
unless list_installed_modules.include? new_resource.module_name
|
|
128
|
+
converge_by "Install SELinux module #{selinux_module_filepath("pp")}" do
|
|
129
|
+
shell_out!("semodule", "--install", selinux_module_filepath("pp"))
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
action :remove, description: "Remove a module from the system." do
|
|
135
|
+
if list_installed_modules.include? new_resource.module_name
|
|
136
|
+
converge_by "Remove SELinux module #{new_resource.module_name}" do
|
|
137
|
+
shell_out!("semodule", "--remove", new_resource.module_name)
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
#
|
|
6
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
#
|
|
8
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
# See the License for the specific language governing permissions and
|
|
12
|
+
# limitations under the License.
|
|
13
|
+
|
|
14
|
+
require_relative "../resource"
|
|
15
|
+
|
|
16
|
+
class Chef
|
|
17
|
+
class Resource
|
|
18
|
+
class SelinuxPermissive < Chef::Resource
|
|
19
|
+
unified_mode true
|
|
20
|
+
|
|
21
|
+
provides :selinux_permissive
|
|
22
|
+
|
|
23
|
+
description "Use the **selinux_permissive** resource to allow some domains to misbehave without stopping them. This is not as good as setting specific policies, but better than disabling SELinux entirely."
|
|
24
|
+
introduced "18.0"
|
|
25
|
+
examples <<~DOC
|
|
26
|
+
**Disable enforcement on Apache**:
|
|
27
|
+
|
|
28
|
+
```ruby
|
|
29
|
+
selinux_permissive 'httpd_t' do
|
|
30
|
+
notifies :restart, 'service[httpd]'
|
|
31
|
+
end
|
|
32
|
+
```
|
|
33
|
+
DOC
|
|
34
|
+
|
|
35
|
+
property :context, String,
|
|
36
|
+
name_property: true,
|
|
37
|
+
description: "The SELinux context to permit."
|
|
38
|
+
|
|
39
|
+
action_class do
|
|
40
|
+
def current_permissives
|
|
41
|
+
shell_out!("semanage permissive -ln").stdout.split("\n")
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Create if doesn't exist, do not touch if permissive is already registered (even under different type)
|
|
46
|
+
action :add, description: "Add a permissive, unless already set." do
|
|
47
|
+
unless current_permissives.include? new_resource.context
|
|
48
|
+
converge_by "adding permissive context #{new_resource.context}" do
|
|
49
|
+
shell_out!("semanage permissive -a '#{new_resource.context}'")
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Delete if exists
|
|
55
|
+
action :delete, description: "Remove a permissive, if set." do
|
|
56
|
+
if current_permissives.include? new_resource.context
|
|
57
|
+
converge_by "deleting permissive context #{new_resource.context}" do
|
|
58
|
+
shell_out!("semanage permissive -d '#{new_resource.context}'")
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|